add some comments

This commit is contained in:
EyeZiS 2018-05-09 01:46:21 +02:00
parent 02b2b9d2aa
commit d6f5514c56
Signed by untrusted user: kate
GPG Key ID: F17AECB58C3A3096
1 changed files with 4 additions and 0 deletions

View File

@ -57,6 +57,8 @@ PARSED_ENTITIES = (
MessageEntityBold, MessageEntityItalic, MessageEntityCode, MessageEntityBold, MessageEntityItalic, MessageEntityCode,
MessageEntityPre, MessageEntityTextUrl MessageEntityPre, MessageEntityTextUrl
) )
# a matcher is a tuple of (regex pattern, parse function)
# where the parse function takes the match and returns (text, entity)
MATCHERS = [ MATCHERS = [
(DEFAULT_URL_RE, parse_url_match), (DEFAULT_URL_RE, parse_url_match),
(get_tag_parser('**', MessageEntityBold)), (get_tag_parser('**', MessageEntityBold)),
@ -105,10 +107,12 @@ def parse(message):
@borg.on(events.NewMessage(outgoing=True)) @borg.on(events.NewMessage(outgoing=True))
async def reparse(event): async def reparse(event):
message, msg_entities = await borg._parse_message_text(event.text, parse) message, msg_entities = await borg._parse_message_text(event.text, parse)
# filter out entities that we don't generate
old_entities = [] old_entities = []
for entity in (event.message.entities or []): for entity in (event.message.entities or []):
if isinstance(entity, PARSED_ENTITIES): if isinstance(entity, PARSED_ENTITIES):
old_entities.append(entity) old_entities.append(entity)
if len(old_entities) == len(msg_entities) and event.raw_text == message: if len(old_entities) == len(msg_entities) and event.raw_text == message:
return return