From 5b78871743896f40c4817784ebf3e1116082f29f Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 1 May 2020 19:07:00 +0200 Subject: [PATCH 1/7] Added support for dice --- botogram/objects/__init__.py | 6 ++++- botogram/objects/media.py | 12 +++++++++ botogram/objects/messages.py | 3 ++- botogram/objects/mixins.py | 15 ++++++++++++ docs/api/telegram.rst | 47 ++++++++++++++++++++++++++++++++++++ docs/changelog/0.7.rst | 8 ++++++ 6 files changed, 89 insertions(+), 2 deletions(-) diff --git a/botogram/objects/__init__.py b/botogram/objects/__init__.py index d933881..e5903f1 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 dd8dbe4..7a5e776 100644 --- a/botogram/objects/media.py +++ b/botogram/objects/media.py @@ -304,3 +304,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.orgf/bots/api#dice + """ + + required = { + "emoji": str, + "value": int + } \ No newline at end of file diff --git a/botogram/objects/messages.py b/botogram/objects/messages.py index 2bd2110..4d84ba1 100644 --- a/botogram/objects/messages.py +++ b/botogram/objects/messages.py @@ -25,7 +25,7 @@ from .. import utils 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 @@ -353,6 +353,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 46c3957..0383878 100644 --- a/botogram/objects/mixins.py +++ b/botogram/objects/mixins.py @@ -380,6 +380,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 message""" + 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""" @@ -609,6 +619,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 poll 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 d561a3c..f6a05f4 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1526,6 +1526,20 @@ about its business. .. versionadded:: 0.7 + .. py:method:: send_dice([emoji, reply_to=None, extra=None, attach=None, notify=True]) + + Use this method to send a dice, which will have a random value from 1 to 6 + + :param str emoji: Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts 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. @@ -1856,6 +1870,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 @@ -2531,6 +2551,19 @@ about its business. .. versionadded:: 0.7 + .. py:method:: reply_with_dice([emoji, extra=None, attach=None, notify=True]) + + Use this method to reply with a dice, which will have a random value from 1 to 6 + + :param str emoji: Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts 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. @@ -3135,6 +3168,20 @@ 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 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 for currently supported base emoji + + .. versionadded:: 0.7 + .. py:class:: botogram.Update This class represents an update received by the bot. You should not need to diff --git a/docs/changelog/0.7.rst b/docs/changelog/0.7.rst index 7555957..9c578b6 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_gif` + * Added support for animations (GIFs) From 551e9c8f2dcaace7aa3318ed98805b80e434e48c Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 1 May 2020 19:10:27 +0200 Subject: [PATCH 2/7] fix pep8 --- botogram/objects/media.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botogram/objects/media.py b/botogram/objects/media.py index 7a5e776..6720668 100644 --- a/botogram/objects/media.py +++ b/botogram/objects/media.py @@ -315,4 +315,4 @@ class Dice(BaseObject): required = { "emoji": str, "value": int - } \ No newline at end of file + } From 015abf104e44561f460768c99502d00b66dffe04 Mon Sep 17 00:00:00 2001 From: matteo Date: Thu, 4 Jun 2020 21:13:00 +0200 Subject: [PATCH 3/7] fix of some texts --- botogram/objects/mixins.py | 4 ++-- docs/api/telegram.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/botogram/objects/mixins.py b/botogram/objects/mixins.py index 0383878..7d34c36 100644 --- a/botogram/objects/mixins.py +++ b/botogram/objects/mixins.py @@ -383,7 +383,7 @@ def send_poll(self, question, *kargs, reply_to=None, extra=None, @_require_api def send_dice(self, emoji=None, reply_to=None, extra=None, attach=None, notify=True): - """Send a message""" + """Send a dice""" args = self._get_call_args(reply_to, extra, attach, notify) if emoji is not None: args["emoji"] = emoji @@ -621,7 +621,7 @@ def reply_with_poll(self, *args, **kwargs): @_require_api def reply_with_dice(self, *args, **kwargs): - """Reply with a poll to the current message""" + """Reply with a dice to the current message""" return self.chat.send_dice(*args, reply_to=self, **kwargs) @_require_api diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index f6a05f4..4ff0f60 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1530,7 +1530,7 @@ about its business. Use this method to send a dice, which will have a random value from 1 to 6 - :param str emoji: Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲” + :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 @@ -2555,7 +2555,7 @@ about its business. Use this method to reply with a dice, which will have a random value from 1 to 6 - :param str emoji: Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲” + :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 From 7efe9ad5abad3efc17511ee869eee3bf80757e49 Mon Sep 17 00:00:00 2001 From: matteo Date: Tue, 16 Jun 2020 16:23:03 +0200 Subject: [PATCH 4/7] fix of some texts --- docs/api/telegram.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index 4ff0f60..d479213 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1526,7 +1526,7 @@ about its business. .. versionadded:: 0.7 - .. py:method:: send_dice([emoji, reply_to=None, extra=None, attach=None, notify=True]) + .. 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 to 6 @@ -2551,7 +2551,7 @@ about its business. .. versionadded:: 0.7 - .. py:method:: reply_with_dice([emoji, extra=None, attach=None, notify=True]) + .. 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 to 6 From a035b7f8160bac82e699dcf622884d7f38ca72d7 Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Wed, 2 Sep 2020 23:41:39 +0200 Subject: [PATCH 5/7] Fixing the PR --- botogram/objects/__init__.py | 2 +- botogram/objects/media.py | 2 +- docs/api/telegram.rst | 2 +- docs/changelog/0.7.rst | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/botogram/objects/__init__.py b/botogram/objects/__init__.py index e5903f1..ea64d62 100644 --- a/botogram/objects/__init__.py +++ b/botogram/objects/__init__.py @@ -63,7 +63,7 @@ "Poll", "PollOption", - #Dice-related objects + # Dice-related objects "Dice", # Updates-related objects diff --git a/botogram/objects/media.py b/botogram/objects/media.py index 6720668..35bebe5 100644 --- a/botogram/objects/media.py +++ b/botogram/objects/media.py @@ -309,7 +309,7 @@ class VideoNote(BaseObject, mixins.FileMixin): class Dice(BaseObject): """Telegram API representation of a venue - https://core.telegram.orgf/bots/api#dice + https://core.telegram.org/bots/api#dice """ required = { diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index d479213..e0e1cd9 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1528,7 +1528,7 @@ about its business. .. 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 to 6 + Use this method to send a dice, which will have a random value from 1 to 6 for “🎲”, “🎯” and from 1 to 5 for "🏀". :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 diff --git a/docs/changelog/0.7.rst b/docs/changelog/0.7.rst index 9c578b6..c2c0434 100644 --- a/docs/changelog/0.7.rst +++ b/docs/changelog/0.7.rst @@ -25,7 +25,7 @@ New features * 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_gif` + * New method :py:meth:`botogram.Message.reply_with_dice` * Added support for animations (GIFs) From 90d43d2dcf3fa6d04642f286f6a23f8e33429fc8 Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Thu, 3 Sep 2020 11:23:11 +0200 Subject: [PATCH 6/7] Fix botogram.Dice docs --- docs/api/telegram.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index d0d1a62..8374024 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -3193,7 +3193,7 @@ about its business. .. py:class:: botogram.Dice - This object represents a dice with a random value from 1 to 6 for currently supported base emoji. + 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 @@ -3201,7 +3201,7 @@ about its business. .. py:attribute:: value - Value of the dice, 1-6 for currently supported base emoji + Value of the dice, 1-6 (or 1-5) for currently supported base emoji .. versionadded:: 0.7 From 63738914e77e65d8de07c8d85e14f01b5a33e9ee Mon Sep 17 00:00:00 2001 From: matteo Date: Thu, 5 Nov 2020 23:31:28 +0100 Subject: [PATCH 7/7] add new emoji to documentation of dice --- docs/api/telegram.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index 8374024..03dbf31 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1531,9 +1531,10 @@ about its business. .. 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 to 6 for “🎲”, “🎯” and from 1 to 5 for "🏀". + 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 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 @@ -2572,9 +2573,10 @@ about its business. .. 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 to 6 + 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 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 @@ -3201,7 +3203,7 @@ about its business. .. py:attribute:: value - Value of the dice, 1-6 (or 1-5) for currently supported base emoji + Value of the dice, 1-6, 1-5 or 1-64 for currently supported base emoji .. versionadded:: 0.7