|
23 | 23 | from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject, |
24 | 24 | User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment, |
25 | 25 | VideoNote) |
| 26 | +from telegram import ParseMode |
26 | 27 | from telegram.utils.deprecate import warn_deprecate_obj |
27 | 28 | from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp |
28 | 29 |
|
@@ -305,6 +306,40 @@ def reply_text(self, *args, **kwargs): |
305 | 306 | self._quote(kwargs) |
306 | 307 | return self.bot.send_message(self.chat_id, *args, **kwargs) |
307 | 308 |
|
| 309 | + def reply_markdown(self, *args, **kwargs): |
| 310 | + """ |
| 311 | + Shortcut for ``bot.sendMessage(update.message.chat_id, parse_mode=ParseMode.MARKDOWN, *args, **kwargs)`` |
| 312 | + Sends a message with markdown formatting. |
| 313 | +
|
| 314 | + Keyword Args: |
| 315 | + quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to |
| 316 | + this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter |
| 317 | + will be ignored. Default: ``True`` in group chats and ``False`` in private chats. |
| 318 | + """ |
| 319 | + |
| 320 | + kwargs['parse_mode'] = ParseMode.MARKDOWN |
| 321 | + |
| 322 | + self._quote(kwargs) |
| 323 | + |
| 324 | + return self.bot.sendMessage(self.chat_id, *args, **kwargs) |
| 325 | + |
| 326 | + def reply_html(self, *args, **kwargs): |
| 327 | + """ |
| 328 | + Shortcut for ``bot.sendMessage(update.message.chat_id, parse_mode=ParseMode.HTML, *args, **kwargs)`` |
| 329 | + Sends a message with HTML formatting. |
| 330 | +
|
| 331 | + Keyword Args: |
| 332 | + quote (Optional[bool]): If set to ``True``, the message is sent as an actual reply to |
| 333 | + this message. If ``reply_to_message_id`` is passed in ``kwargs``, this parameter |
| 334 | + will be ignored. Default: ``True`` in group chats and ``False`` in private chats. |
| 335 | + """ |
| 336 | + |
| 337 | + kwargs['parse_mode'] = ParseMode.HTML |
| 338 | + |
| 339 | + self._quote(kwargs) |
| 340 | + |
| 341 | + return self.bot.sendMessage(self.chat_id, *args, **kwargs) |
| 342 | + |
308 | 343 | def reply_photo(self, *args, **kwargs): |
309 | 344 | """ |
310 | 345 | Shortcut for ``bot.send_photo(update.message.chat_id, *args, **kwargs)`` |
@@ -510,6 +545,48 @@ def edit_text(self, *args, **kwargs): |
510 | 545 | return self.bot.edit_message_text( |
511 | 546 | chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs) |
512 | 547 |
|
| 548 | + def edit_markdown(self, *args, **kwargs): |
| 549 | + """ |
| 550 | + Shortcut for |
| 551 | +
|
| 552 | + >>> bot.editMessageText(chat_id=message.chat_id, |
| 553 | + ... message_id=message.message_id, |
| 554 | + ... parse_mode=ParseMode.MARKDOWN, |
| 555 | + ... *args, **kwargs) |
| 556 | +
|
| 557 | + Note: |
| 558 | + You can only edit messages that the bot sent itself, |
| 559 | + therefore this method can only be used on the |
| 560 | + return value of the ``bot.send_*`` family of methods. |
| 561 | +
|
| 562 | + """ |
| 563 | + |
| 564 | + kwargs['parse_mode'] = ParseMode.MARKDOWN |
| 565 | + |
| 566 | + return self.bot.edit_message_text( |
| 567 | + chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs) |
| 568 | + |
| 569 | + def edit_html(self, *args, **kwargs): |
| 570 | + """ |
| 571 | + Shortcut for |
| 572 | +
|
| 573 | + >>> bot.editMessageText(chat_id=message.chat_id, |
| 574 | + ... message_id=message.message_id, |
| 575 | + ... parse_mode=ParseMode.HTML |
| 576 | + ... *args, **kwargs) |
| 577 | +
|
| 578 | + Note: |
| 579 | + You can only edit messages that the bot sent itself, |
| 580 | + therefore this method can only be used on the |
| 581 | + return value of the ``bot.send_*`` family of methods. |
| 582 | +
|
| 583 | + """ |
| 584 | + |
| 585 | + kwargs['parse_mode'] = ParseMode.HTML |
| 586 | + |
| 587 | + return self.bot.edit_message_text( |
| 588 | + chat_id=self.chat_id, message_id=self.message_id, *args, **kwargs) |
| 589 | + |
513 | 590 | def edit_caption(self, *args, **kwargs): |
514 | 591 | """ |
515 | 592 | Shortcut for |
@@ -610,7 +687,7 @@ def parse_entities(self, types=None): |
610 | 687 | return { |
611 | 688 | entity: self.parse_entity(entity) |
612 | 689 | for entity in self.entities if entity.type in types |
613 | | - } |
| 690 | + } |
614 | 691 |
|
615 | 692 | @property |
616 | 693 | def text_html(self): |
|
0 commit comments