mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-17 04:39:55 +01:00
Documentation update to PEP (#797)
This commit is contained in:
parent
4601eedf0f
commit
e018445513
96 changed files with 545 additions and 661 deletions
|
@ -27,9 +27,7 @@ from abc import ABCMeta
|
|||
|
||||
|
||||
class TelegramObject(object):
|
||||
"""
|
||||
Base class for most telegram objects.
|
||||
"""
|
||||
"""Base class for most telegram objects."""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
_id_attrs = ()
|
||||
|
@ -53,6 +51,7 @@ class TelegramObject(object):
|
|||
"""
|
||||
Returns:
|
||||
:obj:`str`
|
||||
|
||||
"""
|
||||
|
||||
return json.dumps(self.to_dict())
|
||||
|
|
211
telegram/bot.py
211
telegram/bot.py
|
@ -72,8 +72,7 @@ def message(func):
|
|||
|
||||
|
||||
class Bot(TelegramObject):
|
||||
"""
|
||||
This object represents a Telegram Bot.
|
||||
"""This object represents a Telegram Bot.
|
||||
|
||||
Args:
|
||||
token (:obj:`str`): Bot's unique authentication.
|
||||
|
@ -81,6 +80,7 @@ class Bot(TelegramObject):
|
|||
base_file_url (:obj:`str`, optional): Telegram Bot API file URL.
|
||||
request (:obj:`telegram.utils.Request`, optional): Pre initialized
|
||||
:obj:`telegram.utils.Request`.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, token, base_url=None, base_file_url=None, request=None):
|
||||
|
@ -104,7 +104,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@staticmethod
|
||||
def _validate_token(token):
|
||||
"""a very basic validation on token"""
|
||||
"""A very basic validation on token."""
|
||||
if any(x.isspace() for x in token):
|
||||
raise InvalidToken()
|
||||
|
||||
|
@ -117,44 +117,34 @@ class Bot(TelegramObject):
|
|||
@property
|
||||
@info
|
||||
def id(self):
|
||||
"""
|
||||
:obj:`int`: Unique identifier for this bot.
|
||||
"""
|
||||
""":obj:`int`: Unique identifier for this bot."""
|
||||
|
||||
return self.bot.id
|
||||
|
||||
@property
|
||||
@info
|
||||
def first_name(self):
|
||||
"""
|
||||
:obj:`str`: Bot's first name.
|
||||
"""
|
||||
""":obj:`str`: Bot's first name."""
|
||||
|
||||
return self.bot.first_name
|
||||
|
||||
@property
|
||||
@info
|
||||
def last_name(self):
|
||||
"""
|
||||
:obj:`str`: Optional. Bot's last name.
|
||||
"""
|
||||
""":obj:`str`: Optional. Bot's last name."""
|
||||
|
||||
return self.bot.last_name
|
||||
|
||||
@property
|
||||
@info
|
||||
def username(self):
|
||||
"""
|
||||
:obj:`str`: Bot's username.
|
||||
"""
|
||||
""":obj:`str`: Bot's username."""
|
||||
|
||||
return self.bot.username
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
:obj:`str`: Bot's @username.
|
||||
"""
|
||||
""":obj:`str`: Bot's @username."""
|
||||
|
||||
return '@{0}'.format(self.username)
|
||||
|
||||
|
@ -181,8 +171,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def get_me(self, timeout=None, **kwargs):
|
||||
"""
|
||||
A simple method for testing your bot's auth token. Requires no parameters.
|
||||
"""A simple method for testing your bot's auth token. Requires no parameters.
|
||||
|
||||
Args:
|
||||
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
|
||||
|
@ -195,8 +184,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getMe'.format(self.base_url)
|
||||
|
||||
result = self._request.get(url, timeout=timeout)
|
||||
|
@ -217,8 +206,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send text messages.
|
||||
"""Use this method to send text messages.
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
|
||||
|
@ -247,8 +235,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendMessage'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'text': text}
|
||||
|
@ -286,8 +274,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/deleteMessage'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'message_id': message_id}
|
||||
|
@ -305,8 +293,7 @@ class Bot(TelegramObject):
|
|||
disable_notification=False,
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to forward messages of any kind.
|
||||
"""Use this method to forward messages of any kind.
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
|
||||
|
@ -327,8 +314,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/forwardMessage'.format(self.base_url)
|
||||
|
||||
data = {}
|
||||
|
@ -353,8 +340,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=20.,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send photos.
|
||||
"""Use this method to send photos.
|
||||
|
||||
Note:
|
||||
The video argument can be either a file_id, an URL or a file from disk
|
||||
|
@ -385,8 +371,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendPhoto'.format(self.base_url)
|
||||
|
||||
if isinstance(photo, PhotoSize):
|
||||
|
@ -452,8 +438,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendAudio'.format(self.base_url)
|
||||
|
||||
if isinstance(audio, Audio):
|
||||
|
@ -484,8 +470,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=20.,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send general files.
|
||||
"""Use this method to send general files.
|
||||
|
||||
Note:
|
||||
The document argument can be either a file_id, an URL or a file from disk
|
||||
|
@ -518,8 +503,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendDocument'.format(self.base_url)
|
||||
|
||||
if isinstance(document, Document):
|
||||
|
@ -544,8 +529,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send .webp stickers.
|
||||
"""Use this method to send .webp stickers.
|
||||
|
||||
Note:
|
||||
The sticker argument can be either a file_id, an URL or a file from disk
|
||||
|
@ -574,8 +558,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendSticker'.format(self.base_url)
|
||||
|
||||
if isinstance(sticker, Sticker):
|
||||
|
@ -635,8 +619,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendVideo'.format(self.base_url)
|
||||
|
||||
if isinstance(video, Video):
|
||||
|
@ -701,8 +685,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendVoice'.format(self.base_url)
|
||||
|
||||
if isinstance(voice, Voice):
|
||||
|
@ -729,8 +713,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=20.,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send video messages.
|
||||
"""Use this method to send video messages.
|
||||
|
||||
Note:
|
||||
The video_note argument can be either a file_id or a file from disk
|
||||
|
@ -761,8 +744,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendVideoNote'.format(self.base_url)
|
||||
|
||||
if isinstance(video_note, VideoNote):
|
||||
|
@ -789,8 +772,7 @@ class Bot(TelegramObject):
|
|||
timeout=None,
|
||||
location=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send point on the map.
|
||||
"""Use this method to send point on the map.
|
||||
|
||||
Note:
|
||||
You can either supply a :obj:`latitude` and :obj:`longitude` or a :obj:`location`.
|
||||
|
@ -818,8 +800,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendLocation'.format(self.base_url)
|
||||
|
||||
if not (all([latitude, longitude]) or location):
|
||||
|
@ -849,8 +831,7 @@ class Bot(TelegramObject):
|
|||
timeout=None,
|
||||
venue=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send information about a venue.
|
||||
"""Use this method to send information about a venue.
|
||||
|
||||
Note:
|
||||
you can either supply :obj:`venue`, or :obj:`latitude`, :obj:`longitude`,
|
||||
|
@ -882,8 +863,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendVenue'.format(self.base_url)
|
||||
|
||||
if not (venue or all([latitude, longitude, address, title])):
|
||||
|
@ -923,8 +904,7 @@ class Bot(TelegramObject):
|
|||
timeout=None,
|
||||
contact=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send phone contacts.
|
||||
"""Use this method to send phone contacts.
|
||||
|
||||
Note:
|
||||
You can either supply :obj:`contact` or :obj:`phone_number` and :obj:`first_name`
|
||||
|
@ -954,8 +934,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendContact'.format(self.base_url)
|
||||
|
||||
if (not contact) and (not all([phone_number, first_name])):
|
||||
|
@ -984,8 +964,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send a game.
|
||||
"""Use this method to send a game.
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
|
||||
|
@ -1009,8 +988,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendGame'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'game_short_name': game_short_name}
|
||||
|
@ -1040,8 +1019,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendChatAction'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'action': action}
|
||||
|
@ -1104,8 +1083,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/answerInlineQuery'.format(self.base_url)
|
||||
|
||||
results = [res.to_dict() for res in results]
|
||||
|
@ -1131,8 +1110,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def get_user_profile_photos(self, user_id, offset=None, limit=100, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to get a list of profile pictures for a user.
|
||||
"""Use this method to get a list of profile pictures for a user.
|
||||
|
||||
Args:
|
||||
user_id (:obj:`int`): Unique identifier of the target user.
|
||||
|
@ -1150,8 +1128,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getUserProfilePhotos'.format(self.base_url)
|
||||
|
||||
data = {'user_id': user_id}
|
||||
|
@ -1187,8 +1165,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getFile'.format(self.base_url)
|
||||
|
||||
data = {'file_id': file_id}
|
||||
|
@ -1230,8 +1208,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/kickChatMember'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'user_id': user_id}
|
||||
|
@ -1248,8 +1226,8 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def unban_chat_member(self, chat_id, user_id, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to unban a previously kicked user in a supergroup.
|
||||
"""Use this method to unban a previously kicked user in a supergroup.
|
||||
|
||||
The user will not return to the group automatically, but will be able to join via link,
|
||||
etc. The bot must be an administrator in the group for this to work.
|
||||
|
||||
|
@ -1267,8 +1245,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/unbanChatMember'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'user_id': user_id}
|
||||
|
@ -1319,8 +1297,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url_ = '{0}/answerCallbackQuery'.format(self.base_url)
|
||||
|
||||
data = {'callback_query_id': callback_query_id}
|
||||
|
@ -1380,8 +1358,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/editMessageText'.format(self.base_url)
|
||||
|
||||
data = {'text': text}
|
||||
|
@ -1435,8 +1413,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
if inline_message_id is None and (chat_id is None or message_id is None):
|
||||
raise ValueError(
|
||||
'edit_message_caption: Both chat_id and message_id are required when '
|
||||
|
@ -1491,8 +1469,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
if inline_message_id is None and (chat_id is None or message_id is None):
|
||||
raise ValueError(
|
||||
'edit_message_reply_markup: Both chat_id and message_id are required when '
|
||||
|
@ -1520,8 +1498,7 @@ class Bot(TelegramObject):
|
|||
read_latency=2.,
|
||||
allowed_updates=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to receive incoming updates using long polling.
|
||||
"""Use this method to receive incoming updates using long polling.
|
||||
|
||||
Args:
|
||||
offset (:obj:`int`, optional): Identifier of the first update to be returned. Must be
|
||||
|
@ -1557,8 +1534,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getUpdates'.format(self.base_url)
|
||||
|
||||
if network_delay is not None:
|
||||
|
@ -1646,8 +1623,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url_ = '{0}/setWebhook'.format(self.base_url)
|
||||
|
||||
# Backwards-compatibility: 'url' used to be named 'webhook_url'
|
||||
|
@ -1694,8 +1671,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/deleteWebhook'.format(self.base_url)
|
||||
|
||||
data = kwargs
|
||||
|
@ -1706,8 +1683,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def leave_chat(self, chat_id, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method for your bot to leave a group, supergroup or channel.
|
||||
"""Use this method for your bot to leave a group, supergroup or channel.
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
|
||||
|
@ -1722,8 +1698,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/leaveChat'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -1752,8 +1728,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getChat'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -1784,8 +1760,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getChatAdministrators'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -1797,8 +1773,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def get_chat_members_count(self, chat_id, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to get the number of members in a chat
|
||||
"""Use this method to get the number of members in a chat
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
|
||||
|
@ -1813,8 +1788,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getChatMembersCount'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -1826,8 +1801,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def get_chat_member(self, chat_id, user_id, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to get information about a member of a chat.
|
||||
"""Use this method to get information about a member of a chat.
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
|
||||
|
@ -1843,8 +1817,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getChatMember'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'user_id': user_id}
|
||||
|
@ -1855,8 +1829,8 @@ class Bot(TelegramObject):
|
|||
return ChatMember.de_json(result, self)
|
||||
|
||||
def get_webhook_info(self, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to get current webhook status. Requires no parameters.
|
||||
"""Use this method to get current webhook status. Requires no parameters.
|
||||
|
||||
If the bot is using getUpdates, will return an object with the url field empty.
|
||||
|
||||
Args:
|
||||
|
@ -1867,8 +1841,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.WebhookInfo`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getWebhookInfo'.format(self.base_url)
|
||||
|
||||
data = kwargs
|
||||
|
@ -1920,8 +1894,8 @@ class Bot(TelegramObject):
|
|||
Raises:
|
||||
:class:`telegram.TelegramError`: If the new score is not greater than the user's
|
||||
current score in the chat and force is False.
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/setGameScore'.format(self.base_url)
|
||||
|
||||
data = {'user_id': user_id, 'score': score}
|
||||
|
@ -1969,8 +1943,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getGameHighScores'.format(self.base_url)
|
||||
|
||||
data = {'user_id': user_id}
|
||||
|
@ -2012,8 +1986,7 @@ class Bot(TelegramObject):
|
|||
reply_markup=None,
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send invoices.
|
||||
"""Use this method to send invoices.
|
||||
|
||||
Args:
|
||||
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target private chat.
|
||||
|
@ -2060,8 +2033,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/sendInvoice'.format(self.base_url)
|
||||
|
||||
data = {
|
||||
|
@ -2130,8 +2103,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
ok = bool(ok)
|
||||
|
||||
if ok and (shipping_options is None or error_message is not None):
|
||||
|
@ -2189,8 +2162,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
ok = bool(ok)
|
||||
|
||||
if not (ok ^ (error_message is not None)):
|
||||
|
@ -2247,8 +2220,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/restrictChatMember'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'user_id': user_id}
|
||||
|
@ -2314,8 +2287,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/promoteChatMember'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'user_id': user_id}
|
||||
|
@ -2361,8 +2334,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/exportChatInviteLink'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -2374,8 +2347,8 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def set_chat_photo(self, chat_id, photo, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to set a new profile photo for the chat.
|
||||
"""Use this method to set a new profile photo for the chat.
|
||||
|
||||
Photos can't be changed for private chats. The bot must be an administrator in the chat
|
||||
for this to work and must have the appropriate admin rights.
|
||||
|
||||
|
@ -2397,8 +2370,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/setChatPhoto'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'photo': photo}
|
||||
|
@ -2432,8 +2405,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/deleteChatPhoto'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -2468,8 +2441,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/setChatTitle'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'title': title}
|
||||
|
@ -2499,8 +2472,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/setChatDescription'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'description': description}
|
||||
|
@ -2533,8 +2506,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/pinChatMessage'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id, 'message_id': message_id}
|
||||
|
@ -2566,8 +2539,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/unpinChatMessage'.format(self.base_url)
|
||||
|
||||
data = {'chat_id': chat_id}
|
||||
|
@ -2579,8 +2552,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def get_sticker_set(self, name, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to get a sticker set.
|
||||
"""Use this method to get a sticker set.
|
||||
|
||||
Args:
|
||||
name (:obj:`str`): Short name of the sticker set that is used in t.me/addstickers/
|
||||
|
@ -2595,8 +2567,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/getStickerSet'.format(self.base_url)
|
||||
|
||||
data = {'name': name}
|
||||
|
@ -2632,8 +2604,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/uploadStickerFile'.format(self.base_url)
|
||||
|
||||
data = {'user_id': user_id, 'png_sticker': png_sticker}
|
||||
|
@ -2646,8 +2618,8 @@ class Bot(TelegramObject):
|
|||
@log
|
||||
def create_new_sticker_set(self, user_id, name, title, png_sticker, emojis,
|
||||
contains_masks=None, mask_position=None, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to create new sticker set owned by a user.
|
||||
"""Use this method to create new sticker set owned by a user.
|
||||
|
||||
The bot will be able to edit the created sticker set.
|
||||
|
||||
Note:
|
||||
|
@ -2683,8 +2655,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/createNewStickerSet'.format(self.base_url)
|
||||
|
||||
data = {'user_id': user_id, 'name': name, 'title': title, 'png_sticker': png_sticker,
|
||||
|
@ -2703,8 +2675,7 @@ class Bot(TelegramObject):
|
|||
@log
|
||||
def add_sticker_to_set(self, user_id, name, png_sticker, emojis, mask_position=None,
|
||||
timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
"""Use this method to add a new sticker to a set created by the bot.
|
||||
|
||||
Note:
|
||||
The png_sticker argument can be either a file_id, an URL or a file from disk
|
||||
|
@ -2732,8 +2703,8 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
"""
|
||||
|
||||
"""
|
||||
url = '{0}/addStickerToSet'.format(self.base_url)
|
||||
|
||||
data = {'user_id': user_id, 'name': name, 'png_sticker': png_sticker, 'emojis': emojis}
|
||||
|
@ -2748,8 +2719,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def set_sticker_position_in_set(self, sticker, position, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to move a sticker in a set created by the bot to a specific position.
|
||||
"""Use this method to move a sticker in a set created by the bot to a specific position.
|
||||
|
||||
Args:
|
||||
sticker (:obj:`str`): File identifier of the sticker.
|
||||
|
@ -2764,6 +2734,7 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
url = '{0}/setStickerPositionInSet'.format(self.base_url)
|
||||
|
||||
|
@ -2776,8 +2747,7 @@ class Bot(TelegramObject):
|
|||
|
||||
@log
|
||||
def delete_sticker_from_set(self, sticker, timeout=None, **kwargs):
|
||||
"""
|
||||
Use this method to delete a sticker from a set created by the bot.
|
||||
"""Use this method to delete a sticker from a set created by the bot.
|
||||
|
||||
Args:
|
||||
sticker (:obj:`str`): File identifier of the sticker.
|
||||
|
@ -2791,6 +2761,7 @@ class Bot(TelegramObject):
|
|||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
url = '{0}/deleteStickerFromSet'.format(self.base_url)
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ class CallbackQuery(TelegramObject):
|
|||
until you call :attr:`answer`. It is, therefore, necessary to react
|
||||
by calling :attr:`telegram.Bot.answer_callback_query` even if no notification to the user
|
||||
is needed (e.g., without specifying any of the optional parameters).
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -112,20 +113,18 @@ class CallbackQuery(TelegramObject):
|
|||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.answer_callback_query(update.callback_query.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: On success, ``True`` is returned.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.answerCallbackQuery(self.id, *args, **kwargs)
|
||||
|
||||
def edit_message_text(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for either::
|
||||
"""Shortcut for either::
|
||||
|
||||
bot.edit_message_text(chat_id=update.callback_query.message.chat_id,
|
||||
message_id=update.callback_query.message.message_id,
|
||||
|
@ -139,8 +138,8 @@ class CallbackQuery(TelegramObject):
|
|||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
|
||||
edited Message is returned, otherwise ``True`` is returned.
|
||||
"""
|
||||
|
||||
"""
|
||||
if self.inline_message_id:
|
||||
return self.bot.edit_message_text(
|
||||
inline_message_id=self.inline_message_id, *args, **kwargs)
|
||||
|
@ -149,8 +148,7 @@ class CallbackQuery(TelegramObject):
|
|||
chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs)
|
||||
|
||||
def edit_message_caption(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for either::
|
||||
"""Shortcut for either::
|
||||
|
||||
bot.edit_message_caption(chat_id=update.callback_query.message.chat_id,
|
||||
message_id=update.callback_query.message.message_id,
|
||||
|
@ -164,8 +162,8 @@ class CallbackQuery(TelegramObject):
|
|||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
|
||||
edited Message is returned, otherwise ``True`` is returned.
|
||||
"""
|
||||
|
||||
"""
|
||||
if self.inline_message_id:
|
||||
return self.bot.edit_message_caption(
|
||||
inline_message_id=self.inline_message_id, *args, **kwargs)
|
||||
|
@ -174,8 +172,7 @@ class CallbackQuery(TelegramObject):
|
|||
chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs)
|
||||
|
||||
def edit_message_reply_markup(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for either::
|
||||
"""Shortcut for either::
|
||||
|
||||
bot.edit_message_replyMarkup(chat_id=update.callback_query.message.chat_id,
|
||||
message_id=update.callback_query.message.message_id,
|
||||
|
@ -189,8 +186,8 @@ class CallbackQuery(TelegramObject):
|
|||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
|
||||
edited Message is returned, otherwise ``True`` is returned.
|
||||
"""
|
||||
|
||||
"""
|
||||
if self.inline_message_id:
|
||||
return self.bot.edit_message_reply_markup(
|
||||
inline_message_id=self.inline_message_id, *args, **kwargs)
|
||||
|
|
|
@ -23,8 +23,7 @@ from telegram import TelegramObject, ChatPhoto
|
|||
|
||||
|
||||
class Chat(TelegramObject):
|
||||
"""
|
||||
This object represents a chat.
|
||||
"""This object represents a chat.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`int`): Unique identifier for this chat.
|
||||
|
@ -118,32 +117,30 @@ class Chat(TelegramObject):
|
|||
return cls(bot=bot, **data)
|
||||
|
||||
def send_action(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_chat_action(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: If the action was sent successfully.
|
||||
|
||||
"""
|
||||
|
||||
return self.bot.send_chat_action(self.id, *args, **kwargs)
|
||||
|
||||
def leave(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.leave_chat(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`bool` If the action was sent successfully.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.leave_chat(self.id, *args, **kwargs)
|
||||
|
||||
def get_administrators(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.get_chat_administrators(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
|
@ -152,39 +149,36 @@ class Chat(TelegramObject):
|
|||
:class:`telegram.ChatMember` objects that contains information about all
|
||||
chat administrators except other bots. If the chat is a group or a supergroup
|
||||
and no administrators were appointed, only the creator will be returned
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.get_chat_administrators(self.id, *args, **kwargs)
|
||||
|
||||
def get_members_count(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.get_chat_members_count(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`int`
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.get_chat_members_count(self.id, *args, **kwargs)
|
||||
|
||||
def get_member(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.get_chat_member(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:class:`telegram.ChatMember`
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.get_chat_member(self.id, *args, **kwargs)
|
||||
|
||||
def kick_member(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.kick_chat_member(update.message.chat.id, *args, **kwargs)
|
||||
bot.kick_chat_member(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: If the action was sent succesfully.
|
||||
|
@ -193,17 +187,17 @@ class Chat(TelegramObject):
|
|||
This method will only work if the `All Members Are Admins` setting is off in the
|
||||
target group. Otherwise members may only be removed by the group's creator or by the
|
||||
member that added them.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.kick_chat_member(self.id, *args, **kwargs)
|
||||
|
||||
def unban_member(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.unban_chat_member(update.message.chat.id, *args, **kwargs)
|
||||
bot.unban_chat_member(update.message.chat.id, *args, **kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: If the action was sent successfully.
|
||||
|
||||
"""
|
||||
return self.bot.unban_chat_member(self.id, *args, **kwargs)
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
|
||||
|
||||
class ChatAction(object):
|
||||
"""
|
||||
Helper class to provide constants for different chatactions
|
||||
"""
|
||||
"""Helper class to provide constants for different chatactions."""
|
||||
|
||||
FIND_LOCATION = 'find_location'
|
||||
""":obj:`str`: 'find_location'"""
|
||||
|
|
|
@ -23,8 +23,7 @@ from telegram.utils.helpers import to_timestamp, from_timestamp
|
|||
|
||||
|
||||
class ChatMember(TelegramObject):
|
||||
"""
|
||||
This object contains information about one member of the chat.
|
||||
"""This object contains information about one member of the chat.
|
||||
|
||||
Attributes:
|
||||
user (:class:`telegram.User`): Information about the user.
|
||||
|
@ -91,8 +90,8 @@ class ChatMember(TelegramObject):
|
|||
send animations, games, stickers and use inline bots, implies can_send_media_messages.
|
||||
can_add_web_page_previews (:obj:`bool`, optional): Restricted only. True, if user may add
|
||||
web page previews to his messages, implies can_send_media_messages.
|
||||
"""
|
||||
|
||||
"""
|
||||
ADMINISTRATOR = 'administrator'
|
||||
""":obj:`str`: 'administrator'"""
|
||||
CREATOR = 'creator'
|
||||
|
|
|
@ -47,6 +47,7 @@ class ChosenInlineResult(TelegramObject):
|
|||
callback queries and can be used to edit the message.
|
||||
query (:obj:`str`): The query that was used to obtain the result.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""
|
||||
Constants in the Telegram network.
|
||||
"""Constants in the Telegram network.
|
||||
|
||||
The following constants were extracted from the
|
||||
`Telegram Bots FAQ <https://core.telegram.org/bots/faq>`_.
|
||||
|
@ -37,6 +36,7 @@ The following constant have been found by experimentation:
|
|||
Attributes:
|
||||
MAX_MESSAGE_ENTITIES (:obj:`int`): 100 (Beyond this cap telegram will simply ignore further
|
||||
formatting styles)
|
||||
|
||||
"""
|
||||
|
||||
MAX_MESSAGE_LENGTH = 4096
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the CallbackQueryHandler class """
|
||||
"""This module contains the CallbackQueryHandler class."""
|
||||
|
||||
import re
|
||||
|
||||
|
@ -27,8 +27,8 @@ from .handler import Handler
|
|||
|
||||
|
||||
class CallbackQueryHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram callback queries. Optionally based on a regex.
|
||||
"""Handler class to handle Telegram callback queries. Optionally based on a regex.
|
||||
|
||||
Read the documentation of the ``re`` module for more information.
|
||||
|
||||
Attributes:
|
||||
|
@ -79,6 +79,7 @@ class CallbackQueryHandler(Handler):
|
|||
``user_data`` will be passed to the callback function. Default is ``False``.
|
||||
pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
|
||||
``chat_data`` will be passed to the callback function. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -105,16 +106,15 @@ class CallbackQueryHandler(Handler):
|
|||
self.pass_groupdict = pass_groupdict
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
if isinstance(update, Update) and update.callback_query:
|
||||
if self.pattern:
|
||||
if update.callback_query.data:
|
||||
|
@ -124,14 +124,13 @@ class CallbackQueryHandler(Handler):
|
|||
return True
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
if self.pattern:
|
||||
match = re.match(self.pattern, update.callback_query.data)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the ChosenInlineResultHandler class """
|
||||
"""This module contains the ChosenInlineResultHandler class."""
|
||||
|
||||
from .handler import Handler
|
||||
from telegram import Update
|
||||
|
@ -24,8 +24,7 @@ from telegram.utils.deprecate import deprecate
|
|||
|
||||
|
||||
class ChosenInlineResultHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram updates that contain a chosen inline result.
|
||||
"""Handler class to handle Telegram updates that contain a chosen inline result.
|
||||
|
||||
Attributes:
|
||||
callback (:obj:`callable`): The callback function for this handler.
|
||||
|
@ -60,6 +59,7 @@ class ChosenInlineResultHandler(Handler):
|
|||
``user_data`` will be passed to the callback function. Default is ``False``.
|
||||
pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
|
||||
``chat_data`` will be passed to the callback function. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -76,27 +76,25 @@ class ChosenInlineResultHandler(Handler):
|
|||
pass_chat_data=pass_chat_data)
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
return isinstance(update, Update) and update.chosen_inline_result
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the CommandHandler class """
|
||||
"""This module contains the CommandHandler class."""
|
||||
import warnings
|
||||
|
||||
from future.utils import string_types
|
||||
|
@ -26,10 +26,10 @@ from telegram import Update
|
|||
|
||||
|
||||
class CommandHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram commands. Commands are Telegram messages
|
||||
that start with ``/``, optionally followed by an ``@`` and the bot's
|
||||
name and/or some additional text.
|
||||
"""Handler class to handle Telegram commands.
|
||||
|
||||
Commands are Telegram messages that start with ``/``, optionally followed by an ``@`` and the
|
||||
bot's name and/or some additional text.
|
||||
|
||||
Attributes:
|
||||
command (:obj:`str` | List[:obj:`str`]): The command or list of commands this handler
|
||||
|
@ -84,6 +84,7 @@ class CommandHandler(Handler):
|
|||
``user_data`` will be passed to the callback function. Default is ``False``.
|
||||
pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
|
||||
``chat_data`` will be passed to the callback function. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -119,16 +120,15 @@ class CommandHandler(Handler):
|
|||
'instead. More info: https://git.io/vPTbc.')
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
if (isinstance(update, Update)
|
||||
and (update.message or update.edited_message and self.allow_edited)):
|
||||
message = update.message or update.edited_message
|
||||
|
@ -154,14 +154,13 @@ class CommandHandler(Handler):
|
|||
return False
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
|
||||
message = update.message or update.edited_message
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the ConversationHandler """
|
||||
"""This module contains the ConversationHandler."""
|
||||
|
||||
import logging
|
||||
|
||||
|
@ -110,8 +110,8 @@ class ConversationHandler(Handler):
|
|||
|
||||
Raises:
|
||||
ValueError
|
||||
"""
|
||||
|
||||
"""
|
||||
END = -1
|
||||
""":obj:`int`: Used as a constant to return when a conversation is ended."""
|
||||
|
||||
|
@ -203,8 +203,8 @@ class ConversationHandler(Handler):
|
|||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
# Ignore messages in channels
|
||||
if (not isinstance(update, Update) or update.channel_post or self.per_chat
|
||||
and (update.inline_query or update.chosen_inline_result) or self.per_message
|
||||
|
@ -285,14 +285,13 @@ class ConversationHandler(Handler):
|
|||
return True
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the callback for the current state and Handler
|
||||
"""Send the update to the callback for the current state and Handler
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
new_state = self.current_handler.handle_update(update, dispatcher)
|
||||
|
||||
self.update_state(new_state, self.current_conversation)
|
||||
|
|
|
@ -39,15 +39,15 @@ DEFAULT_GROUP = 0
|
|||
|
||||
|
||||
def run_async(func):
|
||||
"""
|
||||
Function decorator that will run the function in a new thread.
|
||||
will run :attr:`telegram.ext.Dispatcher.run_async`.
|
||||
"""Function decorator that will run the function in a new thread.
|
||||
|
||||
Will run :attr:`telegram.ext.Dispatcher.run_async`.
|
||||
|
||||
Using this decorator is only possible when only a single Dispatcher exist in the system.
|
||||
|
||||
Note:
|
||||
Use this decorator to run handlers asynchronously.
|
||||
"""
|
||||
Note: Use this decorator to run handlers asynchronously.
|
||||
|
||||
"""
|
||||
@wraps(func)
|
||||
def async_func(*args, **kwargs):
|
||||
return Dispatcher.get_instance().run_async(func, *args, **kwargs)
|
||||
|
@ -61,8 +61,7 @@ class DispatcherHandlerStop(Exception):
|
|||
|
||||
|
||||
class Dispatcher(object):
|
||||
"""
|
||||
This class dispatches all kinds of updates to its registered handlers.
|
||||
"""This class dispatches all kinds of updates to its registered handlers.
|
||||
|
||||
Attributes:
|
||||
bot (:class:`telegram.Bot`): The bot object that should be passed to the handlers.
|
||||
|
@ -79,6 +78,7 @@ class Dispatcher(object):
|
|||
instance to pass onto handler callbacks.
|
||||
workers (:obj:`int`, optional): Number of maximum concurrent worker threads for the
|
||||
``@run_async`` decorator. defaults to 4.
|
||||
|
||||
"""
|
||||
|
||||
__singleton_lock = Lock()
|
||||
|
@ -133,16 +133,15 @@ class Dispatcher(object):
|
|||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
"""
|
||||
Get the singleton instance of this class.
|
||||
"""Get the singleton instance of this class.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.ext.Dispatcher`
|
||||
|
||||
Raises:
|
||||
RuntimeError
|
||||
"""
|
||||
|
||||
"""
|
||||
if cls.__singleton is not None:
|
||||
return cls.__singleton()
|
||||
else:
|
||||
|
@ -167,8 +166,7 @@ class Dispatcher(object):
|
|||
promise.pooled_function.__name__)
|
||||
|
||||
def run_async(self, func, *args, **kwargs):
|
||||
"""
|
||||
Queue a function (with given args/kwargs) to be run asynchronously.
|
||||
"""Queue a function (with given args/kwargs) to be run asynchronously.
|
||||
|
||||
Args:
|
||||
func (:obj:`callable`): The function to run in the thread.
|
||||
|
@ -186,11 +184,11 @@ class Dispatcher(object):
|
|||
return promise
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Thread target of thread 'dispatcher'. Runs in background and processes
|
||||
the update queue.
|
||||
"""
|
||||
"""Thread target of thread 'dispatcher'.
|
||||
|
||||
Runs in background and processes the update queue.
|
||||
|
||||
"""
|
||||
if self.running:
|
||||
self.logger.warning('already running')
|
||||
return
|
||||
|
@ -224,10 +222,7 @@ class Dispatcher(object):
|
|||
self.logger.debug('Dispatcher thread stopped')
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the thread.
|
||||
"""
|
||||
|
||||
"""Stops the thread."""
|
||||
if self.running:
|
||||
self.__stop_event.set()
|
||||
while self.running:
|
||||
|
@ -254,14 +249,13 @@ class Dispatcher(object):
|
|||
return self.running or bool(self.__async_threads)
|
||||
|
||||
def process_update(self, update):
|
||||
"""
|
||||
Processes a single update.
|
||||
"""Processes a single update.
|
||||
|
||||
Args:
|
||||
update (:obj:`str` | :class:`telegram.Update` | :class:`telegram.TelegramError`):
|
||||
The update to process.
|
||||
"""
|
||||
|
||||
"""
|
||||
# An error happened while polling
|
||||
if isinstance(update, TelegramError):
|
||||
self.dispatch_error(None, update)
|
||||
|
@ -331,14 +325,13 @@ class Dispatcher(object):
|
|||
self.handlers[group].append(handler)
|
||||
|
||||
def remove_handler(self, handler, group=DEFAULT_GROUP):
|
||||
"""
|
||||
Remove a handler from the specified group
|
||||
"""Remove a handler from the specified group.
|
||||
|
||||
Args:
|
||||
handler (:class:`telegram.ext.Handler`): A Handler instance.
|
||||
group (:obj:`object`, optional): The group identifier. Default is 0.
|
||||
"""
|
||||
|
||||
"""
|
||||
if handler in self.handlers[group]:
|
||||
self.handlers[group].remove(handler)
|
||||
if not self.handlers[group]:
|
||||
|
@ -346,35 +339,32 @@ class Dispatcher(object):
|
|||
self.groups.remove(group)
|
||||
|
||||
def add_error_handler(self, callback):
|
||||
"""
|
||||
Registers an error handler in the Dispatcher.
|
||||
"""Registers an error handler in the Dispatcher.
|
||||
|
||||
Args:
|
||||
callback (:obj:`callable`): A function that takes ``Bot, Update, TelegramError`` as
|
||||
arguments.
|
||||
"""
|
||||
|
||||
"""
|
||||
self.error_handlers.append(callback)
|
||||
|
||||
def remove_error_handler(self, callback):
|
||||
"""
|
||||
Removes an error handler.
|
||||
"""Removes an error handler.
|
||||
|
||||
Args:
|
||||
callback (:obj:`callable`): The error handler to remove.
|
||||
"""
|
||||
|
||||
"""
|
||||
if callback in self.error_handlers:
|
||||
self.error_handlers.remove(callback)
|
||||
|
||||
def dispatch_error(self, update, error):
|
||||
"""
|
||||
Dispatches an error.
|
||||
"""Dispatches an error.
|
||||
|
||||
Args:
|
||||
update (:obj:`str` | :class:`telegram.Update` | None): The update that caused the error
|
||||
error (:class:`telegram.TelegramError`): The Telegram error that was raised.
|
||||
"""
|
||||
|
||||
"""
|
||||
for callback in self.error_handlers:
|
||||
callback(self.bot, update, error)
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
#
|
||||
# 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 the Filters for use with the MessageHandler class """
|
||||
"""This module contains the Filters for use with the MessageHandler class."""
|
||||
from telegram import Chat
|
||||
from future.utils import string_types
|
||||
|
||||
|
||||
class BaseFilter(object):
|
||||
"""
|
||||
Base class for all Message Filters
|
||||
"""Base class for all Message Filters.
|
||||
|
||||
Subclassing from this class filters to be combined using bitwise operators:
|
||||
|
||||
|
@ -55,6 +54,7 @@ class BaseFilter(object):
|
|||
|
||||
Attributes:
|
||||
name (:obj:`str`): Name for this filter. Defaults to the type of filter.
|
||||
|
||||
"""
|
||||
|
||||
name = None
|
||||
|
@ -78,14 +78,14 @@ class BaseFilter(object):
|
|||
return self.name
|
||||
|
||||
def filter(self, message):
|
||||
"""
|
||||
This method must be overwritten.
|
||||
"""This method must be overwritten.
|
||||
|
||||
Args:
|
||||
message (:class:`telegram.Message`): The message that is tested.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
@ -96,6 +96,7 @@ class InvertedFilter(BaseFilter):
|
|||
|
||||
Args:
|
||||
f: The filter to invert.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, f):
|
||||
|
@ -115,6 +116,7 @@ class MergedFilter(BaseFilter):
|
|||
base_filter: Filter 1 of the merged filter
|
||||
and_filter: Optional filter to "and" with base_filter. Mutually exclusive with or_filter.
|
||||
or_filter: Optional filter to "or" with base_filter. Mutually exclusive with and_filter.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, base_filter, and_filter=None, or_filter=None):
|
||||
|
@ -134,12 +136,12 @@ class MergedFilter(BaseFilter):
|
|||
|
||||
|
||||
class Filters(object):
|
||||
"""
|
||||
Predefined filters for use with the `filter` argument of :class:`telegram.ext.MessageHandler`.
|
||||
"""Predefined filters for use as the `filter` argument of :class:`telegram.ext.MessageHandler`.
|
||||
|
||||
Examples:
|
||||
Use ``MessageHandler(Filters.video, callback_method)`` to filter all video
|
||||
messages. Use ``MessageHandler(Filters.contact, callback_method)`` for all contacts. etc.
|
||||
|
||||
"""
|
||||
|
||||
class _All(BaseFilter):
|
||||
|
@ -260,12 +262,12 @@ class Filters(object):
|
|||
""":obj:`Filter`: Messages that contain :class:`telegram.Venue`."""
|
||||
|
||||
class _StatusUpdate(BaseFilter):
|
||||
"""
|
||||
Subset for messages containing a status update.
|
||||
"""Subset for messages containing a status update.
|
||||
|
||||
Examples:
|
||||
Use these filters like: ``Filters.status_update.new_chat_member`` etc. Or use just
|
||||
``Filters.status_update`` for all status update messages.
|
||||
|
||||
"""
|
||||
|
||||
class _NewChatMembers(BaseFilter):
|
||||
|
@ -410,6 +412,7 @@ class Filters(object):
|
|||
Args:
|
||||
entity_type: Entity type to check for. All types can be found as constants
|
||||
in :class:`telegram.MessageEntity`.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, entity_type):
|
||||
|
@ -438,8 +441,7 @@ class Filters(object):
|
|||
""":obj:`Filter`: Messages sent in a group chat."""
|
||||
|
||||
class user(BaseFilter):
|
||||
"""
|
||||
Filters messages to allow only those which are from specified user ID.
|
||||
"""Filters messages to allow only those which are from specified user ID.
|
||||
|
||||
Examples:
|
||||
``MessageHandler(Filters.user(1234), callback_method)``
|
||||
|
@ -451,6 +453,7 @@ class Filters(object):
|
|||
|
||||
Raises:
|
||||
ValueError: If chat_id and username are both present, or neither is.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, user_id=None, username=None):
|
||||
|
@ -476,8 +479,7 @@ class Filters(object):
|
|||
message.from_user.username in self.usernames)
|
||||
|
||||
class chat(BaseFilter):
|
||||
"""
|
||||
Filters messages to allow only those which are from specified chat ID.
|
||||
"""Filters messages to allow only those which are from specified chat ID.
|
||||
|
||||
Examples:
|
||||
``MessageHandler(Filters.chat(-1234), callback_method)``
|
||||
|
@ -489,6 +491,7 @@ class Filters(object):
|
|||
|
||||
Raises:
|
||||
ValueError: If chat_id and username are both present, or neither is.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, chat_id=None, username=None):
|
||||
|
@ -531,10 +534,10 @@ class Filters(object):
|
|||
""":obj:`Filter`: Messages that confirm a :class:`telegram.SuccessfulPayment`."""
|
||||
|
||||
class language(BaseFilter):
|
||||
"""
|
||||
Filters messages to only allow those which are from users with a certain language code.
|
||||
Note that according to telegrams documentation, every single user does not have the
|
||||
language_code attribute.
|
||||
"""Filters messages to only allow those which are from users with a certain language code.
|
||||
|
||||
Note: According to telegrams documentation, every single user does not have the
|
||||
`language_code` attribute.
|
||||
|
||||
Examples:
|
||||
``MessageHandler(Filters.language("en"), callback_method)``
|
||||
|
@ -543,6 +546,7 @@ class Filters(object):
|
|||
lang (:obj:`str` | List[:obj:`str`]): Which language code(s) to allow through. This
|
||||
will be matched using ``.startswith`` meaning that 'en' will match both 'en_US'
|
||||
and 'en_GB'.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, lang):
|
||||
|
|
|
@ -16,14 +16,11 @@
|
|||
#
|
||||
# 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 the base class for handlers as used by the
|
||||
Dispatcher """
|
||||
"""This module contains the base class for handlers as used by the Dispatcher."""
|
||||
|
||||
|
||||
class Handler(object):
|
||||
"""
|
||||
The base class for all update handlers. You can create your own handlers by inheriting from
|
||||
this class.
|
||||
"""The base class for all update handlers. Create custom handlers by inheriting from it.
|
||||
|
||||
Attributes:
|
||||
callback (:obj:`callable`): The callback function for this handler.
|
||||
|
@ -58,6 +55,7 @@ class Handler(object):
|
|||
``user_data`` will be passed to the callback function. Default is ``False``.
|
||||
pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
|
||||
``chat_data`` will be passed to the callback function. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -82,6 +80,7 @@ class Handler(object):
|
|||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -101,12 +100,11 @@ class Handler(object):
|
|||
raise NotImplementedError
|
||||
|
||||
def collect_optional_args(self, dispatcher, update=None):
|
||||
"""
|
||||
Prepares the optional arguments that are the same for all types of
|
||||
handlers.
|
||||
"""Prepares the optional arguments that are the same for all types of handlers.
|
||||
|
||||
Args:
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): The dispatcher.
|
||||
|
||||
"""
|
||||
optional_args = dict()
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ class Days(object):
|
|||
|
||||
|
||||
class JobQueue(object):
|
||||
"""
|
||||
This class allows you to periodically perform tasks with the bot.
|
||||
"""This class allows you to periodically perform tasks with the bot.
|
||||
|
||||
Attributes:
|
||||
queue (:obj:`PriorityQueue`): The queue that holds the Jobs.
|
||||
|
@ -48,6 +47,7 @@ class JobQueue(object):
|
|||
Deprecated:
|
||||
prevent_autostart (:obj:`bool`, optional): Thread does not start during initialisation.
|
||||
Use `start` method instead.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, bot, prevent_autostart=None):
|
||||
|
@ -65,8 +65,7 @@ class JobQueue(object):
|
|||
self._running = False
|
||||
|
||||
def put(self, job, next_t=None):
|
||||
"""
|
||||
Queue a new job.
|
||||
"""Queue a new job.
|
||||
|
||||
Note:
|
||||
This method is deprecated. Please use: :attr:`run_once`, :attr:`run_daily`
|
||||
|
@ -87,6 +86,7 @@ class JobQueue(object):
|
|||
* :obj:`datetime.time` will be interpreted as a specific time at which the job
|
||||
should run. This could be either today or, if the time has already passed,
|
||||
tomorrow.
|
||||
|
||||
"""
|
||||
|
||||
warnings.warn("'JobQueue.put' is being deprecated, use 'JobQueue.run_once', "
|
||||
|
@ -125,8 +125,7 @@ class JobQueue(object):
|
|||
self._set_next_peek(next_t)
|
||||
|
||||
def run_once(self, callback, when, context=None, name=None):
|
||||
"""
|
||||
Creates a new ``Job`` that runs once and adds it to the queue.
|
||||
"""Creates a new ``Job`` that runs once and adds it to the queue.
|
||||
|
||||
Args:
|
||||
callback (:obj:`callable`): The callback function that should be executed by the new
|
||||
|
@ -155,15 +154,14 @@ class JobQueue(object):
|
|||
Returns:
|
||||
:class:`telegram.ext.Job`: The new ``Job`` instance that has been added to the job
|
||||
queue.
|
||||
"""
|
||||
|
||||
"""
|
||||
job = Job(callback, repeat=False, context=context, name=name, job_queue=self)
|
||||
self._put(job, next_t=when)
|
||||
return job
|
||||
|
||||
def run_repeating(self, callback, interval, first=None, context=None, name=None):
|
||||
"""
|
||||
Creates a new ``Job`` that runs once and adds it to the queue.
|
||||
"""Creates a new ``Job`` that runs once and adds it to the queue.
|
||||
|
||||
Args:
|
||||
callback (:obj:`callable`): The callback function that should be executed by the new
|
||||
|
@ -196,6 +194,7 @@ class JobQueue(object):
|
|||
Returns:
|
||||
:class:`telegram.ext.Job`: The new ``Job`` instance that has been added to the job
|
||||
queue.
|
||||
|
||||
"""
|
||||
|
||||
job = Job(callback,
|
||||
|
@ -208,8 +207,7 @@ class JobQueue(object):
|
|||
return job
|
||||
|
||||
def run_daily(self, callback, time, days=Days.EVERY_DAY, context=None, name=None):
|
||||
"""
|
||||
Creates a new ``Job`` that runs once and adds it to the queue.
|
||||
"""Creates a new ``Job`` that runs once and adds it to the queue.
|
||||
|
||||
Args:
|
||||
callback (:obj:`callable`): The callback function that should be executed by the new
|
||||
|
@ -227,6 +225,7 @@ class JobQueue(object):
|
|||
Returns:
|
||||
:class:`telegram.ext.Job`: The new ``Job`` instance that has been added to the job
|
||||
queue.
|
||||
|
||||
"""
|
||||
|
||||
job = Job(callback,
|
||||
|
@ -250,9 +249,7 @@ class JobQueue(object):
|
|||
self.__tick.set()
|
||||
|
||||
def tick(self):
|
||||
"""
|
||||
Run all jobs that are due and re-enqueue them with their interval.
|
||||
"""
|
||||
"""Run all jobs that are due and re-enqueue them with their interval."""
|
||||
|
||||
now = time.time()
|
||||
|
||||
|
@ -300,9 +297,7 @@ class JobQueue(object):
|
|||
self.logger.debug('Dropping non-repeating or removed job %s', job.name)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts the job_queue thread.
|
||||
"""
|
||||
"""Starts the job_queue thread."""
|
||||
|
||||
self.__start_lock.acquire()
|
||||
|
||||
|
@ -319,8 +314,8 @@ class JobQueue(object):
|
|||
"""
|
||||
Thread target of thread ``job_queue``. Runs in background and performs ticks on the job
|
||||
queue.
|
||||
"""
|
||||
|
||||
"""
|
||||
while self._running:
|
||||
# self._next_peek may be (re)scheduled during self.tick() or self.put()
|
||||
with self.__next_peek_lock:
|
||||
|
@ -339,9 +334,7 @@ class JobQueue(object):
|
|||
self.logger.debug('%s thread stopped', self.__class__.__name__)
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the thread.
|
||||
"""
|
||||
"""Stops the thread."""
|
||||
|
||||
with self.__start_lock:
|
||||
self._running = False
|
||||
|
@ -351,16 +344,13 @@ class JobQueue(object):
|
|||
self.__thread.join()
|
||||
|
||||
def jobs(self):
|
||||
"""
|
||||
Returns a tuple of all jobs that are currently in the ``JobQueue``
|
||||
"""
|
||||
"""Returns a tuple of all jobs that are currently in the ``JobQueue``."""
|
||||
|
||||
return tuple(job[1] for job in self.queue.queue if job)
|
||||
|
||||
|
||||
class Job(object):
|
||||
"""
|
||||
This class encapsulates a Job
|
||||
"""This class encapsulates a Job.
|
||||
|
||||
Attributes:
|
||||
callback (:obj:`callable`): The callback function that should be executed by the new job.
|
||||
|
@ -385,6 +375,7 @@ class Job(object):
|
|||
Defaults to ``Days.EVERY_DAY``
|
||||
job_queue (class:`telegram.ext.JobQueue`, optional): The ``JobQueue`` this job belongs to.
|
||||
Only optional for backward compatibility with ``JobQueue.put()``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -415,9 +406,7 @@ class Job(object):
|
|||
self._enabled.set()
|
||||
|
||||
def run(self, bot):
|
||||
"""
|
||||
Executes the callback function.
|
||||
"""
|
||||
"""Executes the callback function."""
|
||||
|
||||
self.callback(bot, self)
|
||||
|
||||
|
@ -425,24 +414,19 @@ class Job(object):
|
|||
"""
|
||||
Schedules this job for removal from the ``JobQueue``. It will be removed without executing
|
||||
its callback function again.
|
||||
|
||||
"""
|
||||
|
||||
self._remove.set()
|
||||
|
||||
@property
|
||||
def removed(self):
|
||||
"""
|
||||
:obj:`bool`: Whether this job is due to be removed.
|
||||
"""
|
||||
|
||||
""":obj:`bool`: Whether this job is due to be removed."""
|
||||
return self._remove.is_set()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
"""
|
||||
:obj:`bool`: Whether this job is enabled.
|
||||
"""
|
||||
|
||||
""":obj:`bool`: Whether this job is enabled."""
|
||||
return self._enabled.is_set()
|
||||
|
||||
@enabled.setter
|
||||
|
@ -457,8 +441,8 @@ class Job(object):
|
|||
"""
|
||||
:obj:`int` | :obj:`float` | :obj:`datetime.timedelta`: Optional. The interval in which the
|
||||
job will run.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self._interval
|
||||
|
||||
@interval.setter
|
||||
|
@ -474,10 +458,7 @@ class Job(object):
|
|||
|
||||
@property
|
||||
def interval_seconds(self):
|
||||
"""
|
||||
:obj:`int`: The interval for this job in seconds.
|
||||
"""
|
||||
|
||||
""":obj:`int`: The interval for this job in seconds."""
|
||||
if isinstance(self.interval, datetime.timedelta):
|
||||
return self.interval.total_seconds()
|
||||
else:
|
||||
|
@ -485,10 +466,7 @@ class Job(object):
|
|||
|
||||
@property
|
||||
def repeat(self):
|
||||
"""
|
||||
:obj:`bool`: Optional. If this job should be periodically execute its callback function.
|
||||
"""
|
||||
|
||||
""":obj:`bool`: Optional. If this job should periodically execute its callback function."""
|
||||
return self._repeat
|
||||
|
||||
@repeat.setter
|
||||
|
@ -499,9 +477,7 @@ class Job(object):
|
|||
|
||||
@property
|
||||
def days(self):
|
||||
"""
|
||||
Tuple[:obj:`int`]: Optional. Defines on which days of the week the job should run.
|
||||
"""
|
||||
"""Tuple[:obj:`int`]: Optional. Defines on which days of the week the job should run."""
|
||||
|
||||
return self._days
|
||||
|
||||
|
@ -521,9 +497,7 @@ class Job(object):
|
|||
|
||||
@property
|
||||
def job_queue(self):
|
||||
"""
|
||||
:class:`telegram.ext.JobQueue`: Optional. The ``JobQueue`` this job belongs to.
|
||||
"""
|
||||
""":class:`telegram.ext.JobQueue`: Optional. The ``JobQueue`` this job belongs to."""
|
||||
|
||||
return self._job_queue
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
# TODO: Remove allow_edited
|
||||
""" This module contains the MessageHandler class """
|
||||
"""This module contains the MessageHandler class."""
|
||||
import warnings
|
||||
|
||||
from .handler import Handler
|
||||
|
@ -25,8 +25,7 @@ from telegram import Update
|
|||
|
||||
|
||||
class MessageHandler(Handler):
|
||||
"""
|
||||
Handler class to handle telegram messages. They might contain text, media or status updates.
|
||||
"""Handler class to handle telegram messages. They might contain text, media or status updates.
|
||||
|
||||
Attributes:
|
||||
filters (:obj:`Filter`): Only allow updates with these Filters. See
|
||||
|
@ -86,6 +85,7 @@ class MessageHandler(Handler):
|
|||
|
||||
Raises:
|
||||
ValueError
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -130,16 +130,15 @@ class MessageHandler(Handler):
|
|||
(self.channel_post_updates and update.channel_post)])
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
if isinstance(update, Update) and self._is_allowed_update(update):
|
||||
|
||||
if not self.filters:
|
||||
|
@ -158,14 +157,13 @@ class MessageHandler(Handler):
|
|||
return res
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/]
|
||||
"""A throughput-limiting message processor for Telegram bots"""
|
||||
"""A throughput-limiting message processor for Telegram bots."""
|
||||
from telegram.utils import promise
|
||||
|
||||
import functools
|
||||
|
@ -44,9 +44,7 @@ else:
|
|||
|
||||
|
||||
class DelayQueueError(RuntimeError):
|
||||
"""
|
||||
Indicates processing errors.
|
||||
"""
|
||||
"""Indicates processing errors."""
|
||||
pass
|
||||
|
||||
|
||||
|
@ -78,6 +76,7 @@ class DelayQueue(threading.Thread):
|
|||
creation; if ``False``, should be started manually by `start` method. Defaults to True.
|
||||
name (:obj:`str`, optional): Thread's name. Defaults to ``'DelayQueue-N'``, where N is
|
||||
sequential number of object created.
|
||||
|
||||
"""
|
||||
|
||||
_instcnt = 0 # instance counter
|
||||
|
@ -105,7 +104,8 @@ class DelayQueue(threading.Thread):
|
|||
def run(self):
|
||||
"""
|
||||
Do not use the method except for unthreaded testing purposes, the method normally is
|
||||
automatically called by autostart argument .
|
||||
automatically called by autostart argument.
|
||||
|
||||
"""
|
||||
|
||||
times = [] # used to store each callable processing time
|
||||
|
@ -134,14 +134,14 @@ class DelayQueue(threading.Thread):
|
|||
self.exc_route(exc) # to prevent thread exit
|
||||
|
||||
def stop(self, timeout=None):
|
||||
"""
|
||||
Used to gently stop processor and shutdown its thread.
|
||||
"""Used to gently stop processor and shutdown its thread.
|
||||
|
||||
Args:
|
||||
timeout (:obj:`float`): Indicates maximum time to wait for processor to stop and its
|
||||
thread to exit. If timeout exceeds and processor has not stopped, method silently
|
||||
returns. :attr:`is_alive` could be used afterwards to check the actual status.
|
||||
``timeout`` set to None, blocks until processor is shut down. Defaults to None.
|
||||
|
||||
"""
|
||||
|
||||
self.__exit_req = True # gently request
|
||||
|
@ -153,19 +153,20 @@ class DelayQueue(threading.Thread):
|
|||
"""
|
||||
Dummy exception handler which re-raises exception in thread. Could be possibly overwritten
|
||||
by subclasses.
|
||||
|
||||
"""
|
||||
|
||||
raise exc
|
||||
|
||||
def __call__(self, func, *args, **kwargs):
|
||||
"""
|
||||
Used to process callbacks in throughput-limiting thread through queue.
|
||||
"""Used to process callbacks in throughput-limiting thread through queue.
|
||||
|
||||
Args:
|
||||
func (:obj:`callable`): The actual function (or any callable) that is processed through
|
||||
queue.
|
||||
*args (:obj:`list`): Variable-length `func` arguments.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword-arguments to `func`.
|
||||
|
||||
"""
|
||||
|
||||
if not self.is_alive() or self.__exit_req:
|
||||
|
@ -202,6 +203,7 @@ class MessageQueue(object):
|
|||
autostart (:obj:`bool`, optional): If True, processors are started immediately after
|
||||
object's creation; if ``False``, should be started manually by :attr:`start` method.
|
||||
Defaults to ``True``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -224,9 +226,7 @@ class MessageQueue(object):
|
|||
autostart=autostart)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Method is used to manually start the ``MessageQueue`` processing.
|
||||
"""
|
||||
"""Method is used to manually start the ``MessageQueue`` processing."""
|
||||
self._all_delayq.start()
|
||||
self._group_delayq.start()
|
||||
|
||||
|
@ -258,6 +258,7 @@ class MessageQueue(object):
|
|||
|
||||
Returns:
|
||||
:obj:`callable`: Used as ``promise`` argument.
|
||||
|
||||
"""
|
||||
|
||||
if not is_group_msg: # ignore middle group delay
|
||||
|
@ -268,8 +269,7 @@ class MessageQueue(object):
|
|||
|
||||
|
||||
def queuedmessage(method):
|
||||
"""
|
||||
A decorator to be used with :attr:`telegram.Bot` send* methods.
|
||||
"""A decorator to be used with :attr:`telegram.Bot` send* methods.
|
||||
|
||||
Note:
|
||||
As it probably wouldn't be a good idea to make this decorator a property, it has been coded
|
||||
|
@ -297,6 +297,7 @@ def queuedmessage(method):
|
|||
Returns:
|
||||
``telegram.utils.promise.Promise``: In case call is queued or original method's return
|
||||
value if it's not.
|
||||
|
||||
"""
|
||||
|
||||
@functools.wraps(method)
|
||||
|
|
|
@ -16,15 +16,14 @@
|
|||
#
|
||||
# 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 the PreCheckoutQueryHandler class """
|
||||
"""This module contains the PreCheckoutQueryHandler class."""
|
||||
|
||||
from telegram import Update
|
||||
from .handler import Handler
|
||||
|
||||
|
||||
class PreCheckoutQueryHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram PreCheckout callback queries.
|
||||
"""Handler class to handle Telegram PreCheckout callback queries.
|
||||
|
||||
Attributes:
|
||||
callback (:obj:`callable`): The callback function for this handler.
|
||||
|
@ -59,6 +58,7 @@ class PreCheckoutQueryHandler(Handler):
|
|||
``user_data`` will be passed to the callback function. Default is ``False``.
|
||||
pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
|
||||
``chat_data`` will be passed to the callback function. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -75,26 +75,24 @@ class PreCheckoutQueryHandler(Handler):
|
|||
pass_chat_data=pass_chat_data)
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
return isinstance(update, Update) and update.pre_checkout_query
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
# TODO: Remove allow_edited
|
||||
""" This module contains the RegexHandler class """
|
||||
"""This module contains the RegexHandler class."""
|
||||
|
||||
import re
|
||||
import warnings
|
||||
|
@ -29,11 +29,11 @@ from .handler import Handler
|
|||
|
||||
|
||||
class RegexHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram updates based on a regex. It uses a
|
||||
regular expression to check text messages. Read the documentation of the
|
||||
``re`` module for more information. The ``re.match`` function is used to
|
||||
determine if an update should be handled by this handler.
|
||||
"""Handler class to handle Telegram updates based on a regex.
|
||||
|
||||
It uses a regular expression to check text messages. Read the documentation of the ``re``
|
||||
module for more information. The ``re.match`` function is used to determine if an update should
|
||||
be handled by this handler.
|
||||
|
||||
Attributes:
|
||||
pattern (:obj:`str` | :obj:`Pattern`): The regex pattern.
|
||||
|
@ -91,6 +91,7 @@ class RegexHandler(Handler):
|
|||
|
||||
Raises:
|
||||
ValueError
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -133,14 +134,14 @@ class RegexHandler(Handler):
|
|||
self.edited_updates = edited_updates
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
|
||||
"""
|
||||
if not isinstance(update, Update) and not update.effective_message:
|
||||
return False
|
||||
|
@ -153,12 +154,12 @@ class RegexHandler(Handler):
|
|||
return False
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
|
||||
"""
|
||||
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
|
|
|
@ -16,15 +16,14 @@
|
|||
#
|
||||
# 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 the ShippingQueryHandler class """
|
||||
"""This module contains the ShippingQueryHandler class."""
|
||||
|
||||
from telegram import Update
|
||||
from .handler import Handler
|
||||
|
||||
|
||||
class ShippingQueryHandler(Handler):
|
||||
"""
|
||||
Handler class to handle Telegram shipping callback queries.
|
||||
"""Handler class to handle Telegram shipping callback queries.
|
||||
|
||||
Attributes:
|
||||
callback (:obj:`callable`): The callback function for this handler.
|
||||
|
@ -59,6 +58,7 @@ class ShippingQueryHandler(Handler):
|
|||
``user_data`` will be passed to the callback function. Default is ``False``.
|
||||
pass_chat_data (:obj:`bool`, optional): If set to ``True``, a keyword argument called
|
||||
``chat_data`` will be passed to the callback function. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -75,26 +75,24 @@ class ShippingQueryHandler(Handler):
|
|||
pass_chat_data=pass_chat_data)
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
return isinstance(update, Update) and update.shipping_query
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher, update)
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the StringCommandHandler class """
|
||||
"""This module contains the StringCommandHandler class."""
|
||||
|
||||
from future.utils import string_types
|
||||
|
||||
|
@ -24,9 +24,7 @@ from .handler import Handler
|
|||
|
||||
|
||||
class StringCommandHandler(Handler):
|
||||
"""
|
||||
Handler class to handle string commands. Commands are string updates
|
||||
that start with ``/``.
|
||||
"""Handler class to handle string commands. Commands are string updates that start with ``/``.
|
||||
|
||||
Note:
|
||||
This handler is not used to handle Telegram :attr:`telegram.Update`, but strings manually
|
||||
|
@ -60,6 +58,7 @@ class StringCommandHandler(Handler):
|
|||
``job_queue`` will be passed to the callback function. It will be a
|
||||
class:`telegram.ext.JobQueue` instance created by the :class:`telegram.ext.Updater`
|
||||
which can be used to schedule new jobs. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -74,26 +73,26 @@ class StringCommandHandler(Handler):
|
|||
self.pass_args = pass_args
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:obj:`str`): An incomming command.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
|
||||
"""
|
||||
|
||||
return (isinstance(update, string_types) and update.startswith('/')
|
||||
and update[1:].split(' ')[0] == self.command)
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:obj:`str`): An incomming command.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the command.
|
||||
|
||||
"""
|
||||
|
||||
optional_args = self.collect_optional_args(dispatcher)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the StringRegexHandler class """
|
||||
"""This module contains the StringRegexHandler class."""
|
||||
|
||||
import re
|
||||
|
||||
|
@ -26,11 +26,10 @@ from .handler import Handler
|
|||
|
||||
|
||||
class StringRegexHandler(Handler):
|
||||
"""
|
||||
Handler class to handle string updates based on a regex. It uses a
|
||||
regular expression to check update content. Read the documentation of the
|
||||
``re`` module for more information. The ``re.match`` function is used to
|
||||
determine if an update should be handled by this handler.
|
||||
"""Handler class to handle string updates based on a regex which checks the update content.
|
||||
|
||||
Read the documentation of the ``re`` module for more information. The ``re.match`` function is
|
||||
used to determine if an update should be handled by this handler.
|
||||
|
||||
Note:
|
||||
This handler is not used to handle Telegram :attr:`telegram.Update`, but strings manually
|
||||
|
@ -67,6 +66,7 @@ class StringRegexHandler(Handler):
|
|||
``job_queue`` will be passed to the callback function. It will be a
|
||||
:class:`telegram.ext.JobQueue` instance created by the :class:`telegram.ext.Updater`
|
||||
which can be used to schedule new jobs. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -87,27 +87,25 @@ class StringRegexHandler(Handler):
|
|||
self.pass_groupdict = pass_groupdict
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:obj:`str`): An incomming command.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
return isinstance(update, string_types) and bool(re.match(self.pattern, update))
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:obj:`str`): An incomming command.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the command.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher)
|
||||
match = re.match(self.pattern, update)
|
||||
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
#
|
||||
# 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 the TypeHandler class """
|
||||
"""This module contains the TypeHandler class."""
|
||||
|
||||
from .handler import Handler
|
||||
|
||||
|
||||
class TypeHandler(Handler):
|
||||
"""
|
||||
Handler class to handle updates of custom types.
|
||||
"""Handler class to handle updates of custom types.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`type`): The ``type`` of updates this handler should process.
|
||||
|
@ -51,6 +50,7 @@ class TypeHandler(Handler):
|
|||
``job_queue`` will be passed to the callback function. It will be a
|
||||
:class:`telegram.ext.JobQueue` instance created by the :class:`telegram.ext.Updater`
|
||||
which can be used to schedule new jobs. Default is ``False``.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, type, callback, strict=False, pass_update_queue=False,
|
||||
|
@ -61,14 +61,14 @@ class TypeHandler(Handler):
|
|||
self.strict = strict
|
||||
|
||||
def check_update(self, update):
|
||||
"""
|
||||
Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
"""Determines whether an update should be passed to this handlers :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
|
||||
"""
|
||||
|
||||
if not self.strict:
|
||||
|
@ -77,14 +77,13 @@ class TypeHandler(Handler):
|
|||
return type(update) is self.type
|
||||
|
||||
def handle_update(self, update, dispatcher):
|
||||
"""
|
||||
Send the update to the :attr:`callback`.
|
||||
"""Send the update to the :attr:`callback`.
|
||||
|
||||
Args:
|
||||
update (:class:`telegram.Update`): Incoming telegram update.
|
||||
dispatcher (:class:`telegram.ext.Dispatcher`): Dispatcher that originated the Update.
|
||||
"""
|
||||
|
||||
"""
|
||||
optional_args = self.collect_optional_args(dispatcher)
|
||||
|
||||
return self.callback(dispatcher.bot, update, **optional_args)
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the class Updater, which tries to make creating
|
||||
Telegram bots intuitive."""
|
||||
"""This module contains the class Updater, which tries to make creating Telegram bots intuitive."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
@ -78,6 +77,7 @@ class Updater(object):
|
|||
|
||||
Raises:
|
||||
ValueError: If both :attr:`token` and :attr:`bot` are passed or none of them.
|
||||
|
||||
"""
|
||||
|
||||
_request = None
|
||||
|
@ -159,8 +159,7 @@ class Updater(object):
|
|||
bootstrap_retries=0,
|
||||
read_latency=2.,
|
||||
allowed_updates=None):
|
||||
"""
|
||||
Starts polling updates from Telegram.
|
||||
"""Starts polling updates from Telegram.
|
||||
|
||||
Args:
|
||||
poll_interval (:obj:`float`, optional): Time to wait between polling updates from
|
||||
|
@ -185,6 +184,7 @@ class Updater(object):
|
|||
|
||||
Returns:
|
||||
:obj:`Queue`: The update queue that can be filled from the main thread.
|
||||
|
||||
"""
|
||||
|
||||
if network_delay is not None:
|
||||
|
@ -243,6 +243,7 @@ class Updater(object):
|
|||
|
||||
Returns:
|
||||
:obj:`Queue`: The update queue that can be filled from the main thread.
|
||||
|
||||
"""
|
||||
|
||||
with self.__lock:
|
||||
|
@ -404,9 +405,7 @@ class Updater(object):
|
|||
updates = self.bot.get_updates(updates[-1].update_id + 1)
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the polling/webhook thread, the dispatcher and the job queue.
|
||||
"""
|
||||
"""Stops the polling/webhook thread, the dispatcher and the job queue."""
|
||||
|
||||
self.job_queue.stop()
|
||||
with self.__lock:
|
||||
|
@ -454,15 +453,14 @@ class Updater(object):
|
|||
os._exit(1)
|
||||
|
||||
def idle(self, stop_signals=(SIGINT, SIGTERM, SIGABRT)):
|
||||
"""
|
||||
Blocks until one of the signals are received and stops the updater.
|
||||
"""Blocks until one of the signals are received and stops the updater.
|
||||
|
||||
Args:
|
||||
stop_signals (:obj:`iterable`): Iterable containing signals from the signal module that
|
||||
should be subscribed to. Updater.stop() will be called on receiving one of those
|
||||
signals. Defaults to (``SIGINT``, ``SIGTERM``, ``SIGABRT``).
|
||||
"""
|
||||
|
||||
"""
|
||||
for sig in stop_signals:
|
||||
signal(sig, self.signal_handler)
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class Audio(TelegramObject):
|
||||
"""
|
||||
This object represents an audio file to be treated as music by the Telegram clients.
|
||||
"""This object represents an audio file to be treated as music by the Telegram clients.
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique identifier for this file.
|
||||
|
@ -43,6 +42,7 @@ class Audio(TelegramObject):
|
|||
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -24,8 +24,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class ChatPhoto(TelegramObject):
|
||||
"""
|
||||
This object represents a chat photo.
|
||||
"""This object represents a chat photo.
|
||||
|
||||
Attributes:
|
||||
small_file_id (:obj:`str`): Unique file identifier of small (160x160) chat photo.
|
||||
|
@ -38,6 +37,7 @@ class ChatPhoto(TelegramObject):
|
|||
can be used only for photo download.
|
||||
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, small_file_id, big_file_id, bot=None, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class Contact(TelegramObject):
|
||||
"""
|
||||
This object represents a phone contact.
|
||||
"""This object represents a phone contact.
|
||||
|
||||
Attributes:
|
||||
phone_number (:obj:`str`): Contact's phone number.
|
||||
|
@ -37,6 +36,7 @@ class Contact(TelegramObject):
|
|||
last_name (:obj:`str`, optional): Contact's last name.
|
||||
user_id (:obj:`int`, optional): Contact's user identifier in Telegram.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, phone_number, first_name, last_name=None, user_id=None, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import PhotoSize, TelegramObject
|
|||
|
||||
|
||||
class Document(TelegramObject):
|
||||
"""
|
||||
This object represents a general file (as opposed to photos, voice messages and audio files).
|
||||
"""This object represents a general file (as opposed to photos, voice messages and audio files).
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique file identifier.
|
||||
|
@ -39,8 +38,8 @@ class Document(TelegramObject):
|
|||
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
"""
|
||||
|
||||
"""
|
||||
_id_keys = ('file_id',)
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -44,6 +44,7 @@ class File(TelegramObject):
|
|||
file_path (:obj:`str`, optional): File path. Use :attr:`download` to get the file.
|
||||
bot (:obj:`telegram.Bot`, optional): Bot to use with shortcut method.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, bot=None, file_size=None, file_path=None, **kwargs):
|
||||
|
@ -85,8 +86,8 @@ class File(TelegramObject):
|
|||
|
||||
Raises:
|
||||
ValueError: If both ``custom_path`` and ``out`` are passed.
|
||||
"""
|
||||
|
||||
"""
|
||||
if custom_path is not None and out is not None:
|
||||
raise ValueError('custom_path and out are mutually exclusive')
|
||||
|
||||
|
|
|
@ -40,8 +40,7 @@ FILE_TYPES = ('audio', 'document', 'photo', 'sticker', 'video', 'voice', 'certif
|
|||
|
||||
|
||||
class InputFile(object):
|
||||
"""
|
||||
This object represents a Telegram InputFile.
|
||||
"""This object represents a Telegram InputFile.
|
||||
|
||||
Attributes:
|
||||
data (:obj:`dict`): Data containing an inputfile.
|
||||
|
@ -51,6 +50,7 @@ class InputFile(object):
|
|||
|
||||
Raises:
|
||||
TelegramError
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, data):
|
||||
|
@ -88,28 +88,22 @@ class InputFile(object):
|
|||
|
||||
@property
|
||||
def headers(self):
|
||||
"""
|
||||
:obj:`dict`: Headers.
|
||||
"""
|
||||
""":obj:`dict`: Headers."""
|
||||
|
||||
return {'User-agent': USER_AGENT, 'Content-type': self.content_type}
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
"""
|
||||
:obj:`str`: Content type
|
||||
"""
|
||||
|
||||
""":obj:`str`: Content type"""
|
||||
return 'multipart/form-data; boundary=%s' % self.boundary
|
||||
|
||||
def to_form(self):
|
||||
"""
|
||||
Transform the inputfile to multipart/form data.
|
||||
"""Transform the inputfile to multipart/form data.
|
||||
|
||||
Returns:
|
||||
:obj:`str`
|
||||
"""
|
||||
|
||||
"""
|
||||
form = []
|
||||
form_boundary = '--' + self.boundary
|
||||
|
||||
|
@ -148,16 +142,15 @@ class InputFile(object):
|
|||
|
||||
@staticmethod
|
||||
def is_image(stream):
|
||||
"""
|
||||
Check if the content file is an image by analyzing its headers.
|
||||
"""Check if the content file is an image by analyzing its headers.
|
||||
|
||||
Args:
|
||||
stream (:obj:`str`): A str representing the content of a file.
|
||||
|
||||
Returns:
|
||||
:obj:`str`: The str mime-type of an image.
|
||||
"""
|
||||
|
||||
"""
|
||||
image = imghdr.what(None, stream)
|
||||
if image:
|
||||
return 'image/%s' % image
|
||||
|
@ -166,16 +159,15 @@ class InputFile(object):
|
|||
|
||||
@staticmethod
|
||||
def is_inputfile(data):
|
||||
"""
|
||||
Check if the request is a file request.
|
||||
"""Check if the request is a file request.
|
||||
|
||||
Args:
|
||||
data (Dict[:obj:`str`, :obj:`str`]): A dict of (str, str) key/value pairs.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`
|
||||
"""
|
||||
|
||||
"""
|
||||
if data:
|
||||
file_type = [i for i in iter(data) if i in FILE_TYPES]
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class Location(TelegramObject):
|
||||
"""
|
||||
This object represents a point on the map.
|
||||
"""This object represents a point on the map.
|
||||
|
||||
Attributes:
|
||||
longitude (:obj:`float`): Longitude as defined by sender.
|
||||
|
@ -33,6 +32,7 @@ class Location(TelegramObject):
|
|||
longitude (:obj:`float`): Longitude as defined by sender.
|
||||
latitude (:obj:`float`): Latitude as defined by sender.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, longitude, latitude, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class PhotoSize(TelegramObject):
|
||||
"""
|
||||
This object represents one size of a photo or a file/sticker thumbnail.
|
||||
"""This object represents one size of a photo or a file/sticker thumbnail.
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique identifier for this file.
|
||||
|
@ -37,6 +36,7 @@ class PhotoSize(TelegramObject):
|
|||
height (:obj:`int`): Photo height.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, width, height, file_size=None, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import PhotoSize, TelegramObject
|
|||
|
||||
|
||||
class Sticker(TelegramObject):
|
||||
"""
|
||||
This object represents a sticker.
|
||||
"""This object represents a sticker.
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique identifier for this file.
|
||||
|
@ -50,6 +49,7 @@ class Sticker(TelegramObject):
|
|||
position where the mask should be placed.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -96,8 +96,7 @@ class Sticker(TelegramObject):
|
|||
|
||||
|
||||
class StickerSet(TelegramObject):
|
||||
"""
|
||||
This object represents a sticker set.
|
||||
"""This object represents a sticker set.
|
||||
|
||||
Attributes:
|
||||
name (:obj:`str`): Sticker set name.
|
||||
|
@ -110,6 +109,7 @@ class StickerSet(TelegramObject):
|
|||
title (:obj:`str`): Sticker set title.
|
||||
contains_masks (:obj:`bool`): True, if the sticker set contains masks.
|
||||
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, name, title, contains_masks, stickers, bot=None, **kwargs):
|
||||
|
@ -140,8 +140,7 @@ class StickerSet(TelegramObject):
|
|||
|
||||
|
||||
class MaskPosition(TelegramObject):
|
||||
"""
|
||||
This object describes the position on faces where a mask should be placed by default.
|
||||
"""This object describes the position on faces where a mask should be placed by default.
|
||||
|
||||
Attributes:
|
||||
point (:obj:`str`): The part of the face relative to which the mask should be placed.
|
||||
|
@ -164,8 +163,8 @@ class MaskPosition(TelegramObject):
|
|||
size, from top to bottom. For example, 1.0 will place the mask just below the default
|
||||
mask position.
|
||||
scale (:obj:`float`): Mask scaling coefficient. For example, 2.0 means double size.
|
||||
"""
|
||||
|
||||
"""
|
||||
FOREHEAD = 'forehead'
|
||||
""":obj:`str`: 'forehead'"""
|
||||
EYES = 'eyes'
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, Location
|
|||
|
||||
|
||||
class Venue(TelegramObject):
|
||||
"""
|
||||
This object represents a venue.
|
||||
"""This object represents a venue.
|
||||
|
||||
Attributes:
|
||||
location (:class:`telegram.Location`): Venue location.
|
||||
|
@ -37,6 +36,7 @@ class Venue(TelegramObject):
|
|||
address (:obj:`str`): Address of the venue.
|
||||
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, location, title, address, foursquare_id=None, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import PhotoSize, TelegramObject
|
|||
|
||||
|
||||
class Video(TelegramObject):
|
||||
"""
|
||||
This object represents a video file.
|
||||
"""This object represents a video file.
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique identifier for this file.
|
||||
|
@ -43,6 +42,7 @@ class Video(TelegramObject):
|
|||
mime_type (:obj:`str`, optional): Mime type of a file as defined by sender.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import PhotoSize, TelegramObject
|
|||
|
||||
|
||||
class VideoNote(TelegramObject):
|
||||
"""
|
||||
This object represents a video message (available in Telegram apps as of v.4.0).
|
||||
"""This object represents a video message (available in Telegram apps as of v.4.0).
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique identifier for this file.
|
||||
|
@ -39,6 +38,7 @@ class VideoNote(TelegramObject):
|
|||
thumb (:class:`telegram.PhotoSize`, optional): Video thumbnail.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, length, duration, thumb=None, file_size=None, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class Voice(TelegramObject):
|
||||
"""
|
||||
This object represents a voice note.
|
||||
"""This object represents a voice note.
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique identifier for this file.
|
||||
|
@ -37,6 +36,7 @@ class Voice(TelegramObject):
|
|||
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, duration, mime_type=None, file_size=None, **kwargs):
|
||||
|
|
|
@ -41,6 +41,7 @@ class ForceReply(ReplyMarkup):
|
|||
original message.
|
||||
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, force_reply=True, selective=False, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class Animation(TelegramObject):
|
||||
"""
|
||||
This object represents an animation file to be displayed in the message containing a game.
|
||||
"""This object represents an animation file to be displayed in the message containing a game.
|
||||
|
||||
Attributes:
|
||||
file_id (:obj:`str`): Unique file identifier.
|
||||
|
@ -39,6 +38,7 @@ class Animation(TelegramObject):
|
|||
file_name (:obj:`str`, optional): Original animation filename as defined by sender.
|
||||
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
|
||||
file_size (:obj:`int`, optional): File size.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -22,6 +22,4 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class CallbackGame(TelegramObject):
|
||||
"""
|
||||
A placeholder, currently holds no information. Use BotFather to set up your game.
|
||||
"""
|
||||
"""A placeholder, currently holds no information. Use BotFather to set up your game."""
|
||||
|
|
|
@ -54,6 +54,7 @@ class Game(TelegramObject):
|
|||
appear in text, such as usernames, URLs, bot commands, etc.
|
||||
animation (:class:`telegram.Animation`, optional): Animation that will be displayed in the
|
||||
game message in chats. Upload via BotFather.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -94,8 +95,7 @@ class Game(TelegramObject):
|
|||
return data
|
||||
|
||||
def parse_text_entity(self, entity):
|
||||
"""
|
||||
Returns the text from a given :class:`telegram.MessageEntity`.
|
||||
"""Returns the text from a given :class:`telegram.MessageEntity`.
|
||||
|
||||
Note:
|
||||
This method is present because Telegram calculates the offset and length in
|
||||
|
@ -108,8 +108,8 @@ class Game(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:obj:`str`: The text of the given entity.
|
||||
"""
|
||||
|
||||
"""
|
||||
# Is it a narrow build, if so we don't need to convert
|
||||
if sys.maxunicode == 0xffff:
|
||||
return self.text[entity.offset:entity.offset + entity.length]
|
||||
|
@ -138,8 +138,8 @@ class Game(TelegramObject):
|
|||
Returns:
|
||||
Dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
|
||||
the text that belongs to them, calculated based on UTF-16 codepoints.
|
||||
"""
|
||||
|
||||
"""
|
||||
if types is None:
|
||||
types = MessageEntity.ALL_TYPES
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, User
|
|||
|
||||
|
||||
class GameHighScore(TelegramObject):
|
||||
"""
|
||||
This object represents one row of the high scores table for a game.
|
||||
"""This object represents one row of the high scores table for a game.
|
||||
|
||||
Attributes:
|
||||
position (:obj:`int`): Position in high score table for the game.
|
||||
|
@ -34,6 +33,7 @@ class GameHighScore(TelegramObject):
|
|||
position (:obj:`int`): Position in high score table for the game.
|
||||
user (:class:`telegram.User`): User.
|
||||
score (:obj:`int`): Score.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, position, user, score):
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
#
|
||||
# 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
|
||||
InlineKeyboardButton"""
|
||||
"""This module contains an object that represents a Telegram InlineKeyboardButton."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class InlineKeyboardButton(TelegramObject):
|
||||
"""
|
||||
This object represents one button of an inline keyboard.
|
||||
"""This object represents one button of an inline keyboard.
|
||||
|
||||
Note:
|
||||
You must use exactly one of the optional fields. Mind that :attr:`callback_game` is not
|
||||
|
@ -67,6 +65,7 @@ class InlineKeyboardButton(TelegramObject):
|
|||
pay (:obj:`bool`, optional): Specify True, to send a Pay button. This type of button must
|
||||
always be the ``first`` button in the first row.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -33,6 +33,7 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
|||
inline_keyboard (List[List[:class:`telegram.InlineKeyboardButton`]]): Array of button rows,
|
||||
each represented by an Array of InlineKeyboardButton objects.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, inline_keyboard, **kwargs):
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
# 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 InlineQuery"""
|
||||
"""This module contains an object that represents a Telegram InlineQuery."""
|
||||
|
||||
from telegram import TelegramObject, User, Location
|
||||
|
||||
|
@ -47,6 +47,7 @@ class InlineQuery(TelegramObject):
|
|||
offset (:obj:`str`): Offset of the results to be returned, can be controlled by the bot.
|
||||
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, query, offset, location=None, bot=None, **kwargs):
|
||||
|
@ -83,10 +84,9 @@ class InlineQuery(TelegramObject):
|
|||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.answer_inline_query(update.inline_query.id, *args, **kwargs)
|
||||
bot.answer_inline_query(update.inline_query.id, *args, **kwargs)
|
||||
|
||||
Args:
|
||||
results (List[:class:`telegram.InlineQueryResult`]): A list of results for the inline
|
||||
|
@ -106,6 +106,6 @@ class InlineQuery(TelegramObject):
|
|||
switch_pm_parameter (:obj:`str`, optional): Deep-linking parameter for the /start
|
||||
message sent to the bot when user presses the switch button. 1-64 characters,
|
||||
only A-Z, a-z, 0-9, _ and - are allowed.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.answer_inline_query(self.id, *args, **kwargs)
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResult"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResult."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class InlineQueryResult(TelegramObject):
|
||||
"""
|
||||
Baseclass for the InlineQueryResult* classes.
|
||||
"""Baseclass for the InlineQueryResult* classes.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): Type of the result.
|
||||
|
@ -33,6 +32,7 @@ class InlineQueryResult(TelegramObject):
|
|||
type (:obj:`str`): Type of the result.
|
||||
id (:obj:`str`): Unique identifier for this result, 1-64 Bytes.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, type, id, **kwargs):
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultArticle"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultArticle."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -56,6 +55,7 @@ class InlineQueryResultArticle(InlineQueryResult):
|
|||
thumb_width (:obj:`int`, optional): Thumbnail width.
|
||||
thumb_height (:obj:`int`, optional): Thumbnail height.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultAudio"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultAudio."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -53,6 +52,7 @@ class InlineQueryResultAudio(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the audio.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultCachedAudio"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedAudio."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -47,6 +46,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the audio.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedDocument"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedDocument."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -50,6 +50,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the file.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultCachedGif"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedGif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -50,6 +49,7 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the gif.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultMpeg4Gif"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -50,6 +49,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the MPEG-4 file.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -51,6 +51,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the photo.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedSticker"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedSticker."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -44,6 +44,7 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the sticker.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedVideo"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedVideo."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -51,6 +51,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the video.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedVoice"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedVoice."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -48,6 +48,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the voice.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultContact"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultContact."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
thumb_width (:obj:`int`, optional): Thumbnail width.
|
||||
thumb_height (:obj:`int`, optional): Thumbnail height.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultGame"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultGame."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup
|
||||
|
||||
|
||||
class InlineQueryResultGame(InlineQueryResult):
|
||||
"""
|
||||
Represents a Game.
|
||||
"""Represents a Game.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): 'game'.
|
||||
|
@ -39,6 +37,7 @@ class InlineQueryResultGame(InlineQueryResult):
|
|||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, id, game_short_name, reply_markup=None, **kwargs):
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultGif"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultGif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -57,6 +56,7 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the gif.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultLocation"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultLocation."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultMpeg4Gif"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -57,6 +57,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the MPEG-4 file.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultPhoto"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultPhoto."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -58,6 +58,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the photo.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultVenue"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultVenue."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -58,6 +58,7 @@ class InlineQueryResultVenue(InlineQueryResult):
|
|||
thumb_width (:obj:`int`, optional): Thumbnail width.
|
||||
thumb_height (:obj:`int`, optional): Thumbnail height.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultVideo"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultVideo."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -62,6 +61,7 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the video.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InlineQueryResultVoice"""
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultVoice."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
|
||||
|
@ -52,6 +51,7 @@ class InlineQueryResultVoice(InlineQueryResult):
|
|||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the voice.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InputContactMessageContent"""
|
||||
"""This module contains the classes that represent Telegram InputContactMessageContent."""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InputContactMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a contact message to be sent as the result of an inline query.
|
||||
"""Represents the content of a contact message to be sent as the result of an inline query.
|
||||
|
||||
Attributes:
|
||||
phone_number (:obj:`str`): Contact's phone number.
|
||||
|
@ -36,6 +34,7 @@ class InputContactMessageContent(InputMessageContent):
|
|||
first_name (:obj:`str`): Contact's first name.
|
||||
last_name (:obj:`str`, optional): Contact's last name.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, phone_number, first_name, last_name=None, **kwargs):
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InputLocationMessageContent"""
|
||||
"""This module contains the classes that represent Telegram InputLocationMessageContent."""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
@ -34,6 +33,7 @@ class InputLocationMessageContent(InputMessageContent):
|
|||
latitude (:obj:`float`): Latitude of the location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the location in degrees.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, latitude, longitude, **kwargs):
|
||||
|
|
|
@ -16,18 +16,18 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InputMessageContent"""
|
||||
"""This module contains the classes that represent Telegram InputMessageContent."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class InputMessageContent(TelegramObject):
|
||||
"""
|
||||
Base class for Telegram InputMessageContent Objects
|
||||
"""Base class for Telegram InputMessageContent Objects.
|
||||
|
||||
See: :class:`telegram.InputContactMessageContent`,
|
||||
:class:`telegram.InputLocationMessageContent`, :class:`telegram.InputTextMessageContent` and
|
||||
:class:`telegram.InputVenueMessageContent` for more details.
|
||||
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InputTextMessageContent"""
|
||||
"""This module contains the classes that represent Telegram InputTextMessageContent."""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
@ -41,6 +40,7 @@ class InputTextMessageContent(InputMessageContent):
|
|||
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in the
|
||||
sent message.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, message_text, parse_mode=None, disable_web_page_preview=None, **kwargs):
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
#
|
||||
# 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 the classes that represent Telegram
|
||||
InputVenueMessageContent"""
|
||||
"""This module contains the classes that represent Telegram InputVenueMessageContent."""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InputVenueMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a venue message to be sent as the result of an inline query.
|
||||
"""Represents the content of a venue message to be sent as the result of an inline query.
|
||||
|
||||
Attributes:
|
||||
latitude (:obj:`float`): Latitude of the location in degrees.
|
||||
|
@ -40,6 +38,7 @@ class InputVenueMessageContent(InputMessageContent):
|
|||
address (:obj:`str`): Address of the venue.
|
||||
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue, if known.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, latitude, longitude, title, address, foursquare_id=None, **kwargs):
|
||||
|
|
|
@ -45,6 +45,7 @@ class KeyboardButton(TelegramObject):
|
|||
Note:
|
||||
:attr:`request_contact` and :attr:`request_location` options will only work in Telegram
|
||||
versions released after 9 April, 2016. Older clients will ignore them.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, text, request_contact=None, request_location=None, **kwargs):
|
||||
|
|
|
@ -31,8 +31,7 @@ _UNDEFINED = object()
|
|||
|
||||
|
||||
class Message(TelegramObject):
|
||||
"""
|
||||
This object represents a message.
|
||||
"""This object represents a message.
|
||||
|
||||
Note:
|
||||
* In Python `from` is a reserved word, use `from_user` instead.
|
||||
|
@ -181,6 +180,7 @@ class Message(TelegramObject):
|
|||
author_signature (:obj:`str`, optional): Signature of the post author for messages
|
||||
in channels.
|
||||
"""
|
||||
|
||||
_effective_attachment = _UNDEFINED
|
||||
|
||||
def __init__(self,
|
||||
|
@ -275,9 +275,7 @@ class Message(TelegramObject):
|
|||
|
||||
@property
|
||||
def chat_id(self):
|
||||
"""
|
||||
:obj:`int`: Shortcut for :attr:`telegram.Chat.id` for :attr:`chat`.
|
||||
"""
|
||||
""":obj:`int`: Shortcut for :attr:`telegram.Chat.id` for :attr:`chat`."""
|
||||
return self.chat.id
|
||||
|
||||
@classmethod
|
||||
|
@ -380,7 +378,7 @@ class Message(TelegramObject):
|
|||
return data
|
||||
|
||||
def _quote(self, kwargs):
|
||||
"""Modify kwargs for replying with or without quoting"""
|
||||
"""Modify kwargs for replying with or without quoting."""
|
||||
if 'reply_to_message_id' in kwargs:
|
||||
if 'quote' in kwargs:
|
||||
del kwargs['quote']
|
||||
|
@ -396,8 +394,7 @@ class Message(TelegramObject):
|
|||
kwargs['reply_to_message_id'] = self.message_id
|
||||
|
||||
def reply_text(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_message(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
|
@ -406,14 +403,13 @@ class Message(TelegramObject):
|
|||
reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``, this
|
||||
parameter will be ignored. Default: ``True`` in group chats and ``False`` in
|
||||
private chats.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_message(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_photo(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_photo(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
|
@ -424,14 +420,13 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_photo(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_audio(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_audio(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
|
@ -442,14 +437,13 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_audio(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_document(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_document(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
|
@ -460,14 +454,13 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_document(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_sticker(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_sticker(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
|
@ -478,16 +471,15 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_sticker(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_video(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_video(update.message.chat_id, *args, **kwargs)
|
||||
bot.send_video(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
Keyword Args:
|
||||
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
||||
|
@ -496,16 +488,15 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_video(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_video_note(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_video_note(update.message.chat_id, *args, **kwargs)
|
||||
bot.send_video_note(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
Keyword Args:
|
||||
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
||||
|
@ -514,14 +505,13 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_video_note(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_voice(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_voice(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
|
@ -532,16 +522,15 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_voice(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_location(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_location(update.message.chat_id, *args, **kwargs)
|
||||
bot.send_location(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
Keyword Args:
|
||||
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
||||
|
@ -550,16 +539,15 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_location(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_venue(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_venue(update.message.chat_id, *args, **kwargs)
|
||||
bot.send_venue(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
Keyword Args:
|
||||
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
||||
|
@ -568,16 +556,15 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_venue(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_contact(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.send_contact(update.message.chat_id, *args, **kwargs)
|
||||
bot.send_contact(update.message.chat_id, *args, **kwargs)
|
||||
|
||||
Keyword Args:
|
||||
quote (:obj:`bool`, optional): If set to ``True``, the photo is sent as an actual reply
|
||||
|
@ -586,24 +573,23 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message posted.
|
||||
"""
|
||||
|
||||
"""
|
||||
self._quote(kwargs)
|
||||
return self.bot.send_contact(self.chat_id, *args, **kwargs)
|
||||
|
||||
def forward(self, chat_id, disable_notification=False):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.forward_message(chat_id=chat_id,
|
||||
from_chat_id=update.message.chat_id,
|
||||
disable_notification=disable_notification,
|
||||
message_id=update.message.message_id)
|
||||
bot.forward_message(chat_id=chat_id,
|
||||
from_chat_id=update.message.chat_id,
|
||||
disable_notification=disable_notification,
|
||||
message_id=update.message.message_id)
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the message forwarded.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.forward_message(
|
||||
chat_id=chat_id,
|
||||
from_chat_id=self.chat_id,
|
||||
|
@ -611,13 +597,12 @@ class Message(TelegramObject):
|
|||
message_id=self.message_id)
|
||||
|
||||
def edit_text(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.edit_message_text(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
bot.edit_message_text(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
Note:
|
||||
You can only edit messages that the bot sent itself,
|
||||
|
@ -626,19 +611,18 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the edited message.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.edit_message_text(
|
||||
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
||||
|
||||
def edit_caption(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.edit_message_caption(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
bot.edit_message_caption(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
Note:
|
||||
You can only edit messages that the bot sent itself,
|
||||
|
@ -647,19 +631,18 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the edited message.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.edit_message_caption(
|
||||
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
||||
|
||||
def edit_reply_markup(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.edit_message_reply_markup(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
bot.edit_message_reply_markup(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
Note:
|
||||
You can only edit messages that the bot sent itself,
|
||||
|
@ -669,18 +652,16 @@ class Message(TelegramObject):
|
|||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the edited message.
|
||||
"""
|
||||
|
||||
return self.bot.edit_message_reply_markup(
|
||||
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.delete_message(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
bot.delete_message(chat_id=message.chat_id,
|
||||
message_id=message.message_id,
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: On success, ``True`` is returned.
|
||||
|
@ -690,8 +671,7 @@ class Message(TelegramObject):
|
|||
chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs)
|
||||
|
||||
def parse_entity(self, entity):
|
||||
"""
|
||||
Returns the text from a given :class:`telegram.MessageEntity`.
|
||||
"""Returns the text from a given :class:`telegram.MessageEntity`.
|
||||
|
||||
Note:
|
||||
This method is present because Telegram calculates the offset and length in
|
||||
|
@ -704,8 +684,8 @@ class Message(TelegramObject):
|
|||
|
||||
Returns:
|
||||
str: The text of the given entity
|
||||
"""
|
||||
|
||||
"""
|
||||
# Is it a narrow build, if so we don't need to convert
|
||||
if sys.maxunicode == 0xffff:
|
||||
return self.text[entity.offset:entity.offset + entity.length]
|
||||
|
@ -736,8 +716,8 @@ class Message(TelegramObject):
|
|||
Returns:
|
||||
Dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
|
||||
the text that belongs to them, calculated based on UTF-16 codepoints.
|
||||
"""
|
||||
|
||||
"""
|
||||
if types is None:
|
||||
types = MessageEntity.ALL_TYPES
|
||||
|
||||
|
@ -789,27 +769,27 @@ class Message(TelegramObject):
|
|||
|
||||
@property
|
||||
def text_html(self):
|
||||
"""
|
||||
Creates an HTML-formatted string from the markup entities found in the message.
|
||||
"""Creates an HTML-formatted string from the markup entities found in the message.
|
||||
|
||||
Use this if you want to retrieve the message text with the entities formatted as HTML in
|
||||
the same way the original message was formatted.
|
||||
|
||||
Returns:
|
||||
:obj:`str`: Message text with entities formatted as HTML.
|
||||
|
||||
"""
|
||||
return self._text_html(urled=False)
|
||||
|
||||
@property
|
||||
def text_html_urled(self):
|
||||
"""
|
||||
Creates an HTML-formatted string from the markup entities found in the message.
|
||||
"""Creates an HTML-formatted string from the markup entities found in the message.
|
||||
|
||||
Use this if you want to retrieve the message text with the entities formatted as HTML.
|
||||
This also formats :attr:`telegram.MessageEntity.URL` as a hyperlink.
|
||||
|
||||
Returns:
|
||||
:obj:`str`: Message text with entities formatted as HTML.
|
||||
|
||||
"""
|
||||
return self._text_html(urled=True)
|
||||
|
||||
|
@ -855,30 +835,28 @@ class Message(TelegramObject):
|
|||
|
||||
@property
|
||||
def text_markdown(self):
|
||||
"""
|
||||
Creates an Markdown-formatted string from the markup entities found in the message.
|
||||
"""Creates an Markdown-formatted string from the markup entities found in the message.
|
||||
|
||||
Use this if you want to retrieve the message text with the entities formatted as Markdown
|
||||
in the same way the original message was formatted.
|
||||
|
||||
Returns:
|
||||
:obj:`str`: Message text with entities formatted as Markdown.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self._text_markdown(urled=False)
|
||||
|
||||
@property
|
||||
def text_markdown_urled(self):
|
||||
"""
|
||||
Creates an Markdown-formatted string from the markup entities found in the message.
|
||||
"""Creates an Markdown-formatted string from the markup entities found in the message.
|
||||
|
||||
Use this if you want to retrieve the message text with the entities formatted as Markdown.
|
||||
This also formats :attr:`telegram.MessageEntity.URL` as a hyperlink.
|
||||
|
||||
Returns:
|
||||
:obj:`str`: Message text with entities formatted as Markdown.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self._text_markdown(urled=True)
|
||||
|
||||
@property
|
||||
|
|
|
@ -43,6 +43,7 @@ class MessageEntity(TelegramObject):
|
|||
url (:obj:`str`, optional): For "text_link" only, url that will be opened after usertaps on
|
||||
the text.
|
||||
user (:class:`telegram.User`, optional): For "text_mention" only, the mentioned user.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, type, offset, length, url=None, user=None, **kwargs):
|
||||
|
|
|
@ -17,14 +17,11 @@
|
|||
#
|
||||
# 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
|
||||
Message Parse Modes."""
|
||||
"""This module contains an object that represents a Telegram Message Parse Modes."""
|
||||
|
||||
|
||||
class ParseMode(object):
|
||||
"""
|
||||
This object represents a Telegram Message Parse Modes.
|
||||
"""
|
||||
"""This object represents a Telegram Message Parse Modes."""
|
||||
|
||||
MARKDOWN = 'Markdown'
|
||||
""":obj:`str`: 'Markdown'"""
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class Invoice(TelegramObject):
|
||||
"""
|
||||
This object contains basic information about an invoice.
|
||||
"""This object contains basic information about an invoice.
|
||||
|
||||
Attributes:
|
||||
title (:obj:`str`): Product name.
|
||||
|
@ -41,6 +40,7 @@ class Invoice(TelegramObject):
|
|||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer, not
|
||||
float/double). For example, for a price of US$ 1.45 pass amount = 145.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, title, description, start_parameter, currency, total_amount, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class LabeledPrice(TelegramObject):
|
||||
"""
|
||||
This object represents a portion of the price for goods or services.
|
||||
"""This object represents a portion of the price for goods or services.
|
||||
|
||||
Attributes:
|
||||
label (:obj:`str`): Portion label.
|
||||
|
@ -36,6 +35,7 @@ class LabeledPrice(TelegramObject):
|
|||
parameter in currencies.json, it shows the number of digits past the decimal point for
|
||||
each currency (2 for the majority of currencies).
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, label, amount, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, ShippingAddress
|
|||
|
||||
|
||||
class OrderInfo(TelegramObject):
|
||||
"""
|
||||
This object represents information about an order.
|
||||
"""This object represents information about an order.
|
||||
|
||||
Attributes:
|
||||
name (:obj:`str`): Optional. User name.
|
||||
|
@ -37,6 +36,7 @@ class OrderInfo(TelegramObject):
|
|||
email (:obj:`str`, optional): User email.
|
||||
shipping_address (:class:`telegram.ShippingAddress`, optional): User shipping address.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, name=None, phone_number=None, email=None, shipping_address=None, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, User, OrderInfo
|
|||
|
||||
|
||||
class PreCheckoutQuery(TelegramObject):
|
||||
"""
|
||||
This object contains information about an incoming pre-checkout query.
|
||||
"""This object contains information about an incoming pre-checkout query.
|
||||
|
||||
Note:
|
||||
* In Python `from` is a reserved word, use `from_user` instead.
|
||||
|
@ -53,6 +52,7 @@ class PreCheckoutQuery(TelegramObject):
|
|||
order_info (:class:`telegram.OrderInfo`, optional): Order info provided by the user.
|
||||
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -97,10 +97,9 @@ class PreCheckoutQuery(TelegramObject):
|
|||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)
|
||||
bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)
|
||||
|
||||
Args:
|
||||
ok (:obj:`bool`): Specify True if everything is alright (goods are available, etc.) and
|
||||
|
@ -111,6 +110,6 @@ class PreCheckoutQuery(TelegramObject):
|
|||
were busy filling out your payment details. Please choose a different color or
|
||||
garment!"). Telegram will display this message to the user.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.answer_pre_checkout_query(self.id, *args, **kwargs)
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class ShippingAddress(TelegramObject):
|
||||
"""
|
||||
This object represents a Telegram ShippingAddress.
|
||||
"""This object represents a Telegram ShippingAddress.
|
||||
|
||||
Attributes:
|
||||
country_code (:obj:`str`): ISO 3166-1 alpha-2 country code.
|
||||
|
@ -41,6 +40,7 @@ class ShippingAddress(TelegramObject):
|
|||
street_line2 (:obj:`str`): Second line for the address.
|
||||
post_code (:obj:`str`): Address post code.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, country_code, state, city, street_line1, street_line2, post_code, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, LabeledPrice
|
|||
|
||||
|
||||
class ShippingOption(TelegramObject):
|
||||
"""
|
||||
This object represents one shipping option.
|
||||
"""This object represents one shipping option.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Shipping option identifier.
|
||||
|
@ -35,6 +34,7 @@ class ShippingOption(TelegramObject):
|
|||
title (:obj:`str`): Option title.
|
||||
prices (List[:class:`telegram.LabeledPrice`]): List of price portions.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, id, title, prices, **kwargs):
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, User, ShippingAddress
|
|||
|
||||
|
||||
class ShippingQuery(TelegramObject):
|
||||
"""
|
||||
This object contains information about an incoming shipping query.
|
||||
"""This object contains information about an incoming shipping query.
|
||||
|
||||
Note:
|
||||
* In Python `from` is a reserved word, use `from_user` instead.
|
||||
|
@ -42,6 +41,7 @@ class ShippingQuery(TelegramObject):
|
|||
shipping_address (:class:`telegram.ShippingAddress`): User specified shipping address.
|
||||
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, invoice_payload, shipping_address, bot=None, **kwargs):
|
||||
|
@ -74,10 +74,9 @@ class ShippingQuery(TelegramObject):
|
|||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for::
|
||||
"""Shortcut for::
|
||||
|
||||
bot.answer_shipping_query(update.shipping_query.id, *args, **kwargs)
|
||||
bot.answer_shipping_query(update.shipping_query.id, *args, **kwargs)
|
||||
|
||||
Args:
|
||||
ok (:obj:`bool`): Specify True if delivery to the specified address is possible and
|
||||
|
@ -89,6 +88,6 @@ class ShippingQuery(TelegramObject):
|
|||
readable form that explains why it is impossible to complete the order (e.g.
|
||||
"Sorry, delivery to your desired address is unavailable'). Telegram will display
|
||||
this message to the user.
|
||||
"""
|
||||
|
||||
"""
|
||||
return self.bot.answer_shipping_query(self.id, *args, **kwargs)
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject, OrderInfo
|
|||
|
||||
|
||||
class SuccessfulPayment(TelegramObject):
|
||||
"""
|
||||
This object contains basic information about a successful payment.
|
||||
"""This object contains basic information about a successful payment.
|
||||
|
||||
Attributes:
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code.
|
||||
|
@ -48,6 +47,7 @@ class SuccessfulPayment(TelegramObject):
|
|||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier.
|
||||
provider_payment_charge_id (:obj:`str`): Provider payment identifier.
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import ReplyMarkup, KeyboardButton
|
|||
|
||||
|
||||
class ReplyKeyboardMarkup(ReplyMarkup):
|
||||
"""
|
||||
This object represents a custom keyboard with reply options.
|
||||
"""This object represents a custom keyboard with reply options.
|
||||
|
||||
Attributes:
|
||||
keyboard (List[List[:class:`telegram.KeyboardButton` | :obj:`str`]]): Array of button rows.
|
||||
|
@ -57,6 +56,7 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
|||
Defaults to ``False``.
|
||||
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -46,6 +46,7 @@ class ReplyKeyboardRemove(ReplyMarkup):
|
|||
message.
|
||||
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, selective=False, **kwargs):
|
||||
|
|
|
@ -26,5 +26,6 @@ class ReplyMarkup(TelegramObject):
|
|||
|
||||
See :class:`telegram.ReplyKeyboardMarkup` and :class:`telegram.InlineKeyboardMarkup` for
|
||||
detailed use.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
|
|
@ -23,8 +23,7 @@ from telegram import (Message, TelegramObject, InlineQuery, ChosenInlineResult,
|
|||
|
||||
|
||||
class Update(TelegramObject):
|
||||
"""
|
||||
This object represents an incoming update.
|
||||
"""This object represents an incoming update.
|
||||
|
||||
Note:
|
||||
At most one of the optional parameters can be present in any given update.
|
||||
|
@ -65,6 +64,7 @@ class Update(TelegramObject):
|
|||
pre_checkout_query (:class:`telegram.PreCheckoutQuery`, optional): New incoming
|
||||
pre-checkout query. Contains full information about checkout
|
||||
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -103,8 +103,8 @@ class Update(TelegramObject):
|
|||
"""
|
||||
:class:`telegram.User`: The user that sent this update, no matter what kind of update this
|
||||
is. Will be ``None`` for :attr:`channel_post`.
|
||||
"""
|
||||
|
||||
"""
|
||||
if self._effective_user:
|
||||
return self._effective_user
|
||||
|
||||
|
@ -141,8 +141,8 @@ class Update(TelegramObject):
|
|||
update this is. Will be ``None`` for :attr:`inline_query`,
|
||||
:attr:`chosen_inline_result`, :attr:`callback_query` from inline messages,
|
||||
:attr:`shipping_query` and :attr:`pre_checkout_query`.
|
||||
"""
|
||||
|
||||
"""
|
||||
if self._effective_chat:
|
||||
return self._effective_chat
|
||||
|
||||
|
@ -173,8 +173,8 @@ class Update(TelegramObject):
|
|||
update this is. Will be ``None`` for :attr:`inline_query`,
|
||||
:attr:`chosen_inline_result`, :attr:`callback_query` from inline messages,
|
||||
:attr:`shipping_query` and :attr:`pre_checkout_query`.
|
||||
"""
|
||||
|
||||
"""
|
||||
if self._effective_message:
|
||||
return self._effective_message
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ from telegram.utils.helpers import mention_html as util_mention_html
|
|||
|
||||
|
||||
class User(TelegramObject):
|
||||
"""
|
||||
This object represents a Telegram user or bot.
|
||||
"""This object represents a Telegram user or bot.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`int`): Unique identifier for this user or bot.
|
||||
|
@ -45,6 +44,7 @@ class User(TelegramObject):
|
|||
username (:obj:`str`, optional): User's or bot's username.
|
||||
language_code (:obj:`str`, optional): IETF language tag of the user's language.
|
||||
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
@ -74,6 +74,7 @@ class User(TelegramObject):
|
|||
"""
|
||||
:obj:`str`: The users :attr:`username` if available, if not it returns the first name and
|
||||
if present :attr:`first_name` and :attr:`last_name`.
|
||||
|
||||
"""
|
||||
|
||||
if self.username:
|
||||
|
|
|
@ -22,10 +22,7 @@ from telegram import PhotoSize, TelegramObject
|
|||
|
||||
|
||||
class UserProfilePhotos(TelegramObject):
|
||||
"""
|
||||
This object represents a Telegram UserProfilePhotos.
|
||||
|
||||
This object represent a user's profile pictures.
|
||||
"""This object represent a user's profile pictures.
|
||||
|
||||
Attributes:
|
||||
total_count (:obj:`int`): Total number of profile pictures.
|
||||
|
@ -35,6 +32,7 @@ class UserProfilePhotos(TelegramObject):
|
|||
total_count (:obj:`int`): Total number of profile pictures the target user has.
|
||||
photos (List[List[:class:`telegram.PhotoSize`]]): Requested profile pictures (in up to 4
|
||||
sizes each).
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, total_count, photos, **kwargs):
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 facilitates the deprecation of functions"""
|
||||
"""This module facilitates the deprecation of functions."""
|
||||
|
||||
import warnings
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 helper functions """
|
||||
"""This module contains helper functions."""
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
@ -41,7 +41,7 @@ else:
|
|||
|
||||
|
||||
def escape_markdown(text):
|
||||
"""Helper function to escape telegram markup symbols"""
|
||||
"""Helper function to escape telegram markup symbols."""
|
||||
escape_chars = '\*_`\['
|
||||
return re.sub(r'([%s])' % escape_chars, r'\\\1', text)
|
||||
|
||||
|
@ -53,6 +53,7 @@ def to_timestamp(dt_obj):
|
|||
|
||||
Returns:
|
||||
int:
|
||||
|
||||
"""
|
||||
if not dt_obj:
|
||||
return None
|
||||
|
@ -67,6 +68,7 @@ def from_timestamp(unixtime):
|
|||
|
||||
Returns:
|
||||
datetime.datetime:
|
||||
|
||||
"""
|
||||
if not unixtime:
|
||||
return None
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 the Promise class """
|
||||
"""This module contains the Promise class."""
|
||||
|
||||
import logging
|
||||
from threading import Event
|
||||
|
@ -27,7 +27,7 @@ logger.addHandler(logging.NullHandler())
|
|||
|
||||
|
||||
class Promise(object):
|
||||
"""A simple Promise implementation for the run_async decorator"""
|
||||
"""A simple Promise implementation for the run_async decorator."""
|
||||
|
||||
def __init__(self, pooled_function, args, kwargs):
|
||||
self.pooled_function = pooled_function
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
# 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 methods to make POST and GET requests"""
|
||||
"""This module contains methods to make POST and GET requests."""
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
|
|
@ -120,6 +120,6 @@ class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler, object):
|
|||
arguments (it's just like printf!).
|
||||
|
||||
The client ip is prefixed to every message.
|
||||
"""
|
||||
|
||||
"""
|
||||
self.logger.debug("%s - - %s" % (self.address_string(), format % args))
|
||||
|
|
|
@ -22,8 +22,7 @@ from telegram import TelegramObject
|
|||
|
||||
|
||||
class WebhookInfo(TelegramObject):
|
||||
"""
|
||||
This object represents a Telegram WebhookInfo.
|
||||
"""This object represents a Telegram WebhookInfo.
|
||||
|
||||
Contains information about the current status of a webhook.
|
||||
|
||||
|
@ -51,6 +50,7 @@ class WebhookInfo(TelegramObject):
|
|||
connections to the webhook for update delivery.
|
||||
allowed_updates (List[:obj:`str`], optional): A list of update types the bot is subscribed
|
||||
to. Defaults to all update types.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
Loading…
Add table
Reference in a new issue