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

πŸ§‘β€πŸ’» Change the Message send and sendTo return type to a promise #45

Merged
merged 1 commit into from
Feb 22, 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
15 changes: 9 additions & 6 deletions src/Discord/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Exception;
use Illuminate\Support\Str;
use Laracord\Laracord;
use React\Promise\ExtendedPromiseInterface;
use Throwable;

class Message
Expand Down Expand Up @@ -189,27 +190,27 @@ public function build(): MessageBuilder
/**
* Send the message.
*/
public function send(mixed $destination = null): void
public function send(mixed $destination = null): ?ExtendedPromiseInterface
{
if ($destination) {
$this->channel($destination);
}

$this->getChannel()->sendMessage($this->build());
return $this->getChannel()->sendMessage($this->build());
}

/**
* Send the message to a user.
*/
public function sendTo(mixed $user): void
public function sendTo(mixed $user): ?ExtendedPromiseInterface
{
if (is_numeric($user)) {
$member = $this->bot->discord()->users->get('id', $user);

if (! $member) {
$this->bot->console()->error("Could not find user <fg=red>{$user}</> to send message");

return;
return null;
}

$user = $member;
Expand All @@ -220,10 +221,12 @@ public function sendTo(mixed $user): void
}

if (! $user instanceof User) {
throw new Exception('You must provide a valid Discord user.');
$this->bot->console()->error('You must provide a valid Discord user.');

return null;
}

$user->sendMessage($this->build());
return $user->sendMessage($this->build());
}

/**
Expand Down
Loading