2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Handle minified poll updates

This commit is contained in:
Dan 2019-05-05 15:44:53 +02:00
parent bfda5852b6
commit 6f2c625cd1
2 changed files with 35 additions and 4 deletions

View File

@ -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}

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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
)