|
| 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 | +} |
0 commit comments