Skip to content

Commit

Permalink
Update DiscordDriver.php
Browse files Browse the repository at this point in the history
  • Loading branch information
nhantamz authored Jul 21, 2022
1 parent 030825b commit ca7645b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/DiscordDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct(array $config, Discord $client)
*/
public function connected()
{
$this->bot_id = $this->client->user->tag;
}

/**
Expand Down Expand Up @@ -88,7 +89,7 @@ public function hasMatchingEvent()
*/
public function getConversationAnswer(IncomingMessage $message)
{
return Answer::create($this->message->content)->setMessage($message);
return Answer::create($this->message->content ?? null)->setMessage($message);
}

/**
Expand All @@ -98,9 +99,9 @@ public function getConversationAnswer(IncomingMessage $message)
*/
public function getMessages()
{
$messageText = $this->message->content;
$user_id = $this->message->author->id;
$channel_id = $this->message->channel->id;
$messageText = $this->message->content ?? null;
$user_id = $this->message->author->id ?? null;
$channel_id = $this->message->channel->id ?? null;

$message = new IncomingMessage($messageText, $user_id, $channel_id, $this->message);
$message->setIsFromBot($this->isBot());
Expand All @@ -113,7 +114,7 @@ public function getMessages()
*/
protected function isBot()
{
return false;
return $this->message->author->bot ?? false;;
}

/**
Expand Down Expand Up @@ -156,6 +157,10 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
*/
public function sendPayload($payload)
{
if (empty($this->message)) {
return null;
}

return $this->message->channel->sendMessage($payload['message'], false, $payload['embed']);
}

Expand Down

0 comments on commit ca7645b

Please sign in to comment.