diff --git a/botogram/objects/__init__.py b/botogram/objects/__init__.py index d933881..ea64d62 100644 --- a/botogram/objects/__init__.py +++ b/botogram/objects/__init__.py @@ -22,7 +22,8 @@ from .chats import User, Chat, UserProfilePhotos, Permissions from .media import PhotoSize, Photo, Audio, Voice, Document, Sticker, \ - Video, VideoNote, Animation, Contact, Location, Venue + Video, VideoNote, Animation, Contact, Location, Venue, \ + Dice from .messages import Message from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply from .polls import Poll, PollOption @@ -62,6 +63,9 @@ "Poll", "PollOption", + # Dice-related objects + "Dice", + # Updates-related objects "Update", "Updates", diff --git a/botogram/objects/media.py b/botogram/objects/media.py index fefdb28..e7d2222 100644 --- a/botogram/objects/media.py +++ b/botogram/objects/media.py @@ -305,3 +305,15 @@ class VideoNote(BaseObject, mixins.FileMixin): "file_size": int, } _check_equality_ = "file_id" + + +class Dice(BaseObject): + """Telegram API representation of a venue + + https://core.telegram.org/bots/api#dice + """ + + required = { + "emoji": str, + "value": int + } diff --git a/botogram/objects/messages.py b/botogram/objects/messages.py index d6304ac..6c9c823 100644 --- a/botogram/objects/messages.py +++ b/botogram/objects/messages.py @@ -28,7 +28,7 @@ from ..api import ChatUnavailableError from .chats import User, Chat from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \ - Animation, Contact, Location, Venue + Animation, Contact, Location, Venue, Dice from .polls import Poll @@ -356,6 +356,7 @@ def from_(self): "location": Location, "venue": Venue, "poll": Poll, + "dice": Dice, "new_chat_member": User, "left_chat_member": User, "new_chat_title": str, diff --git a/botogram/objects/mixins.py b/botogram/objects/mixins.py index 61e9a6e..7328cfc 100644 --- a/botogram/objects/mixins.py +++ b/botogram/objects/mixins.py @@ -381,6 +381,16 @@ def send_poll(self, question, *kargs, reply_to=None, extra=None, return self._api.call("sendPoll", args, expect=_objects().Message) + @_require_api + def send_dice(self, emoji=None, reply_to=None, extra=None, attach=None, + notify=True): + """Send a dice""" + args = self._get_call_args(reply_to, extra, attach, notify) + if emoji is not None: + args["emoji"] = emoji + + return self._api.call("sendDice", args, expect=_objects().Message) + @_require_api def delete_message(self, message): """Delete a message from chat""" @@ -662,6 +672,11 @@ def reply_with_poll(self, *args, **kwargs): """Reply with a poll to the current message""" return self.chat.send_poll(*args, reply_to=self, **kwargs) + @_require_api + def reply_with_dice(self, *args, **kwargs): + """Reply with a dice to the current message""" + return self.chat.send_dice(*args, reply_to=self, **kwargs) + @_require_api def delete(self): """Delete the message""" diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index a83dcc0..03dbf31 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1529,6 +1529,21 @@ about its business. .. versionadded:: 0.7 + .. py:method:: send_dice([emoji=None, reply_to=None, extra=None, attach=None, notify=True]) + + Use this method to send a dice, which will have a random value from 1-6 for “🎲” and “🎯” base emoji, + 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji + + :param str emoji: Emoji on which the dice throw animation is based. Currently, must be either “🎲”, “🎯”, "🏀", "⚽" or "🎰". Defaults to “🎲” + :param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to + :param object attach: An extra thing to attach to the message + :param object extra: An extra reply interface object to attach + :param bool notify: If you want to trigger a notification on the client + :returns: The message you sent + :rtype: ~botogram.Message + + .. versionadded:: 0.7 + .. py:method:: delete_message(message) Delete the message with the provided ID or :py:class:`~botogram.Message` object. @@ -1875,6 +1890,12 @@ about its business. *This attribute can be None if the message isn't a venue.* + .. py:attribute:: dice + + A :py:class:`~botogram.Dice` object, when this message is a dice + + *This attribute can be None if it's not provided by Telegram.* + .. py:attribute:: channel_post_author The author of the message. This only works if the message is a channel @@ -2550,6 +2571,20 @@ about its business. .. versionadded:: 0.7 + .. py:method:: reply_with_dice([emoji=None, extra=None, attach=None, notify=True]) + + Use this method to reply with a dice,which will have a random value from 1-6 for “🎲” and “🎯” base emoji, + 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji + + :param str emoji: Emoji on which the dice throw animation is based. Currently, must be either “🎲”, “🎯”, "🏀", "⚽" or "🎰". Defaults to “🎲” + :param object attach: An extra thing to attach to the message + :param object extra: An extra reply interface object to attach + :param bool notify: If you want to trigger a notification on the client + :returns: The message you sent + :rtype: ~botogram.Message + + .. versionadded:: 0.7 + .. py:class:: botogram.Photo This class provides a general representation of a photo received by your bot. @@ -3158,6 +3193,21 @@ about its business. Number of users that voted for this option. +.. py:class:: botogram.Dice + + This object represents a dice with a random value from 1 to 6 (or 1 to 5) for currently supported base emoji. + + .. py:attribute:: emoji + + Emoji on which the dice throw animation is based + + .. py:attribute:: value + + Value of the dice, 1-6, 1-5 or 1-64 for currently supported base emoji + + .. versionadded:: 0.7 + + .. py:class:: botogram.InlineQuery This class represents an inline query update received by the bot. diff --git a/docs/changelog/0.7.rst b/docs/changelog/0.7.rst index a19e0ea..8014a0b 100644 --- a/docs/changelog/0.7.rst +++ b/docs/changelog/0.7.rst @@ -19,6 +19,14 @@ Release description not yet written. New features ------------ +* Added support fo dice + + * New :py:class:`botogram.Dice` class + * New attribute :py:attr:`botogram.Message.dice` + * New method :py:meth:`botogram.Chat.send_dice` + * New method :py:meth:`botogram.User.send_dice` + * New method :py:meth:`botogram.Message.reply_with_dice` + * Added support for inline mode