From 63a702ac5d61431da6de44926a2b96e0c0ac121d Mon Sep 17 00:00:00 2001 From: JosXa Date: Tue, 12 Sep 2017 00:17:11 +0200 Subject: [PATCH 01/10] Added methods to quickly reply to a message with Markdown or HTML --- telegram/message.py | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/telegram/message.py b/telegram/message.py index 58098813885..b614e181eeb 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -23,10 +23,10 @@ from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject, User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment, VideoNote) +from telegram import ParseMode from telegram.utils.deprecate import warn_deprecate_obj from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp - _UNDEFINED = object() @@ -408,6 +408,50 @@ def reply_text(self, *args, **kwargs): self._quote(kwargs) return self.bot.send_message(self.chat_id, *args, **kwargs) + def reply_markdown(self, *args, **kwargs): + """ + Shortcut for:: + + ``bot.sendMessage(update.message.chat_id, + parse_mode=ParseMode.MARKDOWN, + *args, **kwargs)`` + + Sends a message with markdown formatting. + + Keyword Args: + quote (Optional[bool]): If set to ``True``, the message 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. + """ + + kwargs['parse_mode'] = ParseMode.MARKDOWN + + self._quote(kwargs) + + return self.bot.sendMessage(self.chat_id, *args, **kwargs) + + def reply_html(self, *args, **kwargs): + """ + Shortcut for:: + + ``bot.sendMessage(update.message.chat_id, + parse_mode=ParseMode.HTML, + *args, **kwargs)`` + + Sends a message with HTML formatting. + + Keyword Args: + quote (Optional[bool]): If set to ``True``, the message 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. + """ + + kwargs['parse_mode'] = ParseMode.HTML + + self._quote(kwargs) + + return self.bot.sendMessage(self.chat_id, *args, **kwargs) + def reply_photo(self, *args, **kwargs): """Shortcut for:: From 06734c92bdd76ca1fcd3071db34b4e7d9b1d5653 Mon Sep 17 00:00:00 2001 From: JosXa Date: Tue, 12 Sep 2017 00:17:11 +0200 Subject: [PATCH 02/10] Added methods to quickly reply to a message with Markdown or HTML --- telegram/message.py | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/telegram/message.py b/telegram/message.py index 58098813885..b614e181eeb 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -23,10 +23,10 @@ from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject, User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment, VideoNote) +from telegram import ParseMode from telegram.utils.deprecate import warn_deprecate_obj from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp - _UNDEFINED = object() @@ -408,6 +408,50 @@ def reply_text(self, *args, **kwargs): self._quote(kwargs) return self.bot.send_message(self.chat_id, *args, **kwargs) + def reply_markdown(self, *args, **kwargs): + """ + Shortcut for:: + + ``bot.sendMessage(update.message.chat_id, + parse_mode=ParseMode.MARKDOWN, + *args, **kwargs)`` + + Sends a message with markdown formatting. + + Keyword Args: + quote (Optional[bool]): If set to ``True``, the message 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. + """ + + kwargs['parse_mode'] = ParseMode.MARKDOWN + + self._quote(kwargs) + + return self.bot.sendMessage(self.chat_id, *args, **kwargs) + + def reply_html(self, *args, **kwargs): + """ + Shortcut for:: + + ``bot.sendMessage(update.message.chat_id, + parse_mode=ParseMode.HTML, + *args, **kwargs)`` + + Sends a message with HTML formatting. + + Keyword Args: + quote (Optional[bool]): If set to ``True``, the message 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. + """ + + kwargs['parse_mode'] = ParseMode.HTML + + self._quote(kwargs) + + return self.bot.sendMessage(self.chat_id, *args, **kwargs) + def reply_photo(self, *args, **kwargs): """Shortcut for:: From fb2323fc2b7b63ffcb4db655cb8f806cf34ca7eb Mon Sep 17 00:00:00 2001 From: Eldin Date: Thu, 14 Sep 2017 18:00:59 +0200 Subject: [PATCH 03/10] fix docstrings --- telegram/message.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/telegram/message.py b/telegram/message.py index b614e181eeb..3d7b348c7f7 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -419,9 +419,10 @@ def reply_markdown(self, *args, **kwargs): Sends a message with markdown formatting. Keyword Args: - quote (Optional[bool]): If set to ``True``, the message 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. + quote (:obj:`bool`, optional): If set to ``True``, the message 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. """ kwargs['parse_mode'] = ParseMode.MARKDOWN @@ -441,9 +442,10 @@ def reply_html(self, *args, **kwargs): Sends a message with HTML formatting. Keyword Args: - quote (Optional[bool]): If set to ``True``, the message 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. + quote (:obj:`bool`, optional): If set to ``True``, the message 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. """ kwargs['parse_mode'] = ParseMode.HTML From 572686334bf1e62ab12e7f79e0da0f42c1d7e9dc Mon Sep 17 00:00:00 2001 From: JosXa Date: Mon, 18 Sep 2017 14:30:13 +0200 Subject: [PATCH 04/10] Added notice to contribution guidelines --- .github/ISSUE_TEMPLATE.md | 5 +++++ telegram/vendor/ptb_urllib3 | 2 +- tests/test_message.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 8945f449ecb..4a892c5005c 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,9 +1,14 @@