Skip to content

Commit 5b78871

Browse files
committed
Added support for dice
1 parent 4c7598c commit 5b78871

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

botogram/objects/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
from .chats import User, Chat, UserProfilePhotos, Permissions
2424
from .media import PhotoSize, Photo, Audio, Voice, Document, Sticker, \
25-
Video, VideoNote, Animation, Contact, Location, Venue
25+
Video, VideoNote, Animation, Contact, Location, Venue, \
26+
Dice
2627
from .messages import Message
2728
from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply
2829
from .polls import Poll, PollOption
@@ -62,6 +63,9 @@
6263
"Poll",
6364
"PollOption",
6465

66+
#Dice-related objects
67+
"Dice",
68+
6569
# Updates-related objects
6670
"Update",
6771
"Updates",

botogram/objects/media.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,15 @@ class VideoNote(BaseObject, mixins.FileMixin):
304304
"file_size": int,
305305
}
306306
_check_equality_ = "file_id"
307+
308+
309+
class Dice(BaseObject):
310+
"""Telegram API representation of a venue
311+
312+
https://core.telegram.orgf/bots/api#dice
313+
"""
314+
315+
required = {
316+
"emoji": str,
317+
"value": int
318+
}

botogram/objects/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .. import utils
2626
from .chats import User, Chat
2727
from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \
28-
Animation, Contact, Location, Venue
28+
Animation, Contact, Location, Venue, Dice
2929
from .polls import Poll
3030

3131

@@ -353,6 +353,7 @@ def from_(self):
353353
"location": Location,
354354
"venue": Venue,
355355
"poll": Poll,
356+
"dice": Dice,
356357
"new_chat_member": User,
357358
"left_chat_member": User,
358359
"new_chat_title": str,

botogram/objects/mixins.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ def send_poll(self, question, *kargs, reply_to=None, extra=None,
380380

381381
return self._api.call("sendPoll", args, expect=_objects().Message)
382382

383+
@_require_api
384+
def send_dice(self, emoji=None, reply_to=None, extra=None, attach=None,
385+
notify=True):
386+
"""Send a message"""
387+
args = self._get_call_args(reply_to, extra, attach, notify)
388+
if emoji is not None:
389+
args["emoji"] = emoji
390+
391+
return self._api.call("sendDice", args, expect=_objects().Message)
392+
383393
@_require_api
384394
def delete_message(self, message):
385395
"""Delete a message from chat"""
@@ -609,6 +619,11 @@ def reply_with_poll(self, *args, **kwargs):
609619
"""Reply with a poll to the current message"""
610620
return self.chat.send_poll(*args, reply_to=self, **kwargs)
611621

622+
@_require_api
623+
def reply_with_dice(self, *args, **kwargs):
624+
"""Reply with a poll to the current message"""
625+
return self.chat.send_dice(*args, reply_to=self, **kwargs)
626+
612627
@_require_api
613628
def delete(self):
614629
"""Delete the message"""

docs/api/telegram.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,20 @@ about its business.
15261526
15271527
.. versionadded:: 0.7
15281528

1529+
.. py:method:: send_dice([emoji, reply_to=None, extra=None, attach=None, notify=True])
1530+
1531+
Use this method to send a dice, which will have a random value from 1 to 6
1532+
1533+
:param str emoji: Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲”
1534+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
1535+
:param object attach: An extra thing to attach to the message
1536+
:param object extra: An extra reply interface object to attach
1537+
:param bool notify: If you want to trigger a notification on the client
1538+
:returns: The message you sent
1539+
:rtype: ~botogram.Message
1540+
1541+
.. versionadded:: 0.7
1542+
15291543
.. py:method:: delete_message(message)
15301544
15311545
Delete the message with the provided ID or :py:class:`~botogram.Message` object.
@@ -1856,6 +1870,12 @@ about its business.
18561870

18571871
*This attribute can be None if the message isn't a venue.*
18581872

1873+
.. py:attribute:: dice
1874+
1875+
A :py:class:`~botogram.Dice` object, when this message is a dice
1876+
1877+
*This attribute can be None if it's not provided by Telegram.*
1878+
18591879
.. py:attribute:: channel_post_author
18601880
18611881
The author of the message. This only works if the message is a channel
@@ -2531,6 +2551,19 @@ about its business.
25312551

25322552
.. versionadded:: 0.7
25332553

2554+
.. py:method:: reply_with_dice([emoji, extra=None, attach=None, notify=True])
2555+
2556+
Use this method to reply with a dice, which will have a random value from 1 to 6
2557+
2558+
:param str emoji: Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲”
2559+
:param object attach: An extra thing to attach to the message
2560+
:param object extra: An extra reply interface object to attach
2561+
:param bool notify: If you want to trigger a notification on the client
2562+
:returns: The message you sent
2563+
:rtype: ~botogram.Message
2564+
2565+
.. versionadded:: 0.7
2566+
25342567
.. py:class:: botogram.Photo
25352568
25362569
This class provides a general representation of a photo received by your bot.
@@ -3135,6 +3168,20 @@ about its business.
31353168
Number of users that voted for this option.
31363169

31373170

3171+
.. py:class:: botogram.Dice
3172+
3173+
This object represents a dice with a random value from 1 to 6 for currently supported base emoji.
3174+
3175+
.. py:attribute:: emoji
3176+
3177+
Emoji on which the dice throw animation is based
3178+
3179+
.. py:attribute:: value
3180+
3181+
Value of the dice, 1-6 for currently supported base emoji
3182+
3183+
.. versionadded:: 0.7
3184+
31383185
.. py:class:: botogram.Update
31393186
31403187
This class represents an update received by the bot. You should not need to

docs/changelog/0.7.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ Release description not yet written.
1919
New features
2020
------------
2121

22+
* Added support fo dice
23+
24+
* New :py:class:`botogram.Dice` class
25+
* New attribute :py:attr:`botogram.Message.dice`
26+
* New method :py:meth:`botogram.Chat.send_dice`
27+
* New method :py:meth:`botogram.User.send_dice`
28+
* New method :py:meth:`botogram.Message.reply_with_gif`
29+
2230

2331
* Added support for animations (GIFs)
2432

0 commit comments

Comments
 (0)