diff --git a/src/Config/notifications.killmails.php b/src/Config/notifications.killmails.php new file mode 100644 index 0000000..64192f6 --- /dev/null +++ b/src/Config/notifications.killmails.php @@ -0,0 +1,28 @@ + env('NOTIFICATIONS_KILLMAILS_CORPORATION_ID', null), + 'alliance_id' => env('NOTIFICATIONS_KILLMAILS_ALLIANCE_ID', null), + 'process_kills' => env('NOTIFICATIONS_KILLMAILS_KILLS', true), + 'process_losses' => env('NOTIFICATIONS_KILLMAILS_LOSSES', true), +]; diff --git a/src/Notifications/AbstractKillmailNotification.php b/src/Notifications/AbstractKillmailNotification.php new file mode 100644 index 0000000..8ef0986 --- /dev/null +++ b/src/Notifications/AbstractKillmailNotification.php @@ -0,0 +1,81 @@ +killmail->victim->alliance_id === $allianceId && $this->killmail->victim->corporation_id === $corporationId) { + $shouldProcess = $processLosses; + } elseif (in_array($allianceId, $killmail->attackers->pluck('alliance_id')) || in_array($corporationId, $killmail->attackers->pluck('character_id'))) { + $shouldProcess = $processKills; + } else { + $shouldProcess = false; + } + } elseif ($allianceId) { + if ($this->killmail->victim->alliance_id === $allianceId) { + $shouldProcess = $processLosses; + } + elseif (in_array($allianceId, $killmail->attackers->pluck('alliance_id'))) { + $shouldProcess = $processKills; + } else { + $shouldProcess = false; + } + } elseif ($corporationId) { + if ($this->killmail->victim->corporation_id === $corporationId) { + $shouldProcess = $processLosses; + } + elseif (in_array($corporationId, $killmail->attackers->pluck('character_id'))) { + $shouldProcess = $processKills; + } else { + $shouldProcess = false; + } + } + + return $shouldProcess; + } +} diff --git a/src/Notifications/Characters/Mail/Killmail.php b/src/Notifications/Characters/Mail/Killmail.php index a1c10ef..fdca2b0 100644 --- a/src/Notifications/Characters/Mail/Killmail.php +++ b/src/Notifications/Characters/Mail/Killmail.php @@ -24,7 +24,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Seat\Eveapi\Models\Killmails\KillmailDetail; -use Seat\Notifications\Notifications\AbstractNotification; +use Seat\Notifications\Notifications\AbstractKillmailNotification; use Seat\Notifications\Traits\NotificationTools; /** @@ -32,7 +32,7 @@ * * @package Seat\Notifications\Notifications\Characters */ -class Killmail extends AbstractNotification +class Killmail extends AbstractKillmailNotification { use NotificationTools; @@ -44,7 +44,7 @@ class Killmail extends AbstractNotification /** * Create a new notification instance. * - * @param \Seat\Eveapi\Models\Killmails\KillmailDetail $killmail + * @param \Seat\Eveapi\Models\Killmails\KillmailDetail $killmail */ public function __construct(KillmailDetail $killmail) { @@ -55,7 +55,7 @@ public function __construct(KillmailDetail $killmail) /** * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function via($notifiable) @@ -67,12 +67,16 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { + if (! parent::shouldProcessKillmail($notifiable)) { + return null; + } + return (new MailMessage) ->subject('Killmail Notification') ->line( @@ -93,7 +97,7 @@ public function toMail($notifiable) /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable) diff --git a/src/Notifications/Characters/Slack/Killmail.php b/src/Notifications/Characters/Slack/Killmail.php index 3ffceca..5ce436d 100644 --- a/src/Notifications/Characters/Slack/Killmail.php +++ b/src/Notifications/Characters/Slack/Killmail.php @@ -23,9 +23,10 @@ namespace Seat\Notifications\Notifications\Characters\Slack; use Illuminate\Notifications\Messages\SlackMessage; +use Illuminate\Support\Facades\DB; use Seat\Eveapi\Models\Corporation\CorporationInfo; use Seat\Eveapi\Models\Killmails\KillmailDetail; -use Seat\Notifications\Notifications\AbstractNotification; +use Seat\Notifications\Notifications\AbstractKillmailNotification; use Seat\Notifications\Traits\NotificationTools; /** @@ -33,7 +34,7 @@ * * @package Seat\Notifications\Notifications\Characters */ -class Killmail extends AbstractNotification +class Killmail extends AbstractKillmailNotification { use NotificationTools; @@ -45,7 +46,7 @@ class Killmail extends AbstractNotification /** * Create a new notification instance. * - * @param \Seat\Eveapi\Models\Killmails\KillmailDetail $killmail + * @param \Seat\Eveapi\Models\Killmails\KillmailDetail $killmail */ public function __construct(KillmailDetail $killmail) { @@ -56,7 +57,7 @@ public function __construct(KillmailDetail $killmail) /** * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function via($notifiable) @@ -68,12 +69,16 @@ public function via($notifiable) /** * Get the Slack representation of the notification. * - * @param $notifiable + * @param $notifiable * @return SlackMessage */ public function toSlack($notifiable) { + if (! parent::shouldProcessKillmail($notifiable)) { + return null; + } + $message = (new SlackMessage) ->content('A kill has been recorded for your corporation!') ->from('SeAT Kilometer', $this->typeIconUrl($this->killmail->victim->ship_type_id)) @@ -100,7 +105,13 @@ public function toSlack($notifiable) ->footerIcon('https://zkillboard.com/img/wreck.png'); }); - $allied_corporation_ids = CorporationInfo::select('corporation_id')->get()->pluck('corporation_id')->toArray(); + $allied_corporation_ids = DB::table('corporation_infos') + ->join('users', 'corporation_infos.ceo_id', '=', 'users.main_character_id') + ->where('users.active', '=', '1') + ->select('corporation_id') + ->get() + ->pluck('corporation_id') + ->toArray(); (in_array($this->killmail->victim->corporation_id, $allied_corporation_ids)) ? $message->error() : $message->success(); @@ -111,7 +122,7 @@ public function toSlack($notifiable) /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable)