From f1e4bd8ba0b3785b40f11a9c98881952a1a0497b Mon Sep 17 00:00:00 2001 From: Poseidon_281 Date: Sat, 3 Aug 2024 12:19:10 +0200 Subject: [PATCH] Add configurable embed image URL for Discord webhooks - Added a new `DISCORD_EMBED_IMAGE` setting to `Settings.php` for specifying the embed image URL in Discord webhooks. - Updated `SendWebhook` trait to use the `DISCORD_EMBED_IMAGE` setting for the avatar URL in Discord webhooks. - Removed hardcoded Discord image URL from `EggWebhookListener`, `ServerWebhookListener`, and `UserWebhookListener`. - Updated webhook listeners to use the configurable embed image URL. These changes allow for dynamic configuration of the embed image URL, improving flexibility in webhook settings. --- app/Filament/Pages/Settings.php | 5 +++++ app/Listeners/Webhook/EggWebhookListener.php | 2 -- app/Listeners/Webhook/ServerWebhookListener.php | 2 -- app/Listeners/Webhook/UserWebhookListener.php | 2 -- app/Traits/SendWebhook.php | 6 ++++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 735e2bbd3a..bc061087bb 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -418,6 +418,11 @@ private function webhookSettings(): array ColorPicker::make('DISCORD_EMBED_COLOR') ->label('Color') ->default(env('DISCORD_EMBED_COLOR', '#024cc4')), + TextInput::make('DISCORD_EMBED_IMAGE') + ->label('Image') + ->url() + ->placeholder('https://pelican.dev/img/logo.png') + ->default(env('DISCORD_EMBED_IMAGE', 'https://pelican.dev/img/logo.png')), ]), ]; } diff --git a/app/Listeners/Webhook/EggWebhookListener.php b/app/Listeners/Webhook/EggWebhookListener.php index 646ddd1894..12c428ec44 100644 --- a/app/Listeners/Webhook/EggWebhookListener.php +++ b/app/Listeners/Webhook/EggWebhookListener.php @@ -65,7 +65,6 @@ protected function handleEggCreated($event) [ 'author' => [ 'name' => $appName, - 'icon_url' => 'https://pelican.dev/img/logo.png', 'url' => $Url, ], 'title' => 'Egg Added', @@ -115,7 +114,6 @@ protected function handleEggDeleted($event) [ 'author' => [ 'name' => $appName, - 'icon_url' => 'https://pelican.dev/img/logo.png', 'url' => $Url, ], 'title' => 'Egg Deleted', diff --git a/app/Listeners/Webhook/ServerWebhookListener.php b/app/Listeners/Webhook/ServerWebhookListener.php index d800727099..2874a42b49 100644 --- a/app/Listeners/Webhook/ServerWebhookListener.php +++ b/app/Listeners/Webhook/ServerWebhookListener.php @@ -65,7 +65,6 @@ protected function handleServerCreated($event) [ 'author' => [ 'name' => $appName, - 'icon_url' => 'https://pelican.dev/img/logo.png', 'url' => $Url, ], 'title' => 'Server Created', @@ -115,7 +114,6 @@ protected function handleServerDeleted($event) [ 'author' => [ 'name' => $appName, - 'icon_url' => 'https://pelican.dev/img/logo.png', 'url' => $APP_URL, ], 'title' => 'Server Deleted', diff --git a/app/Listeners/Webhook/UserWebhookListener.php b/app/Listeners/Webhook/UserWebhookListener.php index 1c5d187080..99f581ec19 100644 --- a/app/Listeners/Webhook/UserWebhookListener.php +++ b/app/Listeners/Webhook/UserWebhookListener.php @@ -63,7 +63,6 @@ protected function handleUserCreated($event) [ 'author' => [ 'name' => $appName, - 'icon_url' => 'https://pelican.dev/img/logo.png', 'url' => $Url, ], 'title' => 'User Created', @@ -113,7 +112,6 @@ protected function handleUserDeleted($event) [ 'author' => [ 'name' => $appName, - 'icon_url' => 'https://pelican.dev/img/logo.png', 'url' => $Url, ], 'title' => 'User Deleted', diff --git a/app/Traits/SendWebhook.php b/app/Traits/SendWebhook.php index a4853f2a51..f800e2deef 100644 --- a/app/Traits/SendWebhook.php +++ b/app/Traits/SendWebhook.php @@ -62,11 +62,13 @@ public function send($webhook, $message) ]); } elseif (env('WEBHOOK_TYPE') === 'discord') { $color = env('DISCORD_EMBED_COLOR', '#024cc4'); + $image = env('DISCORD_EMBED_IMAGE', 'https://pelican.dev/img/logo.png'); $payload = [ 'username' => env('APP_NAME'), - 'avatar_url' => 'https://pelican.dev/img/logo.png', - 'embeds' => array_map(function ($embed) use ($color) { + 'avatar_url' => env('DISCORD_EMBED_IMAGE', 'https://pelican.dev/img/logo.png'), + 'embeds' => array_map(function ($embed) use ($color, $image) { $embed['color'] = hexdec($color); + $embed['author']['icon_url'] = $image; return $embed; }, $message['embeds'] ?? []),