From 02b2b9d2aa0bbca34f51cbf8ecc453323622cd2c Mon Sep 17 00:00:00 2001 From: EyeZiS Date: Wed, 9 May 2018 01:26:06 +0200 Subject: [PATCH] Don't count entities that can't be generated --- stdplugins/markdown.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index b4da567..0696e36 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -53,6 +53,10 @@ def parse_snip(m): return m.group(1), None +PARSED_ENTITIES = ( + MessageEntityBold, MessageEntityItalic, MessageEntityCode, + MessageEntityPre, MessageEntityTextUrl +) MATCHERS = [ (DEFAULT_URL_RE, parse_url_match), (get_tag_parser('**', MessageEntityBold)), @@ -101,8 +105,11 @@ def parse(message): @borg.on(events.NewMessage(outgoing=True)) async def reparse(event): message, msg_entities = await borg._parse_message_text(event.text, parse) - - if len(event.message.entities or []) == len(msg_entities) and event.raw_text == message: + old_entities = [] + for entity in (event.message.entities or []): + if isinstance(entity, PARSED_ENTITIES): + old_entities.append(entity) + if len(old_entities) == len(msg_entities) and event.raw_text == message: return await borg(EditMessageRequest(