Skip to content

Commit af20359

Browse files
committed
Update Poll object for Polls 2.0
1 parent aa1c0e2 commit af20359

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

  • pyrogram/client/types/messages_and_media

pyrogram/client/types/messages_and_media/poll.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,20 @@ class Poll(Object, Update):
3838
options (List of :obj:`PollOption`):
3939
List of poll options.
4040
41+
total_voter_count (``int``):
42+
Total number of users that voted in the poll.
43+
4144
is_closed (``bool``):
4245
True, if the poll is closed.
4346
44-
total_voters (``int``):
45-
Total count of voters for this poll.
47+
is_anonymous (``bool``, *optional*):
48+
True, if the poll is anonymous
49+
50+
type (``str``, *optional*):
51+
Poll type, currently can be "regular" or "quiz".
52+
53+
allows_multiple_answers (``bool``, *optional*):
54+
True, if the poll allows multiple answers.
4655
4756
chosen_option (``int``, *optional*):
4857
Index of your chosen option (0-9), None in case you haven't voted yet.
@@ -55,24 +64,31 @@ def __init__(
5564
id: str,
5665
question: str,
5766
options: List[PollOption],
67+
total_voter_count: int,
5868
is_closed: bool,
59-
total_voters: int,
69+
is_anonymous: bool = None,
70+
type: str = None,
71+
allows_multiple_answers: bool = None,
72+
# correct_option_id: int,
6073
chosen_option: int = None
6174
):
6275
super().__init__(client)
6376

6477
self.id = id
6578
self.question = question
6679
self.options = options
80+
self.total_voter_count = total_voter_count
6781
self.is_closed = is_closed
68-
self.total_voters = total_voters
82+
self.is_anonymous = is_anonymous
83+
self.type = type
84+
self.allows_multiple_answers = allows_multiple_answers
85+
# self.correct_option_id = correct_option_id
6986
self.chosen_option = chosen_option
7087

7188
@staticmethod
7289
def _parse(client, media_poll: Union[types.MessageMediaPoll, types.UpdateMessagePoll]) -> "Poll":
73-
poll = media_poll.poll
74-
results = media_poll.results.results
75-
total_voters = media_poll.results.total_voters
90+
poll = media_poll.poll # type: types.Poll
91+
results = media_poll.results.results # type: types.PollResults
7692
chosen_option = None
7793
options = []
7894

@@ -99,8 +115,11 @@ def _parse(client, media_poll: Union[types.MessageMediaPoll, types.UpdateMessage
99115
id=str(poll.id),
100116
question=poll.question,
101117
options=options,
118+
total_voter_count=media_poll.results.total_voters,
102119
is_closed=poll.closed,
103-
total_voters=total_voters,
120+
is_anonymous=not poll.public_voters,
121+
type="quiz" if poll.quiz else "regular",
122+
allows_multiple_answers=poll.multiple_choice,
104123
chosen_option=chosen_option,
105124
client=client
106125
)
@@ -131,8 +150,8 @@ def _parse_update(client, update: types.UpdateMessagePoll):
131150
id=str(update.poll_id),
132151
question="",
133152
options=options,
153+
total_voter_count=update.results.total_voters,
134154
is_closed=False,
135-
total_voters=update.results.total_voters,
136155
chosen_option=chosen_option,
137156
client=client
138157
)

0 commit comments

Comments
 (0)