mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
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
This commit is contained in:
parent
8d852cb47e
commit
be5f0c9529
@ -20,6 +20,7 @@ import html
|
|||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
@ -103,7 +104,7 @@ class Parser(HTMLParser):
|
|||||||
|
|
||||||
|
|
||||||
class HTML:
|
class HTML:
|
||||||
def __init__(self, client: "pyrogram.BaseClient" = None):
|
def __init__(self, client: Union["pyrogram.BaseClient", None]):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
def parse(self, text: str):
|
def parse(self, text: str):
|
||||||
@ -126,6 +127,7 @@ class HTML:
|
|||||||
for entity in parser.entities:
|
for entity in parser.entities:
|
||||||
if isinstance(entity, types.InputMessageEntityMentionName):
|
if isinstance(entity, types.InputMessageEntityMentionName):
|
||||||
try:
|
try:
|
||||||
|
if self.client is not None:
|
||||||
entity.user_id = self.client.resolve_peer(entity.user_id)
|
entity.user_id = self.client.resolve_peer(entity.user_id)
|
||||||
except PeerIdInvalid:
|
except PeerIdInvalid:
|
||||||
continue
|
continue
|
||||||
@ -135,7 +137,7 @@ class HTML:
|
|||||||
# TODO: OrderedDict to be removed in Python 3.6
|
# TODO: OrderedDict to be removed in Python 3.6
|
||||||
return OrderedDict([
|
return OrderedDict([
|
||||||
("message", utils.remove_surrogates(parser.text)),
|
("message", utils.remove_surrogates(parser.text)),
|
||||||
("entities", entities)
|
("entities", sorted(entities, key=lambda e: e.offset))
|
||||||
])
|
])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
Loading…
x
Reference in New Issue
Block a user