Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Improve message button style support #43

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions src/Discord/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fg=red>{$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 <fg=red>{$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;
}
Expand Down Expand Up @@ -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)
Expand Down
Loading