-
Notifications
You must be signed in to change notification settings - Fork 0
/
donate_func.py
91 lines (76 loc) · 2.89 KB
/
donate_func.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import telebot
import config
import datetime
import pytz
import database_functions
con = config.connect_with_database()
# CREATE table main_profiles(user_id INT, username TEXT, first_last_names TEXT, acc_type TEXT, coins INT,
# start_prem TIMESTAMP, end_prem TIMESTAMP, used_trail BOOL, admin_type TEXT);
def create_profile(user_id, username, first_last_names):
cur = con.cursor()
cur.execute(f"""SELECT * FROM main_profiles WHERE user_id = {user_id}""")
db = cur.fetchone()
if db is not None:
cur.execute(
f"""INSERT INTO main_profiles (user_id, username, first_lsat_names, acc_type, coins, used_trail)
VALUES ({user_id}, {username}, {first_last_names}, "basic", 0, True)"""
)
con.commit()
return "Аккаунт создан"
def try_start_trail(user_id):
cur = con.cursor()
cur.execute(f"""SELECT used_trail FROM main_profiles WHERE user_id = {user_id}""")
trail = cur.fetchone()
if trail is True:
result = start_trail(user_id)
else:
result = "Вы уже использовали пробный период"
return result
def start_trail(user_id):
try:
trail_prem_day = 3
start_date = datetime.datetime.now(tz=pytz.utc)
end_prem = start_date + datetime.timedelta(days=trail_prem_day)
cur = con.cursor()
cur.execute(
f"""UPDATE main_profiles SET start_prem = {start_date}, end_prem = {end_prem}, used_trail = {False} WHERE user_id = {user_id}"""
)
con.commit()
return f"Премиум на {trail_prem_day} дня"
except:
return "Произошла какая-то ошибка, обратитесь к разработчику"
def check_admin_properties(user_id):
cur = con.cursor()
cur.execute(f"""SELECT admin_type FROM main_profiles WHERE user_id = {user_id}""")
prop = cur.fetchone()
return prop
def add_permission(user_id, add_perm):
try:
cur = con.cursor()
prop = check_admin_properties(user_id)
if add_perm not in prop:
new_perm = prop + add_perm
cur.execute(
f"""UPDATE main_profiles SET admin_type = {new_perm} WHERE user_id = {user_id}"""
)
con.commit()
return "done"
else:
return "that perm in user permission"
except Exception as err:
return str(err)
def del_permission(user_id, del_perm):
try:
cur = con.cursor()
prop = check_admin_properties(user_id=user_id)
if del_perm in prop:
new_perm = prop.replace(del_perm, "")
cur.execute(
f"""UPDATE main_profiles SET admin_type = {new_perm} WHERE user_id = {user_id}"""
)
con.commit()
return "done"
else:
return "User has no such permission"
except Exception as err:
return str(err)