forked from TheretVM/Werewolf_Bot
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_ww.py
673 lines (579 loc) · 32 KB
/
main_ww.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
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
splash = '''
888 888 888 .d888 888888b. 888
888 o 888 888 d88P" 888 "88b 888
888 d8b 888 888 888 888 .88P 888
888 d888b 888 .d88b. 888d888 .d88b. 888 888 888 .d88b. 888 888888 8888888K. .d88b. 888888
888d88888b888 d8P Y8b 888P" d8P Y8b 888 888 888 d88""88b 888 888 888 "Y88b d88""88b 888
88888P Y88888 88888888 888 88888888 888 888 888 888 888 888 888 888 888 888 888 888
8888P Y8888 Y8b. 888 Y8b. Y88b 888 d88P Y88..88P 888 888 888 d88P Y88..88P Y88b.
888P Y888 "Y8888 888 "Y8888 "Y8888888P" "Y88P" 888 888 8888888P" "Y88P" "Y888
- = https://github.com/werewolves-devs/werewolf_bot = -
'''
splashes = [
'Now with 100% less JavaScript',
'I made it, we *HAVE* to use it',
'Standards? What are they?',
'Nah, we don\'t use libraries here.',
'The mailbox system is a \'good idea\'',
'Leaking tokens is fun!',
'Let\'s just shove everything into main.py, who still does organization in 2018',
'Works on my machine',
'Always use a database. What\'s a JSON?',
'Powered by Electricity',
'Who still writes docs in 2018?',
'First normal form? What does that mean?',
'By using a relational database with nonrelational practices we get the worst of both worlds!',
'I haven\'t paid attention or read any comments, therefore it\'s impossible to understand!',
'Don\'t use that! Oh, you\'re asking why? Well... just don\'t it.',
'I don\'t wanna explain, just Google it.',
'What are cogs?',
'This is MY project. You\'re just freeloaders.',
'You\'ve got three weeks to fix EVERYTHING.',
'No-one agrees? Too bad! My idea it is.',
'The next version will be written in Java only!'
]
import discord
import random
import asyncio
# Import config data
# Imports go (folder name).(file name)
import story_time.cc_creation as creation_messages
import story_time.powerup as secret_messages
from config import welcome_channel, game_master, dead_participant, frozen_participant, administrator, peasant
from config import ww_prefix as prefix
from management.db import db_set, db_get
from interpretation.ww_head import process
from interpretation.polls import count_votes
import config
import management.db as db
import management.dynamic as dy
import management.shop as db_shop
import shop
import stats
from emoji import emojize
client = discord.Client()
def get_role(server_roles, target_id):
for each in server_roles:
if each.id == target_id:
return each
return None
async def remove_all_game_roles(member):
for role in member.roles:
if role.id == config.frozen_participant:
await member.remove_roles(role, reason="Updating CC permissions")
if role.id == config.dead_participant:
await member.remove_roles(role, reason="Updating CC permissions")
if role.id == config.suspended:
await member.remove_roles(role, reason="Updating CC permissions")
if role.id == config.participant:
await member.remove_roles(role, reason="Updating CC permissions")
already_quoted = []
@client.event
async def on_reaction_add(reaction, user):
return
# Whenever a message is edited
@client.event
async def on_message_edit(before, after):
if before.author == client.user: # We don't want to respond to our own edits
return
if before.content == after.content: # Ensure it wasn't just a pin
return
stats.increment_stat("messages_edited", 1)
stats.increment_user_stat(before.author.id, "messages_edited", 1)
if before.id != after.id:
db.add_trash_message(after.id,after.channel.id)
#check role of sender
isGameMaster = False
isAdmin = False
isPeasant = False
try:
if after.guild == client.get_channel(int(config.game_log)).guild:
role_table = [y.id for y in after.guild.get_member(after.author.id).roles]
if game_master in role_table:
isGameMaster = True
if administrator in role_table:
isAdmin = True
if peasant in role_table and after.author.bot == True:
isPeasant = True
except Exception:
pass
await process_message(after,process(after,isGameMaster,isAdmin,isPeasant))
# Whenever a message is sent.
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
stats.increment_stat("bot_messages_sent", 1)
return
stats.increment_stat("messages_sent", 1)
stats.increment_user_stat(message.author.id, "messages_sent", 1)
# Add trash messages
db.add_trash_message(message.id,message.channel.id)
#check role of sender
isGameMaster = False
isAdmin = False
isPeasant = False
if message.guild == client.get_channel(int(config.game_log)).guild:
try:
role_table = [y.id for y in message.guild.get_member(message.author.id).roles]
except Exception:
print('Unable to acquire role_table from {}'.format(message.author.display_name))
else:
if game_master in role_table:
isGameMaster = True
if administrator in role_table:
isAdmin = True
if peasant in role_table and message.author.bot == True:
isPeasant = True
await process_message(message,process(message,isGameMaster,isAdmin,isPeasant))
async def process_message(message,result):
if "<@&{}>".format(config.game_master) in message.content:
stats.increment_stat("game_master_pings", 1)
stats.increment_user_stat(message.author.id, "game_master_pings", 1)
if db.isParticipant(message.author.id,True,True,True):
db_set(message.author.id,'activity',0)
gamelog_channel = client.get_channel(int(config.game_log))
botspam_channel = client.get_channel(int(config.bot_spam))
storytime_channel = client.get_channel(int(config.story_time))
# The temp_msg list is for keeping track of temporary messages for deletion.
temp_msg = []
for mailbox in result:
# If a Mailbox says so, all existing polls will be evaluated.
if mailbox.evaluate_polls == True:
for poll in db.get_all_polls():
# poll.msg_table -> list of message ids
# poll.blamed -> name of killer
# poll.purpose -> the reason of the kill
poll_channel = client.get_channel(int(poll.channel))
if poll_channel == None:
await botspam_channel.send("We got a problem! Could you send these results to the appropriate channel, please?")
poll_channel = botspam_channel
user_table = []
for msg in poll.msg_table:
poll_msg = await poll_channel.get_message(msg)
for emoji in poll_msg.reactions:
users = await emoji.users().flatten()
for person in users:
if db.isParticipant(person.id):
user_table.append([person.id,emoji.emoji])
log, result, chosen_emoji = count_votes(user_table,poll.purpose,dy.get_mayor())
await botspam_channel.send(log)
await poll_channel.send(result)
chosen_one = db.emoji_to_player(chosen_emoji)
if chosen_emoji != '' and chosen_one != None:
chosen_one = int(chosen_one)
if poll.purpose == 'lynch':
db.add_kill(chosen_one,'Innocent')
elif poll.purpose == 'Mayor':
dy.set_mayor(chosen_one)
member = gamelog_channel.guild.get_member(int(chosen_one))
if member != None:
await member.add_roles(get_role(gamelog_channel.guild.roles, config.mayor), reason="Promoting {} to Mayor".format(member.display_name))
elif poll.purpose == 'Reporter':
dy.set_reporter(chosen_one)
for channel_id in db.get_secret_channels("Reporter"):
mailbox.edit_cc(channel_id,chosen_one,1)
member = gamelog_channel.guild.get_member(int(chosen_one))
if member != None:
await member.add_roles(get_role(gamelog_channel.guild.roles, config.reporter), reason="Promoting {} to Reporter".format(member.display_name))
elif poll.purpose == 'wolf':
db.add_kill(chosen_one,'Werewolf',db.random_wolf())
elif poll.purpose == 'cult':
db.add_kill(chosen_one,'Cult Leader',db.random_cult())
elif poll.purpose == 'thing':
db.add_kill(chosen_one,'The Thing','')
for user_id in mailbox.demotions:
if user_id == message.author.id and message.guild == gamelog_channel.guild:
member = message.author
else:
member = gamelog_channel.guild.get_member(int(user_id))
if member != None:
for role in member.roles:
if role.id == config.mayor:
await member.remove_roles(role, reason="Demoting the Mayor")
if role.id == config.reporter:
await member.remove_roles(role, reason="Demoting the Reporter")
# Create a new shop instance
for element in mailbox.shops:
shop_data = db_shop.get_shop_config(element.shop_config)
i = 1
j = 0
emoji_table = []
page_amount = int(len(shop_data["items"])-1/20)+1
for item in shop_data["items"]:
if j % 20 == 0:
embed = discord.Embed(title="Shop (Page {}/{})".format(i,page_amount), description=shop_data["shop_description"], color=0x00ff00)
embed.add_field(name="[{}] {}".format(item["emoji"], item["name"]), value="{} {}\n*{}*\n".format(item["price"], shop_data["currency"], item["description"]), inline=False) # Add item to shop
emoji_table.append(emojize(item["emoji"]))
j += 1
if j % 20 == 0:
i += 1
response = await client.get_channel(int(element.destination)).send(embed=embed)
db_shop.add_shop(response.id)
for item in emoji_table:
await response.add_reaction(item)
emoji_table = []
if j % 20 != 0:
response = await client.get_channel(int(element.destination)).send(embed=embed)
db_shop.add_shop(response.id)
for item in emoji_table:
await response.add_reaction(item)
# If the Mailbox has a message for the gamelog, this is where it's sent.
for element in mailbox.gamelog:
msg = await gamelog_channel.send(element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
# If the Mailbox has a message for the botspam, this is where it's sent.
for element in mailbox.botspam:
msg = await botspam_channel.send(element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
# If the Mailbox has a message for the storytime (in-game announcements) channel, this is where it's sent.
for element in mailbox.storytime:
msg = await storytime_channel.send(element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
# The messages are sent here if they are a direct message to the one sending a command.
for element in mailbox.answer:
msg = await message.channel.send(element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
# The messages that are destined for a specific channel, are sent here.
for element in mailbox.channel:
# The following code is sent if the message is an embed.
if element.embed:
if element.destination == "spam":
msg = await botspam_channel.send(embed=element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
else:
msg = await client.get_channel(int(element.destination)).send(embed=element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
# The following code is sent if the message is a regular message.
else:
msg = await client.get_channel(int(element.destination)).send(element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
# DMs are sent here.
for element in mailbox.player:
member = client.get_user(int(element.destination))
main_guild = botspam_channel.guild
if member == None:
member = main_guild.get_member(int(element.destination))
if member == None:
await message.channel.send("Couldn't send a DM to <@{}>!".format(element.destination))
await botspam_channel.send(
"<@{}> has attempted to send a DM to <@{}>, but failed, because we couldn't find the specified user via `client.get_user`.".format(
message.author.id, element.destination))
else:
try:
msg = await member.send(element.content)
for emoji in element.reactions:
await msg.add_reaction(emoji)
if element.temporary == True:
temp_msg.append(msg)
except discord.errors.Forbidden:
botspam_channel.send('I wasn\'t allowed to send a DM to <@{}>! Here\'s the content:'.format(member.id))
botspam_channel.send(element.content)
except Exception:
botspam_channel.send('I failed to send a DM to <@{}>! Could somebody send this, please?'.format(member.id))
botspam_channel.send(element.content)
# Settings of existing channels are altered here.
for element in mailbox.oldchannels:
# element.channel - channel to be edited;
# element.victim - person's permission to be changed;
# element.number - type of setting to set to: see issue #83 for more info.
channel = client.get_channel(element.channel)
user = client.get_user(int(element.victim))
main_guild = botspam_channel.guild
member = main_guild.get_member(int(element.victim))
if member == None:
if user == None:
await botspam_channel.send("That\'s problematic! I couldn\'t edit the cc info of <@{0}> *(<#{0}> <@&{0}> ?)*".format(element.victim))
print('Unable to locate member {}.'.format(element.victim))
member = user
if channel == None:
await botspam_channel.send('Unable to edit channel <#{0}> *(<@{0}> <@&{0}> ?)*'.format(int(element.victim)))
elif member != None:
await remove_all_game_roles(member)
if element.number == 0:
await channel.set_permissions(user, read_messages=False, send_messages=False)
try:
if int(db_get(member.id,'frozen')) == 0:
raise NotImplementedError("This is a purposeful error raise!")
except Exception:
if db.isParticipant(member.id):
await member.add_roles(get_role(main_guild.roles, config.participant), reason="Updating CC Permissions")
elif db.isParticipant(member.id,True,True):
await member.add_roles(get_role(main_guild.roles, config.dead_participant), reason="Updating CC Permissions")
elif db.isParticipant(member.id,True,True,True):
await member.add_roles(get_role(main_guild.roles, config.suspended), reason="Updating CC Permissions")
else:
await member.add_roles(get_role(main_guild.roles, config.frozen_participant), reason="Updating CC Permissions")
elif element.number == 1:
await channel.set_permissions(user, read_messages=True, send_messages=True)
await member.add_roles(get_role(main_guild.roles, config.participant), reason="Updating CC Permissions")
elif element.number == 2:
await channel.set_permissions(user, read_messages=True, send_messages=False)
await member.add_roles(get_role(main_guild.roles, config.frozen_participant), reason="Updating CC Permissions")
elif element.number == 3:
await channel.set_permissions(user, read_messages=False, send_messages=False)
await member.add_roles(get_role(main_guild.roles, config.participant), reason="Updating CC Permissions")
elif element.number == 4:
await channel.set_permissions(user, read_messages=True, send_messages=False)
if db.isParticipant(member.id,False,True):
await member.add_roles(get_role(main_guild.roles, config.dead_participant), reason="Updating CC Permissions")
elif element.number == 5:
await channel.set_permissions(user, read_messages=True, send_messages=False)
await member.add_roles(get_role(main_guild.roles, config.participant), reason="Updating CC Permissions")
elif element.number == 6:
await channel.set_permissions(user, read_messages=False, send_messages=False)
await member.add_roles(get_role(main_guild.roles, config.participant), reason="Updating CC Permissions")
elif element.number == 7:
await channel.set_permissions(user, read_messages=False, send_messages=False)
await member.add_roles(get_role(main_guild.roles, config.participant), reason="Updating CC Permissions")
elif element.number == 8:
await channel.set_permissions(user, read_messages=False, send_messages=False)
await member.add_roles(get_role(main_guild.roles, config.suspended), reason="Updating CC Permissions")
else:
await msg.channel.send('Something went wrong! Please contact a Game Master.')
return
if db.isParticipant(element.victim,True,True):
db.set_user_in_channel(element.channel,element.victim,element.number)
# New channels are created here.
for element in mailbox.newchannels:
# element.name - name of the channel;
# element.owner - owner of the channel;
# element.members - members of the channel
# element.settlers - members for whom this shall become their home channel
# element.secret - boolean if the channel is a secret channel
if element.secret:
element.owner = client.user.id
if ' ' not in element.name:
main_guild = botspam_channel.guild # Find the guild we're in
if element.owner not in element.members:
element.members.append(element.owner)
for buddy in element.settlers:
if buddy not in element.members:
msg = """**Warning:** I'm adding settlers to a channel!\nThis is should not be a problem, \
but it does at least indicate a flaw in the bot's code. Please, report this to the Game Masters!"""
await client.get_channel(message.channel).send(msg)
element.members.append(buddy)
viewers = []
frozones = []
abductees = []
deadies = []
# Add dead people & spectators to cc
if not element.secret:
for user in [dead_buddy for dead_buddy in db.player_list() if dead_buddy not in db.player_list(True)]:
element.members.append(user)
# Categorize all players
for user in element.members:
member = main_guild.get_member(user)
if member == None:
await botspam_channel.send("That\'s problematic! I couldn\'t add <@{0}> to a cc. *(<#{0}> <@&{0}> ?)*".format(element.victim))
await message.author.send("It doesn't seem like <@{}> is part of the server! I am sorry, I can't add them to your **conspiracy channel**.".format(user))
elif db.isParticipant(user,False,True) == True:
if int(db_get(user,'abducted')) == 1:
abductees.append(member)
elif int(db_get(user,'frozen')) == 1:
frozones.append(member)
elif db.isParticipant(user,False,False) == False:
deadies.append(member)
else:
viewers.append(member)
elif db_get(user,'role') == 'Suspended':
pass
else:
deadies.append(member)
# Delete any potential duplicates
viewers = list(set(viewers))
frozones = list(set(frozones))
abductees = list(set(abductees))
deadies = list(set(deadies))
# Role objects (based on ID)
roles = main_guild.roles # Roles from the guild
game_master_role = discord.utils.find(lambda r: r.id == game_master, roles)
# TODO: Add read permissions for spectators if element.secret == False
default_permissions = {
main_guild.default_role: discord.PermissionOverwrite(read_messages=False,send_messages=False),
game_master_role: discord.PermissionOverwrite(read_messages=True,send_messages=True),
client.user: discord.PermissionOverwrite(read_messages=True,send_messages=True),
**{
member: discord.PermissionOverwrite(read_messages=True,send_messages=True) for member in viewers
},
**{
member: discord.PermissionOverwrite(read_messages=True,send_messages=False) for member in frozones
},
**{
member: discord.PermissionOverwrite(read_messages=True,send_messages=False) for member in deadies
}
}
if not element.secret:
intro_msg = creation_messages.cc_intro([v.id for v in viewers])
reason_msg = 'CC requested by ' + message.author.name
title = "s{}_cc_{}".format(config.season,element.name)
category_name = 'S{} CCs PART {}'.format(config.season,db.count_categories(element.secret) + 1)
else:
intro_msg = secret_messages.creation(element.name,[v.id for v in viewers])
reason_msg = 'Secret {} channel created.'.format(element.name)
title = "s{}_{}".format(config.season,element.name)
category_name = 'S{} Secret Channels Part {}'.format(config.season,db.count_categories(element.secret) + 1)
# Create a new category if needed
if db.get_category(element.secret) == None:
category = await main_guild.create_category(category_name, reason='It seems like we couldn\'t use our previous category! Don\'t worry, I just created a new one.')
db.add_category(category.id,element.secret)
else:
category = main_guild.get_channel(db.get_category(element.secret))
try:
# Create the text channel
channel = await main_guild.create_text_channel(
name=title,
category=category,
overwrites=default_permissions,
reason=reason_msg)
db.add_channel(channel.id,element.owner,element.secret)
if element.secret:
db.add_secret_channel(channel.id,element.name)
# If the channel is meant for an amulet holder, assign the amulet holder.
if element.name == 'Amulet_Holder':
for member in viewers:
if db_get(member.id,'role') == 'Amulet Holder':
db_set(member.id,'amulet',channel.id)
if element.trashy:
db.add_trash_channel(channel.id)
await channel.send(intro_msg)
# Set all access rules in the database
for member in viewers:
db.set_user_in_channel(channel.id,member.id,1)
for member in frozones:
db.set_user_in_channel(channel.id,member.id,2)
for member in abductees:
db.set_user_in_channel(channel.id,member.id,3)
for member in deadies:
if db.isParticipant(member.id,True,True) == True:
db.set_user_in_channel(channel.id,member.id,4)
except Exception as e: # Catch any thrown exceptions and send an error to the user.
await message.channel.send('It seems like I\'ve encountered an error! Please let the Game Masters know about this!')
await botspam_channel.send("Oi, Game Masters! I got a problem concerning channel creation for ya to fix.")
await botspam_channel.send(e)
raise e # Send the full log to Buddy1913 and his sketchy VM.
# Give the settlers their own happy little residence
for buddy in element.settlers:
db_set(buddy,"channel",channel.id)
else:
"""This should not happen, but we'll use it, to prevent the bot from purposely causing an error
everytime someone attempts to create a channel that contains spaces. 'cause believe me,
that happens ALL the time."""
msg = await message.channel.send("I\'m terribly sorry, but you can\'t use spaces in your channel name. Try again!")
temp_msg.append(msg)
# Polls are created here.
for element in mailbox.polls:
# element.channel
# element.purpose
# element.user_id
# element.description
msg = element.description + '\n'
emoji_table = []
msg_table = []
i = 0
for user in db.poll_list():
if db.isParticipant(int(user[0])):
i += 1
msg += user[1] + " - <@" + str(user[0]) + "> "
if int(user[2]) + int(user[3]) > 0:
if int(user[2]) == 1:
msg += "**[FROZEN]** "
if int(user[3]) == 1:
msg += "**[ABDUCTED] **"
else:
emoji_table.append(user[1])
if i % 20 == 19:
msg = await client.get_channel(int(element.channel)).send(msg)
for emoji in emoji_table:
await msg.add_reaction(emoji)
msg_table.append(msg)
emoji_table = []
msg = ''
else:
msg += '\n'
if msg != '':
msg = await client.get_channel(element.channel).send(msg)
for emoji in emoji_table:
await msg.add_reaction(emoji)
msg_table.append(msg)
db.add_poll(msg_table,element.purpose,element.channel,element.user_id)
await botspam_channel.send("A poll has been created in <#{}>!".format(element.channel))
# Categories are deleted here.
for element in mailbox.deletecategories:
id = element.channel
category = client.get_channel(id)
if category != None:
bot_message = await message.channel.send('Please react with 👍 to confirm deletion of category `' + category.name + '`.\n\nNote: This action will irreversibly delete all channels contained within the specified category. Please use with discretion.')
await bot_message.add_reaction('👍')
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '👍'
try:
reaction, user = await client.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await message.channel.send('Confirmation timed out.')
try:
await bot_message.delete()
except Exception:
pass
else:
await message.channel.send('Ok, I\'ll get right on that.\n\n*This might take some time.*')
for channel in category.channels:
await channel.delete()
await category.delete()
await message.channel.send('\n:thumbsup: Channels and category deleted')
else:
await message.channel.send('Sorry, I couldn\'t find that category.')
clean_time = len(mailbox.cleaners)
if clean_time > 0:
await botspam_channel.send("Cleaning up {} channels! This may take some time.".format(clean_time))
for channel in mailbox.cleaners:
trash_channel = client.get_channel(int(channel))
if trash_channel != None:
for message_id in db.empty_trash_channel(channel):
message = await trash_channel.get_message(int(message_id))
if message != None:
await message.delete()
# Delete all temporary messages after about two minutes.
await asyncio.sleep(120)
for msg in temp_msg:
try:
await msg.delete()
except Exception:
# Unable to delete the message.
# It was probaly already deleted or something.
pass
# Whenever the bot regains his connection with the Discord API.
@client.event
async def on_ready():
print(' --> Logged in as')
print(' | > ' + client.user.name)
print(' | > ' + str(client.user.id))
await client.get_channel(welcome_channel).send('Beep boop! I just went online!')
print(splash)
print(' --> "' + random.choice(splashes) + '"')
print(' --> Please wait whilst we connect to the Discord API...')
try:
client.run(config.WW_TOKEN)
except:
print(' | > Error logging in. Check your token is valid and you are connected to the Internet.')