Skip to content

Commit 630b389

Browse files
authored
Add support for TowerAlertMsg which should enable notifications for attacked POS (#108)
* Fix a little typo for skyhookèlost_shields in en lang * Add TowerAlertMsg support, for POS under attacks * Fix TowerAlertMsg use of double quote to follow CI rules * Remove unused import of Universe\UniverseStructure * Import Sde\InvType on Structures\Mail\TowerAlertMsg to fix missing import * Removed uncertain translations for tower_alert_msg
1 parent 4e218db commit 630b389

File tree

7 files changed

+285
-1
lines changed

7 files changed

+285
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
aggressorAllianceID: 99011162
2+
aggressorCorpID: 1000001
3+
aggressorID: 2120512110
4+
armorValue: 1.0
5+
hullValue: 1.0
6+
moonID: 40439200
7+
shieldValue: 0.9999006655629918
8+
solarSystemID: 31001703
9+
typeID: 20060

src/Config/notifications.alerts.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@
386386
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureWentLowPower::class,
387387
],
388388
],
389+
'TowerAlertMsg' => [
390+
'label' => 'notifications::alerts.tower_alert_msg',
391+
'handlers' => [
392+
'mail' => \Seat\Notifications\Notifications\Structures\Mail\TowerAlertMsg::class,
393+
'discord' => \Seat\Notifications\Notifications\Structures\Discord\TowerAlertMsg::class,
394+
],
395+
],
389396
'WarDeclared' => [
390397
'label' => 'notifications::alerts.corporation_war_declared',
391398
'handlers' => [
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
/*
4+
* This file is part of SeAT
5+
*
6+
* Copyright (C) 2015 to present Leon Jacobs
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License along
19+
* with this program; if not, write to the Free Software Foundation, Inc.,
20+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*/
22+
23+
namespace Seat\Notifications\Notifications\Structures\Discord;
24+
25+
use Seat\Eveapi\Models\Character\CharacterNotification;
26+
use Seat\Eveapi\Models\Sde\InvType;
27+
use Seat\Eveapi\Models\Sde\MapDenormalize;
28+
use Seat\Notifications\Notifications\AbstractDiscordNotification;
29+
use Seat\Notifications\Services\Discord\Messages\DiscordEmbed;
30+
use Seat\Notifications\Services\Discord\Messages\DiscordEmbedField;
31+
use Seat\Notifications\Services\Discord\Messages\DiscordMessage;
32+
use Seat\Notifications\Traits\NotificationTools;
33+
34+
/**
35+
* Class TowerAlertMsg.
36+
*
37+
* @package Seat\Notifications\Notifications\Structures
38+
*/
39+
class TowerAlertMsg extends AbstractDiscordNotification
40+
{
41+
use NotificationTools;
42+
43+
private CharacterNotification $notification;
44+
45+
public function __construct(CharacterNotification $notification)
46+
{
47+
$this->notification = $notification;
48+
}
49+
50+
public function populateMessage(DiscordMessage $message, $notifiable): void
51+
{
52+
$message
53+
->content('A tower is under attack!')
54+
->embed(function (DiscordEmbed $embed) {
55+
$embed->timestamp($this->notification->timestamp);
56+
$embed->color(DiscordMessage::ERROR);
57+
$embed->author('SeAT Structure Monitor', asset('web/img/favico/apple-icon-180x180.png'));
58+
59+
$embed->field(function (DiscordEmbedField $field) {
60+
$field->name('Character')
61+
->value(
62+
$this->zKillBoardToDiscordLink(
63+
'character',
64+
$this->notification->text['aggressorID'],
65+
'Link to Character'
66+
)
67+
);
68+
});
69+
70+
$embed->field(function (DiscordEmbedField $field) {
71+
$field->name('Corporation')
72+
->value(
73+
$this->zKillBoardToDiscordLink(
74+
'corporation',
75+
$this->notification->text['aggressorCorpID'],
76+
'Link to Corporation'
77+
)
78+
);
79+
});
80+
81+
if (array_key_exists('aggressorAllianceID', $this->notification->text) && ! is_null(
82+
$this->notification->text['aggressorAllianceID']
83+
)) {
84+
$embed->field(function (DiscordEmbedField $field) {
85+
$field->name('Alliance')
86+
->value(
87+
$this->zKillBoardToDiscordLink(
88+
'alliance',
89+
$this->notification->text['aggressorAllianceID'],
90+
'Link to Alliance'
91+
)
92+
);
93+
});
94+
}
95+
96+
$embed->field(function (DiscordEmbedField $field) {
97+
$system = MapDenormalize::find($this->notification->text['solarSystemID']);
98+
99+
$field->name('System')
100+
->value(
101+
$this->zKillBoardToDiscordLink(
102+
'system',
103+
$system->itemID,
104+
$system->itemName . ' (' . number_format($system->security, 2) . ')'
105+
)
106+
);
107+
})
108+
109+
->field(function (DiscordEmbedField $field) {
110+
$moon = MapDenormalize::find($this->notification->text['moonID']);
111+
112+
$field->name('Moon')
113+
->value($moon->itemName);
114+
})
115+
->field(function (DiscordEmbedField $field) {
116+
$type = InvType::find($this->notification->text['typeID']);
117+
118+
$field->name('Structure')
119+
->value($type->typeName);
120+
});
121+
})
122+
->embed(function (DiscordEmbed $embed) {
123+
$embed->field(function (DiscordEmbedField $field) {
124+
$field->name('Shield')
125+
->value(number_format($this->notification->text['shieldValue'] * 100, 2));
126+
})->color(DiscordMessage::SUCCESS);
127+
128+
if ($this->notification->text['shieldValue'] < 0.70) {
129+
$embed->color(DiscordMessage::WARNING);
130+
}
131+
132+
if ($this->notification->text['shieldValue'] < 0.40) {
133+
$embed->color(DiscordMessage::ERROR);
134+
}
135+
})
136+
->embed(function (DiscordEmbed $embed) {
137+
$embed->field(function (DiscordEmbedField $field) {
138+
$field->name('Armor')
139+
->value(number_format($this->notification->text['armorValue'] * 100, 2));
140+
})->color(DiscordMessage::SUCCESS);
141+
142+
if ($this->notification->text['armorValue'] < 0.70) {
143+
$embed->color(DiscordMessage::WARNING);
144+
}
145+
146+
if ($this->notification->text['armorValue'] < 0.40) {
147+
$embed->color(DiscordMessage::ERROR);
148+
}
149+
})
150+
->embed(function (DiscordEmbed $embed) {
151+
$embed->field(function (DiscordEmbedField $field) {
152+
$field->name('Hull')
153+
->value(number_format($this->notification->text['hullValue'] * 100, 2));
154+
})->color(DiscordMessage::SUCCESS);
155+
156+
if ($this->notification->text['hullValue'] < 0.70) {
157+
$embed->color(DiscordMessage::WARNING);
158+
}
159+
160+
if ($this->notification->text['hullValue'] < 0.40) {
161+
$embed->color(DiscordMessage::ERROR);
162+
}
163+
});
164+
}
165+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
/*
4+
* This file is part of SeAT
5+
*
6+
* Copyright (C) 2015 to present Leon Jacobs
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License along
19+
* with this program; if not, write to the Free Software Foundation, Inc.,
20+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*/
22+
23+
namespace Seat\Notifications\Notifications\Structures\Mail;
24+
25+
use Illuminate\Notifications\Messages\MailMessage;
26+
use Seat\Eveapi\Models\Character\CharacterNotification;
27+
use Seat\Eveapi\Models\Sde\InvType;
28+
use Seat\Eveapi\Models\Sde\MapDenormalize;
29+
use Seat\Notifications\Notifications\AbstractMailNotification;
30+
use Seat\Notifications\Traits\NotificationTools;
31+
32+
/**
33+
* Class TowerAlertMsg.
34+
*
35+
* @package Seat\Notifications\Notifications\Structures
36+
*/
37+
class TowerAlertMsg extends AbstractMailNotification
38+
{
39+
use NotificationTools;
40+
41+
/**
42+
* @var \Seat\Eveapi\Models\Character\CharacterNotification
43+
*/
44+
private $notification;
45+
46+
/**
47+
* TowerAlertMsg constructor.
48+
*
49+
* @param \Seat\Eveapi\Models\Character\CharacterNotification $notification
50+
*/
51+
public function __construct(CharacterNotification $notification)
52+
{
53+
$this->notification = $notification;
54+
}
55+
56+
/**
57+
* @param $notifiable
58+
* @return \Illuminate\Notifications\Messages\MailMessage
59+
*/
60+
public function toMail($notifiable)
61+
{
62+
$system = MapDenormalize::find($this->notification->text['solarSystemID']);
63+
$moon = MapDenormalize::find($this->notification->text['moonID']);
64+
$type = InvType::find($this->notification->text['typeID']);
65+
66+
return (new MailMessage)
67+
->subject('Tower Under Attack Notification')
68+
->line('A tower is under attack!')
69+
->line(
70+
sprintf(
71+
'Tower (%s, %s) attacked',
72+
$moon->itemName,
73+
$type->typeName
74+
)
75+
)
76+
->line(
77+
sprintf(
78+
'(%d shield, %d armor, %d hull)',
79+
number_format($this->notification->text['shieldValue'] * 100, 2),
80+
number_format($this->notification->text['armorValue'] * 100, 2),
81+
number_format($this->notification->text['hullValue'] * 100, 2)
82+
)
83+
)
84+
->line(
85+
sprintf(
86+
'in %s',
87+
$system->itemName
88+
)
89+
);
90+
}
91+
92+
/**
93+
* @param $notifiable
94+
* @return mixed
95+
*/
96+
public function toArray($notifiable)
97+
{
98+
return $this->notification->text;
99+
}
100+
}

src/resources/lang/en/alerts.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
'research_mission_available' => 'New Research Mission',
5656
'skyhook_deployed' => 'Skyhook Deployed',
5757
'skyhook_destroyed' => 'Skyhook Destroyed',
58-
'skyhook_lost_shields', 'Skyhook Lost Shields',
58+
'skyhook_lost_shields' => 'Skyhook Lost Shields',
5959
'skyhook_online' => 'Skyhook Online',
6060
'skyhook_under_attack' => 'Skyhook Under Attack',
6161
'sovereignty_command_node_event_started' => 'Sovereignty Command Node Event Started',
@@ -74,6 +74,7 @@
7474
'structure_under_attack' => 'Structures Attacked',
7575
'structure_went_high_power' => 'Structures High Power',
7676
'structure_went_low_power' => 'Structures Low Power',
77+
'tower_alert_msg' => 'Towers Attacked',
7778
'killmails' => 'Killmails',
7879
'contract_created' => 'Contract Created',
7980
'war_inactive_member' => 'War Inactive Member',

src/resources/lang/fr/alerts.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
'structure_under_attack' => 'Structure attaquée',
6565
'structure_went_high_power' => 'Structure à pleine puissance',
6666
'structure_went_low_power' => 'Structure à faible puissance',
67+
'tower_alert_msg' => 'Tour attaquée',
6768
'killmails' => 'Rapport de combat',
6869
];

src/resources/lang/ko/alerts.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
'structure_under_attack' => '구조물 공격받음',
6565
'structure_went_high_power' => '구조물 최고출력상태',
6666
'structure_went_low_power' => '구조물 저전력',
67+
'tower_alert_msg' => '공격받은 타워',
6768
'killmails' => '킬메일',
6869
];

0 commit comments

Comments
 (0)