-
Notifications
You must be signed in to change notification settings - Fork 5.8k
API 4.7 #1858
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 4.7 #1858
Changes from all commits
d0891c1
b79d5af
82537d2
4593e3c
6717253
247a18b
85b474f
9a1285c
43f0162
e1408c7
5bc156b
78fa4d2
33833ea
3227b08
26944e3
bb9380f
f87a54a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
telegram.BotCommand | ||
=================== | ||
|
||
.. autoclass:: telegram.BotCommand | ||
:members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
telegram.Dice | ||
============= | ||
|
||
.. autoclass:: telegram.Dice | ||
:members: | ||
:show-inheritance: |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
# pylint: disable=R0903 | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2020 | ||
# Leandro Toledo de Souza <devs@python-telegram-bot.org> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
"""This module contains an object that represents a Telegram Bot Command.""" | ||
from telegram import TelegramObject | ||
|
||
|
||
class BotCommand(TelegramObject): | ||
""" | ||
This object represents a bot command. | ||
|
||
Attributes: | ||
command (:obj:`str`): Text of the command. | ||
description (:obj:`str`): Description of the command. | ||
|
||
Args: | ||
command (:obj:`str`): Text of the command, 1-32 characters. Can contain only lowercase | ||
English letters, digits and underscores. | ||
description (:obj:`str`): Description of the command, 3-256 characters. | ||
""" | ||
def __init__(self, command, description, **kwargs): | ||
self.command = command | ||
self.description = description | ||
|
||
@classmethod | ||
def de_json(cls, data, bot): | ||
if not data: | ||
return None | ||
|
||
return cls(**data) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python | ||
# pylint: disable=R0903 | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2020 | ||
# Leandro Toledo de Souza <devs@python-telegram-bot.org> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
"""This module contains an object that represents a Telegram Dice.""" | ||
from telegram import TelegramObject | ||
|
||
|
||
class Dice(TelegramObject): | ||
""" | ||
This object represents a dice with random value from 1 to 6. (The singular form of "dice" is | ||
"die". However, PTB mimics the Telegram API, which uses the term "dice".) | ||
|
||
Attributes: | ||
value (:obj:`int`): Value of the dice. | ||
|
||
Args: | ||
value (:obj:`int`): Value of the dice, 1-6. | ||
""" | ||
def __init__(self, value, **kwargs): | ||
self.value = value | ||
|
||
@classmethod | ||
def de_json(cls, data, bot): | ||
if not data: | ||
return None | ||
|
||
return cls(**data) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -272,6 +272,10 @@ def filter(self, message): | |||||
... | ||||||
MessageHandler(Filters.text(buttons), callback_method) | ||||||
|
||||||
Note: | ||||||
Dice messages don't have text. If you want to filter either text or dice messages, use | ||||||
``Filters.text | Filters.dice``. | ||||||
|
||||||
Args: | ||||||
update (Iterable[:obj:`str`], optional): Which messages to allow. Only exact matches | ||||||
are allowed. If not specified, will allow any text message. | ||||||
|
@@ -427,7 +431,7 @@ class category(BaseFilter): | |||||
send media with wrong types that don't fit to this handler. | ||||||
|
||||||
Example: | ||||||
Filters.documents.category('audio/') returnes `True` for all types | ||||||
Filters.documents.category('audio/') returns `True` for all types | ||||||
of audio sent as file, for example 'audio/mpeg' or 'audio/x-wav' | ||||||
""" | ||||||
|
||||||
|
@@ -957,6 +961,48 @@ def filter(self, message): | |||||
poll = _Poll() | ||||||
"""Messages that contain a :class:`telegram.Poll`.""" | ||||||
|
||||||
class _Dice(BaseFilter): | ||||||
name = 'Filters.dice' | ||||||
|
||||||
class _DiceValues(BaseFilter): | ||||||
|
||||||
def __init__(self, values): | ||||||
self.values = [values] if isinstance(values, int) else values | ||||||
self.name = 'Filters.dice({})'.format(values) | ||||||
|
||||||
def filter(self, message): | ||||||
return bool(message.dice and message.dice.value in self.values) | ||||||
|
||||||
def __call__(self, update): | ||||||
if isinstance(update, Update): | ||||||
return self.filter(update.effective_message) | ||||||
else: | ||||||
return self._DiceValues(update) | ||||||
|
||||||
def filter(self, message): | ||||||
return bool(message.dice) | ||||||
|
||||||
dice = _Dice() | ||||||
"""Dice Messages. If an integer or a list of integers is passed, it filters messages to only | ||||||
allow those whose dice value is appearing in the given list. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is slightly more accurate, the sentence feels kinda weird to me. And it should be clear from the context, that only dice messages are allowed. I'll not change for now. If this is important to you, you can PR for it ;) |
||||||
|
||||||
Examples: | ||||||
To allow any dice message, simply use | ||||||
``MessageHandler(Filters.dice, callback_method)``. | ||||||
To allow only dice with value 6, use | ||||||
``MessageHandler(Filters.dice(6), callback_method)``. | ||||||
To allow only dice with value 5 `or` 6, use | ||||||
``MessageHandler(Filters.dice([5, 6]), callback_method)``. | ||||||
|
||||||
Args: | ||||||
update (:obj:`int` | List[:obj:`int`], optional): Which values to allow. If not | ||||||
specified, will allow any dice message. | ||||||
|
||||||
Note: | ||||||
Dice messages don't have text. If you want to filter either text or dice messages, use | ||||||
``Filters.text | Filters.dice``. | ||||||
""" | ||||||
|
||||||
class language(BaseFilter): | ||||||
"""Filters messages to only allow those which are from users with a certain language code. | ||||||
|
||||||
|
Uh oh!
There was an error while loading. Please reload this page.