From 62e76f1fbabf1dffa7a97fedeb1fb80d546b2734 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 12 Feb 2018 16:51:18 +0300 Subject: [PATCH] bot.py: Add shortcut method reply_media_group (#994) fixes #936 --- .gitignore | 1 + AUTHORS.rst | 1 + telegram/message.py | 20 ++++++++++++++++++++ tests/test_message.py | 14 ++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index 1b0919aba..b477f2693 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ htmlcov/ .coverage .coverage.* .cache +.pytest_cache nosetests.xml coverage.xml *,cover diff --git a/AUTHORS.rst b/AUTHORS.rst index d9f87d8ce..9282f2b1f 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -51,6 +51,7 @@ The following wonderful people contributed directly or indirectly to this projec - `njittam `_ - `Noam Meltzer `_ - `Oleg Shlyazhko `_ +- `Oleg Sushchenko `_ - `overquota `_ - `Patrick Hofmann `_ - `Pieter Schutz `_ diff --git a/telegram/message.py b/telegram/message.py index d72d3d12f..3961d6a10 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -468,6 +468,26 @@ class Message(TelegramObject): return self.bot.send_message(self.chat_id, *args, **kwargs) + def reply_media_group(self, *args, **kwargs): + """Shortcut for:: + + bot.reply_media_group(update.message.chat_id, *args, **kwargs) + + Keyword Args: + quote (:obj:`bool`, optional): If set to ``True``, the media group is sent as an + actual 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. + + Returns: + List[:class:`telegram.Message`]: An array of the sent Messages. + + Raises: + :class:`telegram.TelegramError` + """ + self._quote(kwargs) + return self.bot.send_media_group(self.chat_id, *args, **kwargs) + def reply_photo(self, *args, **kwargs): """Shortcut for:: diff --git a/tests/test_message.py b/tests/test_message.py index d547b8dd0..39777fe2c 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -291,6 +291,20 @@ class TestMessage(object): reply_to_message_id=message.message_id, quote=True) + def test_reply_media_group(self, monkeypatch, message): + def test(*args, **kwargs): + id = args[1] == message.chat_id + media = kwargs['media'] == 'reply_media_group' + if kwargs.get('reply_to_message_id'): + reply = kwargs['reply_to_message_id'] == message.message_id + else: + reply = True + return id and media and reply + + monkeypatch.setattr('telegram.Bot.send_media_group', test) + assert message.reply_media_group(media='reply_media_group') + assert message.reply_media_group(media='reply_media_group', quote=True) + def test_reply_photo(self, monkeypatch, message): def test(*args, **kwargs): id = args[1] == message.chat_id