-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.txt
216 lines (185 loc) · 10.4 KB
/
formatter.txt
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
class Formatter:
@classmethod
def query(cls, message, callback=None):
value = text_file.menu.get(callback if callback is not None else message.text)
if value:
prev = QueryDb.get_user(message.chat.id)
if not prev:
user = QueryDb.save_user_state(message.chat.id, message.chat.first_name,
callback if callback is not None else message.text, None)
else:
user = QueryDb.save_user_state(message.chat.id, message.chat.first_name,
callback if callback is not None else message.text, prev.state)
if message.text == '/start' or callback == '?? Íà ãëàâíóþ':
keyboard = helper.make_inline_keyboard(value.keyboard)
if user.admin:
keyboard = helper.make_inline_keyboard(value.keyboard, admin=True)
sub = user.sub
if sub:
# Ïðîâåðêà âðåìåíè è âûñ÷èòûâàíèå îñòàâøèõñÿ äíåé
if sub[0].date:
return value.text[1].format(sub[0].group, (sub[0].date - datetime.now()).days + 1), keyboard
elif sub[0].perm:
return value.text[1].format(sub[0].group, '\U0000221E'), keyboard
return value.text[0], keyboard
elif callback == '?? Ïîëó÷èòü ïàðòíåðñêóþ ññûëêó':
# Âûíåñòè ññûëêó â íàñòðîéêè
kb = helper.make_inline_keyboard(value.keyboard)
return value.text.format(BOT_NAME, message.chat.id), kb
elif callback == '?? Ñòàòèñòèêà':
profit = user.profit
referrals = user.ref
keyboard = helper.make_inline_keyboard(value.keyboard)
return value.text.format(referrals.count(), profit[0].count), keyboard
elif callback == '?? Âûâîä ñðåäñòâ':
kb = helper.make_inline_keyboard(value.keyboard)
profit = user.profit
count = profit[0].count
if count:
return value.text[1].format(count), kb
return value.text[0], kb
# Ñäåëàòü ïðîâåðêó âðåìåíè, åñëè îñòàëîñü 3 äíÿ ïîêàçàòü êíîïêó ïðîäëèòü, èíà÷å íåò
elif callback == '?? Íîâè÷îê':
sub = user.sub
if sub and sub[0].date and (sub[0].date - datetime.now()).days > 2:
return 'Âû ñìîæåòå ïðîäëèòü ïîäïèñêà êàê òîëüêî îñòàíåòñÿ 3 äíÿ', \
helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
elif callback == '?? Îáó÷åíèå':
wikies = '\n\n'.join([f'<a href="{wiki.link}">{wiki.description}</a>' for wiki in QueryDb.get_wiki()])
kb = helper.make_inline_keyboard(value.keyboard)
return value.text.format(wikies), kb
keyboard = helper.make_inline_keyboard(value.keyboard)
return value.text, keyboard
user = QueryDb.get_user(message.chat.id)
if callback == '?? Ïîäïèñàòüñÿ' and user.state == '?? Íîâè÷îê':
user.prev = '?? Íîâè÷îê'
user.save()
sub = QueryDb.save_sub(user, 30)
value = text_file.menu.get('/start')
keyboard = helper.make_inline_keyboard(value.keyboard)
if user.admin:
keyboard = helper.make_inline_keyboard(value.keyboard, admin=True)
return value.text[1].format(sub.group, (sub.date - datetime.now()).days + 1), keyboard
elif user.state in ['?? Òðåéäåð', '?? VIP', '?? Platinum']:
answer = text_file.price.get(user.state).get(callback)
if answer is None:
return 'Èñïîëüçóéòå íîâóþ êëàâèàòóðó', helper.make_inline_keyboard((['?? Íà ãëàâíóþ'],))
prev = QueryDb.get_user(message.chat.id)
user = QueryDb.save_user_state(message.chat.id, message.chat.first_name, callback, prev.state)
keyboard = helper.make_inline_keyboard((['?? Ïîìîùü'], ['?? Íàçàä', '?? Íà ãëàâíóþ']))
sub = user.sub
if not sub:
new_sub = QueryDb.save_sub(user)
return answer.format(new_sub.id), keyboard
return answer.format(sub[0].id), keyboard
if user.admin:
pass
return 'Íå ïîíèìàþ', helper.make_inline_keyboard((['?? Íà ãëàâíóþ'],))
@classmethod
def add_ref(cls, message, uid):
value = text_file.menu.get('/start')
QueryDb.add_referral(message, uid)
return value.text[0], helper.make_inline_keyboard(value.keyboard)
@classmethod
def admin_panel(cls, user, callback):
admin = QueryDb.get_user(user.chat.id)
if admin.admin:
value = text_file.admin.get(callback)
if value:
QueryDb.save_user_state(user.chat.id, user.chat.first_name, callback, None)
if callback == 'Óäàëèòü àäìèíà':
all_admins = '\n'.join([f'{adm.uid} - {adm.f_name}' for adm in QueryDb.get_all_admins()])
keyboard = helper.make_inline_keyboard(value.keyboard)
return value.text.format(all_admins), keyboard
elif callback == 'Óäàëèòü ñòàòüþ':
wikies = '\n\n'.join([f'[{wiki.name}] '
f'{wiki.description}\n{wiki.link}' for wiki in QueryDb.get_wiki()])
keyboard = helper.make_inline_keyboard(value.keyboard)
return value.text.format(wikies), keyboard
elif callback == 'Ñòàòèñòèêà':
kb = helper.make_inline_keyboard(value.keyboard)
statistics = QueryDb.statistics()
return value.text.format(*statistics), kb
keyboard = helper.make_inline_keyboard(value.keyboard)
return value.text, keyboard
elif admin.state == 'Äîáàâèòü àäìèíà' and callback:
if QueryDb.permissions(callback.id):
return 'Àäìèí äîáàâëåí', helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
return 'Òàêîãî ïîëüçîâàòåëÿ íåò', helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
elif admin.state == 'Óäàëèòü àäìèíà':
keyboard = helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
if callback.isdigit() and QueryDb.permissions(int(callback), delete=True):
return 'Àäìèí óäàëåí', keyboard
return '×òî òî ïîøëî íå òàê', keyboard
elif admin.state == 'Äîáàâèòü ñòàòüþ':
keyboard = helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
try:
name, link, description = callback.split('\n', maxsplit=2)
except (IndexError, ValueError):
return 'Âû íåïðàâèëüíî óêàçàëè àðãóìåíòû', keyboard
else:
if not QueryDb.save_wiki(name, link, description):
return 'Âû íåïðàâèëüíî óêàçàëè àðãóìåíòû', keyboard
return 'Ñòàòüÿ äîáàâëåíà', keyboard
elif admin.state == 'Óäàëèòü ñòàòüþ':
keyboard = helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
if QueryDb.delete_wiki(callback):
return 'Ñòàòüÿ óäàëåíà', keyboard
return 'Òàêîé ñòàòüè íåò', keyboard
elif admin.state == 'Äîáàâèòü ïîäïèñ÷èêà':
keyboard = helper.make_inline_keyboard((['?? Íàçàä'], ['?? Íà ãëàâíóþ']))
try:
number, group, days, money = callback.split(':')
except (IndexError, ValueError):
try:
users, group, days = callback.split(':')
except (IndexError, ValueError):
return 'Âû íåïðàâèëüíî óêàçàëè àðãóìåíòû', keyboard
else:
if users.lower() == 'all':
if group.isdigit() and days.isdigit() and -1 < int(group) < 5:
update = QueryDb.mass_update(int(group), int(days))
if update:
return 'Êîëè÷åñòâî äíåé äîáàâëåíî', keyboard
return 'Ó âàñ ïîêà íåò ïîäïèñ÷èêîâ', keyboard
return 'Óêàçûâàéòå òîëüêî öèôðû', keyboard
return 'Ïåðâûé àðãóìåíò äîëæåí áûòü all', keyboard
else:
if number.isdigit() and group.isdigit() and days.isdigit() and 0 < int(group) < 5 and \
money.replace('.','').isdigit():
sub = QueryDb.save_admin_sub(int(number), int(group), int(days))
if sub:
ref = QueryDb.check_ref(sub.uid)
if ref:
money = float(money)
if ref[0].added:
ref[0].added = False
ref[0].save()
if money <= 0.025:
pay = money * 0.7
else:
pay = money * 0.5
else:
pay = money * 0.2
QueryDb.add_money(ref[0].referral.uid, pay)
return 'Ïîäïèñêà îôîðìëåíà', keyboard
return 'Âû ââåëè íåïðàâèëüíûé íîìåð äîãîâîðà', keyboard
return 'Óêàçûâàéòå òîëüêî öèôðû', keyboard
return 'Íå ïîíèìàþ', helper.make_inline_keyboard((['?? Íà ãëàâíóþ'],))
@classmethod
def payments(cls, uid, money):
kb = helper.make_inline_keyboard((['?? Íàçàä', '?? Íà ãëàâíóþ'],))
try:
money = float(money)
except ValueError:
return 'Íåêîððåêòíàÿ ñóììà', kb, False
else:
profit = QueryDb.get_money(uid, money)
if profit:
return f'Âñå ïðîøëî óñïåøíî!\n' \
f'Ó âàñ îñòàëîñü {profit.count} BTC\nÌû ïåðåäàäèì âñþ íåîáõîäìóþ èíôîðìàöèþ àäìèíèñòðàöèè', kb, True
return 'Ó âàñ íåäîñòàòî÷íî ñðåäñòâ, ÷òîáû ñîâåðøèòü âûâîä', kb, False
@classmethod
def sender(cls, photo=False):
users = QueryDb.get_users_id(photo)
return usersadmin@bithub-bot:~/Bot/app$