From c9bbeec5255af24376162266e712eabf00eef4a1 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Fri, 29 Nov 2024 13:19:57 +0700 Subject: [PATCH] pyrofork: Refactor Poll Signed-off-by: wulan17 --- pyrogram/types/messages_and_media/poll.py | 35 ++++++++++++------- .../types/messages_and_media/poll_option.py | 6 ++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py index e8c988eb..20a3923e 100644 --- a/pyrogram/types/messages_and_media/poll.py +++ b/pyrogram/types/messages_and_media/poll.py @@ -158,14 +158,22 @@ class Poll(Object, Update): text=answer.text.text, voter_count=voter_count, data=answer.option, - entities=option_entities, - client=client + entities=option_entities ) ) q_entities = [types.MessageEntity._parse(client, entity, {}) for entity in poll.question.entities] if poll.question.entities else [] question_entities = types.List(filter(lambda x: x is not None, q_entities)) + recent_voters = [] + for user in poll_results.recent_voters: + try: + voter = types.User._parse(client, users.get(user.user_id, None)) + except Exception: + pass + else: + recent_voters.append(voter) + return Poll( id=str(poll.id), question=poll.question.text, @@ -185,10 +193,7 @@ class Poll(Object, Update): ] 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, + recent_voters=recent_voters if len(recent_voters) > 0 else None, client=client ) @@ -217,11 +222,20 @@ class Poll(Object, Update): types.PollOption( text="", voter_count=result.voters, - data=result.option, - client=client + data=result.option ) ) + recent_voters = [] + if update.results.recent_voters: + for user in update.results.recent_voters: + try: + voter = types.User._parse(client, users.get(user.user_id, None)) + except Exception: + pass + else: + recent_voters.append(voter) + return Poll( id=str(update.poll_id), question="", @@ -230,10 +244,7 @@ class Poll(Object, Update): 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, + recent_voters=recent_voters if len(recent_voters) > 0 else None, client=client ) diff --git a/pyrogram/types/messages_and_media/poll_option.py b/pyrogram/types/messages_and_media/poll_option.py index da46b4c6..30d50c0e 100644 --- a/pyrogram/types/messages_and_media/poll_option.py +++ b/pyrogram/types/messages_and_media/poll_option.py @@ -41,15 +41,13 @@ class PollOption(Object): """ def __init__( - self, - *, - client: "pyrogram.Client" = None, + self: "pyrogram.Client", text: str, voter_count: int = 0, data: bytes = None, entities: Optional[List["pyrogram.types.MessageEntity"]] = None, ): - super().__init__(client) + super().__init__(self) self.text = text self.voter_count = voter_count