Skip to content

Commit

Permalink
Add configurable embed image URL for Discord webhooks
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Poseidon281 committed Aug 3, 2024
1 parent f0e97d2 commit f1e4bd8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
]),
];
}
Expand Down
2 changes: 0 additions & 2 deletions app/Listeners/Webhook/EggWebhookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ protected function handleEggCreated($event)
[
'author' => [
'name' => $appName,
'icon_url' => 'https://pelican.dev/img/logo.png',
'url' => $Url,
],
'title' => 'Egg Added',
Expand Down Expand Up @@ -115,7 +114,6 @@ protected function handleEggDeleted($event)
[
'author' => [
'name' => $appName,
'icon_url' => 'https://pelican.dev/img/logo.png',
'url' => $Url,
],
'title' => 'Egg Deleted',
Expand Down
2 changes: 0 additions & 2 deletions app/Listeners/Webhook/ServerWebhookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ protected function handleServerCreated($event)
[
'author' => [
'name' => $appName,
'icon_url' => 'https://pelican.dev/img/logo.png',
'url' => $Url,
],
'title' => 'Server Created',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions app/Listeners/Webhook/UserWebhookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected function handleUserCreated($event)
[
'author' => [
'name' => $appName,
'icon_url' => 'https://pelican.dev/img/logo.png',
'url' => $Url,
],
'title' => 'User Created',
Expand Down Expand Up @@ -113,7 +112,6 @@ protected function handleUserDeleted($event)
[
'author' => [
'name' => $appName,
'icon_url' => 'https://pelican.dev/img/logo.png',
'url' => $Url,
],
'title' => 'User Deleted',
Expand Down
6 changes: 4 additions & 2 deletions app/Traits/SendWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? []),
Expand Down

0 comments on commit f1e4bd8

Please sign in to comment.