Skip to content

Commit be5f0c9

Browse files
committed
Parser's client can be None
In that case, check if is None and don't parse user mentions. This happens only in text content for inline results
1 parent 8d852cb commit be5f0c9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
from collections import OrderedDict
2222
from html.parser import HTMLParser
23+
from typing import Union
2324

2425
import pyrogram
2526
from pyrogram.api import types
@@ -103,7 +104,7 @@ def error(self, message):
103104

104105

105106
class HTML:
106-
def __init__(self, client: "pyrogram.BaseClient" = None):
107+
def __init__(self, client: Union["pyrogram.BaseClient", None]):
107108
self.client = client
108109

109110
def parse(self, text: str):
@@ -126,7 +127,8 @@ def parse(self, text: str):
126127
for entity in parser.entities:
127128
if isinstance(entity, types.InputMessageEntityMentionName):
128129
try:
129-
entity.user_id = self.client.resolve_peer(entity.user_id)
130+
if self.client is not None:
131+
entity.user_id = self.client.resolve_peer(entity.user_id)
130132
except PeerIdInvalid:
131133
continue
132134

@@ -135,7 +137,7 @@ def parse(self, text: str):
135137
# TODO: OrderedDict to be removed in Python 3.6
136138
return OrderedDict([
137139
("message", utils.remove_surrogates(parser.text)),
138-
("entities", entities)
140+
("entities", sorted(entities, key=lambda e: e.offset))
139141
])
140142

141143
@staticmethod

0 commit comments

Comments
 (0)