mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-18 15:20:42 +01:00
Add quote kwarg to Message.reply_copy (#2232)
* add quote kwrag to Message.reply_copy * Add docs & update tests
This commit is contained in:
parent
73b0e29a30
commit
e0dbb99b08
2 changed files with 39 additions and 24 deletions
|
@ -976,10 +976,17 @@ class Message(TelegramObject):
|
||||||
*args,
|
*args,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
quote (:obj:`bool`, optional): If set to :obj:`True`, the copy is sent as an actual
|
||||||
|
reply to this message. If ``reply_to_message_id`` is passed in ``kwargs``,
|
||||||
|
this parameter will be ignored. Default: :obj:`True` in group chats and
|
||||||
|
:obj:`False` in private chats.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:class:`telegram.MessageId`: On success, returns the MessageId of the sent message.
|
:class:`telegram.MessageId`: On success, returns the MessageId of the sent message.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
self._quote(kwargs)
|
||||||
return self.bot.copy_message(
|
return self.bot.copy_message(
|
||||||
chat_id=self.chat_id, from_chat_id=from_chat_id, message_id=message_id, *args, **kwargs
|
chat_id=self.chat_id, from_chat_id=from_chat_id, message_id=message_id, *args, **kwargs
|
||||||
)
|
)
|
||||||
|
|
|
@ -638,7 +638,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
text = args[1] == 'test'
|
text = args[1] == 'test'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -661,7 +661,7 @@ class TestMessage:
|
||||||
cid = args[0] == message.chat_id
|
cid = args[0] == message.chat_id
|
||||||
markdown_text = args[1] == test_md_string
|
markdown_text = args[1] == test_md_string
|
||||||
markdown_enabled = kwargs['parse_mode'] == ParseMode.MARKDOWN
|
markdown_enabled = kwargs['parse_mode'] == ParseMode.MARKDOWN
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -690,7 +690,7 @@ class TestMessage:
|
||||||
cid = args[0] == message.chat_id
|
cid = args[0] == message.chat_id
|
||||||
markdown_text = args[1] == test_md_string
|
markdown_text = args[1] == test_md_string
|
||||||
markdown_enabled = kwargs['parse_mode'] == ParseMode.MARKDOWN_V2
|
markdown_enabled = kwargs['parse_mode'] == ParseMode.MARKDOWN_V2
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -723,7 +723,7 @@ class TestMessage:
|
||||||
cid = args[0] == message.chat_id
|
cid = args[0] == message.chat_id
|
||||||
html_text = args[1] == test_html_string
|
html_text = args[1] == test_html_string
|
||||||
html_enabled = kwargs['parse_mode'] == ParseMode.HTML
|
html_enabled = kwargs['parse_mode'] == ParseMode.HTML
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -743,7 +743,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
media = kwargs['media'] == 'reply_media_group'
|
media = kwargs['media'] == 'reply_media_group'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -757,7 +757,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
photo = kwargs['photo'] == 'test_photo'
|
photo = kwargs['photo'] == 'test_photo'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -771,7 +771,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
audio = kwargs['audio'] == 'test_audio'
|
audio = kwargs['audio'] == 'test_audio'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -785,7 +785,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
document = kwargs['document'] == 'test_document'
|
document = kwargs['document'] == 'test_document'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -799,7 +799,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
animation = kwargs['animation'] == 'test_animation'
|
animation = kwargs['animation'] == 'test_animation'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -813,7 +813,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
sticker = kwargs['sticker'] == 'test_sticker'
|
sticker = kwargs['sticker'] == 'test_sticker'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -827,7 +827,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
video = kwargs['video'] == 'test_video'
|
video = kwargs['video'] == 'test_video'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -841,7 +841,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
video_note = kwargs['video_note'] == 'test_video_note'
|
video_note = kwargs['video_note'] == 'test_video_note'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -855,7 +855,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
voice = kwargs['voice'] == 'test_voice'
|
voice = kwargs['voice'] == 'test_voice'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -869,7 +869,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
location = kwargs['location'] == 'test_location'
|
location = kwargs['location'] == 'test_location'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -883,7 +883,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
venue = kwargs['venue'] == 'test_venue'
|
venue = kwargs['venue'] == 'test_venue'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -897,7 +897,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
contact = kwargs['contact'] == 'test_contact'
|
contact = kwargs['contact'] == 'test_contact'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -911,7 +911,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
contact = kwargs['question'] == 'test_poll'
|
contact = kwargs['question'] == 'test_poll'
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -925,7 +925,7 @@ class TestMessage:
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
id_ = args[0] == message.chat_id
|
id_ = args[0] == message.chat_id
|
||||||
contact = kwargs['disable_notification'] is True
|
contact = kwargs['disable_notification'] is True
|
||||||
if kwargs.get('reply_to_message_id'):
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
reply = kwargs['reply_to_message_id'] == message.message_id
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
else:
|
else:
|
||||||
reply = True
|
reply = True
|
||||||
|
@ -940,7 +940,7 @@ class TestMessage:
|
||||||
chat_id = kwargs['chat_id'] == 123456
|
chat_id = kwargs['chat_id'] == 123456
|
||||||
from_chat = kwargs['from_chat_id'] == message.chat_id
|
from_chat = kwargs['from_chat_id'] == message.chat_id
|
||||||
message_id = kwargs['message_id'] == message.message_id
|
message_id = kwargs['message_id'] == message.message_id
|
||||||
if kwargs.get('disable_notification'):
|
if kwargs.get('disable_notification') is not None:
|
||||||
notification = kwargs['disable_notification'] is True
|
notification = kwargs['disable_notification'] is True
|
||||||
else:
|
else:
|
||||||
notification = True
|
notification = True
|
||||||
|
@ -958,11 +958,11 @@ class TestMessage:
|
||||||
chat_id = kwargs['chat_id'] == 123456
|
chat_id = kwargs['chat_id'] == 123456
|
||||||
from_chat = kwargs['from_chat_id'] == message.chat_id
|
from_chat = kwargs['from_chat_id'] == message.chat_id
|
||||||
message_id = kwargs['message_id'] == message.message_id
|
message_id = kwargs['message_id'] == message.message_id
|
||||||
if kwargs.get('disable_notification'):
|
if kwargs.get('disable_notification') is not None:
|
||||||
notification = kwargs['disable_notification'] is True
|
notification = kwargs['disable_notification'] is True
|
||||||
else:
|
else:
|
||||||
notification = True
|
notification = True
|
||||||
if kwargs.get('reply_markup'):
|
if kwargs.get('reply_markup') is not None:
|
||||||
reply_markup = kwargs['reply_markup'] is keyboard
|
reply_markup = kwargs['reply_markup'] is keyboard
|
||||||
else:
|
else:
|
||||||
reply_markup = True
|
reply_markup = True
|
||||||
|
@ -982,20 +982,28 @@ class TestMessage:
|
||||||
chat_id = kwargs['from_chat_id'] == 123456
|
chat_id = kwargs['from_chat_id'] == 123456
|
||||||
from_chat = kwargs['chat_id'] == message.chat_id
|
from_chat = kwargs['chat_id'] == message.chat_id
|
||||||
message_id = kwargs['message_id'] == 456789
|
message_id = kwargs['message_id'] == 456789
|
||||||
if kwargs.get('disable_notification'):
|
if kwargs.get('disable_notification') is not None:
|
||||||
notification = kwargs['disable_notification'] is True
|
notification = kwargs['disable_notification'] is True
|
||||||
else:
|
else:
|
||||||
notification = True
|
notification = True
|
||||||
if kwargs.get('reply_markup'):
|
if kwargs.get('reply_markup') is not None:
|
||||||
reply_markup = kwargs['reply_markup'] is keyboard
|
reply_markup = kwargs['reply_markup'] is keyboard
|
||||||
else:
|
else:
|
||||||
reply_markup = True
|
reply_markup = True
|
||||||
return chat_id and from_chat and message_id and notification and reply_markup
|
if kwargs.get('reply_to_message_id') is not None:
|
||||||
|
reply = kwargs['reply_to_message_id'] == message.message_id
|
||||||
|
else:
|
||||||
|
reply = True
|
||||||
|
return chat_id and from_chat and message_id and notification and reply_markup and reply
|
||||||
|
|
||||||
monkeypatch.setattr(message.bot, 'copy_message', test)
|
monkeypatch.setattr(message.bot, 'copy_message', test)
|
||||||
assert message.reply_copy(123456, 456789)
|
assert message.reply_copy(123456, 456789)
|
||||||
assert message.reply_copy(123456, 456789, disable_notification=True)
|
assert message.reply_copy(123456, 456789, disable_notification=True)
|
||||||
assert message.reply_copy(123456, 456789, reply_markup=keyboard)
|
assert message.reply_copy(123456, 456789, reply_markup=keyboard)
|
||||||
|
assert message.reply_copy(123456, 456789, quote=True)
|
||||||
|
assert message.reply_copy(
|
||||||
|
123456, 456789, quote=True, reply_to_message_id=message.message_id
|
||||||
|
)
|
||||||
|
|
||||||
def test_edit_text(self, monkeypatch, message):
|
def test_edit_text(self, monkeypatch, message):
|
||||||
def test(*args, **kwargs):
|
def test(*args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue