diff --git a/src/APnutI.php b/src/APnutI.php index f4bd3ee..7b2e46c 100644 --- a/src/APnutI.php +++ b/src/APnutI.php @@ -511,9 +511,26 @@ class APnutI } } - public function getAvatar(int $user_id, array $args = []): array + public function getAvatar(int $user_id, array $args = []): string { - return $this->get('/users/'.$user_id.'/avatar', $args); + //get returns an array with the url at idx 0 + return $this->get('/users/'.$user_id.'/avatar', $args)[0]; + } + + public function getAvatarUrl( + int $user_id, + ?int $width = null, + ?int $height = null + ): string { + //get returns an array with the url at idx 0 + $args = []; + if (!empty($width)) { + $args['w'] = $width; + } + if (!empty($height)) { + $args['h'] = $height; + } + return $this->get('/users/'.$user_id.'/avatar', $args)[0]; } public function updateAvatar( diff --git a/src/Entities/Poll.php b/src/Entities/Poll.php index 2c00d04..ba93fe0 100644 --- a/src/Entities/Poll.php +++ b/src/Entities/Poll.php @@ -25,7 +25,8 @@ class Poll 'general.poll', 'net.unsweets.beta', 'io.pnut.core.poll', - 'io.broadsword.poll' + 'io.broadsword.poll', + 'nl.chimpnut.quizbot.attachment.poll' ]; public function __construct(array $data) @@ -42,29 +43,41 @@ class Poll $this->token = $val['poll_token']; $this->prompt = $val['prompt']; } elseif (in_array($data['type'], Poll::$poll_types)) { - $this->created_at = new \DateTime($data['created_at']); - $this->closed_at = new \DateTime($data['closed_at']); - $this->id = (int)$data['id']; - $this->is_anonymous = (bool)$data['is_anonymous']; - $this->is_public = (bool)$data['is_public']; - foreach ($data['options'] as $option) { - $this->options[] = new PollOption($option); - } - if (!empty($data['poll_token'])) { - $this->token = $data['poll_token']; - } - $this->prompt = $data['prompt']; - if (!empty($data['user'])) { - $this->user = new User($data['user']); - } - if (!empty($data['source'])) { - $this->source = new Source($data['source']); + $this->parsePoll($data); + } elseif (strpos($data['type'], '.poll') !== false) { + // Try parsing unknown types if they *might* be a poll + try { + $this->parsePoll($data); + } catch (\Exception $e) { + throw new NotSupportedPollException($data['type']); } } else { throw new NotSupportedPollException($data['type']); } } + private function parsePoll(array $data) + { + $this->created_at = new \DateTime($data['created_at']); + $this->closed_at = new \DateTime($data['closed_at']); + $this->id = (int)$data['id']; + $this->is_anonymous = (bool)$data['is_anonymous']; + $this->is_public = (bool)$data['is_public']; + foreach ($data['options'] as $option) { + $this->options[] = new PollOption($option); + } + if (!empty($data['poll_token'])) { + $this->token = $data['poll_token']; + } + $this->prompt = $data['prompt']; + if (!empty($data['user'])) { + $this->user = new User($data['user']); + } + if (!empty($data['source'])) { + $this->source = new Source($data['source']); + } + } + /** * Returns the most voted option. If multiple options have the same amount * of voted, return all of them. Always returns an array!