Skip to content

Commit

Permalink
Use id in place of unprintable names in render_user
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowee committed Oct 14, 2020
1 parent b6c3d3f commit e950cd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion telegram_user_tracker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def _extract_target_user_id(event) -> int:
if url[2].startswith("/c/"):
# link to a message in a private chat
_, chat, msgid = url[2].lstrip("/").split("/")
chat = int(chat) # here chat is numeric id
chat = int(chat) # here chat is numeric id
else:
# in a public group
chat, msgid = url[2].lstrip("/").split("/")
Expand Down
6 changes: 5 additions & 1 deletion telegram_user_tracker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def render_user(user: User, html_instead_of_markdown: bool = False) -> str:
for name_part in (user.first_name, user.last_name)
if name_part is not None
)
if not name or name.isspace():
if (
not name
or name.isspace()
or not any(map(lambda char: char.isprintable(), name))
): # e.g. b'\xe2\x81\xa5'
name = str(user.id)
r = render_mention(user.id, name)
if user.username:
Expand Down

0 comments on commit e950cd1

Please sign in to comment.