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

Api 5.0 WP 10 (Dice) #2190

Merged
merged 4 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4255,8 +4255,9 @@ def send_dice(
Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target private chat.
emoji (:obj:`str`, optional): Emoji on which the dice throw animation is based.
Currently, must be one of “🎲”, “🎯” or “🏀”. Dice can have values 1-6 for “🎲” and
“🎯”, and values 1-5 for “🏀” . Defaults to “🎲”
Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6
for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults
to “🎲”.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
Expand Down
12 changes: 11 additions & 1 deletion telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
DICE_DICE (:obj:`str`): '🎲'
DICE_DARTS (:obj:`str`): '🎯'
DICE_BASKETBALL (:obj:`str`): '🏀'
DICE_FOOTBALL (:obj:`str`): '⚽'
DICE_SLOT_MACHINE (:obj:`str`): '🎰'
DICE_ALL_EMOJI (List[:obj:`str`]): List of all supported base emoji.

:class:`telegram.MessageEntity`:
Expand Down Expand Up @@ -172,7 +174,15 @@
DICE_DICE: str = '🎲'
DICE_DARTS: str = '🎯'
DICE_BASKETBALL: str = '🏀'
DICE_ALL_EMOJI: List[str] = [DICE_DICE, DICE_DARTS, DICE_BASKETBALL]
DICE_FOOTBALL: str = '⚽'
DICE_SLOT_MACHINE: str = '🎰'
DICE_ALL_EMOJI: List[str] = [
DICE_DICE,
DICE_DARTS,
DICE_BASKETBALL,
DICE_FOOTBALL,
DICE_SLOT_MACHINE,
]

MESSAGEENTITY_MENTION: str = 'mention'
MESSAGEENTITY_HASHTAG: str = 'hashtag'
Expand Down
15 changes: 14 additions & 1 deletion telegram/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@ class Dice(TelegramObject):
3 indicates that the basket was missed. However, this behaviour is undocumented and might
be changed by Telegram.

If :attr:`emoji` is "⚽", a value of 3 to 5 currently scores a goal, while a value of 1 to
3 indicates that the goal was missed. However, this behaviour is undocumented and might
be changed by Telegram.

If :attr:`emoji` is "🎰", each value corresponds to a unique combination of symbols, which
can be found at our `wiki <https://git.io/JkeC6>`_. However, this behaviour is undocumented
and might be changed by Telegram.

Attributes:
value (:obj:`int`): Value of the dice.
emoji (:obj:`str`): Emoji on which the dice throw animation is based.

Args:
value (:obj:`int`): Value of the dice. 1-6 for dice and darts, 1-5 for basketball.
value (:obj:`int`): Value of the dice. 1-6 for dice and darts, 1-5 for basketball and
football/soccer ball, 1-64 for slot machine.
emoji (:obj:`str`): Emoji on which the dice throw animation is based.
"""

Expand All @@ -62,5 +71,9 @@ def __init__(self, value: int, emoji: str, **_kwargs: Any):
""":const:`telegram.constants.DICE_DARTS`"""
BASKETBALL: ClassVar[str] = constants.DICE_BASKETBALL
""":const:`telegram.constants.DICE_BASKETBALL`"""
FOOTBALL: ClassVar[str] = constants.DICE_FOOTBALL
""":const:`telegram.constants.DICE_FOOTBALL`"""
SLOT_MACHINE: ClassVar[str] = constants.DICE_SLOT_MACHINE
""":const:`telegram.constants.DICE_SLOT_MACHINE`"""
ALL_EMOJI: ClassVar[List[str]] = constants.DICE_ALL_EMOJI
""":const:`telegram.constants.DICE_ALL_EMOJI`"""
6 changes: 6 additions & 0 deletions telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ class _Dice(_DiceEmoji):
dice = _DiceEmoji('🎲', 'dice')
darts = _DiceEmoji('🎯', 'darts')
basketball = _DiceEmoji('🏀', 'basketball')
football = _DiceEmoji('⚽')
slot_machine = _DiceEmoji('🎰')

dice = _Dice()
"""Dice Messages. If an integer or a list of integers is passed, it filters messages to only
Expand Down Expand Up @@ -1687,6 +1689,10 @@ class _Dice(_DiceEmoji):
:attr:`Filters.dice`.
basketball: Dice messages with the emoji 🏀. Passing a list of integers is supported just
as for :attr:`Filters.dice`.
football: Dice messages with the emoji ⚽. Passing a list of integers is supported just
as for :attr:`Filters.dice`.
slot_machine: Dice messages with the emoji 🎰. Passing a list of integers is supported just
as for :attr:`Filters.dice`.
"""

class language(MessageFilter):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,20 @@ def test_filters_dice_type(self, update):
assert not Filters.dice.darts(update)
assert not Filters.dice.basketball([4])(update)

update.message.dice = Dice(5, '⚽')
assert Filters.dice.football(update)
assert Filters.dice.football([4, 5])(update)
assert not Filters.dice.dice(update)
assert not Filters.dice.darts(update)
assert not Filters.dice.football([4])(update)

update.message.dice = Dice(5, '🎰')
assert Filters.dice.slot_machine(update)
assert Filters.dice.slot_machine([4, 5])(update)
assert not Filters.dice.dice(update)
assert not Filters.dice.darts(update)
assert not Filters.dice.slot_machine([4])(update)

def test_language_filter_single(self, update):
update.message.from_user.language_code = 'en_US'
assert (Filters.language('en_US'))(update)
Expand Down