Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for dice #160

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion botogram/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,6 +63,9 @@
"Poll",
"PollOption",

# Dice-related objects
"Dice",

# Updates-related objects
"Update",
"Updates",
Expand Down
12 changes: 12 additions & 0 deletions botogram/objects/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion botogram/objects/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions botogram/objects/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down
48 changes: 48 additions & 0 deletions docs/api/telegram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,20 @@ 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 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
: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.
Expand Down Expand Up @@ -1875,6 +1889,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
Expand Down Expand Up @@ -2550,6 +2570,19 @@ 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 to 6

: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.
Expand Down Expand Up @@ -3158,6 +3191,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 (or 1-5) for currently supported base emoji

.. versionadded:: 0.7


.. py:class:: botogram.InlineQuery

This class represents an inline query update received by the bot.
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog/0.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down