|
16 | 16 | # You should have received a copy of the GNU Lesser General Public License |
17 | 17 | # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
|
19 | | -from typing import List |
| 19 | +from typing import List, Union |
20 | 20 |
|
21 | 21 | import pyrogram |
22 | 22 | from pyrogram.api import types |
@@ -71,12 +71,11 @@ def __init__( |
71 | 71 | self.chosen_option = chosen_option |
72 | 72 |
|
73 | 73 | @staticmethod |
74 | | - def _parse(client, media_poll: types.MessageMediaPoll) -> "Poll": |
| 74 | + def _parse(client, media_poll: Union[types.MessageMediaPoll, types.UpdateMessagePoll]) -> "Poll": |
75 | 75 | poll = media_poll.poll |
76 | 76 | results = media_poll.results.results |
77 | 77 | total_voters = media_poll.results.total_voters |
78 | 78 | chosen_option = None |
79 | | - |
80 | 79 | options = [] |
81 | 80 |
|
82 | 81 | for i, answer in enumerate(poll.answers): |
@@ -107,3 +106,35 @@ def _parse(client, media_poll: types.MessageMediaPoll) -> "Poll": |
107 | 106 | chosen_option=chosen_option, |
108 | 107 | client=client |
109 | 108 | ) |
| 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