mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Support callable parse_mode's
This allows to more easily plug in custom parse methods.
This commit is contained in:
parent
eabaa3854a
commit
07a8a73e3e
|
@ -679,6 +679,7 @@ class TelegramClient(TelegramBareClient):
|
|||
if not parse_mode:
|
||||
return message, []
|
||||
|
||||
if isinstance(parse_mode, str):
|
||||
parse_mode = parse_mode.lower()
|
||||
if parse_mode in {'md', 'markdown'}:
|
||||
message, msg_entities = markdown.parse(message)
|
||||
|
@ -686,6 +687,10 @@ class TelegramClient(TelegramBareClient):
|
|||
message, msg_entities = html.parse(message)
|
||||
else:
|
||||
raise ValueError('Unknown parsing mode: {}'.format(parse_mode))
|
||||
elif callable(parse_mode):
|
||||
message, msg_entities = parse_mode(message)
|
||||
else:
|
||||
raise TypeError('Invalid parsing mode type: {}'.format(parse_mode))
|
||||
|
||||
for i, e in enumerate(msg_entities):
|
||||
if isinstance(e, MessageEntityTextUrl):
|
||||
|
|
Loading…
Reference in New Issue
Block a user