Skip to content

Commit

Permalink
Add missing discord notifications (#89)
Browse files Browse the repository at this point in the history
* Add missing discord notifications.

* Reformat code style

* Fix style check issues.

* Fix missing array key by setting colors as defaults.

* Set required php to 8.2 or above and add trait for duplicate constants and functions.

* Fix colors

StyleCI to be corrected in future commit.
  • Loading branch information
zenobio93 authored Dec 24, 2023
1 parent ba86c22 commit 455901a
Show file tree
Hide file tree
Showing 29 changed files with 2,348 additions and 58 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1",
"php": "^8.2",
"laravel/framework": "^10.0",
"laravel/slack-notification-channel": "^2.0",
"eveseat/eveapi": "^5.0",
Expand Down
24 changes: 24 additions & 0 deletions src/Config/notifications.alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Seat\Mail\SquadApplicationNotification::class,
'slack' => \Seat\Notifications\Notifications\Seat\Slack\SquadApplicationNotification::class,
'discord' => \Seat\Notifications\Notifications\Seat\Discord\SquadApplicationNotification::class,
],
],
'squad_member' => [
'label' => 'notifications::alerts.squad_member',
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Seat\Mail\SquadMemberNotification::class,
'slack' => \Seat\Notifications\Notifications\Seat\Slack\SquadMemberNotification::class,
'discord' => \Seat\Notifications\Notifications\Seat\Discord\SquadMemberNotification::class,
],
],
'squad_member_removed' => [
'label' => 'notifications::alerts.squad_member_removed',
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Seat\Mail\SquadMemberRemovedNotification::class,
'slack' => \Seat\Notifications\Notifications\Seat\Slack\SquadMemberRemovedNotification::class,
'discord' => \Seat\Notifications\Notifications\Seat\Discord\SquadMemberRemovedNotification::class,
],
],
//
Expand All @@ -86,6 +89,7 @@
'label' => 'notifications::alerts.alliance_anchoring',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\AllAnchoringMsg::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\AllAnchoringMsg::class,
],
],
'AllWarDeclaredMsg' => [
Expand Down Expand Up @@ -165,49 +169,57 @@
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Structures\Mail\MoonMiningExtractionFinished::class,
'slack' => \Seat\Notifications\Notifications\Structures\Slack\MoonMiningExtractionFinished::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\MoonMiningExtractionFinished::class,
],
],
'MoonminingExtractionStarted' => [
'label' => 'notifications::alerts.moon_mining_extraction_started',
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Structures\Mail\MoonMiningExtractionStarted::class,
'slack' => \Seat\Notifications\Notifications\Structures\Slack\MoonMiningExtractionStarted::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\MoonMiningExtractionStarted::class,
],
],
'OrbitalAttacked' => [
'label' => 'notifications::alerts.orbital_attacked',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\OrbitalAttacked::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\OrbitalAttacked::class,
],
],
'OwnershipTransferred' => [
'label' => 'notifications::alerts.ownership_transferred',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\OwnershipTransferred::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\OwnershipTransferred::class,
],
],
'RaffleCreated' => [
'label' => 'notifications::alerts.raffle_created',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Characters\Slack\RaffleCreated::class,
'discord' => \Seat\Notifications\Notifications\Characters\Discord\RaffleCreated::class,
],
],
'RaffleExpired' => [
'label' => 'notifications::alerts.raffle_expired',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Characters\Slack\RaffleExpired::class,
'discord' => \Seat\Notifications\Notifications\Characters\Discord\RaffleExpired::class,
],
],
'RaffleFinished' => [
'label' => 'notifications::alerts.raffle_finished',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Characters\Slack\RaffleFinished::class,
'discord' => \Seat\Notifications\Notifications\Characters\Discord\RaffleFinished::class,
],
],
'ResearchMissionAvailableMsg' => [
'label' => 'notifications::alerts.research_mission_available',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Characters\Slack\ResearchMissionAvailableMsg::class,
'discord' => \Seat\Notifications\Notifications\Characters\Discord\ResearchMissionAvailableMsg::class,
],
],
'SovStructureDestroyed' => [
Expand All @@ -230,69 +242,80 @@
'label' => 'notifications::alerts.story_line_mission_available',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Characters\Slack\StoryLineMissionAvailableMsg::class,
'discord' => \Seat\Notifications\Notifications\Characters\Discord\StoryLineMissionAvailableMsg::class,
],
],
'StructureAnchoring' => [
'label' => 'notifications::alerts.structure_anchoring',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureAnchoring::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureAnchoring::class,
],
],
'StructureDestroyed' => [
'label' => 'notifications::alerts.structure_destroyed',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureDestroyed::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureDestroyed::class,
],
],
'StructureFuelAlert' => [
'label' => 'notifications::alerts.structure_fuel_alert',
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Structures\Mail\StructureFuelAlert::class,
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureFuelAlert::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureFuelAlert::class,
],
],
'StructureLostArmor' => [
'label' => 'notifications::alerts.structure_lost_armor',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureLostArmor::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureLostArmor::class,
],
],
'StructureLostShields' => [
'label' => 'notifications::alerts.structure_lost_shield',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureLostShields::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureLostShields::class,
],
],
'StructureServicesOffline' => [
'label' => 'notifications::alerts.structure_services_offline',
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Structures\Mail\StructureServicesOffline::class,
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureServicesOffline::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureServicesOffline::class,
],
],
'StructureUnanchoring' => [
'label' => 'notifications::alerts.structure_unanchoring',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureUnanchoring::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureUnanchoring::class,
],
],
'StructureUnderAttack' => [
'label' => 'notifications::alerts.structure_under_attack',
'handlers' => [
'mail' => \Seat\Notifications\Notifications\Structures\Mail\StructureUnderAttack::class,
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureUnderAttack::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureUnderAttack::class,
],
],
'StructureWentHighPower' => [
'label' => 'notifications::alerts.structure_went_high_power',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureWentHighPower::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureWentHighPower::class,
],
],
'StructureWentLowPower' => [
'label' => 'notifications::alerts.structure_went_low_power',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Structures\Slack\StructureWentLowPower::class,
'discord' => \Seat\Notifications\Notifications\Structures\Discord\StructureWentLowPower::class,
],
],
'inactive_member' => [
Expand All @@ -306,6 +329,7 @@
'label' => 'notifications::alerts.contract_created',
'handlers' => [
'slack' => \Seat\Notifications\Notifications\Contracts\Slack\ContractNotification::class,
'discord' => \Seat\Notifications\Notifications\Contracts\Discord\ContractNotification::class,
],
],
// even though the test notification can't be added to a notification group, it is here for consistency
Expand Down
96 changes: 96 additions & 0 deletions src/Notifications/Characters/Discord/RaffleCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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\Characters\Discord;

