-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable killmail processing #67
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to 2021 Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
return [ | ||
'corporation_id' => 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), | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to 2021 Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
namespace Seat\Notifications\Notifications; | ||
|
||
use AbstractNotification; | ||
|
||
/** | ||
* Class AbstractKillmailNotification. | ||
* | ||
* @package Seat\Notifications\Notifications | ||
*/ | ||
class AbstractKillmailNotification extends AbstractNotification | ||
{ | ||
/** | ||
* Get the Slack representation of the notification. | ||
* | ||
* @param $notifiable | ||
* @return bool | ||
*/ | ||
protected function shouldProcessKillmail($notifiable) { | ||
|
||
$killmailConfig = config('notifications.killmails'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep config for either static content or server configuration (ie: mysql, redis, menu etc...) What about using |
||
|
||
$allianceId = $killmailConfig['alliance_id']; | ||
$corporationId = $killmailConfig['corporation_id']; | ||
$processKills = $killmailConfig['process_kills']; | ||
$processLosses = $killmailConfig['process_losses']; | ||
|
||
$shouldProcess = true; | ||
|
||
if ($allianceId && $corporationId) { | ||
if ($this->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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,15 @@ | |
|
||
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; | ||
|
||
/** | ||
* Class Killmail. | ||
* | ||
* @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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be done in routing section ( |
||
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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,17 +23,18 @@ | |
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; | ||
|
||
/** | ||
* Class Killmail. | ||
* | ||
* @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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be done in routing section ( |
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing
abstract
keyword if class isAbstract*