2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Update vote_poll to allow voting for multiple options

This commit is contained in:
Dan 2020-02-01 15:21:35 +01:00
parent 88f681f0fd
commit aa1c0e226e

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union from typing import Union, List
import pyrogram import pyrogram
from pyrogram.api import functions from pyrogram.api import functions
@ -28,7 +28,7 @@ class VotePoll(BaseClient):
self, self,
chat_id: Union[int, str], chat_id: Union[int, str],
message_id: id, message_id: id,
option: int options: Union[int, List[int]]
) -> "pyrogram.Poll": ) -> "pyrogram.Poll":
"""Vote a poll. """Vote a poll.
@ -41,8 +41,8 @@ class VotePoll(BaseClient):
message_id (``int``): message_id (``int``):
Identifier of the original message with the poll. Identifier of the original message with the poll.
option (``int``): options (``Int`` | List of ``int``):
Index of the poll option you want to vote for (0 to 9). Index or list of indexes (for multiple answers) of the poll option(s) you want to vote for (0 to 9).
Returns: Returns:
:obj:`Poll` - On success, the poll with the chosen option is returned. :obj:`Poll` - On success, the poll with the chosen option is returned.
@ -54,12 +54,13 @@ class VotePoll(BaseClient):
""" """
poll = self.get_messages(chat_id, message_id).poll poll = self.get_messages(chat_id, message_id).poll
options = [options] if not isinstance(options, list) else options
r = self.send( r = self.send(
functions.messages.SendVote( functions.messages.SendVote(
peer=self.resolve_peer(chat_id), peer=self.resolve_peer(chat_id),
msg_id=message_id, msg_id=message_id,
options=[poll.options[option]._data] options=[poll.options[option].data for option in options]
) )
) )