forked from JosXa/TacoBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
39 lines (28 loc) · 1.27 KB
/
tools.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
from dbmodels import Usernames
def get_uid(update): # this makes your life easier
return update.effective_message.from_user.id
def get_cid(update): # this makes your life easier
return update.effective_message.chat.id
def store_name(update): # this function is here only for /tacotop
username = Usernames.select().where(Usernames.uid == get_uid(update))
if username.exists():
return username.get().name
user = update.effective_message.from_user
if user.username is None:
first_name = user.first_name
last_name = user.last_name
if last_name is None:
name = first_name
else:
name = first_name + ' ' + last_name
else:
name = '@' + user.username
Usernames.create(uid=get_uid(update),
name=name)
return name
def resolve_name(uid): # returns username if present in DB
user = Usernames.select().where(Usernames.uid == uid)
if user.exists():
return user.get().name
else:
return uid