-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v5: Add Corporation Wardec notifications (#99)
* fix: Discord ping breaks if UniverseName does not exist for attacker/defender * feat: Added the WarDeclared notification for Corporation Wars
- Loading branch information
Showing
9 changed files
with
256 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present 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\Wars\Discord; | ||
|
||
use Seat\Eveapi\Models\Character\CharacterNotification; | ||
use Seat\Eveapi\Models\Universe\UniverseName; | ||
use Seat\Notifications\Notifications\AbstractDiscordNotification; | ||
use Seat\Notifications\Services\Discord\Messages\DiscordEmbed; | ||
use Seat\Notifications\Services\Discord\Messages\DiscordEmbedField; | ||
use Seat\Notifications\Services\Discord\Messages\DiscordMessage; | ||
use Seat\Notifications\Traits\NotificationTools; | ||
|
||
/** | ||
* Class WarDeclaredMsg. | ||
* | ||
* @package Seat\Notifications\Notifications\Wars\Discord | ||
*/ | ||
class WarDeclaredMsg extends AbstractDiscordNotification | ||
{ | ||
use NotificationTools; | ||
|
||
/** | ||
* @var \Seat\Eveapi\Models\Character\CharacterNotification | ||
*/ | ||
private $notification; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Seat\Eveapi\Models\Character\CharacterNotification $notification | ||
*/ | ||
public function __construct(CharacterNotification $notification) | ||
{ | ||
$this->notification = $notification; | ||
} | ||
|
||
/** | ||
* @param DiscordMessage $message | ||
* @param $notifiable | ||
*/ | ||
public function populateMessage(DiscordMessage $message, $notifiable) | ||
{ | ||
logger()->debug('[DiscordMessage] Init.', $this->notification->toArray()); | ||
|
||
$message | ||
->content('A new War has been declared ! :boom:') | ||
->embed(function (DiscordEmbed $embed) { | ||
$embed->timestamp($this->notification->timestamp); | ||
$embed->color($this->notification->text['hostileState'] ? 13632027 : 16098851); | ||
$embed->author('SeAT War Observer', asset('web/img/favico/apple-icon-180x180.png')); | ||
|
||
$embed->field(function (DiscordEmbedField $field) { | ||
$aggressor = UniverseName::firstOrNew( | ||
['entity_id' => $this->notification->text['declaredByID']], | ||
['name' => trans('web::seat.unknown')] | ||
); | ||
|
||
$field->name('Aggressor')->value( | ||
is_null($aggressor->category) ? | ||
sprintf('Unknown: %d', $aggressor->entity_id) : | ||
$this->zKillBoardToDiscordLink($aggressor->category, $aggressor->entity_id, $aggressor->name) | ||
); | ||
}); | ||
|
||
$embed->field(function (DiscordEmbedField $field) { | ||
$defender = UniverseName::firstOrNew( | ||
['entity_id' => $this->notification->text['againstID']], | ||
['name' => trans('web::seat.unknown')] | ||
); | ||
|
||
$field->name('Defender')->value( | ||
is_null($defender->category) ? | ||
sprintf('Unknown: %d', $defender->entity_id) : | ||
$this->zKillBoardToDiscordLink($defender->category, $defender->entity_id, $defender->name) | ||
); | ||
}); | ||
|
||
$embed->field(function (DiscordEmbedField $field) { | ||
$field->name('Start In') | ||
->value(sprintf('%d hours', $this->notification->text['delayHours'])); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present 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\Wars\Slack; | ||
|
||
use Illuminate\Notifications\Messages\SlackMessage; | ||
use Seat\Eveapi\Models\Character\CharacterNotification; | ||
use Seat\Eveapi\Models\Universe\UniverseName; | ||
use Seat\Notifications\Notifications\AbstractSlackNotification; | ||
|
||
/** | ||
* Class WarDeclaredMsg. | ||
* | ||
* @package Seat\Notifications\Notifications\Corporations\Slack | ||
*/ | ||
class WarDeclaredMsg extends AbstractSlackNotification | ||
{ | ||
/** | ||
* @var \Seat\Eveapi\Models\Character\CharacterNotification | ||
*/ | ||
private $notification; | ||
|
||
/** | ||
* WarDeclaredMsg constructor. | ||
* | ||
* @param \Seat\Eveapi\Models\Character\CharacterNotification $notification | ||
*/ | ||
public function __construct(CharacterNotification $notification) | ||
{ | ||
$this->notification = $notification; | ||
} | ||
|
||
/** | ||
* @param $notifiable | ||
* @return \Illuminate\Notifications\Messages\SlackMessage | ||
*/ | ||
public function toSlack($notifiable) | ||
{ | ||
$message = (new SlackMessage()) | ||
->from('SeAT War Observer') | ||
->content('A new War has been declared !') | ||
->attachment(function ($attachment) { | ||
$attachment | ||
->field(function ($field) { | ||
$entity = UniverseName::firstOrNew( | ||
['entity_id' => $this->notification->text['declaredByID']], | ||
['name' => trans('web::seat.unknown')] | ||
); | ||
|
||
$field->title('Aggressor') | ||
->content($entity->name); | ||
}) | ||
->field(function ($field) { | ||
$entity = UniverseName::firstOrNew( | ||
['entity_id' => $this->notification->text['againstID']], | ||
['name' => trans('web::seat.unknown')] | ||
); | ||
|
||
$field->title('Defender') | ||
->content($entity->name); | ||
}); | ||
}) | ||
->attachment(function ($attachment) { | ||
$attachment->field(function ($field) { | ||
$field->title('Start in') | ||
->content(sprintf('%d hours', $this->notification->text['delayHours'])); | ||
}); | ||
}); | ||
|
||
($this->notification->text['hostileState']) ? | ||
$message->error() : $message->warning(); | ||
|
||
return $message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters