-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
48 lines (40 loc) · 1.54 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
from typing import Union
from telethon.tl import types
from telethon.utils import get_display_name
from .events import NewMessage
LOGGER = logging.getLogger("zthon")
def printUser(entity: types.User) -> None:
"""Print the user's first name + last name upon start"""
user = get_display_name(entity)
LOGGER.warning("Successfully logged in as {0}".format(user))
async def get_chat_link(
arg: Union[types.User, types.Chat, types.Channel, NewMessage.Event], reply=None
) -> str:
if isinstance(arg, (types.User, types.Chat, types.Channel)):
entity = arg
else:
entity = await arg.get_chat()
if isinstance(entity, types.User):
if entity.is_self:
name = 'your "Saved Messages"'
else:
name = get_display_name(entity) or "Deleted Account?"
extra = f"[{name}](tg://user?id={entity.id})"
else:
if hasattr(entity, "username") and entity.username is not None:
username = f"@{entity.username}"
else:
username = entity.id
if reply is not None:
if isinstance(username, str) and username.startswith("@"):
username = username[1:]
else:
username = f"c/{username}"
extra = f"[{entity.title}](https://t.me/{username}/{reply})"
elif isinstance(username, int):
username = f"`{username}`"
extra = f"{entity.title} ( {username} )"
else:
extra = f"[{entity.title}](tg://resolve?domain={username})"
return extra