use Seat\Eveapi\Models\Character\CharacterNotification;
use Seat\Eveapi\Models\Sde\InvType;
use Seat\Eveapi\Models\Sde\MapDenormalize;
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 RaffleCreated.
*
* @package Seat\Notifications\Notifications\Characters\Slack
*/
class RaffleCreated extends AbstractDiscordNotification
{
use NotificationTools;

private CharacterNotification $notification;

public function __construct(CharacterNotification $notification)
{
$this->notification = $notification;
}

public function populateMessage(DiscordMessage $message, $notifiable): void
{
$message
->content('A new raffle has been created!')
->embed(function (DiscordEmbed $embed) {
$embed->author('SeAT Raffle President', asset('web/img/favico/apple-icon-180x180.png'));

$embed->field(function (DiscordEmbedField $field) {
$location = MapDenormalize::firstOrNew(
['itemID' => $this->notification->text['location_id']],
['itemName' => trans('web::seat.unknown')]
);

$field->name('Location')
->value(
$this->zKillBoardToSlackLink(
'location',
$this->notification->text['location_id'],
$location->itemName
)
);
});

$embed->field(function (DiscordEmbedField $field) {
$type = InvType::firstOrNew(
['typeID' => $this->notification->text['typeID']],
['typeName' => trans('web::seat.unknown')]
);

$field->name('Type')
->value($type->typeName);
});
})
->embed(function (DiscordEmbed $embed) {
$embed->field(function (DiscordEmbedField $field) {
$field->name('Ticket Count')
->value($this->notification->text['ticket_count']);
});

$embed->field(function (DiscordEmbedField $field) {
$field->name('Ticket Price')
->value(number_format($this->notification->text['ticket_price'], 2));
});
})
->success();
}
}
96 changes: 96 additions & 0 deletions src/Notifications/Characters/Discord/RaffleExpired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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\Characters\Discord;

use Seat\Eveapi\Models\Character\CharacterNotification;
use Seat\Eveapi\Models\Sde\InvType;
use Seat\Eveapi\Models\Sde\MapDenormalize;
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 RaffleExpired.
*
* @package Seat\Notifications\Notifications\Characters\Slack
*/
class RaffleExpired extends AbstractDiscordNotification
{
use NotificationTools;

private CharacterNotification $notification;

public function __construct(CharacterNotification $notification)
{
$this->notification = $notification;
}

public function populateMessage(DiscordMessage $message, $notifiable): void
{
$message
->content('A raffle has reach end of life!')
->embed(function (DiscordEmbed $embed) {
$embed->author('SeAT Raffle President', asset('web/img/favico/apple-icon-180x180.png'));

$embed->field(function (DiscordEmbedField $field) {
$location = MapDenormalize::firstOrNew(
['itemID' => $this->notification->text['location_id']],
['itemName' => trans('web::seat.unknown')]
);

$field->name('Location')
->value(
$this->zKillBoardToDiscordLink(
'location',
$this->notification->text['location_id'],
$location->itemName
)
);
});

$embed->field(function (DiscordEmbedField $field) {
$type = InvType::firstOrNew(
['typeID' => $this->notification->text['typeID']],
['typeName' => trans('web::seat.unknown')]
);

$field->name('Type')
->value($type->typeName);
});
})
->embed(function (DiscordEmbed $embed) {
$embed->field(function (DiscordEmbedField $field) {
$field->name('Ticket Count')
->value($this->notification->text['ticket_count']);
});

$embed->field(function (DiscordEmbedField $field) {
$field->name('Ticket Price')
->value(number_format($this->notification->text['ticket_price'], 2));
});
})
->warning();
}
}
Loading

0 comments on commit 455901a

Please sign in to comment.