Skip to content

Commit

Permalink
🎨 Improve Poll::addAnswer when passed an array
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Jul 18, 2024
1 parent a4c8b6b commit 42226c2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Discord/Parts/Channel/Poll/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ public function addAnswer(PollAnswer|PollMedia|array|string $answer): self
return $this;
}

$answer = is_string($answer)
? ['text' => $answer]
: $answer;
$text = is_string($answer)
? $answer
: $answer['text'];

$emoji = $answer['emoji'] ?? null;

$answer = $answer instanceof PollMedia
? $answer
: new PollMedia($this->discord, $answer);
: new PollMedia($this->discord);

$answer
->setText($text)
->setEmoji($emoji);

if (poly_strlen($answer->text) > 55) {
throw new \LengthException('Answer must be maximum 55 characters.');
Expand Down

0 comments on commit 42226c2

Please sign in to comment.