Don't count entities that can't be generated

This commit is contained in:
EyeZiS 2018-05-09 01:26:06 +02:00
parent 40f85c162b
commit 02b2b9d2aa
Signed by untrusted user: kate
GPG Key ID: F17AECB58C3A3096
1 changed files with 9 additions and 2 deletions

View File

@ -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(