This repository was archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
684 lines (600 loc) · 26.3 KB
/
main.py
File metadata and controls
684 lines (600 loc) · 26.3 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
'''LICENSED WITH APACHE 2.0'''
# IMPORTANT: CHANGE ALL ELEMENTS WITH '$'
# REMEMBER THAT YOU HAVE TO CHANGE ALSO THE JSON FILE
# Set your password, Set your Api token
import botogram
import sqlite3
import os
import time
from obj.start import r, d, dat, logch
from obj.jsonr import p
from obj.visualizers import visualizer, staffvis, verdict
from obj.checks import checklink, check2, knowit, checkperm
bot = botogram.create(p["values"]["token"])
# Set your api token in the json file (data/lang.json)$
bot.owner = "@Mamiglia & https://github.com/Mamiglia/Requester-Bot"
# Set yourself as the owner$
d.execute("SELECT id FROM ids WHERE type=3")
x = d.fetchone()
if x is not None:
bot.chat(int(x[0])).send('Admins, press /refreshpin!')
def checkreq(cht, typ):
'''Check if the user can make a request, the users can have only one request at time'''
if int(r.get('door')) > 0:
try:
d.execute("INSERT INTO request (userid, type) VALUES (?,?)", (cht.id, typ))
dat.commit()
return True
except sqlite3.IntegrityError:
dat.rollback()
d.execute("SELECT stage FROM request WHERE userid=?", (cht.id, ))
if d.fetchone()[0] == 0:
cht.send(p["checkreq"][2])
else:
cht.send(p["checkreq"][0])
else:
cht.send(p["checkreq"][1])
return False
@bot.command('start')
def start(chat, message):
'''Say Hello to the user'''
if chat.type == 'private':
chat.send(p["start"] % (message.sender.first_name))
@bot.command('help')
def help(chat):
'''Instructions: How do I make a request?'''
if chat.type == 'private':
chat.send(p["help"])
@bot.command('rules')
def rules(chat):
'''Specific rules, remember to set yours in lang.json'''
if chat.type == 'private':
chat.send(p["rules"])
@bot.command("newadmin", hidden=True)
def newadmin(chat, message):
'''Insert a new admin in the admins list, remember to set your password in lang.json $$'''
if p["values"]["password"] in message.text:
d.execute("SELECT id FROM ids WHERE type=0")
if d.fetchone() is None:
d.execute("INSERT INTO ids (id, type) VALUES (?,?)", (bot.itself.id, 0))
dat.commit()
try:
d.execute("INSERT INTO ids (id, type) VALUES (?,?)", (message.sender.id, 0))
chat.send("W-welcome home S-Senpai!")
chat.send("You already know what you what to do with me, right?\nIn any case, if you don't have any idea check it here /adminhelp")
dat.commit()
except sqlite3.IntegrityError:
dat.rollback()
chat.send("You are already an admin UwU, you can't become adminer than this")
else:
chat.send("Who is this CONSOLE-PEASANT??")
@bot.command('adminhelp', hidden=True)
def adminhelp(message, chat):
'''command only for Admins, help admins to understand what actions they can do'''
if checkperm(message.sender.id):
chat.send("These are the commands that only an admin can perform:\n\
-/newadmin Your_password : set you as a new admin\n\
-/refreshpin : refresh and pin the message in public group, if you reply to a message: the text of the messagge will be included in the pin\n\
\n\
-/door N : change the number of requests that the bot can have\n\
-/resizevotes N : resize the number of votes that a request needs to have to be accepted\n\
\n\
-/setstaff : type in the staff group to set the staff group\n\
-/setgroup : type in your group to set it\n\
-/setlog @(your channel username): set your log channel, reboot is needed\n\
\n\
-/block : block an user, first send this command, and then forward a message of the user\n\
-/unblock : a list of the blocked users, click one to unblock\n\
-/delete @username: delete the user's request\n\
\n\
-/cleanreq : delete all the requests\n\
-/sqldb : execute a command on the SQL tables (SQLite3)\n\
-/backup : backup the actual requester db (SQLite3)")
@bot.command("delete", hidden=True)
def deletereq(message, chat):
'''command for Admins only, delete the request of a user. Type: /delete @username'''
if checkperm(message.sender.id):
username = message.text[9::].lower()
print(username)
d.execute("SELECT name FROM request WHERE username=?", (username, ))
b = d.fetchone()
if b is not None:
d.execute("DELETE FROM request WHERE username=?", (username, ))
dat.commit()
chat.send("Deleted >:c")
else:
chat.send("Invalid Username")
@bot.command("refreshpin", hidden=True)
def refreshpin(chat, message):
if message.sender in chat.admins:
if chat.type == 'supergroup':
d.execute("SELECT mesid, name FROM request WHERE stage=5")
reqs = d.fetchall()
bt = botogram.Buttons()
for n, x in enumerate(reqs):
lnk = "t.me/" + chat.username + "/" + str(x[0])
bt[n].url(x[1], lnk)
if message.sender.id != bot.itself.id:
try:
additional_text = "\n\n_%s_\n\n" % (message.reply_to_message.text)
except AttributeError:
additional_text = "\n"
tosend = (p['refreshpin'] % (additional_text))
chat.send(tosend, attach=bt, syntax="markdown", preview=False)
bot.api.call("pinChatMessage", {"chat_id": chat.id, "message_id": (message.id + 1)})
r.set('pinned', message.id + 1)
else:
additional_text = "\n"
tosend = p['refreshpin'] % (additional_text)
mex = r.get('pinned')
bot.edit_message(chat.id, mex, tosend, attach=bt, syntax="markdown", preview=False)
@bot.command("resizevotes", hidden=True)
def resizevotes(message, chat):
'''command for Admins only, resize the number of votes that a request need to be approved'''
if checkperm(message.sender.id):
try:
r.set('votes', int(message.text[12::]))
chat.send("Votes that a request needs to be approved are now %s" % (int(r.get('votes'))))
except ValueError:
chat.send("Insert a valid number!")
@bot.command("cleanreq", hidden=True)
def cleanreq(message, chat):
'''command for Admins only, clean all the requests'''
if checkperm(message.sender.id):
chat.send('cleaning..')
d.execute("DROP TABLE IF EXISTS request")
d.execute("DROP TABLE IF EXISTS mess")
d.execute("VACUUM")
d.execute("CREATE TABLE IF NOT EXISTS request (name TEXT, link TEXT, userid INTEGER PRIMARY KEY, username TEXT, nameuser TEXT, stage INTEGER DEFAULT 1, type TEXT, votes INTEGER DEFAULT 0, mesid INTEGER)")
d.execute('CREATE TABLE IF NOT EXISTS mess (mesid INTEGER, user INTEGER)')
chat.send('Done!')
dat.commit()
@bot.command("cleanall", hidden=True)
def cleanall(message, chat):
'''command for Admins only, clean everything (also the database with the admins and groups)'''
if checkperm(message.sender.id):
chat.send('cleaning..')
d.execute("DROP TABLE IF EXISTS request")
d.execute("DROP TABLE IF EXISTS mess")
d.execute("DROP TABLE IF EXISTS ids")
d.execute("VACUUM")
d.execute("CREATE TABLE IF NOT EXISTS request (name TEXT, link TEXT, userid INTEGER PRIMARY KEY, username TEXT, nameuser TEXT, stage INTEGER DEFAULT 1, type TEXT, votes INTEGER DEFAULT 0, mesid INTEGER)")
d.execute("CREATE TABLE IF NOT EXISTS ids (id INTEGER PRIMARY KEY, username TEXT, type INTEGER)")
d.execute('CREATE TABLE IF NOT EXISTS mess (mesid INTEGER, user INTEGER)')
dat.commit()
chat.send('all proofs cleared ;)')
@bot.command('sqldb', hidden=True)
def executesql(chat, message):
if chat.type == 'private':
if checkperm(message.sender.id):
comm = message.text[6::]
print("\nINFO - This command was executed by %s:" % (message.sender.name), comm, "\n")
try:
d.execute(comm)
chat.send(str(d.fetchall()))
dat.commit()
except sqlite3.OperationalError:
dat.rollback()
chat.send("Can't accept this command")
@bot.command('backup', hidden=True)
def backup_db(chat, message):
'''command for Admins only, send the request's db to backup it'''
if checkperm(message.sender.id):
chat.send_file(path="data/dat1.db", caption=("Backup from %s" % (time.ctime())))
d.execute("SELECT count(*) FROM request")
active_req = d.fetchone()[0]
d.execute("SELECT count(*) FROM mess")
being_voted = d.fetchone()[0]
d.execute("SELECT count(*) FROM request WHERE stage=6")
to_do_reqs = d.fetchone()[0]
chat.send("Active requests: %s\nBeing Voted Requests: %s\nApproved Request to do: %s" % (active_req, being_voted, to_do_reqs))
@bot.command("door", hidden=True)
def changereqnum(message, chat):
'''command for Admins only, change the number of requests that will be accepted, set to 0 to close the requests'''
if checkperm(message.sender.id):
try:
r.set('door', int(message.text[5::]))
chat.send('Now I\'m open to %s requests' % (int(r.get('door'))))
except ValueError:
chat.send('Actually still open to %s requests, Insert a valid number' % (int(r.get('door'))))
@bot.command("block", hidden=True)
def blockuser(message, chat):
'''command for Admins only, block an user'''
if chat.type == "private" and checkperm(message.sender.id):
bt = botogram.Buttons()
bt[0].callback("Cancel", "delete")
chat.send("Now forward a message from the user that you would like to block", attach=bt)
try:
d.execute("INSERT INTO request (userid, stage) VALUES (?, 99)", (message.sender.id, ))
dat.commit()
except sqlite3.IntegrityError:
dat.rollback()
d.execute("UPDATE request SET stage=99 WHERE userid=?", (message.sender.id, ))
dat.commit()
@bot.command("unblock", hidden=True)
def unblock(message, chat):
'''command for Admins only, unblock an user'''
if chat.type == "private" and checkperm(message.sender.id):
bt = botogram.Buttons()
d.execute("SELECT userid, name FROM request WHERE stage=0")
blocklist = d.fetchall()
if blocklist == []:
chat.send("There aren't blocked users")
else:
for index, user in enumerate(blocklist):
bt[index].callback(str(user[1]), "unban", str(user[0]))
chat.send("Who do you want to unblock?", attach=bt)
@bot.command("oliodipalmas", hidden=True)
def easteregg(chat, message):
# $ Put at least one easter egg or you're dead to me
chat.send(p["easteregg"])
@bot.command("info")
def info(chat):
chat.send("You can find the source code of this bot on https://github.com/Mamiglia/Requester-Bot, bot created by @Mamiglia using botogram")
@bot.command("setstaff", hidden=True)
def setstaff(chat, message):
'''command for Admins only, set the staff group'''
if chat.type == "supergroup":
if checkperm(message.sender.id):
try:
d.execute("INSERT INTO ids (id, type) VALUES (?,?)", (chat.id, 1))
chat.send("Staff Group correctly set!")
dat.commit()
except sqlite3.IntegrityError:
dat.rollback()
chat.send("This Chat is already been used for something else")
else:
chat.send("I need to receive the command from an important guy, not a console peasant as you")
else:
chat.send("I should be in a Supergroup, wrong chat!")
@bot.command("setgroup", hidden=True)
def setgroup(chat, message):
'''command for Admins only, set the group where are the users, and the group where the requests will be voted'''
if chat.type == "supergroup":
if checkperm(message.sender.id):
try:
d.execute("INSERT INTO ids (id, type) VALUES (?,?)", (chat.id, 3))
chat.send("Group correctly set!")
dat.commit()
except sqlite3.IntegrityError:
dat.rollback()
chat.send("This Chat is already been used for something else")
else:
chat.send("I need to receive the command from an important guy, not a console peasant as you")
else:
chat.send("I should be in a Supergroup, wrong chat!")
@bot.command("setlog", hidden=True)
def setlogchannel(chat, message):
'''command for Admins only, set the log channel'''
if chat.type == "private":
if checkperm(message.sender.id):
chn = message.text[8::]
try:
global logch
logch = botogram.channel(chn, p["values"]["token"])
d.execute("INSERT INTO ids (username, type) VALUES (?,?)", (chn, 2))
chat.send("Log Channel correctly set! Reboot me")
dat.commit()
except botogram.api.ChatUnavailableError:
dat.rollback()
chat.send('Username invalid')
else:
chat.send("I need to receive the command from an important guy, not a console peasant as you")
else:
chat.send("I should be in a private chat, wrong chat!")
@bot.command("request")
def first(message, chat):
"""Make Your Request!"""
if chat.type == "private":
if checkreq(chat, 'request'):
bt = botogram.Buttons()
bt[0].callback(p["request"][0], "zero", str(chat.id))
chat.send(p["request"][1], attach=bt)
@bot.command(p["values"]["request2"], hidden=False)
def second(message, chat):
'''Request something different'''
# You can have different types of request, or just set hidden=True if you don't want to use this feature
if chat.type == "private":
if checkreq(chat, p["values"]["request2"]) is True:
bt = botogram.Buttons()
bt[0].callback(p["request"][0], "zero", str(chat.id))
chat.send(p["request"][2], attach=bt)
@bot.command("cancel")
def deletemine(message, chat):
'''self-delete the request of the user'''
if chat.type == "private":
d.execute("SELECT stage FROM request WHERE userid=?", (message.sender.id, ))
try:
stage = d.fetchone()[0]
except TypeError:
chat.send(p["deletemine"][0])
return
if stage == 0:
return
elif stage < 5:
d.execute("DELETE FROM request WHERE userid=?", (message.sender.id, ))
dat.commit()
elif stage == 5:
d.execute("SELECT id FROM ids WHERE type=3")
group = d.fetchone()[0]
d.execute("SELECT mesid FROM request WHERE userid=?", (message.sender.id, ))
mesid = d.fetchone()[0]
try:
bot.edit_message(group, mesid, "Request canceled by user")
except (TypeError, botogram.api.APIError):
print("WARNING - You shall not delete the voting messages of an user")
d.execute("DELETE FROM request WHERE userid=?", (message.sender.id, ))
d.execute("DELETE FROM mess WHERE user=?", (message.sender.id, ))
dat.commit()
elif stage > 5:
chat.send(p["deletemine"][1])
return
chat.send(p["deletemine"][2])
refreshpin(chat, message)
@bot.process_message
def stager(chat, message):
'''The core of this code, it just checks at what moment the request is, and ask the specific information to the user'''
if chat.type == "private":
d.execute("SELECT stage FROM request WHERE userid=?", (chat.id, ))
try:
stage = int(d.fetchone()[0])
if stage == 1:
bot.edit_message(chat, int(message.id - 1), p["request"][1])
bt = botogram.Buttons()
d.execute("UPDATE request SET stage=2, name=?, username=?, nameuser=? WHERE userid=?", (message.text, (message.sender.username).lower(), message.sender.name, chat.id,))
dat.commit()
bt[0].callback(p["stager"]["1"][1], "rename")
bt[1].callback(p["stager"]["1"][2], 'void')
chat.send(p["stager"]["1"][3], attach=bt)
elif stage == 2:
try:
d.execute("SELECT link FROM request WHERE userid=?", (chat.id, ))
# selection due to the fact that i use the same stager() function also in the 'No Link' event
lnk = d.fetchone()[0]
if lnk is None:
lnk = str(message.parsed_text.filter("link")[0])
res = checklink(lnk)
bot.edit_message(chat, int(message.id - 1), p["stager"]["1"][3])
else:
lnk = 'No link'
res = True
message.edit(p["stager"]["1"][3])
chat.send(p["stager"]["2"][5])
if res:
bt = botogram.Buttons()
d.execute("UPDATE request SET link=?, stage=3 WHERE userid=?", (lnk, chat.id))
dat.commit()
bt[0].callback(p["stager"]["2"][1], "relink", str(chat.id))
bt[1].callback(p["stager"]["2"][2], "zero", str(chat.id))
bt[1].callback(p["stager"]["2"][3], 'confirm', str(chat.id))
chat.send(visualizer(chat), syntax="markdown", attach=bt)
else:
chat.send(p["stager"]["2"][4])
except IndexError:
dat.rollback()
chat.send(p["stager"]["2"][4])
elif stage == 3:
chat.send(p["stager"]["3"][0])
elif stage == 4:
chat.send(p["stager"]["4"][0])
elif stage == 5:
chat.send(p["stager"]["5"][0])
elif stage == 6:
chat.send(p["stager"]["6"][0])
elif stage == 0:
chat.send(p["stager"]["0"][0])
elif stage == 99:
blocking = message.forward_from
print(blocking.name)
try:
d.execute("INSERT INTO request (userid, name, stage) VALUES (?,?,0)", (blocking.id, blocking.name))
except sqlite3.IntegrityError:
dat.rollback()
d.execute("UPDATE request SET stage=0 WHERE userid=?", (blocking.id, ))
d.execute("DELETE FROM request WHERE userid=?", (message.sender.id, ))
dat.commit()
chat.send("BLOCKED, type /unblock to unblock ")
else:
chat.send(p["stager"]["err"][0])
except TypeError:
chat.send(knowit(int(r.get('door'))))
dat.commit()
return True
@bot.callback("delete")
def dele(query):
query.message.delete()
@bot.callback("rename")
def rename(chat, message):
'''rename the the request'''
d.execute("UPDATE request SET stage=1 WHERE userid=?", (chat.id, ))
dat.commit()
message.edit(p['rename'])
@bot.callback("relink")
def relink(chat, message, data):
'''change the provided link'''
d.execute("UPDATE request SET stage=2, link=NULL WHERE userid=?", (chat.id, ))
dat.commit()
bt = botogram.Buttons()
bt[0].callback(p['stager']['1'][2], 'void')
message.edit(p["relink"], attach=bt)
@bot.callback('void')
def void(message, chat):
'''set null link'''
d.execute('UPDATE request SET link=? WHERE userid=?', ('NULL', chat.id))
dat.commit()
stager(chat, message)
@bot.callback("zero")
def zero(chat, message, data):
'''delete the request'''
d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
dat.commit()
message.edit(p["zero"])
@bot.callback("zero2")
def zero2(chat, message, data):
'''delete the request after that it is solved'''
d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
dat.commit()
message.delete()
try:
bot.chat(int(data)).send(p["zero2"])
except Exception:
pass
@bot.callback("confirm")
def confirm(chat, message, data):
'''confirm the request, and send it to the staff group'''
door = int(r.get('door')) - 1
r.set('door', door)
bt = botogram.Buttons()
d.execute('UPDATE request SET stage=4 WHERE userid=?', (chat.id, ))
dat.commit()
d.execute("SELECT id FROM ids WHERE type=1")
staffs = d.fetchone()
bt[0].callback(p["confirm"][0], "refuse", str(chat.id))
bt[1].callback(p["confirm"][1], "good", str(chat.id))
bt[2].callback(p["confirm"][2], "vote", str(chat.id))
for group in staffs:
bot.chat(group).send(staffvis(str(chat.id)), attach=bt)
message.edit(p["confirm"][3])
@bot.callback("refuse")
def refuse(chat, message, query, data):
'''refuse the request'''
d.execute("SELECT stage FROM request WHERE userid=?", (int(data), ))
try:
if d.fetchone()[0] == 4:
message.edit(verdict(int(data), False, query.sender.name, query.sender.id))
d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
dat.commit()
try:
bot.chat(int(data)).send(p["refuse"])
except Exception:
pass
else:
message.edit("Already in another Stage baby")
except TypeError:
dat.rollback()
message.edit(p["alreadydel"])
@bot.callback("vote")
def groupvote(chat, message, data, query):
'''the request will be voted in the group'''
d.execute("SELECT stage FROM request WHERE userid=?", (int(data), ))
x = d.fetchone()
try:
if x[0] == 4:
try:
bot.chat(int(data)).send(p["vote"])
except botogram.ChatUnavailableError as e:
message.delete()
if e == "blocked":
chat.send("The user has blocked the Bot. Request canceled")
elif e == "account_deleted":
chat.send("The user deleted its account. Request canceled")
else:
chat.send("User unavailable: %s" % (e))
d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
dat.commit()
else:
message.edit("Already in another Stage baby")
except TypeError:
dat.rollback()
message.edit(p["alreadydel"])
else:
d.execute('UPDATE request SET stage=5 WHERE userid=?', (int(data), ))
dat.commit()
message.edit(verdict(int(data), 'vote', query.sender.name, query.sender.id))
d.execute("SELECT id FROM ids WHERE type=3")
groups = d.fetchone()
bt = botogram.Buttons()
bt[0].callback('start', 'startpoll', data)
for group in groups:
bot.chat(group).send("New Poll by %s" % (data), attach=bt)
@bot.callback("good")
def good(chat, message, data, query):
'''Accept the request without voting procedure'''
d.execute("SELECT stage FROM request WHERE userid=?", (int(data), ))
try:
stage = int(d.fetchone()[0])
if stage <= 5:
d.execute('UPDATE request SET stage=6 WHERE userid=?', (int(data), ))
dat.commit()
bt = botogram.Buttons()
bt[0].callback(p["good"][1], 'zero2', str(data))
if stage == 4:
message.edit(verdict(int(data), True, query.sender.name, query.sender.id))
try:
bot.chat(int(data)).send(p["good"][0])
except botogram.ChatUnavailableError as e:
message.delete()
chat.send("User unavailable: %s" % (e))
d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
dat.commit()
else:
logch.send(staffvis(data), attach=bt)
else:
logch.send(staffvis(data), attach=bt)
else:
message.edit("Already in another Stage baby")
except TypeError:
dat.rollback()
message.edit(p["alreadydel"])
@bot.callback('op')
def operation(chat, message, query, data):
d.execute('SELECT user FROM mess WHERE mesid=?', (message.id, ))
users = d.fetchall()
if users == [] or check2(users, query.sender.id):
d.execute('SELECT votes, userid, name, link FROM request WHERE mesid=?', (message.id, ))
ex = d.fetchone()
vote = ex[0] + int(data)
userid = ex[1]
# set how many votes are needed in default for the request to be approved up in line 52
if vote >= int(r.get('votes')):
good(chat, message, userid, None)
message.edit(p["op"][0])
d.execute('DELETE FROM mess WHERE mesid=?', (message.id, ))
dat.commit()
refreshpin(chat, message)
elif vote <= -int(r.get('votes')):
zero(chat, message, userid)
message.edit(p["op"][1])
d.execute('DELETE FROM mess WHERE mesid=?', (message.id, ))
dat.commit()
refreshpin(chat, message)
else:
d.execute('UPDATE request SET votes=? WHERE mesid=?', (vote, message.id))
d.execute('INSERT INTO mess (mesid, user) VALUES (?,?)', (message.id, query.sender.id))
dat.commit()
query.notify(p["op"][2])
qtvis(chat, message, userid)
else:
query.notify(p["op"][3])
@bot.callback('startpoll')
def startpoll(chat, message, data):
'''start the poll in the group'''
d.execute('UPDATE request SET mesid=? WHERE userid=?', (message.id, int(data)))
dat.commit()
refreshpin(chat, message)
qtvis(chat, message, data)
@bot.callback('qtvis')
def qtvis(chat, message, data):
'''a cute indentation for the message with the votes in the user's group'''
d.execute("SELECT * FROM request WHERE userid=?", (int(data), ))
ex = d.fetchone()
name = ex[0]
lnk = ex[1]
userid = int(data)
nameuser = ex[4]
ur = ex[6]
vote = ex[7]
bt = botogram.Buttons()
bt[0].callback('+1', 'op', str(+1))
bt[0].callback('-1', 'op', str(-1))
message.edit(p["qtvis"] % (ur, nameuser, userid, name, lnk, vote), preview=False, attach=bt)
@bot.callback("unban")
def unban(chat, message, data):
d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
dat.commit()
message.edit("Unbanned!")
works = os.cpu_count()
bot.run(workers=works)
dat.commit()
if __name__ == "__main__":
bot.run()