From d2896754ededf8f18648f70e876f9d29eece8147 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Tue, 23 Jul 2024 23:20:45 +0700 Subject: [PATCH] pyrofork: Add recent_voters field to Poll Signed-off-by: wulan17 --- pyrogram/dispatcher.py | 2 +- pyrogram/methods/messages/retract_vote.py | 2 +- pyrogram/methods/messages/stop_poll.py | 2 +- pyrogram/methods/messages/vote_poll.py | 2 +- pyrogram/types/messages_and_media/message.py | 2 +- pyrogram/types/messages_and_media/poll.py | 29 +++++++++++++++++--- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py index f6e522c28..d312cb9c5 100644 --- a/pyrogram/dispatcher.py +++ b/pyrogram/dispatcher.py @@ -171,7 +171,7 @@ async def inline_query_parser(update, users, chats): async def poll_parser(update, users, chats): return ( - pyrogram.types.Poll._parse_update(self.client, update), + await pyrogram.types.Poll._parse_update(self.client, update, users), PollHandler ) diff --git a/pyrogram/methods/messages/retract_vote.py b/pyrogram/methods/messages/retract_vote.py index c81c176cd..09c4efe0e 100644 --- a/pyrogram/methods/messages/retract_vote.py +++ b/pyrogram/methods/messages/retract_vote.py @@ -60,4 +60,4 @@ async def retract_vote( ) ) - return types.Poll._parse(self, r.updates[0]) + return await types.Poll._parse(self, r.updates[0], r.users) diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py index 8a20c8ab8..9c7bfd786 100644 --- a/pyrogram/methods/messages/stop_poll.py +++ b/pyrogram/methods/messages/stop_poll.py @@ -87,4 +87,4 @@ async def stop_poll( else: r = await self.invoke(rpc) - return types.Poll._parse(self, r.updates[0]) + return await types.Poll._parse(self, r.updates[0], r.users) diff --git a/pyrogram/methods/messages/vote_poll.py b/pyrogram/methods/messages/vote_poll.py index 042fd45bf..659f2220b 100644 --- a/pyrogram/methods/messages/vote_poll.py +++ b/pyrogram/methods/messages/vote_poll.py @@ -68,4 +68,4 @@ async def vote_poll( ) ) - return types.Poll._parse(self, r.updates[0]) + return await types.Poll._parse(self, r.updates[0], r.users) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index d88a78bcb..967a5c9bb 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -1086,7 +1086,7 @@ async def _parse( else: media = None elif isinstance(media, raw.types.MessageMediaPoll): - poll = types.Poll._parse(client, media) + poll = await types.Poll._parse(client, media) media_type = enums.MessageMediaType.POLL elif isinstance(media, raw.types.MessageMediaDice): dice = types.Dice._parse(client, media) diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py index c423e8b3b..e8c988eb2 100644 --- a/pyrogram/types/messages_and_media/poll.py +++ b/pyrogram/types/messages_and_media/poll.py @@ -78,6 +78,9 @@ class Poll(Object, Update): close_date (:py:obj:`~datetime.datetime`, *optional*): Point in time when the poll will be automatically closed. + + recent_voters (List of :obj:`~pyrogram.types.User`, *optional*): + List of user whos recently vote. """ def __init__( @@ -98,7 +101,8 @@ def __init__( explanation: Optional[str] = None, explanation_entities: Optional[List["types.MessageEntity"]] = None, open_period: Optional[int] = None, - close_date: Optional[datetime] = None + close_date: Optional[datetime] = None, + recent_voters: List["types.User"] = None ): super().__init__(client) @@ -117,9 +121,14 @@ def __init__( self.explanation_entities = explanation_entities self.open_period = open_period self.close_date = close_date + self.recent_voters = recent_voters @staticmethod - def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.UpdateMessagePoll"]) -> "Poll": + async def _parse( + client, + media_poll: Union["raw.types.MessageMediaPoll", "raw.types.UpdateMessagePoll"], + users: List["raw.base.User"] + ) -> "Poll": poll: raw.types.Poll = media_poll.poll poll_results: raw.types.PollResults = media_poll.results results: List[raw.types.PollAnswerVoters] = poll_results.results @@ -176,13 +185,21 @@ def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.Up ] if poll_results.solution_entities else None, open_period=poll.close_period, close_date=utils.timestamp_to_datetime(poll.close_date), + recent_voters=[ + await client.get_users(user.user_id) + for user in poll_results.recent_voters + ] if poll_results.recent_voters else None, client=client ) @staticmethod - def _parse_update(client, update: "raw.types.UpdateMessagePoll"): + async def _parse_update( + client, + update: "raw.types.UpdateMessagePoll", + users: List["raw.base.User"] + ) -> "Poll": if update.poll is not None: - return Poll._parse(client, update) + return await Poll._parse(client, update, users) results = update.results.results chosen_option_id = None @@ -213,6 +230,10 @@ def _parse_update(client, update: "raw.types.UpdateMessagePoll"): is_closed=False, chosen_option_id=chosen_option_id, correct_option_id=correct_option_id, + recent_voters=[ + types.User._parse(client, users.get(user.user_id, None)) + for user in update.results.recent_voters + ] if update.results.recent_voters else None, client=client )