Skip to content

Commit

Permalink
v5: Add Corporation Wardec notifications (#99)
Browse files Browse the repository at this point in the history
* fix: Discord ping breaks if UniverseName does not exist for attacker/defender

* feat: Added the WarDeclared notification for Corporation Wars
  • Loading branch information
moppa authored Mar 28, 2024
1 parent d9f947a commit 7d9b7af
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 30 deletions.
7 changes: 7 additions & 0 deletions src/Config/notifications.alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureWentLowPower::class,
],
],
'WarDeclared' => [
'label' => 'notifications::alerts.corporation_war_declared',
'handlers' => [
'discord' => \Seat\Notifications\Notifications\Wars\Discord\WarDeclaredMsg::class,
'slack' => \Seat\Notifications\Notifications\Wars\Slack\WarDeclaredMsg::class,
],
],
'inactive_member' => [
'label' => 'notifications::alerts.war_inactive_member',
'handlers' => [
Expand Down
16 changes: 10 additions & 6 deletions src/Notifications/Wars/Discord/AllWarDeclaredMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Aggressor')
->value($this->zKillBoardToDiscordLink(
$aggressor->category, $aggressor->entity_id, $aggressor->name));
$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) {
Expand All @@ -84,9 +86,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Defender')
->value($this->zKillBoardToDiscordLink(
$defender->category, $defender->entity_id, $defender->name));
$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) {
Expand Down
16 changes: 10 additions & 6 deletions src/Notifications/Wars/Discord/AllWarInvalidatedMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Aggressor')
->value($this->zKillBoardToDiscordLink(
$aggressor->category, $aggressor->entity_id, $aggressor->name));
$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) {
Expand All @@ -83,9 +85,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Defender')
->value($this->zKillBoardToDiscordLink(
$defender->category, $defender->entity_id, $defender->name));
$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) {
Expand Down
16 changes: 10 additions & 6 deletions src/Notifications/Wars/Discord/AllyJoinedWarAggressorMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Aggressor')
->value($this->zKillBoardToDiscordLink(
$aggressor->category, $aggressor->entity_id, $aggressor->name));
$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) {
Expand All @@ -83,9 +85,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Defender')
->value($this->zKillBoardToDiscordLink(
$defender->category, $defender->entity_id, $defender->name));
$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) {
Expand Down
16 changes: 10 additions & 6 deletions src/Notifications/Wars/Discord/AllyJoinedWarAllyMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Aggressor')
->value($this->zKillBoardToDiscordLink(
$aggressor->category, $aggressor->entity_id, $aggressor->name));
$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) {
Expand All @@ -83,9 +85,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Defender')
->value($this->zKillBoardToDiscordLink(
$defender->category, $defender->entity_id, $defender->name));
$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) {
Expand Down
16 changes: 10 additions & 6 deletions src/Notifications/Wars/Discord/AllyJoinedWarDefenderMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Aggressor')
->value($this->zKillBoardToDiscordLink(
$aggressor->category, $aggressor->entity_id, $aggressor->name));
$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) {
Expand All @@ -83,9 +85,11 @@ public function populateMessage(DiscordMessage $message, $notifiable)
['name' => trans('web::seat.unknown')]
);

$field->name('Defender')
->value($this->zKillBoardToDiscordLink(
$defender->category, $defender->entity_id, $defender->name));
$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) {
Expand Down
104 changes: 104 additions & 0 deletions src/Notifications/Wars/Discord/WarDeclaredMsg.php
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']));
});
});
}
}
94 changes: 94 additions & 0 deletions src/Notifications/Wars/Slack/WarDeclaredMsg.php
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;
}
}
1 change: 1 addition & 0 deletions src/resources/lang/en/alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'character_left_corporation' => 'Corporation Leaving Character',
'corporation_alliance_bill' => 'New Alliance Bill',
'corporation_application_new' => 'New Corporation Application',
'corporation_war_declared' => 'Corporation War Declared',
'entosis_capture_started' => 'Entosis Capture Started',
'moon_mining_extraction_finished' => 'MM Finished Extractions',
'moon_mining_extraction_started' => 'MM Started Extractions',
Expand Down

0 comments on commit 7d9b7af

Please sign in to comment.