Skip to content

Commit 6f2c625

Browse files
committed
Handle minified poll updates
1 parent bfda585 commit 6f2c625

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

pyrogram/client/ext/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, client, workers: int):
8282
lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler),
8383

8484
(types.UpdateMessagePoll,):
85-
lambda upd, usr, cht: (pyrogram.Poll._parse(self.client, upd), PollHandler)
85+
lambda upd, usr, cht: (pyrogram.Poll._parse_update(self.client, upd), PollHandler)
8686
}
8787

8888
self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}

pyrogram/client/types/messages_and_media/poll.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import List
19+
from typing import List, Union
2020

2121
import pyrogram
2222
from pyrogram.api import types
@@ -71,12 +71,11 @@ def __init__(
7171
self.chosen_option = chosen_option
7272

7373
@staticmethod
74-
def _parse(client, media_poll: types.MessageMediaPoll) -> "Poll":
74+
def _parse(client, media_poll: Union[types.MessageMediaPoll, types.UpdateMessagePoll]) -> "Poll":
7575
poll = media_poll.poll
7676
results = media_poll.results.results
7777
total_voters = media_poll.results.total_voters
7878
chosen_option = None
79-
8079
options = []
8180

8281
for i, answer in enumerate(poll.answers):
@@ -107,3 +106,35 @@ def _parse(client, media_poll: types.MessageMediaPoll) -> "Poll":
107106
chosen_option=chosen_option,
108107
client=client
109108
)
109+
110+
@staticmethod
111+
def _parse_update(client, update: types.UpdateMessagePoll):
112+
if update.poll is not None:
113+
return Poll._parse(client, update)
114+
115+
results = update.results.results
116+
chosen_option = None
117+
options = []
118+
119+
for i, result in enumerate(results):
120+
if result.chosen:
121+
chosen_option = i
122+
123+
options.append(
124+
PollOption(
125+
text="",
126+
voter_count=result.voters,
127+
data=result.option,
128+
client=client
129+
)
130+
)
131+
132+
return Poll(
133+
id=str(update.poll_id),
134+
question="",
135+
options=options,
136+
is_closed=False,
137+
total_voters=update.results.total_voters,
138+
chosen_option=chosen_option,
139+
client=client
140+
)

0 commit comments

Comments
 (0)