File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020import re
2121from collections import OrderedDict
2222from html .parser import HTMLParser
23+ from typing import Union
2324
2425import pyrogram
2526from pyrogram .api import types
@@ -103,7 +104,7 @@ def error(self, message):
103104
104105
105106class 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
You can’t perform that action at this time.
0 commit comments