From 2a05013f6670748cb6827bcbaada2edd932fa845 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 4 Jun 2021 15:16:36 -0400 Subject: [PATCH] Discord: Only add fields and footer if they're not empty --- .../Channels/Discord/DiscordMessage.php | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/app/Notifications/Channels/Discord/DiscordMessage.php b/app/Notifications/Channels/Discord/DiscordMessage.php index 9dbebfd9..3875e9db 100644 --- a/app/Notifications/Channels/Discord/DiscordMessage.php +++ b/app/Notifications/Channels/Discord/DiscordMessage.php @@ -119,22 +119,27 @@ class DiscordMessage public function toArray(): array { + $embeds = [ + 'title' => $this->title, + 'url' => $this->url, + 'type' => 'rich', + 'description' => $this->description, + 'author' => $this->author, + 'timestamp' => Carbon::now('UTC'), + ]; + + if (!empty($this->fields)) { + $embeds['fields'] = $this->fields; + } + + if (!empty($this->footer)) { + $embeds['footer'] = [ + 'text' => $this->footer, + ]; + } + return [ - 'embeds' => [ - [ - 'title' => $this->title, - 'url' => $this->url, - 'type' => 'rich', - 'description' => $this->description, - // 'color' => hexdec($this->color), - 'author' => $this->author, - 'fields' => $this->fields, - 'footer' => [ - 'text' => $this->footer ?? '', - ], - 'timestamp' => Carbon::now('UTC'), - ], - ], + 'embeds' => [$embeds], ]; } }