Fix and update usage of parse_mode

This commit is contained in:
Lonami Exo
2022-02-04 12:19:53 +01:00
parent 4b477e5b27
commit 56faccf151
7 changed files with 35 additions and 74 deletions

View File

@@ -284,11 +284,7 @@ async def sign_up(
pass # code is correct and was used, now need to sign in
if self._tos and self._tos.text:
if self.parse_mode:
t = self.parse_mode.unparse(self._tos.text, self._tos.entities)
else:
t = self._tos.text
sys.stderr.write("{}\n".format(t))
sys.stderr.write("{}\n".format(self._tos.text))
sys.stderr.flush()
phone, phone_code_hash = \

View File

@@ -4,6 +4,7 @@ import typing
from .._misc import helpers, utils
from ..types import _custom
from ..types._custom.inputmessage import InputMessage
from .. import _tl
if typing.TYPE_CHECKING:
@@ -29,7 +30,7 @@ async def _parse_message_text(self: 'TelegramClient', message, parse_mode):
Returns a (parsed message, entities) tuple depending on ``parse_mode``.
"""
if parse_mode == ():
parse_mode = self._parse_mode
parse_mode = InputMessage._default_parse_mode
else:
parse_mode = utils.sanitize_parse_mode(parse_mode)

View File

@@ -141,7 +141,6 @@ def init(
self._connect_timeout = connect_timeout
self.flood_sleep_threshold = flood_sleep_threshold
self._flood_waited_requests = {} # prevent calls that would floodwait entirely
self._parse_mode = markdown
# Update handling.
self._catch_up = catch_up

View File

@@ -2196,7 +2196,8 @@ class TelegramClient:
await client.send_message('me', 'Hello **world**!')
# Default to another parse mode
client.parse_mode = 'html'
from telethon.types import Message
Message.set_default_parse_mode('html')
await client.send_message('me', 'Some <b>bold</b> and <i>italic</i> text')
await client.send_message('me', 'An <a href="https://example.com">URL</a>')
@@ -2204,8 +2205,8 @@ class TelegramClient:
await client.send_message('me', '<a href="tg://user?id=me">Mentions</a>')
# Explicit parse mode
# No parse mode by default
client.parse_mode = None
# No parse mode by default (import Message first)
Message.set_default_parse_mode(None)
# ...but here I want markdown
await client.send_message('me', 'Hello, **world**!', parse_mode='md')