diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index d325cc01..8aa8dd64 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -47,8 +47,8 @@ from pyrogram.api.types import ( InputPeerUser, InputPeerChat, InputPeerChannel ) from pyrogram.crypto import CTR -from pyrogram.extensions import Markdown, HTML from pyrogram.session import Auth, Session +from .style import Markdown, HTML log = logging.getLogger(__name__) @@ -472,6 +472,7 @@ class Client: def send_message(self, chat_id: int or str, text: str, + parse_mode: str = "", disable_web_page_preview: bool = None, disable_notification: bool = None, reply_to_msg_id: int = None): @@ -486,6 +487,10 @@ class Client: text (:obj:`str`): Text of the message to be sent. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your message. Defaults to "Markdown". + disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in this message. @@ -502,6 +507,8 @@ class Client: Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown + return self.send( functions.messages.SendMessage( peer=self.resolve_peer(chat_id), @@ -509,7 +516,7 @@ class Client: silent=disable_notification or None, reply_to_msg_id=reply_to_msg_id, random_id=self.rnd_id(), - **self.markdown.parse(text) + **style.parse(text) ) ) @@ -558,6 +565,7 @@ class Client: chat_id: int or str, photo: str, caption: str = "", + parse_mode: str = "", ttl_seconds: int = None, disable_notification: bool = None, reply_to_message_id: int = None): @@ -576,6 +584,10 @@ class Client: caption (:obj:`bool`, optional): Photo caption, 0-200 characters. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your caption. Defaults to "Markdown". + ttl_seconds (:obj:`int`, optional): Self-Destruct Timer. If you set a timer, the photo will self-destruct in :obj:`ttl_seconds` @@ -594,6 +606,7 @@ class Client: Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown file = self.save_file(photo) while True: @@ -608,7 +621,7 @@ class Client: silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), - **self.markdown.parse(caption) + **style.parse(caption) ) ) except FilePartMissing as e: @@ -620,6 +633,7 @@ class Client: chat_id: int or str, audio: str, caption: str = "", + parse_mode: str = "", duration: int = 0, performer: str = None, title: str = None, @@ -642,6 +656,10 @@ class Client: caption (:obj:`str`, optional): Audio caption, 0-200 characters. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your caption. Defaults to "Markdown". + duration (:obj:`int`, optional): Duration of the audio in seconds. @@ -664,6 +682,7 @@ class Client: Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown file = self.save_file(audio) while True: @@ -686,7 +705,7 @@ class Client: silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), - **self.markdown.parse(caption) + **style.parse(caption) ) ) except FilePartMissing as e: @@ -698,6 +717,7 @@ class Client: chat_id: int or str, document: str, caption: str = "", + parse_mode: str = "", disable_notification: bool = None, reply_to_message_id: int = None): """Use this method to send general files. @@ -715,6 +735,10 @@ class Client: caption (:obj:`str`, optional): Document caption, 0-200 characters. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your caption. Defaults to "Markdown". + disable_notification (:obj:`bool`, optional): Sends the message silently. Users will receive a notification with no sound. @@ -728,6 +752,7 @@ class Client: Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown file = self.save_file(document) while True: @@ -745,7 +770,7 @@ class Client: silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), - **self.markdown.parse(caption) + **style.parse(caption) ) ) except FilePartMissing as e: @@ -756,10 +781,11 @@ class Client: def send_video(self, chat_id: int or str, video: str, + caption: str = "", + parse_mode: str = "", duration: int = 0, width: int = 0, height: int = 0, - caption: str = "", disable_notification: bool = None, reply_to_message_id: int = None): """Use this method to send video files. @@ -774,6 +800,13 @@ class Client: Video to send. Pass a file path as string to send a video that exists on your local machine. + caption (:obj:`str`, optional): + Video caption, 0-200 characters. + + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your caption. Defaults to "Markdown". + duration (:obj:`int`, optional): Duration of sent video in seconds. @@ -783,9 +816,6 @@ class Client: height (:obj:`int`, optional): Video height. - caption (:obj:`str`, optional): - Video caption, 0-200 characters. - disable_notification (:obj:`bool`, optional): Sends the message silently. Users will receive a notification with no sound. @@ -799,6 +829,7 @@ class Client: Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown file = self.save_file(video) while True: @@ -820,7 +851,7 @@ class Client: silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), - **self.markdown.parse(caption) + **style.parse(caption) ) ) except FilePartMissing as e: @@ -832,6 +863,7 @@ class Client: chat_id: int or str, voice: str, caption: str = "", + parse_mode: str = "", duration: int = 0, disable_notification: bool = None, reply_to_message_id: int = None): @@ -850,6 +882,10 @@ class Client: caption (:obj:`str`, optional): Voice message caption, 0-200 characters. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your caption. Defaults to "Markdown". + duration (:obj:`int`, optional): Duration of the voice message in seconds. @@ -866,6 +902,7 @@ class Client: Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown file = self.save_file(voice) while True: @@ -886,7 +923,7 @@ class Client: silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), - **self.markdown.parse(caption) + **style.parse(caption) ) ) except FilePartMissing as e: @@ -1193,6 +1230,7 @@ class Client: chat_id: int or str, message_id: int, text: str, + parse_mode: str = "", disable_web_page_preview: bool = None): """Use this method to edit text messages. @@ -1208,25 +1246,32 @@ class Client: text (:obj:`str`): New text of the message. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your message. Defaults to "Markdown". + disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in this message. Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown + return self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), id=message_id, no_webpage=disable_web_page_preview or None, - **self.markdown.parse(text) + **style.parse(text) ) ) def edit_message_caption(self, chat_id: int or str, message_id: int, - caption: str): + caption: str, + parse_mode: str = ""): """Use this method to edit captions of messages. Args: @@ -1241,14 +1286,20 @@ class Client: caption (:obj:`str`): New caption of the message. + parse_mode (:obj:`str`): + Use "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your caption. Defaults to "Markdown". + Raises: :class:`pyrogram.Error` """ + style = self.html if parse_mode.lower() == "html" else self.markdown + return self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), id=message_id, - **self.markdown.parse(caption) + **style.parse(caption) ) )