Allow sending helcase battle to custom discord webhook
All checks were successful
Push image to registry / build-image (push) Successful in 4m24s

This commit is contained in:
2025-03-20 19:28:40 +01:00
parent fadb4d2748
commit c26a09701a
4 changed files with 18 additions and 7 deletions

View File

@ -152,7 +152,14 @@ class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProce
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to screenshot battle")); AllNotification::send(new JobDebugNotification($this->jobId, "Failed to screenshot battle"));
} }
$this->battlesSent[$battle->getUrl()] = $battle->value; $this->battlesSent[$battle->getUrl()] = $battle->value;
AllNotification::send(new HellcaseBattlesNofication($this->jobId, $battle));
$options = [];
if ($this->jobInfos->get("hellcase_battles_discord_webhook_url") !== null) { // Custom discord webhook
$options["discord_webhook_url"] = $this->jobInfos->get("hellcase_battles_discord_webhook_url");
}
AllNotification::send(new HellcaseBattlesNofication($this->jobId, $battle), $options);
} }
private function createNewBattles() { private function createNewBattles() {

View File

@ -3,5 +3,5 @@
namespace App\Notification; namespace App\Notification;
abstract class NotificationProvider { abstract class NotificationProvider {
abstract public static function send(Notification $notification): void; abstract public static function send(Notification $notification, array $options): void;
} }

View File

@ -12,9 +12,9 @@ class AllNotification extends NotificationProvider {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function send(\App\Notification\Notification $notification): void { public static function send(\App\Notification\Notification $notification, array $options = []): void {
foreach (self::NOTIFICATIONS_PROVIDERS as $provider) { foreach (self::NOTIFICATIONS_PROVIDERS as $provider) {
$provider::send($notification); $provider::send($notification, $options);
} }
} }
} }

View File

@ -13,7 +13,7 @@ class DiscordWebHookNotification extends NotificationProvider {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function send(\App\Notification\Notification $notification): void { public static function send(\App\Notification\Notification $notification, array $options): void {
/* /*
Test Json for a complete embed : Test Json for a complete embed :
{ {
@ -44,7 +44,7 @@ class DiscordWebHookNotification extends NotificationProvider {
"avatar_url": "https://www.fairytailrp.com/t40344-here-come-dat-boi" "avatar_url": "https://www.fairytailrp.com/t40344-here-come-dat-boi"
} }
*/ */
$webHookUrl = static::getDiscordWebHookUrl($notification->isError); $webHookUrl = static::getDiscordWebHookUrl($notification->isError, $options);
$body = [ $body = [
"content"=> "", "content"=> "",
"tts"=> false, "tts"=> false,
@ -86,7 +86,11 @@ class DiscordWebHookNotification extends NotificationProvider {
curl_close($ch); curl_close($ch);
} }
private static function getDiscordWebHookUrl(bool $isError): string { private static function getDiscordWebHookUrl(bool $isError, array $options): string {
if ($options["discord_webhook_url"] !== null) {
return $options["discord_webhook_url"];
}
$generalWebHookUrlKey = 'discord_webhook_url'; $generalWebHookUrlKey = 'discord_webhook_url';
$generalWebHookUrl = Cache::rememberForever($generalWebHookUrlKey, function () use ($generalWebHookUrlKey) { $generalWebHookUrl = Cache::rememberForever($generalWebHookUrlKey, function () use ($generalWebHookUrlKey) {
return JobInfo::where('key', $generalWebHookUrlKey)->first()->value; return JobInfo::where('key', $generalWebHookUrlKey)->first()->value;