diff --git a/pyrogram/client/ext/dispatcher.py b/pyrogram/client/ext/dispatcher.py index 46be47f7..1004095b 100644 --- a/pyrogram/client/ext/dispatcher.py +++ b/pyrogram/client/ext/dispatcher.py @@ -82,7 +82,7 @@ class Dispatcher: lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler), (types.UpdateMessagePoll,): - lambda upd, usr, cht: (pyrogram.Poll._parse(self.client, upd), PollHandler) + lambda upd, usr, cht: (pyrogram.Poll._parse_update(self.client, upd), PollHandler) } self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple} diff --git a/pyrogram/client/types/messages_and_media/poll.py b/pyrogram/client/types/messages_and_media/poll.py index acaf8697..fa68f669 100644 --- a/pyrogram/client/types/messages_and_media/poll.py +++ b/pyrogram/client/types/messages_and_media/poll.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import List +from typing import List, Union import pyrogram from pyrogram.api import types @@ -71,12 +71,11 @@ class Poll(PyrogramType, Update): self.chosen_option = chosen_option @staticmethod - def _parse(client, media_poll: types.MessageMediaPoll) -> "Poll": + def _parse(client, media_poll: Union[types.MessageMediaPoll, types.UpdateMessagePoll]) -> "Poll": poll = media_poll.poll results = media_poll.results.results total_voters = media_poll.results.total_voters chosen_option = None - options = [] for i, answer in enumerate(poll.answers): @@ -107,3 +106,35 @@ class Poll(PyrogramType, Update): chosen_option=chosen_option, client=client ) + + @staticmethod + def _parse_update(client, update: types.UpdateMessagePoll): + if update.poll is not None: + return Poll._parse(client, update) + + results = update.results.results + chosen_option = None + options = [] + + for i, result in enumerate(results): + if result.chosen: + chosen_option = i + + options.append( + PollOption( + text="", + voter_count=result.voters, + data=result.option, + client=client + ) + ) + + return Poll( + id=str(update.poll_id), + question="", + options=options, + is_closed=False, + total_voters=update.results.total_voters, + chosen_option=chosen_option, + client=client + )