Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62e76f1

Browse files
feuillemortetsnoam
authored andcommitted
bot.py: Add shortcut method reply_media_group (python-telegram-bot#994)
fixes python-telegram-bot#936
1 parent f0dfdfb commit 62e76f1

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ htmlcov/
4040
.coverage
4141
.coverage.*
4242
.cache
43+
.pytest_cache
4344
nosetests.xml
4445
coverage.xml
4546
*,cover

AUTHORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The following wonderful people contributed directly or indirectly to this projec
5151
- `njittam <https://github.com/njittam>`_
5252
- `Noam Meltzer <https://github.com/tsnoam>`_
5353
- `Oleg Shlyazhko <https://github.com/ollmer>`_
54+
- `Oleg Sushchenko <https://github.com/feuillemorte>`_
5455
- `overquota <https://github.com/overquota>`_
5556
- `Patrick Hofmann <https://github.com/PH89>`_
5657
- `Pieter Schutz <https://github.com/eldinnie>`_

telegram/message.py

+20
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,26 @@ def reply_html(self, *args, **kwargs):
468468

469469
return self.bot.send_message(self.chat_id, *args, **kwargs)
470470

471+
def reply_media_group(self, *args, **kwargs):
472+
"""Shortcut for::
473+
474+
bot.reply_media_group(update.message.chat_id, *args, **kwargs)
475+
476+
Keyword Args:
477+
quote (:obj:`bool`, optional): If set to ``True``, the media group is sent as an
478+
actual reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``,
479+
this parameter will be ignored. Default: ``True`` in group chats and ``False`` in
480+
private chats.
481+
482+
Returns:
483+
List[:class:`telegram.Message`]: An array of the sent Messages.
484+
485+
Raises:
486+
:class:`telegram.TelegramError`
487+
"""
488+
self._quote(kwargs)
489+
return self.bot.send_media_group(self.chat_id, *args, **kwargs)
490+
471491
def reply_photo(self, *args, **kwargs):
472492
"""Shortcut for::
473493

tests/test_message.py

+14
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ def test(*args, **kwargs):
291291
reply_to_message_id=message.message_id,
292292
quote=True)
293293

294+
def test_reply_media_group(self, monkeypatch, message):
295+
def test(*args, **kwargs):
296+
id = args[1] == message.chat_id
297+
media = kwargs['media'] == 'reply_media_group'
298+
if kwargs.get('reply_to_message_id'):
299+
reply = kwargs['reply_to_message_id'] == message.message_id
300+
else:
301+
reply = True
302+
return id and media and reply
303+
304+
monkeypatch.setattr('telegram.Bot.send_media_group', test)
305+
assert message.reply_media_group(media='reply_media_group')
306+
assert message.reply_media_group(media='reply_media_group', quote=True)
307+
294308
def test_reply_photo(self, monkeypatch, message):
295309
def test(*args, **kwargs):
296310
id = args[1] == message.chat_id

0 commit comments

Comments
 (0)