-
Notifications
You must be signed in to change notification settings - Fork 0
/
Moderation.py
594 lines (541 loc) · 33.6 KB
/
Moderation.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
import discord
from discord.ext import commands
from discord.ext import tasks
def Update(cpage, cdict, tpage):
key = cdict.keys()
cpagekey = list(key)[cpage-1]
updEmbed = discord.Embed(title=cpagekey, description=f"Displaying the {cpagekey} now.")
for user in cdict[cpagekey]:
updEmbed.add_field(name=f"Case {list(cdict[cpagekey].keys()).index(user) + 1}", value= f"<@{int(user)}>: {cdict[cpagekey][user]}")
return updEmbed
class ForwardButton(discord.ui.Button):
def __init__(self, currentpage, c, totalpages):
super().__init__(style= discord.ButtonStyle.blurple, label= "Forward", row= 0)
self.currentpage = currentpage
self.c = c
self.totalpages = totalpages
async def callback(self, interaction : discord.Interaction):
if self.currentpage != self.totalpages:
self.currentpage +=1
await interaction.response.edit_message(embed = Update(self.currentpage, self.c, self.totalpages))
for component in self.view.children:
component.currentpage = self.currentpage
class BackwardButton(discord.ui.Button):
def __init__(self, currentpage, c, totalpages):
super().__init__(style=discord.ButtonStyle.blurple, label= "Backward", row = 0)
self.currentpage = currentpage
self.c = c
self.totalpages = totalpages
async def callback(self, interaction : discord.Interaction):
if self.currentpage > 1:
self.currentpage -=1
await interaction.response.edit_message(embed = Update(self.currentpage, self.c, self.totalpages))
for component in self.view.children:
component.currentpage = self.currentpage
class Moderation(commands.Cog):
def __init__(self, bot):
self.bot = bot
#Here, I loop the task of cleaning the spam file every 20 seconds
@tasks.loop(seconds = 15)
async def clean_spam(seconds = 15):
with open("spam_detect.txt", "w+") as file:
file.truncate(0)
class helpView(discord.ui.View):
def __init__(self, currentpage, c, totalpages):
super().__init__()
self.currentpage = currentpage
self.c = c
self.totalpages = totalpages
self.add_item(BackwardButton(self.currentpage, self.c, self.totalpages))
self.add_item(ForwardButton(self.currentpage, self.c, self.totalpages))
#This listener detects spam in the channels except those marked for spam
@commands.Cog.listener()
async def on_message(self, message):
dic = self.bot.col.find_one({"_id": "server_configs"})
try:
words = dic[str(message.guild.id)]["Words"]
except:
pass
mod = self.bot.col.find_one({"_id": "role_configs"})[str(message.guild.id)]["Moderator"]
for word in words:
if word in message.content:
await message.channel.send(f"Usage of prohibited word detected!!! Pinging <@{mod}> to take action now.")
spamchannels = []
Spambool = False
data = dict(self.bot.col.find_one({"_id": "server_configs"}))
spamchannels = data[str(message.guild.id)]["Spam Ignore"]
Spambool = data[str(message.guild.id)]["Spam"]
if Spambool and (not spamchannels or message.channel.id not in spamchannels):
counter = 0
with open ("spam_detect.txt", "r+") as file:
for lines in file:
if lines.strip("\n") == str(message.author.id) + str(message.channel.id) + message.content:
counter += 1
#If messages sent by the user and the channel + the content of the message is the same for 5 times, we ping the mods
file.writelines(f"{str(message.author.id) + str(message.channel.id) + message.content}\n")
if counter > 5:
file.truncate(0)
id = 0
data = dict(self.bot.col.find_one({"_id": "role_configs"}))
id = data[str(message.guild.id)]["Moderator"]
await message.channel.send(f"You are spamming. Proceeding to ping <@&{id}> to take action.")
#This is the kick command, pretty self explanatory imo
@commands.hybrid_command(description = "Kicks members, supa simple lil command all of ya folks should know right?", aliases = ["yeet"])
@commands.has_permissions(kick_members = True)
async def kick(self, ctx, member: discord.Member, *, reason = "No reason provided"):
await member.kick(reason= reason)
await ctx.send(f"{member.name} has been kicked for {reason}. All hail Da YEETs!!!")
await member.send(f"Thou hast been kicked, pestilence, for {reason}.")
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Kick case administered", description= f"<@{member.id}> was kicked by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Kick command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
#If the user doesn't have the permission, we display this message
@kick.error
async def kickerror(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("Hey mods! We have an imposter tryna kick someone without thy permissions. Do with him as thou wisheth.")
else:
print(error)
#Repeat the same thing for ban command
@commands.hybrid_command(description = "Bans pesky motherlovers from the server once and for all for greater good of the server.", aliases = ["superyeet"])
@commands.has_permissions(ban_members = True)
async def ban(self, ctx, member : discord.Member, *, reason = "No reason provided."):
await ctx.guild.ban(member, reason= reason)
await ctx.send("The pestilence has been Banned. All hail YEET GOD.")
await member.send(f"Hey punk, by the grace of the Yeet GOD, you have been banned for {reason}.")
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Ban case administered", description= f"<@{member.id}> was banned by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Ban command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
@ban.error
async def banerror(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("Hey mods! We have an imposter tryna ban someone without thy permissions. Do with him as thou wisheth.")
#Unban command to not indulge in the manual hassle of unbanning
@commands.hybrid_command(
description = "Unbans reformed exiles who have redeemed themselves. Do remember, don't hesitate to ban again.",
aliases = ["unyeet"]
)
@commands.has_permissions(ban_members = True)
async def unban(self, ctx, memberid, reason):
member = await self.bot.fetch_user(memberid)
await ctx.guild.unban(member, reason= reason)
await ctx.send(f"Member Unbanned!!!! All hail {ctx.guild.name}")
@unban.error
async def ubanerror(self,ctx,error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have the supreme power to unyeet the yeeted! Begone before I yeet you as well.")
#repeat the same thing for clean command as well so yep
@commands.hybrid_command(description = "Clears the given set of commands so you don't have to dirty your hands.", aliases = ["clean", "tidy", "purge"])
@commands.has_permissions(manage_messages = True)
async def clear(self, ctx, amt):
await ctx.channel.purge(limit = int(amt) + 1)
@clear.error
async def clearError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("Sorry but it seems you do not have the permissions to use this command. Thanks with the goodwill for cleannup though! :thumbsup:.")
@commands.hybrid_command(description = "Voids the pestilence into your void! After all, there's no sound in space.", aliases = ["void"])
@commands.has_permissions(kick_members = True)
async def mute(self, ctx, user : discord.Member, *, reason= "No reason provided."):
role = None
MuteRole = None
data = dict(self.bot.col.find_one({"_id": "role_configs"}))
role = data[str(ctx.guild.id)]["Member"]
MuteRole = data[str(ctx.guild.id)]["Mute"]
if MuteRole is not None and role is not None:
Role = ctx.guild.get_role(role)
muteRole = ctx.guild.get_role(MuteRole)
await user.remove_roles(Role, reason= reason)
await user.add_roles(muteRole, reason= reason)
await ctx.send(f"{user.name} has been muted for {reason}!!! All hail {ctx.guild.name}!!!")
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Mute case administered", description= f"<@{user.id}> was muted by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Mute command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
await ctx.send("You have not configured either the member or the muted role. Configure both to be able to mute members.")
@mute.error
async def muteError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You tried to mute someone but can't! Hah! Why shut others' mouths when you can't zip it up yourself?")
@commands.hybrid_command(description = "Gives the disabled peasants their ability to talk back.", aliases = ["unvoid"])
@commands.has_permissions(kick_members = True)
async def unmute(self, ctx, user : discord.Member, *, reason= "No reason provided."):
role = None
MuteRole = None
data = dict(self.bot.col.find_one({"_id": "role_configs"}))
role = data[str(ctx.guild.id)]["Member"]
MuteRole = data[str(ctx.guild.id)]["Mute"]
if MuteRole is not None and role is not None:
Role = ctx.guild.get_role(role)
muteRole = ctx.guild.get_role(MuteRole)
await user.remove_roles(muteRole, reason= reason)
await user.add_roles(Role, reason= reason)
await ctx.send(f"{user.name} has been unmuted for {reason}!!! All hail {ctx.guild.name}!!!")
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Unmute case administered", description= f"<@{user.id}> was unmuted by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Unmute command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
else:
await ctx.send("You have not configured either the member or the muted role. Configure both to be able to mute members.")
@mute.error
async def unmuteError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You tried to unmute someone but can't! Hah! You shouldn't try to be a god by giving other their speech back, mortal.")
#A warm command to give members warnings before voiding them :kekw:
@commands.hybrid_command(description = "Warns members that might commit wrongdoings. [Note: A reason is compulsory for using this command.]")
@commands.has_permissions(kick_members = True)
async def warn(self, ctx, user : discord.Member, *, reason):
#Check if the user has warns from the file
warns = {}
data = self.bot.col.find_one({"_id": "warns"})
warns = data[str(ctx.guild.id)]["Warns"]
if str(user.id) in warns:
if warns[str(user.id)] == 2:
#we use the same code we used with mute
data = self.bot.col.find_one({"_id": "role_configs"})
role = data[str(ctx.guild.id)]["Member"]
MuteRole = data[str(ctx.guild.id)]["Mute"]
if MuteRole is not None and role is not None:
Role = ctx.guild.get_role(role)
muteRole = ctx.guild.get_role(MuteRole)
await user.remove_roles(Role, reason= reason)
await user.add_roles(muteRole, reason= reason)
warns.pop(str(user.id))
await ctx.send(f"{user.name} has been muted over accumulation of 3 warnings. The current reason for warning was {reason}!!! All hail Satan!!!")
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Warn/Mute case administered", description= f"<@{user.id}> was muted by warning by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Warn command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
else:
await ctx.send("Cannot warn further, muted role has not been set up. What kind of moderation do you think I'd do if you don't give me the roles, dummy.")
data[str(ctx.guild.id)]["Warns"] = warns
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
else:
warnnum = warns[str(user.id)]
warnnum += 1
warns.pop(str(user.id))
warns[str(user.id)] = warnnum
data[str(ctx.guild.id)]["Warns"] = warns
await ctx.send(f"{user.name} has been warned for {reason}. Behave yourself or I'm getting the spaceship. Warnings remaining = 1.")
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Warn case administered", description= f"<@{user.id}> was warned by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Warn command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
else:
await ctx.send(f"{user.mention} has been warned for {reason}. Behave yourself or I'm getting the spaceship. Warnings remaining = 2.")
warns[str(user.id)] = 1
data[str(ctx.guild.id)]["Warns"] = warns
self.bot.col.find_one_and_update({"_id": "warns"}, data)
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Warn case administered", description= f"<@{user.id}> was warned by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Warn command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
@warn.error
async def warnError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You can't even handle your own habit of stealing the job of Mods, why try to warn others?")
#A superwarn commands for more serious stuff
@commands.hybrid_command(description = "Warns pestilence for more serious stuff. These get YEETed instantly on 3 superwarns.")
@commands.has_permissions(kick_members = True)
async def superwarn(self, ctx, user : discord.Member, *, reason):
superwarns = {}
data = self.bot.col.find_one({"_id": "warns"})
superwarns = data[str(ctx.guild.id)]["Superwarns"]
if superwarns:
if str(user.id) in superwarns:
if superwarns[str(user.id)] == 2:
await user.kick(reason= reason)
await ctx.send(f"{user.name} has been kicked after the accumulation of 3 superwarnings. The reason for the last superwarning was {reason}. All hail Da YEETs!!!")
await user.send(f"Thou hast been kicked, pestilence, after 3 superwarnings. The reason for thy last warning was {reason}.")
superwarns.pop(str(user.id))
data[str(ctx.guild.id)]["Superwarns"] = superwarns
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Superwarn/Kick case administered", description= f"<@{user.id}> was kicked by superwarning by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Superwarn command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
else:
superwarns[str(user.id)] += 1
data[str(ctx.guild.id)]["Superwarns"] = superwarns
await ctx.send(f"{user.name} has been superwarned for {reason}. Behave yourself or face the wrath of Quatara!! Superwarnings remaining = 1.")
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
else:
superwarns[str(user.id)] = 1
data[str(ctx.guild.id)]["Superwarns"] = superwarns
await ctx.send(f"{user.name} has been superwarned for {reason}. Behave yourself or face the wrath of Quatara!! Superwarnings remaining = 2.")
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Superwarn case administered", description= f"<@{user.id}> was superwarned by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Superwarn command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
else:
superwarns[str(user.id)] = 1
data[str(ctx.guild.id)]["Superwarns"] = superwarns
await ctx.send(f"{user.name} has been superwarned for {reason}. Behave yourself or face the wrath of Quatara!! Superwarnings remaining = 2.")
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Superwarn case administered", description= f"<@{user.id}> was superwarned by <@{ctx.author.id}> for {reason}")
embed.set_footer(text=f"Superwarn command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
@superwarn.error
async def superwarnError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You tried to superwarn without permissions. Satan surely has a separate role reserved for you in hell.")
#A forgive command in case someone did a lot of good work and you are like, okay let's pardon this guy's warnings
@commands.hybrid_command(description = "Clears the warnings from a redeemed soul. Good work, boi!")
@commands.has_permissions(kick_members = True)
async def forgive(self, ctx, user : discord.Member):
data = self.bot.col.find_one({"_id": "warns"})
warns = data[str(ctx.guild.id)]["Warns"]
superwarns = data[str(ctx.guild.id)]["Superwarns"]
if str(user.id) in warns and str(user.id) in superwarns:
warns.pop(str(user.id))
superwarns.pop(str(user.id))
await ctx.send(f"{user.name}, you have been forgiven for your good deeds from the sins of your pasts. You live as a free man now. Just remember: Try not to repeat the mistakes you made. Have a good day.")
data[str(ctx.guild.id)]["Warns"] = warns
data[str(ctx.guild.id)]["Superwarns"] = superwarns
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Forgive case administered", description= f"<@{user.id}> was forgived by <@{ctx.author.id}>.")
embed.set_footer(text=f"Forgive command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
elif str(user.id) in warns:
warns.pop(str(user.id))
await ctx.send(f"{user.name}, you have been forgiven for your good deeds from the sins of your pasts. You live as a free man now. Just remember: Try not to repeat the mistakes you made. Have a good day.")
data[str(ctx.guild.id)]["Warns"] = warns
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Forgive case administered", description= f"<@{user.id}> was forgived by <@{ctx.author.id}>.")
embed.set_footer(text=f"Forgive command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
elif str(user.id) in superwarns:
superwarns.pop(str(user.id))
await ctx.send(f"{user.name}, you have been forgiven for your good deeds from the sins of your pasts. You live as a free man now. Just remember: Try not to repeat the mistakes you made. Have a good day.")
data[str(ctx.guild.id)]["Superwarns"]
self.bot.col.find_one_and_update({"_id": "warns"}, {"$set":data})
config = self.bot.col.find_one({"_id": "server_configs"})
try:
commandlog = self.bot.get_channel(config[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Forgive case administered", description= f"<@{user.id}> was forgived by <@{ctx.author.id}>.")
embed.set_footer(text=f"Forgive command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
else:
await ctx.send("We can't find any warns for our good boi. I don't think they've sinned before, mind checking your records?")
@forgive.error
async def forgiveError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You can't forgive when you don't have the power to. So don't try to act smart, it's scummy. And sus.")
#A command to add spam channels.
@commands.hybrid_command(description = "Adds spam channels where spamming is allowed.")
@commands.has_permissions(administrator = True)
async def addspam(self, ctx, channel : discord.TextChannel):
spam_channels = []
data = dict(self.bot.col.find_one({"_id": "server_configs"}))
spam_channels = data[str(ctx.guild.id)]["Spam Ignore"]
if channel.id in spam_channels:
await ctx.send("This channel already exists in our spam list.")
else:
data[str(ctx.guild.id)]["Spam Ignore"].append(channel.id)
self.bot.col.find_one_and_update({"_id": "server_configs"}, {"$set":data})
await ctx.send(f"Spam channel has been added to our list. We shall not ping the moderators on spams in {channel.name} from now on.")
@addspam.error
async def addspamError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not decide which channels I do not detect spam in! Begone thot!")
#Aaaaaand another command to remove them
@commands.hybrid_command(description = "Removes a channel from spam channels where spamming is allowed.")
@commands.has_permissions(administrator = True)
async def rmspam(self, ctx, channel : discord.TextChannel):
spam_channels = []
data = dict(self.bot.col.find_one({"_id": "server_configs"}))
spam_channels = data[str(ctx.guild.id)]["Spam Ignore"]
if channel.id in spam_channels:
data[str(ctx.guild.id)]["Spam Ignore"].remove(channel.id)
self.bot.col.find_one_and_update({"_id": "server_configs"}, {"$set":data})
await ctx.send("Spam channel removed!!!")
else:
await ctx.send("The channel isn't in the list of channels where spamming is allowed. Look again, maybe?")
@rmspam.error
async def rmspamError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not decide which channels I detect spam in! Begone thot!")
#Flips the spam on or off
@commands.hybrid_command(description = "Toggles the spam to on or off on your server. Gotta keep spammers at bay!")
@commands.has_permissions(administrator = True)
async def togglespam(self, ctx):
data = dict(self.bot.col.find_one({"_id": "server_configs"}))
data[str(ctx.guild.id)]["Spam"] = not(data[str(ctx.guild.id)]["Spam"])
truth = data[str(ctx.guild.id)]["Spam"]
self.bot.col.find_one_and_update({"_id": "server_configs"}, {"$set":data})
await ctx.send(f"Spam detection has been set to {truth} on your server.")
@togglespam.error
async def tserror(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have the authorisation to decide to toggle the spam for this server! Next time, consult your superiors.")
#Sets the Moderator role to be pinged when Spam occurs on your server
@commands.hybrid_command(description = "Sets the role to be mentioned when spam is detected on your server to start the spicy drama.")
@commands.has_permissions(administrator = True)
async def setmod(self, ctx, role : discord.Role):
data = dict(self.bot.col.find_one({"_id": "role_configs"}))
data[str(ctx.guild.id)]["Moderator"] = role.id
self.bot.col.find_one_and_update({"_id": "role_configs"}, {"$set":data})
await ctx.send(f"Moderator role is now set to {role.mention}. This role will now be pinged when spam is detected.")
@setmod.error
async def sMerror(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("Begone mortal! You cannot set the moderator role for this server! Have an admin try to use the command!")
@commands.hybrid_command(description = "Sets the Member role which is to logged to members when they join and removed when they are muted.")
@commands.has_permissions(kick_members = True)
async def setmember(self, ctx, role : discord.Role):
data = {}
data = dict(self.bot.col.find_one({"_id": "role_configs"}))
data[str(ctx.guild.id)]["Member"] = role.id
self.bot.col.find_one_and_update({"_id": "role_configs"}, {"$set":data})
await ctx.send(f"The Member role is now set to {role.mention}. This role will now be given to members when they join the server and will be taken away when muted.")
@setmember.error
async def sMembError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You cannot set the member role when your own role in the server is negligible. Begone!")
@commands.hybrid_command(description = "Sets the mute role to be given to members whence they are muted.")
@commands.has_permissions(kick_members = True)
async def setmute(self, ctx, role : discord.Role):
data = {}
data = dict(self.bot.col.find_one({"_id": "role_configs"}))
data[str(ctx.guild.id)]["Mute"] = role.id
self.bot.col.find_one_and_update({"_id": "role_configs"}, {"$set":data})
await ctx.send(f"The Muted role is now set to {role.mention}. This role will now be given to members when they are muted in replacement of the general Member role.")
@setmute.error
async def setMuteError(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You cannot set the muted role when your own role in the server is negligible. Begone!")
#Flips the spam on or off
@commands.hybrid_command(description = "Toggles the autorole to on or off on your server. Autorole automatically assigns member role.")
@commands.has_permissions(administrator = True)
async def toggleautorole(self, ctx):
data = dict(self.bot.col.find_one({"_id": "server_configs"}))
data[str(ctx.guild.id)]["Autorole"] = not(data[str(ctx.guild.id)]["Autorole"])
truth = data[str(ctx.guild.id)]["Spam"]
self.bot.col.find_one_and_update({"_id": "server_configs"}, {"$set":data})
await ctx.send(f"Autoroles has been set to {truth} on your server.")
@toggleautorole.error
async def tarerror(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You are not authorised to decide who gets what role. Begone!")
#A display command to display the Warnings and Superwarnings in the server
@commands.hybrid_command(
description = "A command which enables you to view the warns and superwarns of the members in your server.",
aliases = ["viewwarns", "warns"]
)
async def displaywarns(self, ctx):
data = self.bot.col.find_one({"_id": "warns"})
Warns = data[str(ctx.guild.id)]
if Warns["Warns"].__len__() == 0 and Warns["Superwarns"].__len__() == 0:
await ctx.send("No data to show, nobody has warns or superwarns in your server!")
else:
totalPages = 2
currentPage = 1
message = await ctx.send(embed= Update(currentPage, Warns, totalPages), view = self.helpView(currentPage, Warns, totalPages))
#Now a command to add to the moderation of certain special words
@commands.hybrid_command(
description = "Adds new keywords to moderate. You don't want those dum dums to spoil the kids after all, do you?",
)
async def addword(self, ctx, *, word):
dic = self.bot.col.find_one({"_id": "server_configs"})
if "Words" not in dic[str(ctx.guild.id)]:
words = [word]
await ctx.send("The word has now been registered!!! We shall now ping the moderators whenever said word or phrase is detected in chat. ")
dic[str(ctx.guild.id)]["Words"] = words
else:
words = dic[str(ctx.guild.id)]["Words"]
if word in words:
await ctx.send("The word/phrase already exists in our record!")
else:
words.append(word)
await ctx.send("The word has now been registered!!! We shall now ping the moderators whenever said word or phrase is detected in chat. ")
dic[str(ctx.guild.id)]["Words"] = words
self.bot.col.find_one_and_update({"_id": "server_configs"}, {"$set":dic})
try:
commandlog = self.bot.get_channel(dic[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Word Remove case administered", description= f"<@{ctx.author.id}> has added ||{word}|| to moderated words!!")
embed.set_footer(text=f"Remove Word command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
#And now a command to remove said words.
@commands.hybrid_command(
description = "Adds new keywords to moderate. You don't want those dum dums to spoil the kids after all, do you?",
)
async def rmword(self, ctx, *, word):
dic = self.bot.col.find_one({"_id": "server_configs"})
if "Words" not in dic[str(ctx.guild.id)]:
await ctx.send("Word not found in our record. Mind checking it again?")
else:
words = dic[str(ctx.guild.id)]["Words"]
if word in words:
words.remove(word)
await ctx.send("The word/phrase has been removed from the record!")
dic[str(ctx.guild.id)]["Words"] = words
else:
await ctx.send("Word not found in our record. Mind checking it again?")
self.bot.col.find_one_and_update({"_id": "server_configs"}, {"$set":dic})
try:
commandlog = self.bot.get_channel(dic[str(ctx.guild.id)]["Command Log"])
embed = discord.Embed(title= "Word Remove case administered", description= f"<@{ctx.author.id}> has added ||{word}|| to moderated words!!")
embed.set_footer(text=f"Remove Word command recorded in {ctx.channel.name}")
await commandlog.send(embed = embed)
except:
pass
async def setup(bot):
await bot.add_cog(Moderation(bot))