From 5b042a65467f83a11be595b08854353d6cfc1370 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 24 Apr 2020 15:51:40 +0200 Subject: [PATCH] Add support for darts mini-game with send_dice --- pyrogram/client/methods/messages/send_dice.py | 11 ++++++++++- pyrogram/client/types/messages_and_media/dice.py | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/methods/messages/send_dice.py b/pyrogram/client/methods/messages/send_dice.py index c5f95d4b..f90bc852 100644 --- a/pyrogram/client/methods/messages/send_dice.py +++ b/pyrogram/client/methods/messages/send_dice.py @@ -27,6 +27,7 @@ class SendDice(BaseClient): def send_dice( self, chat_id: Union[int, str], + emoji: str = "🎲", disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, @@ -45,6 +46,10 @@ class SendDice(BaseClient): For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). + emoji (``str``, *optional*): + Emoji on which the dice throw animation is based. Currently, must be one of "🎲" or "🎯". + Defauts to "🎲". + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -65,13 +70,17 @@ class SendDice(BaseClient): Example: .. code-block:: python + # Send a dice app.send_dice("pyrogramlounge") + + # Send a dart + app.send_dice("pyrogramlounge", "🎯") """ r = self.send( functions.messages.SendMedia( peer=self.resolve_peer(chat_id), - media=types.InputMediaDice(), + media=types.InputMediaDice(emoticon=emoji), silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), diff --git a/pyrogram/client/types/messages_and_media/dice.py b/pyrogram/client/types/messages_and_media/dice.py index c579a890..7552f083 100644 --- a/pyrogram/client/types/messages_and_media/dice.py +++ b/pyrogram/client/types/messages_and_media/dice.py @@ -27,18 +27,26 @@ from ...ext.utils import encode_file_id, encode_file_ref class Dice(Object): - """A dice containing a value that is randomly generated by Telegram. + """A dice with a random value from 1 to 6 for currently supported base emoji. Parameters: + emoji (``string``): + Emoji on which the dice throw animation is based. + value (``int``): - Dice value, 1-6. + Value of the dice, 1-6 for currently supported base emoji. """ - def __init__(self, *, client: "pyrogram.BaseClient" = None, value: int): + def __init__(self, *, client: "pyrogram.BaseClient" = None, emoji: str, value: int): super().__init__(client) + self.emoji = emoji self.value = value @staticmethod def _parse(client, dice: types.MessageMediaDice) -> "Dice": - return Dice(value=dice.value, client=client) + return Dice( + emoji=dice.emoticon, + value=dice.value, + client=client + )