From 455901a79e3c63cf6696adb0c132447da9b0fc09 Mon Sep 17 00:00:00 2001 From: Christian Hellmund Date: Sun, 24 Dec 2023 01:58:17 +0100 Subject: [PATCH] Add missing discord notifications (#89) * Add missing discord notifications. * Reformat code style * Fix style check issues. * Fix missing array key by setting colors as defaults. * Set required php to 8.2 or above and add trait for duplicate constants and functions. * Fix colors StyleCI to be corrected in future commit. --- composer.json | 2 +- src/Config/notifications.alerts.php | 24 +++ .../Characters/Discord/RaffleCreated.php | 96 +++++++++++ .../Characters/Discord/RaffleExpired.php | 96 +++++++++++ .../Characters/Discord/RaffleFinished.php | 96 +++++++++++ .../Discord/ResearchMissionAvailableMsg.php | 52 ++++++ .../Discord/StoryLineMissionAvailableMsg.php | 52 ++++++ .../Discord/ContractNotification.php | 75 +++++++++ .../Discord/SquadApplicationNotification.php | 60 +++++++ .../Seat/Discord/SquadMemberNotification.php | 67 ++++++++ .../SquadMemberRemovedNotification.php | 73 ++++++++ .../AbstractDiscordMoonMiningExtraction.php | 67 ++++++++ .../Structures/Discord/AllAnchoringMsg.php | 106 ++++++++++++ .../Discord/MoonMiningExtractionFinished.php | 93 +++++++++++ .../Discord/MoonMiningExtractionStarted.php | 93 +++++++++++ .../Structures/Discord/OrbitalAttacked.php | 135 +++++++++++++++ .../Discord/OwnershipTransferred.php | 102 ++++++++++++ .../Structures/Discord/StructureAnchoring.php | 110 ++++++++++++ .../Structures/Discord/StructureDestroyed.php | 95 +++++++++++ .../Structures/Discord/StructureFuelAlert.php | 93 +++++++++++ .../Structures/Discord/StructureLostArmor.php | 87 ++++++++++ .../Discord/StructureLostShields.php | 87 ++++++++++ .../Discord/StructureServicesOffline.php | 88 ++++++++++ .../Discord/StructureUnanchoring.php | 105 ++++++++++++ .../Discord/StructureUnderAttack.php | 156 ++++++++++++++++++ .../Discord/StructureWentHighPower.php | 87 ++++++++++ .../Discord/StructureWentLowPower.php | 86 ++++++++++ .../AbstractSlackMoonMiningExtraction.php | 59 +------ .../Traits/MoonMiningNotificationTrait.php | 64 +++++++ 29 files changed, 2348 insertions(+), 58 deletions(-) create mode 100644 src/Notifications/Characters/Discord/RaffleCreated.php create mode 100644 src/Notifications/Characters/Discord/RaffleExpired.php create mode 100644 src/Notifications/Characters/Discord/RaffleFinished.php create mode 100644 src/Notifications/Characters/Discord/ResearchMissionAvailableMsg.php create mode 100644 src/Notifications/Characters/Discord/StoryLineMissionAvailableMsg.php create mode 100644 src/Notifications/Contracts/Discord/ContractNotification.php create mode 100644 src/Notifications/Seat/Discord/SquadApplicationNotification.php create mode 100644 src/Notifications/Seat/Discord/SquadMemberNotification.php create mode 100644 src/Notifications/Seat/Discord/SquadMemberRemovedNotification.php create mode 100644 src/Notifications/Structures/Discord/AbstractDiscordMoonMiningExtraction.php create mode 100644 src/Notifications/Structures/Discord/AllAnchoringMsg.php create mode 100644 src/Notifications/Structures/Discord/MoonMiningExtractionFinished.php create mode 100644 src/Notifications/Structures/Discord/MoonMiningExtractionStarted.php create mode 100644 src/Notifications/Structures/Discord/OrbitalAttacked.php create mode 100644 src/Notifications/Structures/Discord/OwnershipTransferred.php create mode 100644 src/Notifications/Structures/Discord/StructureAnchoring.php create mode 100644 src/Notifications/Structures/Discord/StructureDestroyed.php create mode 100644 src/Notifications/Structures/Discord/StructureFuelAlert.php create mode 100644 src/Notifications/Structures/Discord/StructureLostArmor.php create mode 100644 src/Notifications/Structures/Discord/StructureLostShields.php create mode 100644 src/Notifications/Structures/Discord/StructureServicesOffline.php create mode 100644 src/Notifications/Structures/Discord/StructureUnanchoring.php create mode 100644 src/Notifications/Structures/Discord/StructureUnderAttack.php create mode 100644 src/Notifications/Structures/Discord/StructureWentHighPower.php create mode 100644 src/Notifications/Structures/Discord/StructureWentLowPower.php create mode 100644 src/Notifications/Structures/Traits/MoonMiningNotificationTrait.php diff --git a/composer.json b/composer.json index ff570c0..96d4bd1 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^8.1", + "php": "^8.2", "laravel/framework": "^10.0", "laravel/slack-notification-channel": "^2.0", "eveseat/eveapi": "^5.0", diff --git a/src/Config/notifications.alerts.php b/src/Config/notifications.alerts.php index 26d049c..7969b72 100644 --- a/src/Config/notifications.alerts.php +++ b/src/Config/notifications.alerts.php @@ -52,6 +52,7 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Seat\Mail\SquadApplicationNotification::class, 'slack' => \Seat\Notifications\Notifications\Seat\Slack\SquadApplicationNotification::class, + 'discord' => \Seat\Notifications\Notifications\Seat\Discord\SquadApplicationNotification::class, ], ], 'squad_member' => [ @@ -59,6 +60,7 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Seat\Mail\SquadMemberNotification::class, 'slack' => \Seat\Notifications\Notifications\Seat\Slack\SquadMemberNotification::class, + 'discord' => \Seat\Notifications\Notifications\Seat\Discord\SquadMemberNotification::class, ], ], 'squad_member_removed' => [ @@ -66,6 +68,7 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Seat\Mail\SquadMemberRemovedNotification::class, 'slack' => \Seat\Notifications\Notifications\Seat\Slack\SquadMemberRemovedNotification::class, + 'discord' => \Seat\Notifications\Notifications\Seat\Discord\SquadMemberRemovedNotification::class, ], ], // @@ -86,6 +89,7 @@ 'label' => 'notifications::alerts.alliance_anchoring', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\AllAnchoringMsg::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\AllAnchoringMsg::class, ], ], 'AllWarDeclaredMsg' => [ @@ -165,6 +169,7 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Structures\Mail\MoonMiningExtractionFinished::class, 'slack' => \Seat\Notifications\Notifications\Structures\Slack\MoonMiningExtractionFinished::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\MoonMiningExtractionFinished::class, ], ], 'MoonminingExtractionStarted' => [ @@ -172,42 +177,49 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Structures\Mail\MoonMiningExtractionStarted::class, 'slack' => \Seat\Notifications\Notifications\Structures\Slack\MoonMiningExtractionStarted::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\MoonMiningExtractionStarted::class, ], ], 'OrbitalAttacked' => [ 'label' => 'notifications::alerts.orbital_attacked', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\OrbitalAttacked::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\OrbitalAttacked::class, ], ], 'OwnershipTransferred' => [ 'label' => 'notifications::alerts.ownership_transferred', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\OwnershipTransferred::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\OwnershipTransferred::class, ], ], 'RaffleCreated' => [ 'label' => 'notifications::alerts.raffle_created', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Characters\Slack\RaffleCreated::class, + 'discord' => \Seat\Notifications\Notifications\Characters\Discord\RaffleCreated::class, ], ], 'RaffleExpired' => [ 'label' => 'notifications::alerts.raffle_expired', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Characters\Slack\RaffleExpired::class, + 'discord' => \Seat\Notifications\Notifications\Characters\Discord\RaffleExpired::class, ], ], 'RaffleFinished' => [ 'label' => 'notifications::alerts.raffle_finished', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Characters\Slack\RaffleFinished::class, + 'discord' => \Seat\Notifications\Notifications\Characters\Discord\RaffleFinished::class, ], ], 'ResearchMissionAvailableMsg' => [ 'label' => 'notifications::alerts.research_mission_available', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Characters\Slack\ResearchMissionAvailableMsg::class, + 'discord' => \Seat\Notifications\Notifications\Characters\Discord\ResearchMissionAvailableMsg::class, ], ], 'SovStructureDestroyed' => [ @@ -230,18 +242,21 @@ 'label' => 'notifications::alerts.story_line_mission_available', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Characters\Slack\StoryLineMissionAvailableMsg::class, + 'discord' => \Seat\Notifications\Notifications\Characters\Discord\StoryLineMissionAvailableMsg::class, ], ], 'StructureAnchoring' => [ 'label' => 'notifications::alerts.structure_anchoring', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureAnchoring::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureAnchoring::class, ], ], 'StructureDestroyed' => [ 'label' => 'notifications::alerts.structure_destroyed', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureDestroyed::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureDestroyed::class, ], ], 'StructureFuelAlert' => [ @@ -249,18 +264,21 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Structures\Mail\StructureFuelAlert::class, 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureFuelAlert::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureFuelAlert::class, ], ], 'StructureLostArmor' => [ 'label' => 'notifications::alerts.structure_lost_armor', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureLostArmor::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureLostArmor::class, ], ], 'StructureLostShields' => [ 'label' => 'notifications::alerts.structure_lost_shield', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureLostShields::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureLostShields::class, ], ], 'StructureServicesOffline' => [ @@ -268,12 +286,14 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Structures\Mail\StructureServicesOffline::class, 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureServicesOffline::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureServicesOffline::class, ], ], 'StructureUnanchoring' => [ 'label' => 'notifications::alerts.structure_unanchoring', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureUnanchoring::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureUnanchoring::class, ], ], 'StructureUnderAttack' => [ @@ -281,18 +301,21 @@ 'handlers' => [ 'mail' => \Seat\Notifications\Notifications\Structures\Mail\StructureUnderAttack::class, 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureUnderAttack::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureUnderAttack::class, ], ], 'StructureWentHighPower' => [ 'label' => 'notifications::alerts.structure_went_high_power', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureWentHighPower::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureWentHighPower::class, ], ], 'StructureWentLowPower' => [ 'label' => 'notifications::alerts.structure_went_low_power', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureWentLowPower::class, + 'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureWentLowPower::class, ], ], 'inactive_member' => [ @@ -306,6 +329,7 @@ 'label' => 'notifications::alerts.contract_created', 'handlers' => [ 'slack' => \Seat\Notifications\Notifications\Contracts\Slack\ContractNotification::class, + 'discord' => \Seat\Notifications\Notifications\Contracts\Discord\ContractNotification::class, ], ], // even though the test notification can't be added to a notification group, it is here for consistency diff --git a/src/Notifications/Characters/Discord/RaffleCreated.php b/src/Notifications/Characters/Discord/RaffleCreated.php new file mode 100644 index 0000000..76cc45d --- /dev/null +++ b/src/Notifications/Characters/Discord/RaffleCreated.php @@ -0,0 +1,96 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A new raffle has been created!') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT Raffle President', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $location = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['location_id']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('Location') + ->value( + $this->zKillBoardToSlackLink( + 'location', + $this->notification->text['location_id'], + $location->itemName + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['typeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Type') + ->value($type->typeName); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Ticket Count') + ->value($this->notification->text['ticket_count']); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Ticket Price') + ->value(number_format($this->notification->text['ticket_price'], 2)); + }); + }) + ->success(); + } +} diff --git a/src/Notifications/Characters/Discord/RaffleExpired.php b/src/Notifications/Characters/Discord/RaffleExpired.php new file mode 100644 index 0000000..d6a1000 --- /dev/null +++ b/src/Notifications/Characters/Discord/RaffleExpired.php @@ -0,0 +1,96 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A raffle has reach end of life!') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT Raffle President', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $location = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['location_id']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('Location') + ->value( + $this->zKillBoardToDiscordLink( + 'location', + $this->notification->text['location_id'], + $location->itemName + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['typeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Type') + ->value($type->typeName); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Ticket Count') + ->value($this->notification->text['ticket_count']); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Ticket Price') + ->value(number_format($this->notification->text['ticket_price'], 2)); + }); + }) + ->warning(); + } +} diff --git a/src/Notifications/Characters/Discord/RaffleFinished.php b/src/Notifications/Characters/Discord/RaffleFinished.php new file mode 100644 index 0000000..52ca2b4 --- /dev/null +++ b/src/Notifications/Characters/Discord/RaffleFinished.php @@ -0,0 +1,96 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A new raffle has been completed!') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT Raffle President', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $location = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['location_id']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('Location') + ->value( + $this->zKillBoardToDiscordLink( + 'location', + $this->notification->text['location_id'], + $location->itemName + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['typeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Type') + ->value($type->typeName); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Ticket Count') + ->value($this->notification->text['ticket_count']); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Ticket Price') + ->value(number_format($this->notification->text['ticket_price'], 2)); + }); + }) + ->error(); + } +} diff --git a/src/Notifications/Characters/Discord/ResearchMissionAvailableMsg.php b/src/Notifications/Characters/Discord/ResearchMissionAvailableMsg.php new file mode 100644 index 0000000..770c121 --- /dev/null +++ b/src/Notifications/Characters/Discord/ResearchMissionAvailableMsg.php @@ -0,0 +1,52 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable) + { + $message + ->content('A new Mission from a Research Agent is available') + ->from('SeAT Agent Notifier'); + } +} diff --git a/src/Notifications/Characters/Discord/StoryLineMissionAvailableMsg.php b/src/Notifications/Characters/Discord/StoryLineMissionAvailableMsg.php new file mode 100644 index 0000000..f7bac0d --- /dev/null +++ b/src/Notifications/Characters/Discord/StoryLineMissionAvailableMsg.php @@ -0,0 +1,52 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A new Story Line Mission is available') + ->from('SeAT Agent Notifier'); + } +} diff --git a/src/Notifications/Contracts/Discord/ContractNotification.php b/src/Notifications/Contracts/Discord/ContractNotification.php new file mode 100644 index 0000000..ac3ed80 --- /dev/null +++ b/src/Notifications/Contracts/Discord/ContractNotification.php @@ -0,0 +1,75 @@ +contract = $contract; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A new event related to a contract has been recorded!') + ->from('SeAT Contract Monitor') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT Contract Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $type = $this->contract->type; + if ($type == 'item_exchange') { + $type = 'item exchange'; + } + + $embed + ->fields([ + 'Issuer' => $this->contract->issuer->name, + 'Assignee' => $this->contract->assignee->name, + 'Acceptor' => $this->contract->acceptor()->exists() ? $this->contract->acceptor->name : '-', + 'Type' => $type, + 'Status' => $this->contract->status, + 'Description' => $this->contract->title ?? '-', + 'Issued' => carbon($this->contract->date_issued)->toDayDateTimeString(), + 'Completed' => $this->contract->date_completed ? carbon( + $this->contract->date_completed + )->toDayDateTimeString() : '-', + ]); + }); + } +} diff --git a/src/Notifications/Seat/Discord/SquadApplicationNotification.php b/src/Notifications/Seat/Discord/SquadApplicationNotification.php new file mode 100644 index 0000000..9aa1fbc --- /dev/null +++ b/src/Notifications/Seat/Discord/SquadApplicationNotification.php @@ -0,0 +1,60 @@ +application = $application; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->warning() + ->content('A SeAT Squad has a new Application!') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT State of Things', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->title('Squad Application', $this->application->squad->link) + ->fields([ + 'User' => $this->application->user->name, + 'Squad' => $this->application->squad->name, + 'Message' => $this->application->message, + ]); + }); + } +} diff --git a/src/Notifications/Seat/Discord/SquadMemberNotification.php b/src/Notifications/Seat/Discord/SquadMemberNotification.php new file mode 100644 index 0000000..dc2945a --- /dev/null +++ b/src/Notifications/Seat/Discord/SquadMemberNotification.php @@ -0,0 +1,67 @@ +squad_id); + $user = User::find($member->user_id); + + $this->squad = $squad; + $this->user = $user; + } + + public function populateMessage(DiscordMessage $message, $notifiable) + { + $message + ->success() + ->content('A SeAT Squad has a new Member!') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT State of Things', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->title('Squad', $this->squad->link) + ->fields([ + 'User' => $this->user->name, + 'Squad' => $this->squad->name, + ]); + }); + } +} diff --git a/src/Notifications/Seat/Discord/SquadMemberRemovedNotification.php b/src/Notifications/Seat/Discord/SquadMemberRemovedNotification.php new file mode 100644 index 0000000..6f18c98 --- /dev/null +++ b/src/Notifications/Seat/Discord/SquadMemberRemovedNotification.php @@ -0,0 +1,73 @@ +squad_id); + $user = User::find($member->user_id); + + $this->squad = $squad; + $this->user = $user; + } + + /** + * Get the Slack representation of the notification. + * + * @param $notifiable + * @return \Illuminate\Notifications\Messages\SlackMessage + */ + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->error() + ->content('A SeAT Squad has lost a Member!') + ->embed(function (DiscordEmbed $embed) { + $embed->author('SeAT State of Things', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->title('Squad', $this->squad->link) + ->fields([ + 'User' => $this->user->name, + 'Squad' => $this->squad->name, + ]); + }); + } +} diff --git a/src/Notifications/Structures/Discord/AbstractDiscordMoonMiningExtraction.php b/src/Notifications/Structures/Discord/AbstractDiscordMoonMiningExtraction.php new file mode 100644 index 0000000..50d5dd7 --- /dev/null +++ b/src/Notifications/Structures/Discord/AbstractDiscordMoonMiningExtraction.php @@ -0,0 +1,67 @@ +mapOreToColorsArray(); + + foreach ($ore_categories as $color => $ore) { + if (! empty($ore)) { + $message->embed(function (DiscordEmbed $embed) use ($color, $ore) { + $embed->color($color); + + foreach ($ore as $type_id => $volume) { + $embed->field(function (DiscordEmbedField $field) use ($type_id, $volume) { + $type = InvType::find($type_id); + + $field->name($type->typeName) + ->value(sprintf('%s m3', number_format($volume, 2))); + }); + } + }); + } + } + } +} diff --git a/src/Notifications/Structures/Discord/AllAnchoringMsg.php b/src/Notifications/Structures/Discord/AllAnchoringMsg.php new file mode 100644 index 0000000..0ca91f4 --- /dev/null +++ b/src/Notifications/Structures/Discord/AllAnchoringMsg.php @@ -0,0 +1,106 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A structure is anchoring!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::INFO); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed + ->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarSystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }) + ->field(function (DiscordEmbedField $field) { + $moon = MapDenormalize::find($this->notification->text['moonID']); + + $field->name('Moon') + ->value($moon->itemName); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed + ->field(function (DiscordEmbedField $field) { + $corporation = UniverseName::firstOrNew( + ['entity_id' => $this->notification->text['corpID']], + ['name' => trans('web::seat.unkown')] + ); + + $field->name('Corporation') + ->value($corporation->name); + }) + ->field(function (DiscordEmbedField $field) { + $type = InvType::find($this->notification->text['typeID']); + + $field->name('Structure') + ->value( + $this->zKillBoardToDiscordLink( + 'ship', + $type->typeID, + $type->typeName + ) + ); + }) + ->thumb($this->typeIconUrl($this->notification->text['typeID'])); + }); + } +} diff --git a/src/Notifications/Structures/Discord/MoonMiningExtractionFinished.php b/src/Notifications/Structures/Discord/MoonMiningExtractionFinished.php new file mode 100644 index 0000000..dc9c789 --- /dev/null +++ b/src/Notifications/Structures/Discord/MoonMiningExtractionFinished.php @@ -0,0 +1,93 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Moon Mining Extraction has been successfully completed.') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::SUCCESS); + $embed->author('SeAT Moon Tracker', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarSystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + })->field(function (DiscordEmbedField $field) { + $moon = MapDenormalize::find($this->notification->text['moonID']); + + $field->name('Moon') + ->value($moon->itemName); + })->field(function (DiscordEmbedField $field) { + $type = InvType::find($this->notification->text['structureTypeID']); + + $field->name('Structure') + ->value( + sprintf('%s (%s)', $this->notification->text['structureName'], $type->typeName) + ); + })->field(function (DiscordEmbedField $field) { + $field->name('Self Fractured') + ->value($this->mssqlTimestampToDate($this->notification->text['autoTime'])->toRfc7231String()); + }); + }); + + $this->addOreAttachments($message); + } + + /** + * @param $notifiable + * @return array + */ + public function toArray($notifiable) + { + return $this->notification->text; + } +} diff --git a/src/Notifications/Structures/Discord/MoonMiningExtractionStarted.php b/src/Notifications/Structures/Discord/MoonMiningExtractionStarted.php new file mode 100644 index 0000000..f55493d --- /dev/null +++ b/src/Notifications/Structures/Discord/MoonMiningExtractionStarted.php @@ -0,0 +1,93 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Moon Mining Extraction has been started.') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::INFO); + $embed->author('SeAT Moon Tracker', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarSystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + })->field(function (DiscordEmbedField $field) { + $moon = MapDenormalize::find($this->notification->text['moonID']); + + $field->name('Moon') + ->value($moon->itemName); + })->field(function (DiscordEmbedField $field) { + $type = InvType::find($this->notification->text['structureTypeID']); + + $field->name('Structure') + ->value( + sprintf('%s (%s)', $this->notification->text['structureName'], $type->typeName) + ); + })->field(function (DiscordEmbedField $field) { + $field->name('Available') + ->value($this->mssqlTimestampToDate($this->notification->text['readyTime'])->toRfc7231String()); + }); + }); + + $this->addOreAttachments($message); + } + + /** + * @param $notifiable + * @return array + */ + public function toArray($notifiable) + { + return $this->notification->text; + } +} diff --git a/src/Notifications/Structures/Discord/OrbitalAttacked.php b/src/Notifications/Structures/Discord/OrbitalAttacked.php new file mode 100644 index 0000000..627d660 --- /dev/null +++ b/src/Notifications/Structures/Discord/OrbitalAttacked.php @@ -0,0 +1,135 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A customs office is under attack!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::ERROR); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Attacker') + ->value( + $this->zKillBoardToDiscordLink( + 'corporation', + $this->notification->text['aggressorCorpID'], + UniverseName::firstOrNew( + ['entity_id' => $this->notification->text['aggressorCorpID']], + ['category' => 'corporation', 'name' => trans('web::seat.unknown')] + ) + ->name + ) + ); + }) + ->field(function (DiscordEmbedField $field) { + if (! array_key_exists('aggressorAllianceID', $this->notification->text) || is_null( + $this->notification->text['aggressorAllianceID'] + )) { + return; + } + + $field->name('Alliance') + ->value( + $this->zKillBoardToDiscordLink( + 'alliance', + $this->notification->text['aggressorAllianceID'], + UniverseName::firstOrNew( + ['entity_id' => $this->notification->text['aggressorAllianceID']], + ['category' => 'alliance', 'name' => trans('web::seat.unknown')] + ) + ->name + ) + ); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarSystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + $system->itemName . ' (' . number_format($system->security, 2) . ')' + ) + ); + }) + ->field(function (DiscordEmbedField $field) { + $planet = MapDenormalize::find($this->notification->text['planetID']); + + $field->name('Planet') + ->value( + $this->zKillBoardToDiscordLink( + 'location', + $planet->itemID, + $planet->itemName . ' (' . number_format($planet->security, 2) . ')' + ) + ); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Shield') + ->value(number_format($this->notification->text['shieldLevel'] * 100, 2)); + })->color(DiscordMessage::SUCCESS); + + if ($this->notification->text['shieldLevel'] * 100 < 70) { + $embed->color(DiscordMessage::WARNING); + } + + if ($this->notification->text['shieldLevel'] * 100 < 40) { + $embed->color(DiscordMessage::ERROR); + } + }); + } +} diff --git a/src/Notifications/Structures/Discord/OwnershipTransferred.php b/src/Notifications/Structures/Discord/OwnershipTransferred.php new file mode 100644 index 0000000..1e385a5 --- /dev/null +++ b/src/Notifications/Structures/Discord/OwnershipTransferred.php @@ -0,0 +1,102 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A structure has been transferred!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::INFO); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarSystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::find($this->notification->text['structureTypeID']); + + $field->name('Structure') + ->value(sprintf('%s | %s', $type->typeName, $this->notification->text['structureName'])); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $old = UniverseName::firstOrNew( + ['entity_id' => $this->notification->text['oldOwnerCorpID']], + ['name' => trans('web::seat.unknown')] + ); + + $field->name('Old Corporation') + ->value($this->zKillBoardToDiscordLink('corporation', $old->entity_id, $old->name)); + }); + + $embed->field(function (DiscordEmbedField $field) { + $new = UniverseName::firstOrNew( + ['entity_id' => $this->notification->text['newOwnerCorpID']], + ['name' => trans('web::seat.unknown')] + ); + + $field->name('New Corporation') + ->value($this->zKillBoardToDiscordLink('corporation', $new->entity_id, $new->name)); + }); + }); + } +} diff --git a/src/Notifications/Structures/Discord/StructureAnchoring.php b/src/Notifications/Structures/Discord/StructureAnchoring.php new file mode 100644 index 0000000..181c401 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureAnchoring.php @@ -0,0 +1,110 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A new Structure is anchoring!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::INFO); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Owner') + ->value( + $this->zKillBoardToDiscordLink( + 'corporation', + $this->notification->text['ownerCorpLinkData'][2], + $this->notification->text['ownerCorpName'] + ) + ); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Remaining Time') + ->value($this->notification->text['timeLeft']); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Vulnerability Time') + ->value($this->notification->text['vulnerableTime']); + }); + }) + ->warning(); + } +} diff --git a/src/Notifications/Structures/Discord/StructureDestroyed.php b/src/Notifications/Structures/Discord/StructureDestroyed.php new file mode 100644 index 0000000..cf7bee3 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureDestroyed.php @@ -0,0 +1,95 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Structure has been destroyed!') + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Owner') + ->value( + $this->zKillBoardToDiscordLink( + 'corporation', + $this->notification->text['ownerCorpLinkData'][2], + $this->notification->text['ownerCorpName'] + ) + ); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }) + ->error(); + } +} diff --git a/src/Notifications/Structures/Discord/StructureFuelAlert.php b/src/Notifications/Structures/Discord/StructureFuelAlert.php new file mode 100644 index 0000000..4b8c31e --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureFuelAlert.php @@ -0,0 +1,93 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A structure is running low in fuel!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::WARNING); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarsystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::find($this->notification->text['structureShowInfoData'][1]); + + $field->name('Structure') + ->value($type->typeName); + }); + }) + ->embed(function (DiscordEmbed $embed) { + foreach ($this->notification->text['listOfTypesAndQty'] as $item) { + $embed->field(function (DiscordEmbedField $field) use ($item) { + $type = InvType::find($item[1]); + $quantity = $item[0]; + + $field->name($type->typeName) + ->value($quantity); + }); + } + + $embed->color('#439fe0'); + }); + } +} diff --git a/src/Notifications/Structures/Discord/StructureLostArmor.php b/src/Notifications/Structures/Discord/StructureLostArmor.php new file mode 100644 index 0000000..2a5ab4d --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureLostArmor.php @@ -0,0 +1,87 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Structure lost Armor!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::ERROR); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }) + ->warning(); + } +} diff --git a/src/Notifications/Structures/Discord/StructureLostShields.php b/src/Notifications/Structures/Discord/StructureLostShields.php new file mode 100644 index 0000000..87bd072 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureLostShields.php @@ -0,0 +1,87 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Structure lost Shield!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::ERROR); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }) + ->warning(); + } +} diff --git a/src/Notifications/Structures/Discord/StructureServicesOffline.php b/src/Notifications/Structures/Discord/StructureServicesOffline.php new file mode 100644 index 0000000..7639c40 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureServicesOffline.php @@ -0,0 +1,88 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A structure service has been shutdown!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::WARNING); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarsystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, $system->security) + ) + ); + })->field(function (DiscordEmbedField $field) { + $type = InvType::find($this->notification->text['structureShowInfoData'][1]); + + $field->name('Structure') + ->value($type->typeName); + }); + })->embed(function (DiscordEmbed $embed) { + foreach ($this->notification->text['listOfServiceModuleIDs'] as $type_id) { + $embed->field(function ($field) use ($type_id) { + $type = InvType::find($type_id); + + $field->value($type->typeName); + }); + } + + $embed->color(DiscordMessage::ERROR); + }); + } +} diff --git a/src/Notifications/Structures/Discord/StructureUnanchoring.php b/src/Notifications/Structures/Discord/StructureUnanchoring.php new file mode 100644 index 0000000..05b6d97 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureUnanchoring.php @@ -0,0 +1,105 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A new Structure is un-anchoring!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::INFO); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Owner') + ->value( + $this->zKillBoardToDiscordLink( + 'corporation', + $this->notification->text['ownerCorpLinkData'][2], + $this->notification->text['ownerCorpName'] + ) + ); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Remaining Time') + ->value($this->notification->text['timeLeft']); + }); + }) + ->warning(); + } +} diff --git a/src/Notifications/Structures/Discord/StructureUnderAttack.php b/src/Notifications/Structures/Discord/StructureUnderAttack.php new file mode 100644 index 0000000..43ef970 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureUnderAttack.php @@ -0,0 +1,156 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A structure is under attack!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::ERROR); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $field->name('Attacker') + ->value( + $this->zKillBoardToDiscordLink( + 'corporation', + $this->notification->text['corpLinkData'][2], + $this->notification->text['corpName'] + ) + ); + }) + ->field(function (DiscordEmbedField $field) { + if (! array_key_exists('allianceID', $this->notification->text) || is_null( + $this->notification->text['allianceID'] + )) { + return; + } + + $field->name('Alliance') + ->value( + $this->zKillBoardToDiscordLink( + 'alliance', + $this->notification->text['allianceID'], + $this->notification->text['allianceName'] + ) + ); + }) + ->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::find($this->notification->text['solarsystemID']); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + $system->itemName . ' (' . number_format($system->security, 2) . ')' + ) + ); + }) + ->field(function (DiscordEmbedField $field) { + $structure = UniverseStructure::find($this->notification->text['structureID']); + + $type = InvType::find($this->notification->text['structureShowInfoData'][1]); + + $title = 'Structure'; + + if (! is_null($structure)) { + $title = $structure->name; + } + + $field->name($title) + ->value($type->typeName); + }); + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Shield') + ->value(number_format($this->notification->text['shieldPercentage'], 2)); + })->color(DiscordMessage::SUCCESS); + + if ($this->notification->text['shieldPercentage'] < 70) { + $embed->color(DiscordMessage::WARNING); + } + + if ($this->notification->text['shieldPercentage'] < 40) { + $embed->color(DiscordMessage::ERROR); + } + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Armor') + ->value(number_format($this->notification->text['armorPercentage'], 2)); + })->color(DiscordMessage::SUCCESS); + + if ($this->notification->text['armorPercentage'] < 70) { + $embed->color(DiscordMessage::WARNING); + } + + if ($this->notification->text['armorPercentage'] < 40) { + $embed->color(DiscordMessage::ERROR); + } + }) + ->embed(function (DiscordEmbed $embed) { + $embed->field(function (DiscordEmbedField $field) { + $field->name('Hull') + ->value(number_format($this->notification->text['hullPercentage'], 2)); + })->color(DiscordMessage::SUCCESS); + + if ($this->notification->text['hullPercentage'] < 70) { + $embed->color(DiscordMessage::WARNING); + } + + if ($this->notification->text['hullPercentage'] < 40) { + $embed->color(DiscordMessage::ERROR); + } + }); + } +} diff --git a/src/Notifications/Structures/Discord/StructureWentHighPower.php b/src/Notifications/Structures/Discord/StructureWentHighPower.php new file mode 100644 index 0000000..1777366 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureWentHighPower.php @@ -0,0 +1,87 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Structure went into High Power!') + ->from('SeAT Structure Monitor') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::SUCCESS); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }); + } +} diff --git a/src/Notifications/Structures/Discord/StructureWentLowPower.php b/src/Notifications/Structures/Discord/StructureWentLowPower.php new file mode 100644 index 0000000..04e3437 --- /dev/null +++ b/src/Notifications/Structures/Discord/StructureWentLowPower.php @@ -0,0 +1,86 @@ +notification = $notification; + } + + public function populateMessage(DiscordMessage $message, $notifiable): void + { + $message + ->content('A Structure went into Low Power!') + ->embed(function (DiscordEmbed $embed) { + $embed->timestamp($this->notification->timestamp); + $embed->color(DiscordMessage::ERROR); + $embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png')); + + $embed->field(function (DiscordEmbedField $field) { + $system = MapDenormalize::firstOrNew( + ['itemID' => $this->notification->text['solarsystemID']], + ['itemName' => trans('web::seat.unknown')] + ); + + $field->name('System') + ->value( + $this->zKillBoardToDiscordLink( + 'system', + $system->itemID, + sprintf('%s (%s)', $system->itemName, number_format($system->security, 2)) + ) + ); + }); + + $embed->field(function (DiscordEmbedField $field) { + $type = InvType::firstOrNew( + ['typeID' => $this->notification->text['structureTypeID']], + ['typeName' => trans('web::seat.unknown')] + ); + + $field->name('Structure') + ->value($this->zKillBoardToDiscordLink('ship', $type->typeID, $type->typeName)); + }); + }); + } +} diff --git a/src/Notifications/Structures/Slack/AbstractSlackMoonMiningExtraction.php b/src/Notifications/Structures/Slack/AbstractSlackMoonMiningExtraction.php index 3f0f365..cd86e9a 100644 --- a/src/Notifications/Structures/Slack/AbstractSlackMoonMiningExtraction.php +++ b/src/Notifications/Structures/Slack/AbstractSlackMoonMiningExtraction.php @@ -25,6 +25,7 @@ use Illuminate\Notifications\Messages\SlackMessage; use Seat\Eveapi\Models\Sde\InvType; use Seat\Notifications\Notifications\AbstractSlackNotification; +use Seat\Notifications\Notifications\Structures\Traits\MoonMiningNotificationTrait; use Seat\Notifications\Traits\NotificationTools; /** @@ -35,40 +36,13 @@ abstract class AbstractSlackMoonMiningExtraction extends AbstractSlackNotification { use NotificationTools; - - const GAZ_MARKET_GROUP_ID = 2396; - - const R8_MARKET_GROUP_ID = 2397; - - const R16_MARKET_GROUP_ID = 2398; - - const R32_MARKET_GROUP_ID = 2400; - - const R64_MARKET_GROUP_ID = 2401; - - const ORE_COLOR = '#d2d6de'; - - const GAZ_COLOR = '#00a65a'; - - const R8_COLOR = '#3c8dbc'; - - const R16_COLOR = '#00c0ef'; - - const R32_COLOR = '#f39c12'; - - const R64_COLOR = '#dd4b39'; + use MoonMiningNotificationTrait; /** * @var \Seat\Eveapi\Models\Character\CharacterNotification */ protected $notification; - /** - * @param $notifiable - * @return \Illuminate\Notifications\Messages\SlackMessage - */ - abstract public function toSlack($notifiable); - /** * @param \Illuminate\Notifications\Messages\SlackMessage $message */ @@ -98,33 +72,4 @@ protected function addOreAttachments(SlackMessage $message) return $message; } - - /** - * @return array - */ - private function mapOreToColorsArray(): array - { - $category_color_map = [ - self::GAZ_MARKET_GROUP_ID => self::GAZ_COLOR, - self::R8_MARKET_GROUP_ID => self::R8_COLOR, - self::R16_MARKET_GROUP_ID => self::R16_COLOR, - self::R32_MARKET_GROUP_ID => self::R32_COLOR, - self::R64_MARKET_GROUP_ID => self::R64_COLOR, - ]; - - $ore_categories = []; - - foreach ($this->notification->text['oreVolumeByType'] as $type_id => $volume) { - $type = InvType::find($type_id); - - $color = self::ORE_COLOR; - - if (array_key_exists($type->marketGroupID, $category_color_map)) - $color = $category_color_map[$type->marketGroupID]; - - $ore_categories[$color][$type_id] = $volume; - } - - return $ore_categories; - } } diff --git a/src/Notifications/Structures/Traits/MoonMiningNotificationTrait.php b/src/Notifications/Structures/Traits/MoonMiningNotificationTrait.php new file mode 100644 index 0000000..6c568cb --- /dev/null +++ b/src/Notifications/Structures/Traits/MoonMiningNotificationTrait.php @@ -0,0 +1,64 @@ +> + */ + private function mapOreToColorsArray(): array + { + $category_color_map = [ + self::GAZ_MARKET_GROUP_ID => self::GAZ_COLOR, + self::R8_MARKET_GROUP_ID => self::R8_COLOR, + self::R16_MARKET_GROUP_ID => self::R16_COLOR, + self::R32_MARKET_GROUP_ID => self::R32_COLOR, + self::R64_MARKET_GROUP_ID => self::R64_COLOR, + ]; + + $ore_categories = []; + + foreach ($this->notification->text['oreVolumeByType'] as $type_id => $volume) { + $type = InvType::find($type_id); + + $color = self::ORE_COLOR; + + if (array_key_exists($type->marketGroupID, $category_color_map)) { + $color = $category_color_map[$type->marketGroupID]; + } + + $ore_categories[$color][$type_id] = $volume; + } + + return $ore_categories; + } +} \ No newline at end of file