From ca46090f2791d83df153d57cffde621e1824172d Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 18 Jun 2024 17:52:29 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8E=A8=20Make=20`SlashCommand::value(?= =?UTF-8?q?)`=20protected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Commands/SlashCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/SlashCommand.php b/src/Commands/SlashCommand.php index 5e99c61..277c9a4 100644 --- a/src/Commands/SlashCommand.php +++ b/src/Commands/SlashCommand.php @@ -206,7 +206,7 @@ protected function option(?string $key = null, mixed $default = null): mixed /** * Retrieve the option value. */ - public function value(?string $option = null, mixed $default = null): mixed + protected function value(?string $option = null, mixed $default = null): mixed { $options = $this->flattenOptions($this->getOptions()); From d6e1d2a3fb9c70d6bf1cb1b3f1572120c68320d0 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 18 Jun 2024 17:53:35 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20c?= =?UTF-8?q?onditional=20methods=20to=20Message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Discord/Message.php | 60 ++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/src/Discord/Message.php b/src/Discord/Message.php index 0032d4d..74505ab 100644 --- a/src/Discord/Message.php +++ b/src/Discord/Message.php @@ -203,21 +203,21 @@ public function build(): MessageBuilder ->setContent($this->body) ->setComponents($this->getComponents()); - if ($this->content || $this->fields) { + if ($this->hasContent() || $this->hasFields()) { $message->addEmbed($this->getEmbed()); } - if ($this->selects) { + if ($this->hasSelects()) { foreach ($this->selects as $select) { $message->addComponent($select); } } - if ($this->buttons) { + if ($this->hasButtons()) { $message->addComponent($this->getButtons()); } - if ($this->files) { + if ($this->hasFiles()) { foreach ($this->files as $file) { $message->addFileFromContent($file['filename'], $file['content']); } @@ -383,7 +383,7 @@ public function getComponents(): array */ public function getButtons() { - if (empty($this->buttons)) { + if (! $this->hasButtons()) { return; } @@ -450,6 +450,14 @@ public function content(?string $content): self return $this; } + /** + * Determine if the message has content. + */ + public function hasContent(): bool + { + return ! empty($this->content); + } + /** * Set the message avatar. */ @@ -531,6 +539,14 @@ public function filePath(string $path, string $filename = ''): self return $this; } + /** + * Determine if the message has files. + */ + public function hasFiles(): bool + { + return ! empty($this->files); + } + /** * Set the message color. */ @@ -765,6 +781,14 @@ public function clearFields(): self return $this; } + /** + * Determine if the message has fields. + */ + public function hasFields(): bool + { + return ! empty($this->fields); + } + /** * Set the message components. */ @@ -854,6 +878,24 @@ public function select( return $this; } + /** + * Clear the select menus from the message. + */ + public function clearSelects(): self + { + $this->selects = []; + + return $this; + } + + /** + * Determine if the message has select menus. + */ + public function hasSelects(): bool + { + return ! empty($this->selects); + } + /** * Add a button to the message. */ @@ -950,13 +992,11 @@ public function clearButtons(): self } /** - * Clear the select menus from the message. + * Determine if the message has buttons. */ - public function clearSelects(): self + public function hasButtons(): bool { - $this->selects = []; - - return $this; + return ! empty($this->buttons); } /**