From ceb9a03460191b312f7196a0fa93786c3bb5fbeb Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 21 Feb 2024 08:04:42 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20message=20button=20sty?= =?UTF-8?q?le=20support=20=F0=9F=8E=A8=20Improve=20message=20file=20method?= =?UTF-8?q?=20naming=20conventions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Discord/Message.php | 45 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Discord/Message.php b/src/Discord/Message.php index ac8ae67..ece1d57 100644 --- a/src/Discord/Message.php +++ b/src/Discord/Message.php @@ -377,34 +377,34 @@ public function body(string $body = ''): self } /** - * Add a file to the message. + * Add a file from content to the message. */ - public function file(string $path, string $filename = ''): self + public function file(string $content = '', string $filename = ''): self { - if (! file_exists($path)) { - $this->bot->console()->error("File {$path} does not exist"); - - return $this; - } - - $filename = $filename ?? basename($path); + $filename = $filename ?? 'file.txt'; - $this->rawFile(file_get_contents($path), $filename); + $this->files[] = [ + 'content' => $content, + 'filename' => $filename, + ]; return $this; } /** - * Add a file from content to the message. + * Add a file to the message. */ - public function rawFile(string $content = '', string $filename = ''): self + public function filePath(string $path, string $filename = ''): self { - $filename = $filename ?? 'file.txt'; + if (! file_exists($path)) { + $this->bot->console()->error("File {$path} does not exist"); - $this->files[] = [ - 'content' => $content, - 'filename' => $filename, - ]; + return $this; + } + + $filename = $filename ?? basename($path); + + $this->file(file_get_contents($path), $filename); return $this; } @@ -604,8 +604,17 @@ public function components(array $components): self /** * Add a URL button to the message. */ - public function button(string $label, mixed $value, mixed $emoji = null, ?int $style = null, array $options = []): self + public function button(string $label, mixed $value, mixed $emoji = null, ?string $style = null, array $options = []): self { + $style = match ($style) { + 'link' => Button::STYLE_LINK, + 'primary' => Button::STYLE_PRIMARY, + 'secondary' => Button::STYLE_SECONDARY, + 'success' => Button::STYLE_SUCCESS, + 'danger' => Button::STYLE_DANGER, + default => $style, + }; + $style = $style ?? (is_string($value) ? Button::STYLE_LINK : Button::STYLE_PRIMARY); $button = Button::new($style)