Skip to content

Commit e1242b3

Browse files
authored
message.py: add quote keyword argument to reply_x methods (python-telegram-bot#420)
1 parent 93dde1a commit e1242b3

File tree

1 file changed

+117
-10
lines changed

1 file changed

+117
-10
lines changed

telegram/message.py

Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,44 +250,151 @@ def _totimestamp(dt_obj):
250250
# Python 3 (< 3.3) and Python 2
251251
return int(mktime(dt_obj.timetuple()))
252252

253+
def _quote(self, kwargs):
254+
"""Modify kwargs for replying with or without quoting"""
255+
256+
if 'reply_to_message_id' in kwargs:
257+
if 'quote' in kwargs:
258+
del kwargs['quote']
259+
260+
elif 'quote' in kwargs:
261+
if kwargs['quote']:
262+
kwargs['reply_to_message_id'] = self.message_id
263+
264+
del kwargs['quote']
265+
266+
else:
267+
if self.chat.type != Chat.PRIVATE:
268+
kwargs['reply_to_message_id'] = self.message_id
269+
253270
def reply_text(self, *args, **kwargs):
254-
"""Shortcut for ``bot.sendMessage(update.message.chat_id, *args, **kwargs)``"""
271+
"""
272+
Shortcut for ``bot.sendMessage(update.message.chat_id, *args, **kwargs)``
273+
274+
Keyword Args:
275+
quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to
276+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
277+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
278+
"""
279+
280+
self._quote(kwargs)
255281
return self.bot.sendMessage(self.chat_id, *args, **kwargs)
256282

257283
def reply_photo(self, *args, **kwargs):
258-
"""Shortcut for ``bot.sendPhoto(update.message.chat_id, *args, **kwargs)``"""
284+
"""
285+
Shortcut for ``bot.sendPhoto(update.message.chat_id, *args, **kwargs)``
286+
287+
Keyword Args:
288+
quote (Optional[bool]): If set to ``True``, the photo is sent as an actual reply to
289+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
290+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
291+
"""
292+
293+
self._quote(kwargs)
259294
return self.bot.sendPhoto(self.chat_id, *args, **kwargs)
260295

261296
def reply_audio(self, *args, **kwargs):
262-
"""Shortcut for ``bot.sendAudio(update.message.chat_id, *args, **kwargs)``"""
297+
"""
298+
Shortcut for ``bot.sendAudio(update.message.chat_id, *args, **kwargs)``
299+
300+
Keyword Args:
301+
quote (Optional[bool]): If set to ``True``, the audio is sent as an actual reply to
302+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
303+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
304+
"""
305+
306+
self._quote(kwargs)
263307
return self.bot.sendAudio(self.chat_id, *args, **kwargs)
264308

265309
def reply_document(self, *args, **kwargs):
266-
"""Shortcut for ``bot.sendDocument(update.message.chat_id, *args, **kwargs)``"""
310+
"""
311+
Shortcut for ``bot.sendDocument(update.message.chat_id, *args, **kwargs)``
312+
313+
Keyword Args:
314+
quote (Optional[bool]): If set to ``True``, the document is sent as an actual reply to
315+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
316+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
317+
"""
318+
319+
self._quote(kwargs)
267320
return self.bot.sendDocument(self.chat_id, *args, **kwargs)
268321

269322
def reply_sticker(self, *args, **kwargs):
270-
"""Shortcut for ``bot.sendSticker(update.message.chat_id, *args, **kwargs)``"""
323+
"""
324+
Shortcut for ``bot.sendSticker(update.message.chat_id, *args, **kwargs)``
325+
326+
Keyword Args:
327+
quote (Optional[bool]): If set to ``True``, the sticker is sent as an actual reply to
328+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
329+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
330+
"""
331+
332+
self._quote(kwargs)
271333
return self.bot.sendSticker(self.chat_id, *args, **kwargs)
272334

273335
def reply_video(self, *args, **kwargs):
274-
"""Shortcut for ``bot.sendVideo(update.message.chat_id, *args, **kwargs)``"""
336+
"""
337+
Shortcut for ``bot.sendVideo(update.message.chat_id, *args, **kwargs)``
338+
339+
Keyword Args:
340+
quote (Optional[bool]): If set to ``True``, the video is sent as an actual reply to
341+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
342+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
343+
"""
344+
345+
self._quote(kwargs)
275346
return self.bot.sendVideo(self.chat_id, *args, **kwargs)
276347

277348
def reply_voice(self, *args, **kwargs):
278-
"""Shortcut for ``bot.sendVoice(update.message.chat_id, *args, **kwargs)``"""
349+
"""
350+
Shortcut for ``bot.sendVoice(update.message.chat_id, *args, **kwargs)``
351+
352+
Keyword Args:
353+
quote (Optional[bool]): If set to ``True``, the voice is sent as an actual reply to
354+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
355+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
356+
"""
357+
358+
self._quote(kwargs)
279359
return self.bot.sendVoice(self.chat_id, *args, **kwargs)
280360

281361
def reply_location(self, *args, **kwargs):
282-
"""Shortcut for ``bot.sendLocation(update.message.chat_id, *args, **kwargs)``"""
362+
"""
363+
Shortcut for ``bot.sendLocation(update.message.chat_id, *args, **kwargs)``
364+
365+
Keyword Args:
366+
quote (Optional[bool]): If set to ``True``, the location is sent as an actual reply to
367+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
368+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
369+
"""
370+
371+
self._quote(kwargs)
283372
return self.bot.sendLocation(self.chat_id, *args, **kwargs)
284373

285374
def reply_venue(self, *args, **kwargs):
286-
"""Shortcut for ``bot.sendVenue(update.message.chat_id, *args, **kwargs)``"""
375+
"""
376+
Shortcut for ``bot.sendVenue(update.message.chat_id, *args, **kwargs)``
377+
378+
Keyword Args:
379+
quote (Optional[bool]): If set to ``True``, the venue is sent as an actual reply to
380+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
381+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
382+
"""
383+
384+
self._quote(kwargs)
287385
return self.bot.sendVenue(self.chat_id, *args, **kwargs)
288386

289387
def reply_contact(self, *args, **kwargs):
290-
"""Shortcut for ``bot.sendContact(update.message.chat_id, *args, **kwargs)``"""
388+
"""
389+
Shortcut for ``bot.sendContact(update.message.chat_id, *args, **kwargs)``
390+
391+
Keyword Args:
392+
quote (Optional[bool]): If set to ``True``, the contact is sent as an actual reply to
393+
this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter
394+
will be ignored. Default: ``True`` in group chats and ``False`` in private chats.
395+
"""
396+
397+
self._quote(kwargs)
291398
return self.bot.sendContact(self.chat_id, *args, **kwargs)
292399

293400
def forward(self, chat_id, disable_notification=False):

0 commit comments

Comments
 (0)