Add optional parameter parse_mode

This commit is contained in:
Dan 2018-01-23 15:18:52 +01:00
parent c39bf3043d
commit e7cbff8087

View File

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