Skip to content

Commit

Permalink
fix: nickname unescaped
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongronggg9 committed Oct 17, 2023
1 parent 002f583 commit 9d1dd01
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions SlashBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import re
import html
import requests
import telegram
from loguru import logger as _logger
Expand Down Expand Up @@ -171,10 +172,13 @@ def __init__(self, uid: Optional[int] = None, username: Optional[str] = None, na

def __get_user_by_username(self):
r = requests.get(f'https://t.me/{self.username}', proxies=REQUEST_PROXIES)
self.name = re.search(r'(?<=<meta property="og:title" content=").*(?=")', r.text, re.IGNORECASE).group(0)
og_t = re.search(r'(?<=<meta property="og:title" content=").*(?=")', r.text, re.IGNORECASE).group(0)
name = html.unescape(og_t) if og_t else None
page_title = re.search(r'(?<=<title>).*(?=</title>)', r.text, re.IGNORECASE).group(0)
if page_title == self.name: # user does not exist
if page_title == og_t: # user does not exist
self.name = None
elif name:
self.name = name

def mention(self, mention_self: bool = False, pure: bool = False) -> str:
if not self.name:
Expand All @@ -184,6 +188,7 @@ def mention(self, mention_self: bool = False, pure: bool = False) -> str:
if (self.username and (not self.uid or self.uid < 0))
else f'tg://user?id={self.uid}')
name = self.name if not mention_self else "自己"
name = htmlEscape(name)
return f'<a href="{mention_deep_link}">{name}</a>' if not pure else name

def __eq__(self, other):
Expand Down

0 comments on commit 9d1dd01

Please sign in to comment.