Allow multiple inputfiles in requests by jsmnbom · Pull Request #1184 · python-telegram-bot/python-telegram-bot · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions telegram/__init__.py
267 changes: 205 additions & 62 deletions telegram/bot.py

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ def send_document(self, *args, **kwargs):
"""
return self.bot.send_document(self.id, *args, **kwargs)

def send_animation(self, *args, **kwargs):
"""Shortcut for::

bot.send_animation(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:
:class:`telegram.Message`: On success, instance representing the message posted.

"""
return self.bot.send_animation(self.id, *args, **kwargs)

def send_sticker(self, *args, **kwargs):
"""Shortcut for::

Expand Down
2 changes: 1 addition & 1 deletion telegram/ext/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_instance(cls):

"""
if cls.__singleton is not None:
return cls.__singleton()
return cls.__singleton() # pylint: disable=not-callable
else:
raise RuntimeError('{} not initialized or multiple instances exist'.format(
cls.__name__))
Expand Down
9 changes: 9 additions & 0 deletions telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ def filter(self, message):
document = _Document()
""":obj:`Filter`: Messages that contain :class:`telegram.Document`."""

class _Animation(BaseFilter):
name = 'Filters.animation'

def filter(self, message):
return bool(message.animation)

animation = _Animation()
""":obj:`Filter`: Messages that contain :class:`telegram.Animation`."""

class _Photo(BaseFilter):
name = 'Filters.photo'

Expand Down
16 changes: 15 additions & 1 deletion telegram/games/animation.py → telegram/files/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Animation(TelegramObject):

Attributes:
file_id (:obj:`str`): Unique file identifier.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
thumb (:class:`telegram.PhotoSize`): Optional. Animation thumbnail as defined
by sender.
file_name (:obj:`str`): Optional. Original animation filename as defined by sender.
Expand All @@ -34,6 +37,9 @@ class Animation(TelegramObject):

Args:
file_id (:obj:`str`): Unique file identifier.
width (:obj:`int`): Video width as defined by sender.
height (:obj:`int`): Video height as defined by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
thumb (:class:`telegram.PhotoSize`, optional): Animation thumbnail as defined by sender.
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.
Expand All @@ -43,12 +49,20 @@ class Animation(TelegramObject):

def __init__(self,
file_id,
width,
height,
duration,
thumb=None,
file_name=None,
mime_type=None,
file_size=None,
**kwargs):
self.file_id = file_id
# Required
self.file_id = str(file_id)
self.width = int(width)
self.height = int(height)

self.duration = duration
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
Expand Down
10 changes: 9 additions & 1 deletion telegram/files/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Audio."""

from telegram import TelegramObject
from telegram import TelegramObject, PhotoSize


class Audio(TelegramObject):
Expand All @@ -32,6 +32,8 @@ 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.
thumb (:class:`telegram.PhotoSize`): Optional. Thumbnail of the album cover to
which the music file belongs
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.

Args:
Expand All @@ -42,6 +44,8 @@ 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.
thumb (:class:`telegram.PhotoSize`, optional): Thumbnail of the album cover to
which the music file belongs
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

Expand All @@ -54,6 +58,7 @@ def __init__(self,
title=None,
mime_type=None,
file_size=None,
thumb=None,
bot=None,
**kwargs):
# Required
Expand All @@ -64,6 +69,7 @@ def __init__(self,
self.title = title
self.mime_type = mime_type
self.file_size = file_size
self.thumb = thumb
self.bot = bot

self._id_attrs = (self.file_id,)
Expand All @@ -73,6 +79,8 @@ def de_json(cls, data, bot):
if not data:
return None

data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)

return cls(bot=bot, **data)

def get_file(self, timeout=None, **kwargs):
Expand Down
144 changes: 32 additions & 112 deletions telegram/files/inputfile.py
Loading