This repository was archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
1334 lines (1134 loc) · 66.3 KB
/
setup.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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import discord
import cogs.tools
from utils.dataIO import fileIO
from discord.ext import commands
from datetime import datetime
from cogs.tools import client_role_color, get_prefix, modlog_toggle_messages
class Setup(commands.Cog, name="setup"):
def __init__(self, client):
self.client = client
self.path = "data/write/setup.json"
self.db = fileIO(self.path, "load")
self.template = {"JOINLEAVE" : None,
"STARBOARD" : None,
"TRUST" : None,
"VIP" : None,
"AGREE" : {"CHANNEL" : None, "ROLE" : None},
"MODLOG" : {"CHANNEL" : None, "MESSAGES" : True},
"COLORS" : []}
self.coloremoji = ['💖', '💛', '💚', '💙', '💜']
@commands.guild_only()
@commands.command()
async def settings(self, ctx):
"""CATEG_ADM Shows the bot's settings for the current guild."""
guild = ctx.message.guild
guildstr = str(guild.id)
disabled = []
if not self.db[guildstr]["AGREE"]["CHANNEL"]:
disabled.append("agree")
if not self.db[guildstr]["MODLOG"]["CHANNEL"]:
disabled.append("modlog")
if not self.db[guildstr]["JOINLEAVE"]:
disabled.append("joinleave")
if not self.db[guildstr]["STARBOARD"]:
disabled.append("starboard")
if not self.db[guildstr]["TRUST"]:
disabled.append("trust")
if not self.db[guildstr]["VIP"]:
disabled.append("vip")
embed = discord.Embed(title="⚙️ Server Settings", description="Bot feature settings for this server:", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
if self.db[guildstr]["AGREE"]["CHANNEL"]:
channel = guild.get_channel(int(self.db[guildstr]["AGREE"]["CHANNEL"]))
embed.add_field(name="Agree channel:", value=channel.mention)
if self.db[guildstr]["MODLOG"]["CHANNEL"]:
channel = guild.get_channel(int(self.db[guildstr]["MODLOG"]["CHANNEL"]))
embed.add_field(name="Modlog channel:", value=channel.mention)
if self.db[guildstr]["JOINLEAVE"]:
channel = guild.get_channel(int(self.db[guildstr]["JOINLEAVE"]))
embed.add_field(name="Join / Leave message channel:", value=channel.mention)
if self.db[guildstr]["STARBOARD"]:
channel = guild.get_channel(int(self.db[guildstr]["STARBOARD"]))
embed.add_field(name="Starboard channel:", value=channel.mention)
if self.db[guildstr]["TRUST"]:
role = guild.get_role(int(self.db[guildstr]["TRUST"]))
embed.add_field(name="Trusted user role:", value=role.name)
if self.db[guildstr]["VIP"]:
role = guild.get_role(int(self.db[guildstr]["VIP"]))
embed.add_field(name="VIP user role:", value=role.name)
if len(disabled) > 0:
embed.add_field(name="Disabled features:", value=", ".join(disabled), inline=False)
await ctx.send(embed=embed)
@commands.guild_only()
@commands.group()
async def setup(self, ctx):
"""CATEG_ADM Sets up commands that require specific channels or roles. Valid subcommands are: `agree` `joinleave` `modlog` `starboard` `colorroles` `trust` `vip` `reset`"""
self.pre = get_prefix(self, ctx)
if ctx.message.author.guild_permissions.manage_guild == False:
embed=discord.Embed(title="🔴 Error", description="You do not have the required permissions for this command.", color=0xdd2e44, timestamp=datetime.utcnow())
await ctx.send(embed=embed)
return
if ctx.invoked_subcommand == None:
embed=discord.Embed(title="🔴 Error", description="You didn't provide a valid subcommand.\nAvailable options are: `agree` `joinleave` `modlog` `starboard` `colorroles` `reset`.", color=0xdd2e44, timestamp=datetime.utcnow())
await ctx.send(embed=embed)
return
@setup.command()
@commands.has_permissions(manage_guild=True)
async def agree(self, ctx, channel: discord.TextChannel = None):
"""CATEG_SUB """
author = ctx.message.author
rechannel = ctx.message.channel
guild = ctx.message.guild
guildstr = str(guild.id)
perm_member = discord.Permissions()
perm_member.update(create_instant_invite=True,
add_reactions=True, read_messages=True,
send_messages=True, embed_links=True,
attach_files=True, read_message_history=True,
external_emojis=True, connect=True, speak=True,
use_voice_activation=True, change_nickname=True)
def check(m):
return m.channel == rechannel and m.author == author
if guild.me.guild_permissions.manage_channels == False:
await ctx.send("I require the `manage channels` permissions to do this.")
return
if guild.me.guild_permissions.manage_roles == False:
await ctx.send("I require the `manage roles` permissions to do this.")
return
if channel == None:
embed=discord.Embed(title=":warning: {}".format(self.client.user.name), description="You didn't give me a channel, would you like me to create a new one?", color=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url,text="Reply with yes to continue.")
await ctx.send(embed=embed)
msg = await self.client.wait_for('message', check=check)
if msg.content == "yes" or msg.content == "y":
await guild.create_text_channel(name="agree")
channel = discord.utils.get(guild.text_channels, name="agree")
else:
embed = discord.Embed(title="⚙️ Setup", description="Cancelling...", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if guildstr not in self.db:
self.db[guildstr] = self.template
self.db[guildstr]["AGREE"]["CHANNEL"] = str(channel.id)
memberrole = discord.utils.get(guild.roles, name="Member")
if memberrole == None:
guild.create_role(name="Member", permissions=perm_member)
memberrole = discord.utils.get(guild.roles, name="Member")
self.db[guildstr]["AGREE"]["ROLE"] = str(memberrole.id)
memberlist = guild.members
memberlist.remove(guild.me)
for x in memberlist:
if memberrole not in x.roles:
await x.add_roles(memberrole)
await guild.default_role.edit(permissions=discord.Permissions.none())
await channel.set_permissions(target=memberrole, read_messages=False)
await channel.set_permissions(target=guild.default_role, read_messages=True, send_messages=True, read_message_history=True)
welcome = discord.Embed(title="🔵 {}".format(self.client.user.name), description="Welcome to {}! If you agree with our rules, type ``{}agree`` to unlock the rest of the server.".format(guild.name, self.pre), colour=client_role_color(self, ctx), timestamp=datetime.utcnow())
welcome.set_thumbnail(url=ctx.message.guild.icon_url)
await channel.send(embed=welcome)
embed=discord.Embed(title=":warning: {}".format(self.client.user.name), description="What is your rules channel?", color=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url,text="Mention a channel to continue.")
await ctx.send(embed=embed)
msg = await self.client.wait_for('message', check=check)
if msg.content == "cancel" or msg.content == "no" or msg.content == "n":
await ctx.send("Cancelling...")
await guild.default_role.edit(permissions=discord.Permissions(permissions=104193089))
while len(msg.channel_mentions) != 1:
await ctx.send("Please mention a channel.")
msg = await self.client.wait_for('message', check=check)
if len(msg.channel_mentions) == 1:
for TextChannel in msg.channel_mentions:
await TextChannel.set_permissions(target=guild.default_role, send_messages=False, read_messages=True, read_message_history=True, add_reactions=False)
await TextChannel.set_permissions(target=memberrole, send_messages=False, read_messages=True, read_message_history=True, add_reactions=False)
fileIO(self.path, "save", self.db)
embed = discord.Embed(title="⚙️ Setup", description="`{}agree` setup complete".format(self.pre), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
@commands.command(name="agree")
@commands.guild_only()
async def _agree(self, ctx):
"""CATEG_NONE"""
guild = ctx.message.guild
author = ctx.message.author
guildstr = str(guild.id)
channelstr = str(ctx.message.channel.id)
if guildstr not in self.db:
return
if self.db[guildstr]["AGREE"]["CHANNEL"] == channelstr:
memberrole = discord.utils.get(guild.roles, name="Member")
if self.db[guildstr]["AGREE"]["ROLE"] == str(memberrole.id):
await author.add_roles(memberrole)
await ctx.message.delete()
@setup.command()
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def joinleave(self, ctx, channel: discord.TextChannel = None):
"""CATEG_SUB """
guildstr = str(ctx.message.guild.id)
if channel == None:
embed=discord.Embed(title=":warning: {}".format(self.client.user.name), description="You didn't give me a channel, would you like me set up here?", color=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url,text="Reply with yes to continue.")
await ctx.send(embed=embed)
def check(m):
return m.channel == ctx.channel and m.author == ctx.message.author
msg = await self.client.wait_for('message', check=check)
if msg.content == "yes" or msg.content == "y":
channel = ctx.channel
else:
embed = discord.Embed(title="⚙️ Setup", description="Cancelling...", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if guildstr not in self.db:
self.db[guildstr] = self.template
self.db[guildstr]["JOINLEAVE"] = str(channel.id)
fileIO(self.path, "save", self.db)
embed = discord.Embed(title="⚙️ Setup", description="Set join / leave message channel.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
@setup.command()
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def starboard(self, ctx, channel: discord.TextChannel = None):
"""CATEG_SUB """
guild = ctx.message.guild
guildstr = str(guild.id)
if channel == None:
embed=discord.Embed(title=":warning: {}".format(self.client.user.name), description="You didn't give me a channel, would you like me to make a new one?", color=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url,text="Reply with yes to continue.")
await ctx.send(embed=embed)
def check(m):
return m.channel == ctx.channel and m.author == ctx.message.author
msg = await self.client.wait_for('message', check=check)
if msg.content == "yes" or msg.content == "y":
await guild.create_text_channel(name="starboard")
channel = discord.utils.get(guild.text_channels, name="starboard")
else:
embed = discord.Embed(title="⚙️ Setup", description="Cancelling...", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
memberrole = discord.utils.get(guild.roles, name="Member")
if memberrole is not None:
await channel.set_permissions(target=memberrole, send_messages=False, read_messages=True, read_message_history=True, add_reactions=False)
await channel.set_permissions(target=guild.default_role, send_messages=False, read_messages=True, read_message_history=True, add_reactions=False)
if guildstr not in self.db:
self.db[guildstr] = self.template
self.db[guildstr]["STARBOARD"] = str(channel.id)
fileIO(self.path, "save", self.db)
embed = discord.Embed(title="⚙️ Setup", description="Set starboard channel.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
#
# COMMANDS BELOW ARE TAKEN STRAIGHT FROM YEETBOT WITH MINOR CHANGES
# SOME THINGS MIGHT NOT BE FULLY FUNCTIONAL
#
@setup.group()
@commands.has_permissions(manage_guild=True)
async def modlog(self, ctx):
"""CATEG_SUB """
if ctx.invoked_subcommand == None:
embed=discord.Embed(title="🔴 Error", description="You didn't provide a valid subcommand.\nAvailable options are: `channel` `messages` `disable`.", color=0xdd2e44)
return await ctx.send(embed=embed)
@modlog.command()
@commands.has_permissions(manage_guild=True)
async def disable(self, ctx):
"""CATEG_SUB """
guild = ctx.message.guild
if not str(guild.id) in self.db:
embed=discord.Embed(title="🔴 Error", description="This server already has modlogs disabled.", color=0xdd2e44)
await ctx.send(embed=embed)
return
elif str(guild.id) in self.db:
self.db[str(guild.id)]["MODLOG"]["CHANNEL"] = None
self.db[str(guild.id)]["MODLOG"]["MESSAGES"] = None
fileIO(self.path, "save", self.db)
embed=discord.Embed(title="🔵 {}".format(self.client.user.name), description="I will no longer send modlog notifications to this server.", color=client_role_color(self, ctx))
await ctx.send(embed=embed)
@modlog.command()
@commands.has_permissions(manage_guild=True)
async def channel(self, ctx, channel: discord.TextChannel = None):
"""CATEG_SUB """
guild = ctx.message.guild
channel = ctx.message.channel
author = ctx.message.author
if channel == None:
embed=discord.Embed(title="🔵 {}".format(self.client.user.name), description="Where would you like me to send my modlogs?", color=client_role_color(self, ctx))
embed.set_footer(text="Mention a channel to continue.")
await ctx.send(embed=embed)
def check(m):
return m.channel == channel and m.author == author
msg = await self.client.wait_for('message', check=check)
if msg.channel_mentions:
if len(msg.channel_mentions) > 1:
await ctx.send("You cannot provide more than one channel, try again.")
msg = await self.client.wait_for('message', check=check)
if not msg.channel_mentions or len(msg.channel_mentions) > 1:
await ctx.send("You failed a second time. Closing setup...")
return
if len(msg.channel_mentions) == 1:
for TextChannel in msg.channel_mentions:
chn = discord.utils.get(guild.text_channels, name=TextChannel.name)
if guild.me.permissions_in(chn).send_messages and guild.me.permissions_in(chn).embed_links:
if str(guild.id) in self.db:
self.db[str(guild.id)]["MODLOG"]["CHANNEL"] = str(chn.id)
fileIO(self.path, "save", self.db)
embed=discord.Embed(title="🔵 {}".format(self.client.user.name), description="Channel changed to {}.".format(chn.mention), color=client_role_color(self, ctx))
await ctx.send(embed=embed)
elif str(guild.id) not in self.db or self.db[str(guild.id)]["MODLOG"] == None:
self.db[str(guild.id)] = self.template
self.db[str(guild.id)]["MODLOG"]["CHANNEL"] = str(chn.id)
self.db[str(guild.id)]["MODLOG"]["MESSAGES"] = str(chn.id)
fileIO(self.path, "save", self.db)
embed=discord.Embed(title="🔵 {}".format(self.client.user.name), description="I will now send modlog notifications in {}.".format(chn.mention), color=client_role_color(self, ctx))
await ctx.send(embed=embed)
else:
await ctx.send("No channel provided, cancelling...")
else:
if len(ctx.message.channel_mentions) == 1:
for TextChannel in ctx.message.channel_mentions:
chn = discord.utils.get(guild.text_channels, name=TextChannel.name)
if guild.me.permissions_in(chn).send_messages and guild.me.permissions_in(chn).embed_links:
if str(guild.id) in self.db:
self.db[str(guild.id)]["MODLOG"]["CHANNEL"] = str(chn.id)
fileIO(self.path, "save", self.db)
embed=discord.Embed(title="🔵 {}".format(self.client.user.name), description="Channel changed to {}.".format(chn.mention), color=client_role_color(self, ctx))
await ctx.send(embed=embed)
elif str(guild.id) not in self.db:
self.db[str(guild.id)] = self.template
self.db[str(guild.id)]["MODLOG"]["CHANNEL"] = str(chn.id)
fileIO(self.path, "save", self.db)
embed=discord.Embed(title="🔵 {}".format(self.client.user.name), description="I will now send modlog notifications in {}.".format(chn.mention), color=client_role_color(self, ctx))
await ctx.send(embed=embed)
@modlog.command()
@commands.has_permissions(manage_guild=True)
async def messages(self, ctx):
"""CATEG_SUB """
msg = "deleted and edited message logging"
await modlog_toggle_messages(self, ctx, msg)
@setup.command()
@commands.has_permissions(manage_guild=True)
async def trust(self, ctx, role: discord.Role = None):
"""CATEG_SUB """
guild = ctx.guild
guildstr = str(guild.id)
if role == None:
embed = discord.Embed(title="⚙️ Setup", description="You didn't give me a role! Please try again.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if role not in ctx.guild.roles:
embed = discord.Embed(title="⚙️ Setup", description="I couldn't find that role.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if guildstr not in self.db:
self.db[guildstr] = self.template
self.db[guildstr]["TRUST"] = str(role.id)
fileIO(self.path, "save", self.db)
embed = discord.Embed(title="⚙️ Setup", description="Set `{}trust` role.".format(get_prefix(self, ctx)), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
@commands.command(name="trust", aliases=['verify'])
@commands.guild_only()
async def _trust(self, ctx, user: discord.Member = None):
"""CATEG_MOD """
guildstr = str(ctx.guild.id)
if user == None:
embed = discord.Embed(title=":white_check_mark: Trust", description="You need to provide a user.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if user == ctx.message.author:
embed = discord.Embed(title=":white_check_mark: Trust", description="You can't do that to yourself!", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if guildstr not in self.db:
embed = discord.Embed(title=":white_check_mark: Trust", description="This server didn't setup `trust`.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if self.db[guildstr]["TRUST"] == None:
embed = discord.Embed(title=":white_check_mark: Trust", description="This server didn't setup `trust`.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
role = discord.utils.get(ctx.guild.roles, id=int(self.db[guildstr]["TRUST"]))
if role == None:
embed = discord.Embed(title=":white_check_mark: Trust", description="There was a problem finding the trust role, if you're an admin please run `setup trust`.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
await user.add_roles(role)
embed = discord.Embed(title=":white_check_mark: Trust", description="{} is now verified!".format(user.mention), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
@setup.command()
@commands.has_permissions(manage_guild=True)
async def vip(self, ctx, role: discord.Role = None):
"""CATEG_SUB """
guild = ctx.guild
guildstr = str(guild.id)
if role == None:
embed = discord.Embed(title="⚙️ Setup", description="You didn't give me a role! Please try again.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if role not in ctx.guild.roles:
embed = discord.Embed(title="⚙️ Setup", description="I couldn't find that role.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if guildstr not in self.db:
self.db[guildstr] = self.template
self.db[guildstr]["VIP"] = str(role.id)
fileIO(self.path, "save", self.db)
embed = discord.Embed(title="⚙️ Setup", description="Set `{}vip` role.".format(get_prefix(self, ctx)), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
@commands.command(name="vip")
@commands.guild_only()
async def _vip(self, ctx, user: discord.Member = None):
"""CATEG_MOD """
guildstr = str(ctx.guild.id)
if user == None:
embed = discord.Embed(title=":white_check_mark: Trust", description="You need to provide a user.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if user == ctx.message.author:
embed = discord.Embed(title=":white_check_mark: Trust", description="You can't do that to yourself!", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if guildstr not in self.db:
embed = discord.Embed(title=":white_check_mark: Trust", description="This server didn't setup `vip`.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
if self.db[guildstr]["TRUST"] == None:
embed = discord.Embed(title=":white_check_mark: Trust", description="This server didn't setup `vip`.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
role = discord.utils.get(ctx.guild.roles, id=int(self.db[guildstr]["VIP"]))
if role == None:
embed = discord.Embed(title=":white_check_mark: Trust", description="There was a problem finding the VIP role, if you're an admin please run `setup trust`.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
await user.add_roles(role)
embed = discord.Embed(title=":white_check_mark: Trust", description="{} is now a VIP!".format(user.mention), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
@setup.command()
async def colorroles(self, ctx):
"""CATEG_SUB """
# :heart::yellow_heart::green_heart::blue_heart::purple_heart:
red = discord.utils.get(ctx.guild.roles, name="Red", color=discord.Color.red())
yellow = discord.utils.get(ctx.guild.roles, name="Yellow", color=discord.Color.gold())
green = discord.utils.get(ctx.guild.roles, name="Green", color=discord.Color.green())
blue = discord.utils.get(ctx.guild.roles, name="Blue", color=discord.Color.blue())
purple = discord.utils.get(ctx.guild.roles, name="Purple", color=discord.Color.purple())
if red == None:
await ctx.guild.create_role(name="Red", color=discord.Color.red())
if yellow == None:
await ctx.guild.create_role(name="Yellow", color=discord.Color.gold())
if green == None:
await ctx.guild.create_role(name="Green", color=discord.Color.green())
if blue == None:
await ctx.guild.create_role(name="Blue", color=discord.Color.blue())
if purple == None:
await ctx.guild.create_role(name="Purple", color=discord.Color.purple())
await ctx.send("Color roles created! Send `{}colorroles` in a channel to let members change their display color by reacting to a message. Also please remember to set up the role hierarchy in a way that makes the colors show up.".format(get_prefix(self, ctx)))
@commands.command(name="colorroles")
@commands.has_permissions(manage_messages=True)
async def _colorroles(self, ctx):
"""CATEG_MOD allows members who react to the sent message to get a chosen color-role"""
guildstr = str(ctx.guild.id)
red = discord.utils.get(ctx.guild.roles, name="Red", color=discord.Color.red())
yellow = discord.utils.get(ctx.guild.roles, name="Yellow", color=discord.Color.gold())
green = discord.utils.get(ctx.guild.roles, name="Green", color=discord.Color.green())
blue = discord.utils.get(ctx.guild.roles, name="Blue", color=discord.Color.blue())
purple = discord.utils.get(ctx.guild.roles, name="Purple", color=discord.Color.purple())
roles = []
roles.append(red)
roles.append(green)
roles.append(yellow)
roles.append(blue)
roles.append(purple)
for x in roles:
if x == None:
await ctx.send("This server hasn't set up color roles.")
break
embed = discord.Embed(title="Color roles (non-staff)", description="Add one of the following colored role to your current default role without affecting permissions.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
msg = await ctx.send(embed=embed)
for x in self.coloremoji:
await msg.add_reaction(x)
await ctx.message.delete()
if guildstr not in self.db:
self.db[guildstr] = self.template
self.db[guildstr]["COLORS"].append(str(msg.id))
fileIO(self.path, "save", self.db)
#################################################################################
#################################### EVENTS #####################################
#################################################################################
# starboard and colors
@commands.Cog.listener()
@commands.guild_only()
async def on_raw_reaction_add(self, payload):
reaction = payload
guild = self.client.get_guild(reaction.guild_id)
user_notguild = self.client.get_user(reaction.user_id)
user = guild.get_member(user_notguild.id)
channel = self.client.get_channel(reaction.channel_id)
message = await channel.fetch_message(reaction.message_id)
msgreacts = 0
for x in message.reactions:
if x.emoji == "⭐":
msgreacts = x.count
guildstr = str(guild.id)
if not str(guild.id) in self.db:
return
if msgreacts == 0:
return
if reaction.emoji.name == "⭐":
if self.db[str(guild.id)]["STARBOARD"] == None:
return
if user == guild.me:
return
if msgreacts < 2:
return
channelid = self.db[str(guild.id)]["STARBOARD"]
channelx = guild.get_channel(int(channelid))
embed = discord.Embed(title="New star! :star:", color=0xffcd4c)
embed.add_field(name="Author", value=str(message.author))
embed.add_field(name="Channel", value=message.channel.mention)
embed.add_field(name="Message", value="[Jump]({})".format(message.jump_url))
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
async for x in channelx.history(limit=200):
for y in x.embeds:
for z in y.fields:
if z.value == '[Jump]({})'.format(message.jump_url):
return
if message.content != '' and message.content != None:
content = message.content
embed.add_field(name="Content", value=content, inline=False)
if len(message.attachments) == 1:
for x in message.attachments:
if x.filename.endswith(".png") or x.filename.endswith(".gif") or x.filename.endswith(".jpg") or x.filename.endswith(".jpeg"):
embed.set_image(url=x.url)
await channelx.send(embed=embed)
pass
elif reaction.emoji.name in self.coloremoji: #['❤️', '💛', '💚', '💙', '💜']
if str(message.id) not in self.db[guildstr]["COLORS"]:
return
role = None
if reaction.emoji.name == '💖':
role = discord.utils.get(message.guild.roles, name="Red", color=discord.Color.red())
if reaction.emoji.name == '💛':
role = discord.utils.get(message.guild.roles, name="Yellow", color=discord.Color.gold())
if reaction.emoji.name == '💚':
role = discord.utils.get(message.guild.roles, name="Green", color=discord.Color.green())
if reaction.emoji.name == '💙':
role = discord.utils.get(message.guild.roles, name="Blue", color=discord.Color.blue())
if reaction.emoji.name == '💜':
role = discord.utils.get(message.guild.roles, name="Purple", color=discord.Color.purple())
if role != None:
if role not in user.roles:
await user.add_roles(role)
pass
@commands.Cog.listener()
@commands.guild_only()
async def on_raw_reaction_remove(self, payload):
reaction = payload
guild = self.client.get_guild(reaction.guild_id)
user_notguild = self.client.get_user(reaction.user_id)
user = guild.get_member(user_notguild.id)
channel = self.client.get_channel(reaction.channel_id)
message = await channel.fetch_message(reaction.message_id)
guildstr = str(guild.id)
if not str(guild.id) in self.db:
return
if reaction.emoji.name in self.coloremoji: #['❤️', '💛', '💚', '💙', '💜']
if str(message.id) not in self.db[guildstr]["COLORS"]:
return
role = None
if reaction.emoji.name == '💖':
role = discord.utils.get(message.guild.roles, name="Red", color=discord.Color.red())
if reaction.emoji.name == '💛':
role = discord.utils.get(message.guild.roles, name="Yellow", color=discord.Color.gold())
if reaction.emoji.name == '💚':
role = discord.utils.get(message.guild.roles, name="Green", color=discord.Color.green())
if reaction.emoji.name == '💙':
role = discord.utils.get(message.guild.roles, name="Blue", color=discord.Color.blue())
if reaction.emoji.name == '💜':
role = discord.utils.get(message.guild.roles, name="Purple", color=discord.Color.purple())
if role != None:
if role in user.roles:
await user.remove_roles(role)
pass
# message delete
@commands.Cog.listener()
@commands.guild_only()
async def on_message_delete(self, message):
guild = message.guild
if not str(guild.id) in self.db:
return
if self.db[str(guild.id)]["MODLOG"]["MESSAGES"] == False:
return
if message.author.bot == True:
return
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
name = str(message.author)
logmsg = ":warning: A message by {} was deleted in #{}".format(name, message.channel.name)
if message.content == '':
return
elif message.content != '':
before = message.content
elif len(message.attachments) > 0:
before = "The message contained only an attachment, but since that is now deleted I can't display it."
embed = discord.Embed(title=logmsg, description=before, colour=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
return
for i in message.mentions:
before = before.replace(i.mention, str(i))
embed = discord.Embed(title=logmsg, colour=0xffcd4c, timestamp=datetime.utcnow())
embed.add_field(name="Content:", value=before)
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
pass
# message edit
@commands.Cog.listener()
@commands.guild_only()
async def on_message_edit(self, before, after):
guild = before.guild
try:
if str(guild.id) not in self.db:
return
if self.db[str(guild.id)]["MODLOG"]["CHANNEL"] == None:
return
except AttributeError:
return
if self.db[str(guild.id)]["MODLOG"]["MESSAGES"] == False:
return
if before.content == after.content:
return
if before.author.bot == True:
return
if before.pinned != after.pinned:
return
for i in before.mentions:
before.content = before.content.replace(i.mention, str(i))
for i in after.mentions:
after.content = after.content.replace(i.mention, str(i))
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
name = str(before.author)
logmsg = ":warning: A message by {} was edited in {}".format(name, before.channel.name)
embed = discord.Embed(title=logmsg, colour=0xffcd4c, timestamp=datetime.utcnow())
embed.add_field(name="Before edit:", value=before.content, inline=False)
embed.add_field(name="After edit:", value=after.content, inline=False)
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
pass
@commands.Cog.listener()
@commands.guild_only()
async def on_member_join(self, member):
guild = member.guild
guildstr = str(guild.id)
name = str(member)
if str(guild.id) not in self.db:
return
if self.db[str(guild.id)]["MODLOG"]["CHANNEL"] == None:
return
if self.db[guildstr]["JOINLEAVE"] != None:
strwelcome = self.db[str(guild.id)]["JOINLEAVE"]
welcome = guild.get_channel(int(strwelcome))
logmsg = '**{}** has joined **{}**'.format(name, guild.name)
embed = discord.Embed(title=":wave: Member Joined", description=logmsg, color=discord.Color.green(), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await welcome.send(embed=embed)
if member != None:
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
logmsg = '{} has joined {}'.format(name, guild.name)
embed = discord.Embed(title=logmsg, color=discord.Color.green(), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
pass
@commands.Cog.listener()
@commands.guild_only()
async def on_member_remove(self, member):
guild = member.guild
guildstr = str(guild.id)
name = str(member)
if str(guild.id) not in self.db:
return
if self.db[str(guild.id)]["MODLOG"]["CHANNEL"] == None:
return
if self.db[guildstr]["JOINLEAVE"] != None:
strwelcome = self.db[str(guild.id)]["JOINLEAVE"]
welcome = guild.get_channel(int(strwelcome))
logmsg = '**{}** has left **{}**'.format(name, guild.name)
embed = discord.Embed(title=":wave: Member Left", description=logmsg, color=discord.Color.red(), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await welcome.send(embed=embed)
if member != None:
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
logmsg = '{} has left {}'.format(name, guild.name)
embed = discord.Embed(title=logmsg, color=discord.Color.green(), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
pass
@commands.Cog.listener()
@commands.guild_only()
async def on_member_ban(self, guild, user):
self.db = fileIO(self.path, 'load')
if not str(guild.id) in self.db:
return
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
name = str(user)
logmsg = '{} has been banned from the server'.format(name)
embed = discord.Embed(title=logmsg, color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
pass
@commands.Cog.listener()
@commands.guild_only()
async def on_member_unban(self, guild, user):
self.db = fileIO(self.path, 'load')
if not str(guild.id) in self.db:
return
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
name = str(user)
logmsg = '{} has been unbanned'.format(name)
embed = discord.Embed(title=logmsg, color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await channel.send(embed=embed)
pass
@commands.Cog.listener()
@commands.guild_only()
async def on_guild_update(self, before, after):
guild = before
if str(guild.id) not in self.db:
return
if self.db[str(guild.id)]["MODLOG"]["CHANNEL"] == None:
return
channelid = self.db[str(guild.id)]["MODLOG"]["CHANNEL"]
channel = guild.get_channel(int(channelid))
###################################################################
if guild.region == discord.VoiceRegion.amsterdam:
fancyregion = "🇳🇱 Amsterdam"
elif guild.region == discord.VoiceRegion.brazil:
fancyregion = "🇧🇷 Brazil"
elif guild.region == discord.VoiceRegion.eu_central:
fancyregion = "🇪🇺 Central Europe"
elif guild.region == discord.VoiceRegion.eu_west:
fancyregion = "🇪🇺 West Europe"
elif guild.region == discord.VoiceRegion.frankfurt:
fancyregion = "🇩🇪 Frankfurt"
elif guild.region == discord.VoiceRegion.hongkong:
fancyregion = "🇨🇳 Hong Kong"
elif guild.region == discord.VoiceRegion.japan:
fancyregion = "🇯🇵 Japan"
elif guild.region == discord.VoiceRegion.london:
fancyregion = "🇬🇧 London"
elif guild.region == discord.VoiceRegion.russia:
fancyregion = "🇷🇺 Russia"
elif guild.region == discord.VoiceRegion.singapore:
fancyregion = "🇸🇬 Singapore"
elif guild.region == discord.VoiceRegion.southafrica:
fancyregion = "🇿🇦 South Africa"
elif guild.region == discord.VoiceRegion.sydney:
fancyregion = "🇦🇺 Sydney"
elif guild.region == discord.VoiceRegion.us_central:
fancyregion = "🇺🇸 US Central"
elif guild.region == discord.VoiceRegion.us_east:
fancyregion = "🇺🇸 US East"
elif guild.region == discord.VoiceRegion.us_south:
fancyregion = "🇺🇸 US South"
elif guild.region == discord.VoiceRegion.us_west:
fancyregion = "🇺🇸 US West"
elif guild.region == discord.VoiceRegion.vip_amsterdam:
fancyregion = "🌟 VIP Amsterdam"
elif guild.region == discord.VoiceRegion.vip_us_east:
fancyregion = "🌟 VIP US East"
elif guild.region == discord.VoiceRegion.vip_us_west:
fancyregion = "🌟 VIP US West"
if after.region == discord.VoiceRegion.amsterdam:
fancyregion_a = "🇳🇱 Amsterdam"
elif after.region == discord.VoiceRegion.brazil:
fancyregion_a = "🇧🇷 Brazil"
elif after.region == discord.VoiceRegion.eu_central:
fancyregion_a = "🇪🇺 Central Europe"
elif after.region == discord.VoiceRegion.eu_west:
fancyregion_a = "🇪🇺 West Europe"
elif after.region == discord.VoiceRegion.frankfurt:
fancyregion_a = "🇩🇪 Frankfurt"
elif after.region == discord.VoiceRegion.hongkong:
fancyregion_a = "🇨🇳 Hong Kong"
elif after.region == discord.VoiceRegion.japan:
fancyregion_a = "🇯🇵 Japan"
elif after.region == discord.VoiceRegion.london:
fancyregion_a = "🇬🇧 London"
elif after.region == discord.VoiceRegion.russia:
fancyregion_a = "🇷🇺 Russia"
elif after.region == discord.VoiceRegion.singapore:
fancyregion_a = "🇸🇬 Singapore"
elif after.region == discord.VoiceRegion.southafrica:
fancyregion_a = "🇿🇦 South Africa"
elif after.region == discord.VoiceRegion.sydney:
fancyregion_a = "🇦🇺 Sydney"
elif after.region == discord.VoiceRegion.us_central:
fancyregion_a = "🇺🇸 US Central"
elif after.region == discord.VoiceRegion.us_east:
fancyregion_a = "🇺🇸 US East"
elif after.region == discord.VoiceRegion.us_south:
fancyregion_a = "🇺🇸 US South"
elif after.region == discord.VoiceRegion.us_west:
fancyregion_a = "🇺🇸 US West"
elif after.region == discord.VoiceRegion.vip_amsterdam:
fancyregion_a = "🌟 VIP Amsterdam"
elif after.region == discord.VoiceRegion.vip_us_east:
fancyregion_a = "🌟 VIP US East"
elif after.region == discord.VoiceRegion.vip_us_west:
fancyregion_a = "🌟 VIP US West"
if before.default_notifications == discord.NotificationLevel.all_messages:
notifbefore = "all messages"
if after.default_notifications == discord.NotificationLevel.all_messages:
notifafter = "all messages"
if before.default_notifications == discord.NotificationLevel.only_mentions:
notifbefore = "only mentions"
if after.default_notifications == discord.NotificationLevel.only_mentions:
notifafter = "only mentions"
if before.explicit_content_filter == discord.ContentFilter.disabled:
beforefilter = "disabled"
if before.explicit_content_filter == discord.ContentFilter.no_role:
beforefilter = "members without a role"
if before.explicit_content_filter == discord.ContentFilter.all_members:
beforefilter = "all members"
if after.explicit_content_filter == discord.ContentFilter.disabled:
afterfilter = "disabled"
if after.explicit_content_filter == discord.ContentFilter.no_role:
afterfilter = "members without a role"
if after.explicit_content_filter == discord.ContentFilter.all_members:
afterfilter = "all members"
if before.verification_level == discord.VerificationLevel.none:
beforeverif = "none"
if before.verification_level == discord.VerificationLevel.low:
beforeverif = "low"
if before.verification_level == discord.VerificationLevel.medium:
beforeverif = "medium"
if before.verification_level == discord.VerificationLevel.high:
beforeverif = "high"
if before.verification_level == discord.VerificationLevel.extreme:
beforeverif = "extreme"
if after.verification_level == discord.VerificationLevel.none:
afterverif = "none"
if after.verification_level == discord.VerificationLevel.low:
afterverif = "low"
if after.verification_level == discord.VerificationLevel.medium:
afterverif = "medium"
if after.verification_level == discord.VerificationLevel.high:
afterverif = "high"
if after.verification_level == discord.VerificationLevel.extreme:
afterverif = "extreme"
timeout_b = before.afk_timeout / 60
timeout_a = after.afk_timeout / 60
###################################################################
#guild.region
logmsg_region = "Server region has been changed from **{}** to **{}**.".format(fancyregion, fancyregion_a)
#guild.name
logmsg_name = "Server name has been changed from **{}** to **{}**.".format(before.name, after.name)
#guild.afk_channel
logmsg_afk = "Server AFK Channel has been changed from **{}** to **{}**.".format(str(before.afk_channel), str(after.afk_channel))
#guild.afk_timeout
logmsg_timeout = "Server AFK Timeout has been changed from **{}min** to **{}min**.".format(str(timeout_b), str(timeout_a))
#guild.default_notifications
logmsg_notif = "Server default notification setting has been changed from **{}** to **{}**.".format(notifbefore, notifafter)
#guild.verification_level
logmsg_veriflevel = "Server verification level has been changed from **{}** to **{}**.".format(beforeverif, afterverif)
#guild.explicit_content_filter
logmsg_filter = "Server explicit content filter setting has been changed from **{}** to **{}**.".format(beforefilter, afterfilter)
#guild.mfa_level
logmsg_mfa_true = "Server Two-Factor Authentication requirement has been **enabled**."
logmsg_mfa_false = "Server Two-Factor Authentication requirement has been **disabled**."
#guild.icon
logmsg_icon = "Server icon has been changed."
###################################################################
if before.region != after.region:
embed = discord.Embed(title="🔴 Server settings have been changed", description=logmsg_region, color=0xdd2e44, timestamp=datetime.utcnow())