From 58674e87f335ecc5945b9d8b0762e5a4f2d62c7a Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Wed, 3 Jan 2018 16:03:15 +0100 Subject: [PATCH 1/9] Bot.get_file now allows passing a file instead of file_id --- telegram/bot.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index ef66cf7dff5..2979f21d0e0 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # pylint: disable=E0611,E0213,E1102,C0103,E1101,W0613,R0913,R0904 +# flake8: noqa E501 # # A library that provides a Python interface to the Telegram Bot API # Copyright (C) 2015-2017 @@ -1305,7 +1306,7 @@ def get_user_profile_photos(self, user_id, offset=None, limit=100, timeout=None, return UserProfilePhotos.de_json(result, self) @log - def get_file(self, file_id, timeout=None, **kwargs): + def get_file(self, file_or_file_id, timeout=None, **kwargs): """ Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. The file can then be downloaded @@ -1314,7 +1315,9 @@ def get_file(self, file_id, timeout=None, **kwargs): calling getFile again. Args: - file_id (:obj:`str`): File identifier to get info about. + file_or_file_id (:obj:`str` | :class:`telegram.Audio` | :class:`telegram.Document` | :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | :class:`telegram.Video` | :class:`telegram.VideoNote` | :class:`telegram.Voice`): + Either the file identifier or an object that has a file_id attribute + to get file information about. timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool). @@ -1329,7 +1332,12 @@ def get_file(self, file_id, timeout=None, **kwargs): """ url = '{0}/getFile'.format(self.base_url) - data = {'file_id': file_id} + try: + file_or_file_id = file_or_file_id.file_id + except AttributeError: + pass + + data = {'file_id': file_or_file_id} data.update(kwargs) result = self._request.post(url, data, timeout=timeout) From bc6e2d3f569aa2d8774b26e2ddbabd4c52272ead Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Wed, 3 Jan 2018 16:24:48 +0100 Subject: [PATCH 2/9] Add .get_file() to Audio, Document, PhotoSize, Sticker, Video, VideoNote and Voice --- telegram/bot.py | 2 +- telegram/files/audio.py | 29 ++++++++++++++++++++++++++++- telegram/files/document.py | 29 ++++++++++++++++++++++++++++- telegram/files/photosize.py | 30 ++++++++++++++++++++++++++++-- telegram/files/sticker.py | 31 +++++++++++++++++++++++++++++-- telegram/files/video.py | 29 ++++++++++++++++++++++++++++- telegram/files/videonote.py | 30 ++++++++++++++++++++++++++++-- telegram/files/voice.py | 30 ++++++++++++++++++++++++++++-- 8 files changed, 198 insertions(+), 12 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 2979f21d0e0..98a6db48ac7 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -1312,7 +1312,7 @@ def get_file(self, file_or_file_id, timeout=None, **kwargs): moment, bots can download files of up to 20MB in size. The file can then be downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by - calling getFile again. + calling get_file again. Args: file_or_file_id (:obj:`str` | :class:`telegram.Audio` | :class:`telegram.Document` | :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | :class:`telegram.Video` | :class:`telegram.VideoNote` | :class:`telegram.Voice`): diff --git a/telegram/files/audio.py b/telegram/files/audio.py index 03913e52d55..67f2132eced 100644 --- a/telegram/files/audio.py +++ b/telegram/files/audio.py @@ -32,6 +32,7 @@ class Audio(TelegramObject): title (:obj:`str`): Optional. Title of the audio as defined by sender or by audio tags. mime_type (:obj:`str`): Optional. MIME type of the file as defined by sender. file_size (:obj:`int`): Optional. File size. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique identifier for this file. @@ -41,6 +42,7 @@ class Audio(TelegramObject): title (:obj:`str`, optional): Title of the audio as defined by sender or by audio tags. mime_type (:obj:`str`, optional): MIME type of the file as defined by sender. file_size (:obj:`int`, optional): File size. + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ @@ -52,6 +54,7 @@ def __init__(self, title=None, mime_type=None, file_size=None, + bot=None, **kwargs): # Required self.file_id = str(file_id) @@ -61,6 +64,7 @@ def __init__(self, self.title = title self.mime_type = mime_type self.file_size = file_size + self.bot = bot self._id_attrs = (self.file_id,) @@ -69,4 +73,27 @@ def de_json(cls, data, bot): if not data: return None - return cls(**data) + return cls(bot=bot, **data) + + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the audio file and prepare it for downloading. + For the moment, bots can download files of up to 20MB in size. The file can then be + downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be + valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) diff --git a/telegram/files/document.py b/telegram/files/document.py index 73b27ea728a..4ad71bb3057 100644 --- a/telegram/files/document.py +++ b/telegram/files/document.py @@ -30,6 +30,7 @@ class Document(TelegramObject): file_name (:obj:`str`): Original filename. mime_type (:obj:`str`): Optional. MIME type of the file. file_size (:obj:`int`): Optional. File size. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique file identifier @@ -37,6 +38,7 @@ class Document(TelegramObject): file_name (:obj:`str`, optional): Original 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. + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ @@ -48,6 +50,7 @@ def __init__(self, file_name=None, mime_type=None, file_size=None, + bot=None, **kwargs): # Required self.file_id = str(file_id) @@ -56,6 +59,7 @@ def __init__(self, self.file_name = file_name self.mime_type = mime_type self.file_size = file_size + self.bot = bot self._id_attrs = (self.file_id,) @@ -68,4 +72,27 @@ def de_json(cls, data, bot): data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return cls(**data) + return cls(**data, bot=bot) + + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the document and prepare it for downloading. For + the moment, bots can download files of up to 20MB in size. The file can then be downloaded + with :attr:`telegram.File.download`. It is guaranteed that the link will be + valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) diff --git a/telegram/files/photosize.py b/telegram/files/photosize.py index fabd339520c..6dfbf623398 100644 --- a/telegram/files/photosize.py +++ b/telegram/files/photosize.py @@ -29,23 +29,26 @@ class PhotoSize(TelegramObject): width (:obj:`int`): Photo width. height (:obj:`int`): Photo height. file_size (:obj:`int`): Optional. File size. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique identifier for this file. width (:obj:`int`): Photo width. height (:obj:`int`): Photo height. file_size (:obj:`int`, optional): File size. + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ - def __init__(self, file_id, width, height, file_size=None, **kwargs): + def __init__(self, file_id, width, height, file_size=None, bot=None, **kwargs): # Required self.file_id = str(file_id) self.width = int(width) self.height = int(height) # Optionals self.file_size = file_size + self.bot = bot self._id_attrs = (self.file_id,) @@ -54,7 +57,7 @@ def de_json(cls, data, bot): if not data: return None - return cls(**data) + return cls(bot=bot, **data) @classmethod def de_list(cls, data, bot): @@ -66,3 +69,26 @@ def de_list(cls, data, bot): photos.append(cls.de_json(photo, bot)) return photos + + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the photo (only one size) and prepare it for + downloading. For the moment, bots can download files of up to 20MB in size. The file can + then be downloaded with :attr:`telegram.File.download`. It is guaranteed that the link + will be valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) diff --git a/telegram/files/sticker.py b/telegram/files/sticker.py index cec8cd72baf..8e79ce0ef34 100644 --- a/telegram/files/sticker.py +++ b/telegram/files/sticker.py @@ -35,6 +35,7 @@ class Sticker(TelegramObject): mask_position (:class:`telegram.MaskPosition`): Optional. For mask stickers, the position where the mask should be placed. file_size (:obj:`int`): Optional. File size. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique identifier for this file. @@ -48,7 +49,8 @@ class Sticker(TelegramObject): mask_position (:class:`telegram.MaskPosition`, optional): For mask stickers, the position where the mask should be placed. file_size (:obj:`int`, optional): File size. - **kwargs (obj:`dict`): Arbitrary keyword arguments. + **kwargs (obj:`dict`): Arbitrary keyword arguments.7 + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. """ @@ -61,6 +63,7 @@ def __init__(self, file_size=None, set_name=None, mask_position=None, + bot=None, **kwargs): # Required self.file_id = str(file_id) @@ -72,6 +75,7 @@ def __init__(self, self.file_size = file_size self.set_name = set_name self.mask_position = mask_position + self.bot = bot self._id_attrs = (self.file_id,) @@ -85,7 +89,7 @@ def de_json(cls, data, bot): data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) data['mask_position'] = MaskPosition.de_json(data.get('mask_position'), bot) - return cls(**data) + return cls(bot=bot, **data) @classmethod def de_list(cls, data, bot): @@ -94,6 +98,29 @@ def de_list(cls, data, bot): return [cls.de_json(d, bot) for d in data] + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the sticker file and prepare it for downloading. + For the moment, bots can download files of up to 20MB in size. The file can then be + downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be + valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) + class StickerSet(TelegramObject): """This object represents a sticker set. diff --git a/telegram/files/video.py b/telegram/files/video.py index c53b873fcd4..0b61ce44444 100644 --- a/telegram/files/video.py +++ b/telegram/files/video.py @@ -32,6 +32,7 @@ class Video(TelegramObject): thumb (:class:`telegram.PhotoSize`): Optional. Video thumbnail. mime_type (:obj:`str`): Optional. Mime type of a file as defined by sender. file_size (:obj:`int`): Optional. File size. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique identifier for this file. @@ -41,6 +42,7 @@ class Video(TelegramObject): thumb (:class:`telegram.PhotoSize`, optional): Video thumbnail. mime_type (:obj:`str`, optional): Mime type of a file as defined by sender. file_size (:obj:`int`, optional): File size. + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ @@ -53,6 +55,7 @@ def __init__(self, thumb=None, mime_type=None, file_size=None, + bot=None, **kwargs): # Required self.file_id = str(file_id) @@ -63,6 +66,7 @@ def __init__(self, self.thumb = thumb self.mime_type = mime_type self.file_size = file_size + self.bot = bot self._id_attrs = (self.file_id,) @@ -75,4 +79,27 @@ def de_json(cls, data, bot): data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return cls(**data) + return cls(bot=bot, **data) + + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the video file and prepare it for downloading. + For the moment, bots can download files of up to 20MB in size. The file can then be + downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be + valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) diff --git a/telegram/files/videonote.py b/telegram/files/videonote.py index 2f17fdbbdf7..da521897aae 100644 --- a/telegram/files/videonote.py +++ b/telegram/files/videonote.py @@ -30,6 +30,7 @@ class VideoNote(TelegramObject): duration (:obj:`int`): Duration of the video in seconds as defined by sender. thumb (:class:`telegram.PhotoSize`): Optional. Video thumbnail. file_size (:obj:`int`): Optional. File size. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique identifier for this file. @@ -37,11 +38,12 @@ class VideoNote(TelegramObject): duration (:obj:`int`): Duration of the video in seconds as defined by sender. thumb (:class:`telegram.PhotoSize`, optional): Video thumbnail. file_size (:obj:`int`, optional): File size. + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ - def __init__(self, file_id, length, duration, thumb=None, file_size=None, **kwargs): + def __init__(self, file_id, length, duration, thumb=None, file_size=None, bot=None, **kwargs): # Required self.file_id = str(file_id) self.length = int(length) @@ -49,6 +51,7 @@ def __init__(self, file_id, length, duration, thumb=None, file_size=None, **kwar # Optionals self.thumb = thumb self.file_size = file_size + self.bot = bot self._id_attrs = (self.file_id,) @@ -61,4 +64,27 @@ def de_json(cls, data, bot): data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot) - return cls(**data) + return cls(bot=bot, **data) + + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the video message file and prepare it for + downloading. For the moment, bots can download files of up to 20MB in size. The file can + then be downloaded with :attr:`telegram.File.download`. It is guaranteed that the link + will be valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) diff --git a/telegram/files/voice.py b/telegram/files/voice.py index bc324a3f3e3..71bbf85faa4 100644 --- a/telegram/files/voice.py +++ b/telegram/files/voice.py @@ -29,23 +29,26 @@ class Voice(TelegramObject): duration (:obj:`int`): Duration of the audio in seconds 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. + bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. Args: file_id (:obj:`str`): Unique identifier for this file. duration (:obj:`int`, optional): Duration of the audio in seconds 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. + bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods. **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ - def __init__(self, file_id, duration, mime_type=None, file_size=None, **kwargs): + def __init__(self, file_id, duration, mime_type=None, file_size=None, bot=None, **kwargs): # Required self.file_id = str(file_id) self.duration = int(duration) # Optionals self.mime_type = mime_type self.file_size = file_size + self.bot = bot self._id_attrs = (self.file_id,) @@ -56,4 +59,27 @@ def de_json(cls, data, bot): data = super(Voice, cls).de_json(data, bot) - return cls(**data) + return cls(bot=bot, **data) + + def get_file(self, timeout=None, **kwargs): + """ + Use this method to get basic info about the sticker file and prepare it for downloading. + For the moment, bots can download files of up to 20MB in size. The file can then be + downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be + valid for at least 1 hour. When the link expires, a new one can be requested by + calling get_file again. + + Args: + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as + the read timeout from the server (instead of the one specified during creation of + the connection pool). + **kwargs (:obj:`dict`): Arbitrary keyword arguments. + + Returns: + :class:`telegram.File` + + Raises: + :class:`telegram.TelegramError` + + """ + return self.bot.get_file(self.file_id, timeout=timeout, **kwargs) From 5662fff524509f2b235923747f9bdc1af9aaba2e Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Wed, 3 Jan 2018 16:36:28 +0100 Subject: [PATCH 3/9] Add .send_*() methods to User and Chat --- telegram/chat.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++ telegram/user.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 209 insertions(+), 1 deletion(-) diff --git a/telegram/chat.py b/telegram/chat.py index b1db4dca1d1..36e686ba6b7 100644 --- a/telegram/chat.py +++ b/telegram/chat.py @@ -212,3 +212,107 @@ def unban_member(self, *args, **kwargs): """ return self.bot.unban_chat_member(self.id, *args, **kwargs) + + def send_message(self, *args, **kwargs): + """Shortcut for:: + + bot.send_message(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_message(chat_id=self.id, *args, **kwargs) + + def send_photo(self, *args, **kwargs): + """Shortcut for:: + + bot.send_photo(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_photo(chat_id=self.id, *args, **kwargs) + + def send_audio(self, *args, **kwargs): + """Shortcut for:: + + bot.send_audio(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_audio(chat_id=self.id, *args, **kwargs) + + def send_document(self, *args, **kwargs): + """Shortcut for:: + + bot.send_document(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_document(chat_id=self.id, *args, **kwargs) + + def send_sticker(self, *args, **kwargs): + """Shortcut for:: + + bot.send_sticker(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_sticker(chat_id=self.id, *args, **kwargs) + + def send_video(self, *args, **kwargs): + """Shortcut for:: + + bot.send_video(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_video(chat_id=self.id, *args, **kwargs) + + def send_video_note(self, *args, **kwargs): + """Shortcut for:: + + bot.send_video_note(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_video_note(chat_id=self.id, *args, **kwargs) + + def send_voice(self, *args, **kwargs): + """Shortcut for:: + + bot.send_voice(Chat.chat_id, *args, **kwargs) + + Where Chat is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_voice(chat_id=self.id, *args, **kwargs) diff --git a/telegram/user.py b/telegram/user.py index 66024250e06..389ae7eca05 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -20,8 +20,8 @@ """This module contains an object that represents a Telegram User.""" from telegram import TelegramObject -from telegram.utils.helpers import mention_markdown as util_mention_markdown from telegram.utils.helpers import mention_html as util_mention_html +from telegram.utils.helpers import mention_markdown as util_mention_markdown class User(TelegramObject): @@ -146,3 +146,107 @@ def mention_html(self, name=None): return util_mention_html(self.id, self.name) else: return util_mention_html(self.id, name) + + def send_message(self, *args, **kwargs): + """Shortcut for:: + + bot.send_message(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_message(chat_id=self.id, *args, **kwargs) + + def send_photo(self, *args, **kwargs): + """Shortcut for:: + + bot.send_photo(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_photo(chat_id=self.id, *args, **kwargs) + + def send_audio(self, *args, **kwargs): + """Shortcut for:: + + bot.send_audio(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_audio(chat_id=self.id, *args, **kwargs) + + def send_document(self, *args, **kwargs): + """Shortcut for:: + + bot.send_document(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_document(chat_id=self.id, *args, **kwargs) + + def send_sticker(self, *args, **kwargs): + """Shortcut for:: + + bot.send_sticker(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_sticker(chat_id=self.id, *args, **kwargs) + + def send_video(self, *args, **kwargs): + """Shortcut for:: + + bot.send_video(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_video(chat_id=self.id, *args, **kwargs) + + def send_video_note(self, *args, **kwargs): + """Shortcut for:: + + bot.send_video_note(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_video_note(chat_id=self.id, *args, **kwargs) + + def send_voice(self, *args, **kwargs): + """Shortcut for:: + + bot.send_voice(User.chat_id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.send_voice(chat_id=self.id, *args, **kwargs) From 65ee2b618ad4003dadb99a87be803fd39b58aacf Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Wed, 3 Jan 2018 16:44:17 +0100 Subject: [PATCH 4/9] Tests for *.get_file() instance methods --- tests/test_audio.py | 7 +++++++ tests/test_document.py | 7 +++++++ tests/test_photo.py | 7 +++++++ tests/test_sticker.py | 7 +++++++ tests/test_video.py | 7 +++++++ tests/test_videonote.py | 7 +++++++ tests/test_voice.py | 7 +++++++ 7 files changed, 49 insertions(+) diff --git a/tests/test_audio.py b/tests/test_audio.py index efad15925f7..610b9d7b385 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -165,6 +165,13 @@ def test_error_send_without_required_args(self, bot, chat_id): with pytest.raises(TypeError): bot.send_audio(chat_id=chat_id) + def test_get_file_instance_method(self, monkeypatch, audio): + def test(*args, **kwargs): + return args[1] == audio.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert audio.get_file() + def test_equality(self, audio): a = Audio(audio.file_id, audio.duration) b = Audio(audio.file_id, audio.duration) diff --git a/tests/test_document.py b/tests/test_document.py index ef92203a972..0dfc645741a 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -162,6 +162,13 @@ def test_error_send_without_required_args(self, bot, chat_id): with pytest.raises(TypeError): bot.send_document(chat_id=chat_id) + def test_get_file_instance_method(self, monkeypatch, document): + def test(*args, **kwargs): + return args[1] == document.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert document.get_file() + def test_equality(self, document): a = Document(document.file_id) b = Document(document.file_id) diff --git a/tests/test_photo.py b/tests/test_photo.py index 0563c485b1e..28564d0c410 100644 --- a/tests/test_photo.py +++ b/tests/test_photo.py @@ -246,6 +246,13 @@ def test_error_without_required_args(self, bot, chat_id): with pytest.raises(TypeError): bot.send_photo(chat_id=chat_id) + def test_get_file_instance_method(self, monkeypatch, photo): + def test(*args, **kwargs): + return args[1] == photo.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert photo.get_file() + def test_equality(self, photo): a = PhotoSize(photo.file_id, self.width, self.height) b = PhotoSize(photo.file_id, self.width, self.height) diff --git a/tests/test_sticker.py b/tests/test_sticker.py index d6aa68b23e6..bbe3ec42df6 100644 --- a/tests/test_sticker.py +++ b/tests/test_sticker.py @@ -277,6 +277,13 @@ def test_bot_methods_3(self, bot, sticker_set): file_id = sticker_set.stickers[-1].file_id assert bot.delete_sticker_from_set(file_id) + def test_get_file_instance_method(self, monkeypatch, sticker): + def test(*args, **kwargs): + return args[1] == sticker.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert sticker.get_file() + def test_equality(self): a = StickerSet(self.name, self.title, self.contains_masks, self.stickers) b = StickerSet(self.name, self.title, self.contains_masks, self.stickers) diff --git a/tests/test_video.py b/tests/test_video.py index 9eec87cb10a..32a477eb013 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -183,6 +183,13 @@ def test_error_without_required_args(self, bot, chat_id): with pytest.raises(TypeError): bot.send_video(chat_id=chat_id) + def test_get_file_instance_method(self, monkeypatch, video): + def test(*args, **kwargs): + return args[1] == video.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert video.get_file() + def test_equality(self, video): a = Video(video.file_id, self.width, self.height, self.duration) b = Video(video.file_id, self.width, self.height, self.duration) diff --git a/tests/test_videonote.py b/tests/test_videonote.py index 3e386642ff1..2998885fa2a 100644 --- a/tests/test_videonote.py +++ b/tests/test_videonote.py @@ -146,6 +146,13 @@ def test_error_without_required_args(self, bot, chat_id): with pytest.raises(TypeError): bot.send_video_note(chat_id=chat_id) + def test_get_file_instance_method(self, monkeypatch, video_note): + def test(*args, **kwargs): + return args[1] == video_note.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert video_note.get_file() + def test_equality(self, video_note): a = VideoNote(video_note.file_id, self.length, self.duration) b = VideoNote(video_note.file_id, self.length, self.duration) diff --git a/tests/test_voice.py b/tests/test_voice.py index e12106eb565..fa676cca270 100644 --- a/tests/test_voice.py +++ b/tests/test_voice.py @@ -150,6 +150,13 @@ def test_error_without_required_args(self, bot, chat_id): with pytest.raises(TypeError): bot.sendVoice(chat_id) + def test_get_file_instance_method(self, monkeypatch, voice): + def test(*args, **kwargs): + return args[1] == voice.file_id + + monkeypatch.setattr('telegram.Bot.get_file', test) + assert voice.get_file() + def test_equality(self, voice): a = Voice(voice.file_id, self.duration) b = Voice(voice.file_id, self.duration) From e3505bdece32361d0149b3708be71777e3f317b4 Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Wed, 3 Jan 2018 16:57:35 +0100 Subject: [PATCH 5/9] Fix in send_*() for Chat and User --- telegram/chat.py | 16 ++++++++-------- telegram/user.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/telegram/chat.py b/telegram/chat.py index 36e686ba6b7..c9ed9832df6 100644 --- a/telegram/chat.py +++ b/telegram/chat.py @@ -224,7 +224,7 @@ def send_message(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_message(chat_id=self.id, *args, **kwargs) + return self.bot.send_message(chat_id=self.id, *args, **kwargs) def send_photo(self, *args, **kwargs): """Shortcut for:: @@ -237,7 +237,7 @@ def send_photo(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_photo(chat_id=self.id, *args, **kwargs) + return self.bot.send_photo(chat_id=self.id, *args, **kwargs) def send_audio(self, *args, **kwargs): """Shortcut for:: @@ -250,7 +250,7 @@ def send_audio(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_audio(chat_id=self.id, *args, **kwargs) + return self.bot.send_audio(chat_id=self.id, *args, **kwargs) def send_document(self, *args, **kwargs): """Shortcut for:: @@ -263,7 +263,7 @@ def send_document(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_document(chat_id=self.id, *args, **kwargs) + return self.bot.send_document(chat_id=self.id, *args, **kwargs) def send_sticker(self, *args, **kwargs): """Shortcut for:: @@ -276,7 +276,7 @@ def send_sticker(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_sticker(chat_id=self.id, *args, **kwargs) + return self.bot.send_sticker(chat_id=self.id, *args, **kwargs) def send_video(self, *args, **kwargs): """Shortcut for:: @@ -289,7 +289,7 @@ def send_video(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_video(chat_id=self.id, *args, **kwargs) + return self.bot.send_video(chat_id=self.id, *args, **kwargs) def send_video_note(self, *args, **kwargs): """Shortcut for:: @@ -302,7 +302,7 @@ def send_video_note(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_video_note(chat_id=self.id, *args, **kwargs) + return self.bot.send_video_note(chat_id=self.id, *args, **kwargs) def send_voice(self, *args, **kwargs): """Shortcut for:: @@ -315,4 +315,4 @@ def send_voice(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_voice(chat_id=self.id, *args, **kwargs) + return self.bot.send_voice(chat_id=self.id, *args, **kwargs) diff --git a/telegram/user.py b/telegram/user.py index 389ae7eca05..f56e23fa4df 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -158,7 +158,7 @@ def send_message(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_message(chat_id=self.id, *args, **kwargs) + return self.bot.send_message(chat_id=self.id, *args, **kwargs) def send_photo(self, *args, **kwargs): """Shortcut for:: @@ -171,7 +171,7 @@ def send_photo(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_photo(chat_id=self.id, *args, **kwargs) + return self.bot.send_photo(chat_id=self.id, *args, **kwargs) def send_audio(self, *args, **kwargs): """Shortcut for:: @@ -184,7 +184,7 @@ def send_audio(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_audio(chat_id=self.id, *args, **kwargs) + return self.bot.send_audio(chat_id=self.id, *args, **kwargs) def send_document(self, *args, **kwargs): """Shortcut for:: @@ -197,7 +197,7 @@ def send_document(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_document(chat_id=self.id, *args, **kwargs) + return self.bot.send_document(chat_id=self.id, *args, **kwargs) def send_sticker(self, *args, **kwargs): """Shortcut for:: @@ -210,7 +210,7 @@ def send_sticker(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_sticker(chat_id=self.id, *args, **kwargs) + return self.bot.send_sticker(chat_id=self.id, *args, **kwargs) def send_video(self, *args, **kwargs): """Shortcut for:: @@ -223,7 +223,7 @@ def send_video(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_video(chat_id=self.id, *args, **kwargs) + return self.bot.send_video(chat_id=self.id, *args, **kwargs) def send_video_note(self, *args, **kwargs): """Shortcut for:: @@ -236,7 +236,7 @@ def send_video_note(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_video_note(chat_id=self.id, *args, **kwargs) + return self.bot.send_video_note(chat_id=self.id, *args, **kwargs) def send_voice(self, *args, **kwargs): """Shortcut for:: @@ -249,4 +249,4 @@ def send_voice(self, *args, **kwargs): :class:`telegram.Message`: On success, instance representing the message posted. """ - return self.send_voice(chat_id=self.id, *args, **kwargs) + return self.bot.send_voice(chat_id=self.id, *args, **kwargs) From 45f27004ac5bf19a1a3591745f3c17955ba20960 Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Wed, 3 Jan 2018 16:59:25 +0100 Subject: [PATCH 6/9] Tests for .send_*() for Chat and User --- tests/test_chat.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_user.py | 51 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/tests/test_chat.py b/tests/test_chat.py index dd4e3ee22fb..5655679cab1 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -124,6 +124,55 @@ def test(*args, **kwargs): monkeypatch.setattr('telegram.Bot.unban_chat_member', test) assert chat.unban_member(42) + def test_instance_method_send_message(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and args[1] == 'test' + + monkeypatch.setattr('telegram.Bot.send_message', test) + assert chat.send_message('test') + + def test_instance_method_send_audio(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and kwargs['audio'] == 'test_audio' + + monkeypatch.setattr('telegram.Bot.send_audio', test) + assert chat.send_audio(audio='test_audio') + + def test_instance_method_send_document(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and kwargs['document'] == 'test_document' + + monkeypatch.setattr('telegram.Bot.send_document', test) + assert chat.send_document(document='test_document') + + def test_instance_method_send_sticker(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and kwargs['sticker'] == 'test_sticker' + + monkeypatch.setattr('telegram.Bot.send_sticker', test) + assert chat.send_sticker(sticker='test_sticker') + + def test_instance_method_send_video(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and kwargs['video'] == 'test_video' + + monkeypatch.setattr('telegram.Bot.send_video', test) + assert chat.send_video(video='test_video') + + def test_instance_method_send_video_note(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and kwargs['video_note'] == 'test_video_note' + + monkeypatch.setattr('telegram.Bot.send_video_note', test) + assert chat.send_video_note(video_note='test_video_note') + + def test_instance_method_send_voice(self, monkeypatch, chat): + def test(*args, **kwargs): + return kwargs['chat_id'] == chat.id and kwargs['voice'] == 'test_voice' + + monkeypatch.setattr('telegram.Bot.send_voice', test) + assert chat.send_voice(voice='test_voice') + def test_equality(self): a = Chat(self.id, self.title, self.type) b = Chat(self.id, self.title, self.type) diff --git a/tests/test_user.py b/tests/test_user.py index 14ddab2e2fb..8bf275a28ec 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -90,7 +90,7 @@ def test_name(self, user): assert user.name == 'first_name' user.username = self.username assert user.name == '@username' - + def test_full_name(self, user): assert user.full_name == 'first_name last_name' user.last_name = None @@ -103,6 +103,55 @@ def test(_, *args, **kwargs): monkeypatch.setattr('telegram.Bot.get_user_profile_photos', test) assert user.get_profile_photos() + def test_instance_method_send_message(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and args[1] == 'test' + + monkeypatch.setattr('telegram.Bot.send_message', test) + assert user.send_message('test') + + def test_instance_method_send_audio(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and kwargs['audio'] == 'test_audio' + + monkeypatch.setattr('telegram.Bot.send_audio', test) + assert user.send_audio(audio='test_audio') + + def test_instance_method_send_document(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and kwargs['document'] == 'test_document' + + monkeypatch.setattr('telegram.Bot.send_document', test) + assert user.send_document(document='test_document') + + def test_instance_method_send_sticker(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and kwargs['sticker'] == 'test_sticker' + + monkeypatch.setattr('telegram.Bot.send_sticker', test) + assert user.send_sticker(sticker='test_sticker') + + def test_instance_method_send_video(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and kwargs['video'] == 'test_video' + + monkeypatch.setattr('telegram.Bot.send_video', test) + assert user.send_video(video='test_video') + + def test_instance_method_send_video_note(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and kwargs['video_note'] == 'test_video_note' + + monkeypatch.setattr('telegram.Bot.send_video_note', test) + assert user.send_video_note(video_note='test_video_note') + + def test_instance_method_send_voice(self, monkeypatch, user): + def test(*args, **kwargs): + return kwargs['chat_id'] == user.id and kwargs['voice'] == 'test_voice' + + monkeypatch.setattr('telegram.Bot.send_voice', test) + assert user.send_voice(voice='test_voice') + def test_equality(self): a = User(self.id, self.first_name, self.is_bot, self.last_name) b = User(self.id, self.first_name, self.is_bot, self.last_name) From f1550bcd1907a56aa99dbc3ca64d7817a75d92c0 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sun, 18 Feb 2018 12:00:24 +0200 Subject: [PATCH 7/9] bot.py: Fix documentation style --- telegram/bot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 98a6db48ac7..39e718cd355 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # pylint: disable=E0611,E0213,E1102,C0103,E1101,W0613,R0913,R0904 -# flake8: noqa E501 # # A library that provides a Python interface to the Telegram Bot API # Copyright (C) 2015-2017 @@ -1315,7 +1314,10 @@ def get_file(self, file_or_file_id, timeout=None, **kwargs): calling get_file again. Args: - file_or_file_id (:obj:`str` | :class:`telegram.Audio` | :class:`telegram.Document` | :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | :class:`telegram.Video` | :class:`telegram.VideoNote` | :class:`telegram.Voice`): + file_or_file_id (:obj:`str` | :class:`telegram.Audio` | :class:`telegram.Document` | \ + :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | \ + :class:`telegram.Video` | :class:`telegram.VideoNote` | \ + :class:`telegram.Voice`): Either the file identifier or an object that has a file_id attribute to get file information about. timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as From dbe4c1c8a188c223b5b5f22a7b215fd2a3c7a8a2 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sun, 18 Feb 2018 12:17:46 +0200 Subject: [PATCH 8/9] Revert parameter name to 'file_id' to maintain backward compat --- telegram/bot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 39e718cd355..252a6190927 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -1305,7 +1305,7 @@ def get_user_profile_photos(self, user_id, offset=None, limit=100, timeout=None, return UserProfilePhotos.de_json(result, self) @log - def get_file(self, file_or_file_id, timeout=None, **kwargs): + def get_file(self, file_id, timeout=None, **kwargs): """ Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. The file can then be downloaded @@ -1314,10 +1314,10 @@ def get_file(self, file_or_file_id, timeout=None, **kwargs): calling get_file again. Args: - file_or_file_id (:obj:`str` | :class:`telegram.Audio` | :class:`telegram.Document` | \ - :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | \ - :class:`telegram.Video` | :class:`telegram.VideoNote` | \ - :class:`telegram.Voice`): + file_id (:obj:`str` | :class:`telegram.Audio` | :class:`telegram.Document` | \ + :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | \ + :class:`telegram.Video` | :class:`telegram.VideoNote` | \ + :class:`telegram.Voice`): Either the file identifier or an object that has a file_id attribute to get file information about. timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as @@ -1335,11 +1335,11 @@ def get_file(self, file_or_file_id, timeout=None, **kwargs): url = '{0}/getFile'.format(self.base_url) try: - file_or_file_id = file_or_file_id.file_id + file_id = file_id.file_id except AttributeError: pass - data = {'file_id': file_or_file_id} + data = {'file_id': file_id} data.update(kwargs) result = self._request.post(url, data, timeout=timeout) From 39f4f3664bf9b4f823c65d8688095486f9f37aaa Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sun, 18 Feb 2018 12:29:07 +0200 Subject: [PATCH 9/9] Fix documentation --- telegram/files/audio.py | 7 +------ telegram/files/document.py | 7 +------ telegram/files/photosize.py | 7 +------ telegram/files/sticker.py | 7 +------ telegram/files/video.py | 7 +------ telegram/files/videonote.py | 7 +------ telegram/files/voice.py | 7 +------ 7 files changed, 7 insertions(+), 42 deletions(-) diff --git a/telegram/files/audio.py b/telegram/files/audio.py index 67f2132eced..9be69666560 100644 --- a/telegram/files/audio.py +++ b/telegram/files/audio.py @@ -76,12 +76,7 @@ def de_json(cls, data, bot): return cls(bot=bot, **data) def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the audio file and prepare it for downloading. - For the moment, bots can download files of up to 20MB in size. The file can then be - downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be - valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as diff --git a/telegram/files/document.py b/telegram/files/document.py index 4ad71bb3057..85b58882581 100644 --- a/telegram/files/document.py +++ b/telegram/files/document.py @@ -75,12 +75,7 @@ def de_json(cls, data, bot): return cls(**data, bot=bot) def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the document and prepare it for downloading. For - the moment, bots can download files of up to 20MB in size. The file can then be downloaded - with :attr:`telegram.File.download`. It is guaranteed that the link will be - valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as diff --git a/telegram/files/photosize.py b/telegram/files/photosize.py index 6dfbf623398..561fed5b436 100644 --- a/telegram/files/photosize.py +++ b/telegram/files/photosize.py @@ -71,12 +71,7 @@ def de_list(cls, data, bot): return photos def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the photo (only one size) and prepare it for - downloading. For the moment, bots can download files of up to 20MB in size. The file can - then be downloaded with :attr:`telegram.File.download`. It is guaranteed that the link - will be valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as diff --git a/telegram/files/sticker.py b/telegram/files/sticker.py index 8e79ce0ef34..27444d8eaab 100644 --- a/telegram/files/sticker.py +++ b/telegram/files/sticker.py @@ -99,12 +99,7 @@ def de_list(cls, data, bot): return [cls.de_json(d, bot) for d in data] def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the sticker file and prepare it for downloading. - For the moment, bots can download files of up to 20MB in size. The file can then be - downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be - valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as diff --git a/telegram/files/video.py b/telegram/files/video.py index 0b61ce44444..f3c3efcdac6 100644 --- a/telegram/files/video.py +++ b/telegram/files/video.py @@ -82,12 +82,7 @@ def de_json(cls, data, bot): return cls(bot=bot, **data) def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the video file and prepare it for downloading. - For the moment, bots can download files of up to 20MB in size. The file can then be - downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be - valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as diff --git a/telegram/files/videonote.py b/telegram/files/videonote.py index da521897aae..95bb0238752 100644 --- a/telegram/files/videonote.py +++ b/telegram/files/videonote.py @@ -67,12 +67,7 @@ def de_json(cls, data, bot): return cls(bot=bot, **data) def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the video message file and prepare it for - downloading. For the moment, bots can download files of up to 20MB in size. The file can - then be downloaded with :attr:`telegram.File.download`. It is guaranteed that the link - will be valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as diff --git a/telegram/files/voice.py b/telegram/files/voice.py index 71bbf85faa4..4f2f870964a 100644 --- a/telegram/files/voice.py +++ b/telegram/files/voice.py @@ -62,12 +62,7 @@ def de_json(cls, data, bot): return cls(bot=bot, **data) def get_file(self, timeout=None, **kwargs): - """ - Use this method to get basic info about the sticker file and prepare it for downloading. - For the moment, bots can download files of up to 20MB in size. The file can then be - downloaded with :attr:`telegram.File.download`. It is guaranteed that the link will be - valid for at least 1 hour. When the link expires, a new one can be requested by - calling get_file again. + """Convenience wrapper over :attr:`telegram.Bot.get_file` Args: timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy