Fix broken mentions for both HTML and Markdown · fourstring/pyrogram@ef5dd96 · GitHub
Skip to content

Commit ef5dd96

Browse files
committed
Fix broken mentions for both HTML and Markdown
1 parent f4cb31d commit ef5dd96

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

pyrogram/client/ext/base_client.py

Lines changed: 2 additions & 2 deletions

pyrogram/client/style/html.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
from collections import OrderedDict
2121

22+
import pyrogram
2223
from pyrogram.api.types import (
2324
MessageEntityBold as Bold,
2425
MessageEntityItalic as Italic,
@@ -28,15 +29,16 @@
2829
MessageEntityMentionName as MentionInvalid,
2930
InputMessageEntityMentionName as Mention,
3031
)
32+
from pyrogram.errors import PeerIdInvalid
3133
from . import utils
3234

3335

3436
class HTML:
3537
HTML_RE = re.compile(r"<(\w+)(?: href=([\"'])([^<]+)\2)?>([^>]+)</\1>")
3638
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
3739

38-
def __init__(self, peers_by_id: dict = None):
39-
self.peers_by_id = peers_by_id or {}
40+
def __init__(self, client: "pyrogram.BaseClient" = None):
41+
self.client = client
4042

4143
def parse(self, message: str):
4244
entities = []
@@ -52,7 +54,11 @@ def parse(self, message: str):
5254

5355
if mention:
5456
user_id = int(mention.group(1))
55-
input_user = self.peers_by_id.get(user_id, None)
57+
58+
try:
59+
input_user = self.client.resolve_peer(user_id)
60+
except PeerIdInvalid:
61+
input_user = None
5662

5763
entity = (
5864
Mention(offset=start, length=len(body), user_id=input_user)

pyrogram/client/style/markdown.py

Lines changed: 10 additions & 5 deletions

0 commit comments

Comments
 (0)