From 93988d262e0db3fb297ecc8f65e91f1a3c38dc5b Mon Sep 17 00:00:00 2001 From: MattFalahe <47831385+MattFalahe@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:18:31 +0100 Subject: [PATCH] Added missing Structure name. (#106) * CorpAppNewMsg.php * Update StructureWentLowPower.php Added information with structure name Update StructureWentLowPower.php StructureWentLowPower.php Update StructureWentLowPower.php StructureWentLowPower.php StructureWentLowPower.php StructureWentLowPower.php * StructureLostShields.php Added message with structure name Update StructureLostShields.php StructureLostShields.php StructureLostShields.php StructureLostShields.php StructureLostShields.php * StructureLostArmor.php Added information with structure name Update StructureLostArmor.php StructureLostArmor.php StructureLostArmor.php StructureLostArmor.php StructureLostArmor.php * StructureFuelAlert.php squash StructureFuelAlert.php squash StyleCI StructureFuelAlert.php StructureFuelAlert.php null added StructureFuelAlert.php StructureFuelAlert.php Update StructureFuelAlert.php Added information name of the structure that is running low on fuel. * StructureWentHighPower.php squash StructureWentHighPower.php squash StyleCI StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php StructureWentHighPower.php Added information with structure name --- .../Corporations/Discord/CorpAppNewMsg.php | 2 +- .../Structures/Discord/StructureFuelAlert.php | 21 ++++++++++++++-- .../Discord/StructureWentHighPower.php | 24 +++++++++++++++---- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/Notifications/Corporations/Discord/CorpAppNewMsg.php b/src/Notifications/Corporations/Discord/CorpAppNewMsg.php index 4da39d4..539c7a4 100644 --- a/src/Notifications/Corporations/Discord/CorpAppNewMsg.php +++ b/src/Notifications/Corporations/Discord/CorpAppNewMsg.php @@ -73,7 +73,7 @@ public function populateMessage(DiscordMessage $message, $notifiable) $embed->field(function (DiscordEmbedField $field) { $field - ->name('Character Name') + ->name('Corporation Name') ->long(); $entity = UniverseName::find($this->notification->text['corpID']); diff --git a/src/Notifications/Structures/Discord/StructureFuelAlert.php b/src/Notifications/Structures/Discord/StructureFuelAlert.php index cfdf2d6..5a2c0f0 100644 --- a/src/Notifications/Structures/Discord/StructureFuelAlert.php +++ b/src/Notifications/Structures/Discord/StructureFuelAlert.php @@ -25,6 +25,7 @@ use Seat\Eveapi\Models\Character\CharacterNotification; use Seat\Eveapi\Models\Sde\InvType; use Seat\Eveapi\Models\Sde\MapDenormalize; +use Seat\Eveapi\Models\Universe\UniverseStructure; use Seat\Notifications\Notifications\AbstractDiscordNotification; use Seat\Notifications\Services\Discord\Messages\DiscordEmbed; use Seat\Notifications\Services\Discord\Messages\DiscordEmbedField; @@ -70,10 +71,26 @@ public function populateMessage(DiscordMessage $message, $notifiable): void }); $embed->field(function (DiscordEmbedField $field) { + // Find the structure by its ID from the notification data. + // If the structure ID exists in the notification, retrieve it from the UniverseStructure model. + $structure = UniverseStructure::find($this->notification->text['structureID']); + + // Retrieve the structure's type information using the structureShowInfoData from the notification. + // The second index ([1]) contains the type ID which is used to look up the structure type from the InvType model. $type = InvType::find($this->notification->text['structureShowInfoData'][1]); - $field->name('Structure') - ->value($type->typeName); + // Initialize a default title for the structure field as 'Structure'. + $title = 'Structure'; + + // If a structure is found (i.e., it's not null), set the title to the name of the structure. + if (! is_null($structure)) { + $title = $structure->name; + } + + // Set the field's name to the title (either 'Structure' or the structure's actual name). + // Set the field's value to a zKillboard link, formatted for Discord. This uses the structure's type ID and name. + $field->name($title) + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); }); }) ->embed(function (DiscordEmbed $embed) { diff --git a/src/Notifications/Structures/Discord/StructureWentHighPower.php b/src/Notifications/Structures/Discord/StructureWentHighPower.php index 1777366..8a59472 100644 --- a/src/Notifications/Structures/Discord/StructureWentHighPower.php +++ b/src/Notifications/Structures/Discord/StructureWentHighPower.php @@ -25,6 +25,7 @@ use Seat\Eveapi\Models\Character\CharacterNotification; use Seat\Eveapi\Models\Sde\InvType; use Seat\Eveapi\Models\Sde\MapDenormalize; +use Seat\Eveapi\Models\Universe\UniverseStructure; use Seat\Notifications\Notifications\AbstractDiscordNotification; use Seat\Notifications\Services\Discord\Messages\DiscordEmbed; use Seat\Notifications\Services\Discord\Messages\DiscordEmbedField; @@ -74,12 +75,25 @@ public function populateMessage(DiscordMessage $message, $notifiable): void }); $embed->field(function (DiscordEmbedField $field) { - $type = InvType::firstOrNew( - ['typeID' => $this->notification->text['structureTypeID']], - ['typeName' => trans('web::seat.unknown')] - ); + // Find the structure by its ID from the notification data. + // If the structure ID exists in the notification, retrieve it from the UniverseStructure model. + $structure = UniverseStructure::find($this->notification->text['structureID']); + + // Retrieve the structure's type information using the structureShowInfoData from the notification. + // The second index ([1]) contains the type ID which is used to look up the structure type from the InvType model. + $type = InvType::find($this->notification->text['structureShowInfoData'][1]); + + // Initialize a default title for the structure field as 'Structure'. + $title = 'Structure'; + + // If a structure is found (i.e., it's not null), set the title to the name of the structure. + if (! is_null($structure)) { + $title = $structure->name; + } - $field->name('Structure') + // Set the field's name to the title (either 'Structure' or the structure's actual name). + // Set the field's value to a zKillboard link, formatted for Discord. This uses the structure's type ID and name. + $field->name($title) ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); }); });