-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
894 lines (802 loc) · 39.6 KB
/
bot.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
from datetime import datetime
from discord.ext import commands
from dotenv import dotenv_values
import asyncio
import auxfunctions as aux
import math
import discord
import sqlite3
import random
import time
config = dotenv_values('.env')
#healthbot = sqlite3.connect(config['SQLITE_DB_FILE'])
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='!', intents=intents)
bot.remove_command('help') #removing the default help command
mod_support = (int(config['MOD_SUPPORT_MESSAGE_ID']),int(config['MOD_SUPPORT_CHANNEL_ID']))
merch_support = (int(config['MERCH_SUPPORT_MESSAGE_ID']),int(config['MERCH_SUPPORT_CHANNEL_ID']))
roles_support = (int(config['ROLES_SUPPORT_MESSAGE_ID']),int(config['ROLES_SUPPORT_CHANNEL_ID']))
open_tickets = {}
closed_tickets = {}
open_tickets_id = set()
closed_tickets_id = set()
@bot.event
async def on_ready():
print('HEALTHbot is online')
@bot.command()
async def ping(ctx):
await ctx.message.reply("Pong!")
#HELP COMMAND
@bot.command()
async def help(ctx, *arg):
arg = ' '.join(arg)
if arg == "help" or not(arg):
helpstr = "Use ``!help [command]`` for more info on a command.\n\n**__List of commands:__\n!help** shows the list of commands and info about them.\n**!ping** not sure what this does even."
helpstr += "\n\n\n__User commands:__\n**!timeout** [amount of time]"
helpstr += "\n\n\n__Mod commands:__\n**!kick** [mention user] [optional reason]\n**!ban** [mention user] [optional reason]\n**!warn** [mention user] [optional reason]\n**!mute** [mention user] [optional reason]\n**!unmute** [mention user] [optional reason]\n**!unban (not recommended)** [mention user] [optional reason]"
helpstr += "\n\n**!purge** [no. of messages]\n**!purgeuser (unstable for now)** [mention user] [no. of messages]\n**!spam** [no. of messages]\n**!motd** [mention user]\n\n**!createtrigger (inactive)** [name] [content]\n**!deletetrigger (inactive)** [name]"
embed=discord.Embed(title="Help",description=helpstr,color=0xff0000)
elif arg == "kick":
embed=discord.Embed(title="!kick",description= "kicks member from HEALTHcord and stores information - including the reason for the kick - in the <#733746271684263936>. They might rejoin the server whenever they want.")
elif arg == "ban":
embed=discord.Embed(title="!ban",description= "bans member from HEALTHcord and stores information - including the reason for the ban - in the <#733746271684263936>.")
else:
await ctx.author.send(arg + " is not a valid command.")
return
await ctx.author.send(embed=embed)
if ctx.author.dm_channel != ctx.channel:
await ctx.send(ctx.author.mention + ", I've sent you a DM with the help menu.")
def checkdb(t):
mycursor = healthbot.cursor()
mycursor.execute("SELECT name,content,embed FROM `Trigger`")
myresult = mycursor.fetchall()
possible = []
trigger = False
flag = False
for x,y,z in myresult:
print(x + " " + t)
if x == t:
if z == 0:
possible.append(y)
else:
possible.append(y)
flag = True
if possible:
trigger = random.choice(possible)
return trigger,flag
def convertembed(t):
return
## MOD COMMANDS ##
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def warn(ctx, *, arg):
reason, member = aux.getvars(bot, ctx, arg)
if not(member):
await ctx.send(member.mention + " is not a member of HEALTHcord.")
return
embed,message = aux.modactions(ctx, reason, member, "warned")
if embed:
await ctx.send(embed=embed)
embed2,modlog = aux.modlogembed(bot,"warn", reason, ctx, 0xfffcbb, member)
await modlog.send(embed= embed2)
try:
await member.send(message)
except:
print(member.mention + " doesn't allow DMs. It's likely a bot.")
else:
await ctx.send("You cannot warn this user.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def ban(ctx, *, arg):
reason, member = aux.getvars(bot, ctx, arg)
if not(member):
await ctx.send(member.mention + " is not a member of HEALTHcord.")
return
embed,message = aux.modactions(ctx, reason, member, "banned")
if embed:
if reason =="":
await ctx.guild.ban(member,reason="", delete_message_days=0)
else:
await ctx.guild.ban(member,reason=reason + "", delete_message_days=0)
await ctx.send(embed=embed)
embed2,modlog = aux.modlogembed(bot,"ban", reason, ctx, 0xff0000, member)
await modlog.send(embed = embed2)
try:
await member.send(message)
except:
print(member.mention + " doesn't allow DMs. It's likely a bot.")
else:
await ctx.send("You cannot ban this user.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def unban(ctx, *, arg):
reason, member = aux.getvars(bot, ctx, arg)
if not(member):
await ctx.send("I cannot find this user. Please unban " + member.mention + " manually.")
return
embed,message = aux.modactions(ctx, reason, member, "unbanned")
if embed:
if reason == "":
await ctx.guild.unban(member,reason="")
else:
await ctx.guild.unban(member,reason=reason + "")
await ctx.send(embed=embed)
embed2,modlog = aux.modlogembed(bot,"unban", reason, ctx, 0x149414, member)
await modlog.send(embed = embed2)
try:
await member.send(message)
except:
print(member.mention + " doesn't allow DMs. It's likely a bot.")
else:
await ctx.send("You cannot ban this user.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def kick(ctx, *, arg):
reason, member = aux.getvars(bot, ctx, arg)
if not(member):
await ctx.send(member.mention + " is not a member of HEALTHcord.")
return
embed,message = aux.modactions(ctx, reason, member, "kicked")
if embed:
await member.kick()
await ctx.send(embed=embed)
embed2,modlog = aux.modlogembed(bot,"kick", reason, ctx, 0xffa500, member)
await modlog.send(embed = embed2)
try:
await member.send(message)
except:
print(member.mention + " doesn't allow DMs. It's likely a bot.")
else:
await ctx.send("You cannot kick this user.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def mute(ctx, *, arg):
reason, member = aux.getvars(bot, ctx, arg)
if not(member):
await ctx.send(member.mention + " is not a member of HEALTHcord.")
return
seconds = ""
x = 0
for x in range(len(reason)):
seconds += reason[x]
if not(reason[x].isnumeric()):
break
suffix = seconds[:-1]
if suffix:
reason = reason[x+2:]
secondsint = int(seconds[:-1])
timestr, secondsint = aux.timestrbuilder(seconds,secondsint,suffix)
embed,message = aux.modactions(ctx, reason, member, "muted for " + timestr)
else:
embed,message = aux.modactions(ctx, reason, member, "muted")
muted = ctx.guild.get_role(int(config['MUTED_ROLE_ID']))
if embed:
await member.add_roles(muted,reason="Muted", atomic=True)
await ctx.send(embed=embed)
embed2,modlog = aux.modlogembed(bot,"mute", reason, ctx, 0xfffcbb, member)
await modlog.send(embed = embed2)
try:
await member.send(message)
except:
print(member.mention + " doesn't allow DMs. It's likely a bot.")
if timestr:
await asyncio.sleep(secondsint)
await member.remove_roles(muted, reason="Unmuted", atomic=True)
embed2,modlog = aux.modlogembed(bot,"unmute", "Timed unmute", ctx, 0x149414, member)
await modlog.send(embed = embed2)
else:
await ctx.send("You cannot mute this user.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def unmute(ctx, *, arg):
reason, member = aux.getvars(bot, ctx, arg)
if not(member):
await ctx.send(member.mention + " is not a member of HEALTHcord.")
return
embed,message = aux.modactions(ctx, reason, member, "unmuted")
muted = ctx.guild.get_role(int(config['MUTED_ROLE_ID']))
if embed:
await member.remove_roles(muted, reason="Unmuted", atomic=True)
await ctx.send(embed=embed)
embed2,modlog = aux.modlogembed(bot,"unmute", reason, ctx, 0x149414, member)
await modlog.send(embed = embed2)
try:
await member.send(message)
except:
print(member.mention + " doesn't allow DMs. It's likely a bot.")
else:
await ctx.send("You cannot unmute this user.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def spam(ctx, *, arg):
await ctx.send("spam")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def purge(ctx, *, arg):
await ctx.message.delete()
deleted = await ctx.channel.purge(limit= int(arg))
deletedstr = ""
users = []
visited = []
for message in deleted:
if message.author not in visited:
users.append((message.author,1))
visited.append(message.author)
else:
i = visited.index(message.author)
users[i] = (message.author,users[i][1] + 1)
users.sort(reverse=True, key=lambda x:x[1])
for x in users:
deletedstr += "**" + x[0].name + "#" + x[0].discriminator + ":** " + str(x[1]) + "\n"
modlog = bot.get_channel(int(config['MOD_LOG_ID']))
embed = discord.Embed(title=" ", description="Messages deleted:\n\n" + deletedstr, color=0xff0000)
embed.set_author(name= str(len(deleted)) + " messages purged | #" + ctx.channel.name)
await modlog.send(embed= embed)
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def backup(ctx):
now = str(datetime.now())
now = now.split(' ')[0]
templates = await ctx.guild.templates()
if templates:
template = templates[0]
await template.sync()
else:
await ctx.guild.create_template(name= "back up " + now)
templates = await ctx.guild.templates()
template = templates[0]
backup_guild = await template.create_guild(name= "back up " + now)
await template.delete()
channel = await backup_guild.create_text_channel(name= "invite-link-channel")
invite = await channel.create_invite(max_uses=1)
await ctx.send("Backup server created.\n" + invite.url)
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def ticketmessage(ctx, *, arg):
global mod_support
global merch_support
global roles_support
channel_id = ""
for x in range(len(arg)):
if arg[x].isnumeric():
channel_id += arg[x]
if arg[x] == ">" or arg[x] == " ":
break
channel_id = int(channel_id)
ticket_type = arg[x+2:]
channel = ctx.guild.get_channel(channel_id)
await channel.purge()
embed = discord.Embed(description="To create a ticket react with 📩", color=0xff0000)
if ticket_type == "mod":
embed.set_author(name="Raise an issue with the mod team")
message = await channel.send(embed= embed)
mod_support = (message.id, channel_id)
await message.add_reaction("📩")
elif ticket_type == "merch":
embed.set_author(name="Got a problem with a merch order? Here's your place to raise a ticket.")
message = await channel.send(embed= embed)
await message.add_reaction("📩")
merch_support = (message.id, channel_id)
elif ticket_type == "roles":
embed.set_author(name="Missing a role?")
message = await channel.send(embed= embed)
await message.add_reaction("📩")
roles_support = (message.id, channel_id)
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def deletebackup(ctx):
await ctx.guild.delete()
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def motd(ctx, *, arg): # setting someone as the member of the day
motd = ctx.guild.get_role(int(config['MOTD_ROLE_ID']))
reason, member = aux.getvars(bot, ctx, arg)
emojis = [697621015337107466,737315507509657661,697879872391086113,697880868743544903,753291933950017627,753291934008606762,804113756622684220,709794793051390153]
emoji = bot.get_emoji(random.choice(emojis))
await member.add_roles(motd,reason="Member of the day", atomic=True)
message = await ctx.send(member.mention + " is member of the day!")
await message.add_reaction(emoji)
await asyncio.sleep(86400)
await member.remove_roles(motd,reason="End of the member of the day", atomic=True)
@bot.command()
async def roledump(ctx, *, arg):
role_id, role_name = False, False
try:
role_id = int(arg)
except:
role_name = arg
if role_id:
role = ctx.guild.get_role(role_id)
if not(role):
await ctx.reply("Invalid role ID provided.")
return
else:
role = discord.utils.get(ctx.guild.roles, name=role_name)
if not(role):
await ctx.reply("Invalid role name provided.")
return
memberlist = ""
embed = discord.Embed(title="ROLE DUMP",description=role.name)
i = 1
j = 0
for member in ctx.guild.members:
if i == 40:
j += 1
embed.add_field(name="Part " + str(j), value=memberlist, inline=False)
memberlist = ""
i = 1
if role in member.roles:
i += 1
memberlist += member.name + "#" + member.discriminator + "\n"
if memberlist:
j += 1
embed.add_field(name="Part " + str(j), value=memberlist, inline=False)
await ctx.send(embed= embed)
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def createtrigger(ctx, *, arg):
'''sql = "INSERT INTO `Trigger` (name, content,embed) VALUES (%s, %s, 0)"
val = (arg1, arg2)
mycursor = healthbot.cursor()
mycursor.execute(sql, val)
healthbot.commit()
await ctx.send("Trigger created successfully.")'''
left = False
for x in range(len(arg)):
if arg[x] == " ":
left = arg[:x]
right = arg[x+1:]
break
if not(left):
await ctx.send("Invalid trigger.")
@bot.command()
@commands.has_any_role("THE VIBEGUARD", "ADMIN")
async def deletetrigger(ctx, *, arg):
'''mycursor = healthbot.cursor()
sql = "DELETE FROM `Trigger` WHERE name = '" + arg + "'"
mycursor.execute(sql)
healthbot.commit()
await ctx.send("Trigger deleted successfully.")'''
@bot.command()
async def timeout(ctx, *, arg):
seconds = arg
suffix = seconds[:-1]
secondsint = int(seconds[:-1])
muted = ctx.guild.get_role(int(config['MUTED_ROLE_ID']))
timestr,secondsint = aux.timestrbuilder(seconds,secondsint,suffix)
embed=discord.Embed(title=" ", color=0xff0000)
embed.set_author(name="Enjoy your timeout. (" + timestr + ")")
await ctx.author.add_roles(muted,reason="Self-requested timeout", atomic=True)
await ctx.send(embed=embed)
await asyncio.sleep(secondsint)
await ctx.author.remove_roles(muted, reason="Timout ended", atomic=True)
await ctx.author.send("Your timeout in HEALTHcord has ended.")
club_channels = [config['MOVIE_CLUB_ID'],config['BOOK_CLUB_ID'],config['ANIME_CLUB_ID'],config['MUSIC_CLUB_ID'],config['ART_CLUB_ID'],config['GAMING_CLUB_ID'],config['FOOD_CLUB_ID'], config['HEALTH_BOYZ_ID']]
@bot.command()
@commands.has_any_role("CLUB LEADER", "THE VIBEGUARD", "ADMIN", "WARBOSS")
async def pin(ctx):
if str(ctx.channel.id) in club_channels:
if not(ctx.message.reference):
await ctx.reply("Reply to the message you want to pin.")
else:
message_to_pin = await ctx.channel.fetch_message(ctx.message.reference.message_id)
await message_to_pin.pin(reason="Pinned by " + ctx.author.name)
await ctx.message.delete()
elif aux.checkmod(ctx):
if not(ctx.message.reference):
await ctx.reply("Reply to the message you want to pin.")
else:
message_to_pin = await ctx.channel.fetch_message(ctx.message.reference.message_id)
await message_to_pin.pin(reason="Pinned by " + ctx.author.name)
await ctx.message.delete()
@bot.command()
@commands.has_any_role("CLUB LEADER", "THE VIBEGUARD", "ADMIN", "WARBOSS")
async def unpin(ctx):
if str(ctx.channel.id) in club_channels:
if not(ctx.message.reference):
await ctx.reply("Reply to the message you want to pin.")
else:
message_to_unpin = await ctx.channel.fetch_message(ctx.message.reference.message_id)
pinned_messages = await ctx.channel.pins()
for message in pinned_messages:
if message.id == message_to_unpin.id:
await message.unpin(reason="Unpinned by " + ctx.author.name)
await ctx.message.delete()
break
elif aux.checkmod(ctx):
if not(ctx.message.reference):
await ctx.reply("Reply to the message you want to pin.")
else:
message_to_unpin = await ctx.channel.fetch_message(ctx.message.reference.message_id)
pinned_messages = await ctx.channel.pins()
for message in pinned_messages:
if message.id == message_to_unpin.id:
await message.unpin(reason="Unpinned by " + ctx.author.name)
await ctx.message.delete()
break
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith("!"): #recognising a command
#trigger,e = checkdb(message.content[1:])
#if trigger:
# if e:
# embed = convertembed(trigger)
# await message.channel.send(embed=embed)
# else:
# await message.channel.send(trigger)
# return
if message.content.startswith("!<:dovide:734404973466484816>"):
message.content = "!timeout" + message.content[29:]
try:
await bot.process_commands(message)
except:
print(message.content + " is an invalid command.")
return
if not(aux.checkmod(message)):
if str(message.channel.id) == config['ART_CLUB_ID']:
flag = True
for role in message.author.roles:
if role.name == "CLUB LEADER":
flag = False
break
if flag and message.content and not(message.attachments) and not(aux.check_url(message.content)):
await message.delete()
elif str(message.channel.id) in [config['WHOLESOME_MEMES_ID'], config['ART_SHARE_ID']]:
if message.content and not(message.attachments) and not(aux.check_url(message.content)):
await message.delete()
if message.content.lower() in ["musik make love to " + bot.user.mention,"musik make love to health bot","musik make love to health :: bot"]:
await asyncio.sleep(1)
o = ["Oh no... not me.","Why would anyone want this","What is wrong with you?","No no no no no no"]
await message.channel.send(random.choice(o))
if message.channel.id != 707011962898481254: #we dont want this on #on-the-real certainly
emojialbum = aux.album(message.content,message.mentions) #finding if there is a mention to a HEALTH album in a message and reacting with the album cover
if emojialbum:
for x in emojialbum:
emoji = bot.get_emoji(x)
await message.add_reaction(emoji)
## MISC EVENTS ##
@bot.event
async def on_message_edit(before,after):
if before.channel.id in [733412404351991846,791453462063742987]: # curated channels, it prevents the channel to be spammed with cacostar counter updates
return
if before.content != after.content:
userstr = before.author.name + "#" + before.author.discriminator
if before.author.avatar:
avatarurl = "https://cdn.discordapp.com/avatars/" + str(before.author.id) + "/" + before.author.avatar + ".webp"
else:
avatarurl = "https://cdn.discordapp.com/avatars/774402228084670515/5ef539d5f3e8d576c4854768727bc75a.png"
embed=discord.Embed(title="Message edited in #" + before.channel.name, description= "**Before:** " + before.content + "\n**After:** " + after.content,color=0x45b6fe)
embed.set_author(name=userstr, icon_url=avatarurl)
await bot.get_channel(int(config['BIG_BROTHER_ID'])).send(embed= embed)
if after.channel.id == int(config['WHOLESOME_MEMES_ID']) or after.channel.id ==int (config['ART_SHARE_ID']):
if after.content and not(after.attachments) and not(aux.check_url(after.content)):
await after.delete()
@bot.event
async def on_message_delete(message):
if message.author.id in [372175794895585280,225522547154747392]: #its the haikubot and stock bot's ID, its useless showing when these are deleted
return
userstr = message.author.name + "#" + message.author.discriminator
if message.author.avatar:
avatarurl = "https://cdn.discordapp.com/avatars/" + str(message.author.id) + "/" + message.author.avatar + ".webp"
else:
avatarurl = "https://cdn.discordapp.com/avatars/774402228084670515/5ef539d5f3e8d576c4854768727bc75a.png"
if message.content:
description = message.content
else:
description = "*[This message only contained attachements.]*"
embed=discord.Embed(title="Message deleted in #" + message.channel.name, description= description,color=0xff0000)
embed.set_author(name=userstr, icon_url=avatarurl)
await bot.get_channel(int(config['BIG_BROTHER_ID'])).send(embed= embed)
@bot.event
async def on_member_ban(guild,user):
logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.ban).flatten()
logs = logs[0]
if not(logs.reason):
logs.reason = "No reason specified."
if logs.user.id != bot.user.id:
modlog = bot.get_channel(int(config['MOD_LOG_ID']))
embed=discord.Embed(title= "manual ban", description= "**Offender:** " + user.mention + "\n**Reason:** " + logs.reason + "\n**Responsible moderator: **" + logs.user.mention,color= 0xff0000)
@bot.event
async def on_member_unban(guild, user):
logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.ban).flatten()
logs = logs[0]
if not(logs.reason):
logs.reason = "No reason specified."
if logs.user.id != bot.user.id:
modlog = bot.get_channel(int(config['MOD_LOG_ID']))
embed = discord.Embed(title= "manual unban", description= "**Offender:** " + user.mention + "\n**Responsible moderator: **" + logs.user.mention, color= 0xff0000)
await modlog.send(embed= embed)
invitemessage = {}
@bot.event
async def on_invite_create(invite):
global invitemessage
modlog = bot.get_channel(int(config['MOD_LOG_ID']))
user = invite.inviter
userstr = user.name + "#" + user.discriminator
if invite.max_uses:
maxuses = " out of " + str(invite.max_uses)
else:
maxuses = ""
if user.avatar:
avatarurl = "https://cdn.discordapp.com/avatars/" + str(user.id) + "/" + user.avatar + ".webp"
embed = discord.Embed(title= "Created by " + userstr, description= "**Link:** " + invite.url + "\n**Channel: **" + invite.channel.mention + "\n**Uses:** " + str(invite.uses) + maxuses, color= 0xfffcbb)
embed.set_author(name="New invite", icon_url= avatarurl)
else:
embed = discord.Embed(title= "Created by " + userstr, description= "**Link:** " + invite.url + "\n**Channel: **" + invite.channel.mention + "\n**Uses:** " + str(invite.uses) + maxuses + "\n```glsl\n# User has a default profile picture.\n```", color= 0xfffcbb)
embed.set_author(name="New invite")
embed.set_footer(text="React to this message with ❌ to delete this invite.")
message = await modlog.send(embed= embed)
await message.add_reaction("❌")
invitemessage[message] = invite
async def support_check(ids, reaction, user):
if reaction.message.id == ids[0]:
await reaction.remove(user)
return reaction.emoji == "📩"
async def create_ticket_channel(init_message,name,user):
global open_tickets
global open_tickets_id
merch_support_role = user.guild.get_role(int(config['MERCH_SUPPORT_ID']))
mod_role = user.guild.get_role(int(config['MOD_ROLE_ID']))
overwrites = {user.guild.default_role: discord.PermissionOverwrite(read_messages=False), user: discord.PermissionOverwrite(read_messages=True), mod_role:discord.PermissionOverwrite(read_messages=True)}
if name == "merch-ticket":
overwrites[merch_support_role] = discord.PermissionOverwrite(read_messages=True)
open_ticket_cat = user.guild.get_channel(int(config['OPEN_TICKET_CAT_ID']))
channel = await user.guild.create_text_channel(name + "-" + user.name, category= open_ticket_cat, overwrites= overwrites)
message = await channel.send(init_message)
await message.add_reaction("🔒")
open_tickets[message] = (user,name)
open_tickets_id.add(message.id)
curated_messages = set()
@bot.event
async def on_raw_reaction_add(payload):
if payload.user_id != bot.user.id:
# tickets
global mod_support
global merch_support
global roles_support
global open_tickets
global open_tickets_id
global closed_tickets
global closed_tickets_id
if payload.channel_id in [mod_support[1],merch_support[1],roles_support[1]] or payload.message_id in open_tickets_id or payload.message_id in closed_tickets_id:
# converting payload to usable variables
healthcord = bot.get_guild(payload.guild_id)
user = healthcord.get_member(payload.user_id)
channel = healthcord.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = None
for reaction_temp in message.reactions:
if str(reaction_temp.emoji) == str(payload.emoji):
reaction = reaction_temp
break
init_message = "Hello! " + user.mention
if await support_check(mod_support, reaction, user):
for ticket_message,ticket_info in open_tickets.items():
if ticket_info == (user,"general-ticket"):
await ticket_message.channel.send(user.mention + " hello! You still have this opened ticket. A mod can assist you on whatever else you might need.")
return
init_message += "\nWhat's the issue?\n\n``(React to this message with 🔒 to close this ticket.)``"
await create_ticket_channel(init_message,"general-ticket",user)
elif await support_check(merch_support, reaction, user):
for ticket_message,ticket_info in open_tickets.items():
if ticket_info == (user,"merch-ticket"):
await ticket_message.channel.send(user.mention + " hello! You still have this opened ticket. A mod can assist you on whatever else you might need.")
return
init_message += "\nDo you have an issue with a merch order?\n" + user.guild.get_role(int(config['MERCH_SUPPORT_ID'])).mention +" will get back to you shortly.\n\n``(React to this message with 🔒 to close this ticket.)``"
await create_ticket_channel(init_message,"merch-ticket",user)
elif await support_check(roles_support, reaction, user):
for ticket_message,ticket_info in open_tickets.items():
if ticket_info == (user,"roles-ticket"):
await ticket_message.channel.send(user.mention + " hello! You still have this opened ticket. A mod can assist you on whatever else you might need.")
return
init_message += "\nAre you missing some roles?\n\n``(React to this message with 🔒 to close this ticket.)``"
await create_ticket_channel(init_message,"roles-ticket",user)
if message in open_tickets and reaction.emoji == "🔒":
await reaction.remove(user)
closed_ticket_cat = user.guild.get_channel(int(config['CLOSED_TICKET_CAT_ID']))
await reaction.message.channel.move(category= closed_ticket_cat, end= True)
mod_role = user.guild.get_role(int(config['MOD_ROLE_ID']))
overwrites = {user.guild.default_role: discord.PermissionOverwrite(read_messages=False), open_tickets[message][0]: discord.PermissionOverwrite(read_messages=False), mod_role: discord.PermissionOverwrite(read_messages=True)}
if "merch" in reaction.message.channel.name:
overwrites[user.guild.get_role(int(config['MERCH_SUPPORT_ID']))] = discord.PermissionOverwrite(read_messages=True)
await reaction.message.channel.edit(overwrites= overwrites)
new_message = await reaction.message.channel.send("``React to this message with 🔓 to re-open this ticket.``")
await new_message.add_reaction("🔓")
closed_tickets[new_message] = open_tickets[message]
closed_tickets_id.add(new_message.id)
open_tickets.pop(message)
open_tickets_id.remove(message.id)
elif message in closed_tickets and reaction.emoji == "🔓":
await reaction.remove(user)
open_ticket_cat = user.guild.get_channel(int(config['OPEN_TICKET_CAT_ID']))
await reaction.message.channel.move(category= open_ticket_cat, end= True)
overwrites = {user.guild.default_role: discord.PermissionOverwrite(read_messages=False), closed_tickets[message][0]: discord.PermissionOverwrite(read_messages=True)}
if "merch" in reaction.message.channel.name:
overwrites[user.guild.get_role(int(config['MERCH_SUPPORT_ID']))] = discord.PermissionOverwrite(read_messages=True)
await reaction.message.channel.edit(overwrites= overwrites)
new_message = await reaction.message.channel.send("``React to this message with 🔒 to close this ticket.``")
await new_message.add_reaction("🔒")
open_tickets[new_message] = closed_tickets[message]
open_tickets_id.add(new_message.id)
closed_tickets.pop(message)
closed_tickets_id.remove(message.id)
# mod-log invites
if payload.channel_id == int(config['MOD_LOG_ID']):
global invitemessage
modlog = bot.get_channel(payload.channel_id)
message = await modlog.fetch_message(payload.message_id)
if message in invitemessage and payload.emoji == "❌":
invite = invitemessage[message]
if invite.max_uses:
maxuses = " out of " + str(invite.max_uses)
else:
maxuses = ""
embed = discord.Embed(title= " ", description= "**Invite deleted** \n**Channel: **" + invite.channel.mention + "\n**Uses:** " + str(invite.uses) + maxuses, color= 0xfffcbb)
embed.set_author(name="New invite (deleted)")
await invite.delete()
await message.edit(embed = embed)
# curation
global curated_messages
if payload.emoji != str(payload.emoji) and (payload.emoji.name == "cacostar" or payload.emoji.name == "russtar") and payload.message_id not in curated_messages:
healthcord = bot.get_guild(payload.guild_id)
channel = healthcord.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = None
for reaction_temp in message.reactions:
if str(reaction_temp.emoji) == str(payload.emoji):
reaction = reaction_temp
break
if reaction.count == 5:
curated_messages.add(payload.message_id)
serverid = str(message.guild.id)
channelid = str(message.channel.id)
messageid = str(message.id)
messageurl = "https://discord.com/channels/" + serverid + "/" + channelid + "/" + messageid
if reaction.message.author.avatar:
avatarurl = "https://cdn.discordapp.com/avatars/" + str(message.author.id) + "/" + message.author.avatar + ".webp"
else:
avatarurl = "https://cdn.discordapp.com/avatars/774402228084670515/5ef539d5f3e8d576c4854768727bc75a.png"
if message.embeds and message.author.id == 372175794895585280: # haiku bot ID
description = message.embeds[0].description.replace("\n\n","\n")
embed = discord.Embed(description= description, color=0xff0000)
embed.set_author(name= "Haiku by " + message.embeds[0].footer.text[2:])
else:
embed = discord.Embed(description= message.content, color=0xff0000)
embed.set_author(name= message.author.display_name, icon_url=avatarurl)
if message.attachments:
embed.set_image(url= message.attachments[0].url)
embed.add_field(name="#" + message.channel.name, value="[Jump to message!](" + messageurl + ")", inline=False)
if message.reference:
replied_message = await message.channel.fetch_message(message.reference.message_id) # getting the message it's being replied to
if replied_message.author.avatar:
replied_avatarurl = "https://cdn.discordapp.com/avatars/" + str(replied_message.author.id) + "/" + replied_message.author.avatar + ".webp"
else:
replied_avatarurl = "https://cdn.discordapp.com/avatars/774402228084670515/5ef539d5f3e8d576c4854768727bc75a.png"
embed.add_field(name="──────", value= "*This was a reply to:*")
embed.set_footer(text=replied_message.author.display_name + "\n" + replied_message.content, icon_url=replied_avatarurl)
else:
embed.set_footer(text= str(message.created_at)[:-10] + " UTC")
healthcurated = bot.get_channel(int(config['CURATION_CHANNEL_ID']))
await healthcurated.send(embed= embed)
@bot.event
async def on_member_join(member):
if member.avatar:
avatarurl = "https://cdn.discordapp.com/avatars/" + str(member.id) + "/" + member.avatar + ".webp"
else:
avatarurl = "https://cdn.discordapp.com/avatars/774402228084670515/5ef539d5f3e8d576c4854768727bc75a.png"
memberstr = member.name + "#" + member.discriminator
embed = discord.Embed(title=" ", description="User ID: " + str(member.id), color=0xff0000)
embed.set_author(name= memberstr + " has joined the server.", icon_url= avatarurl)
await bot.get_channel(int(config['NEW_USERS_ID'])).send(embed= embed)
@bot.event
async def on_member_remove(member):
now = datetime.now()
modlog = bot.get_channel(int(config['MOD_LOG_ID']))
memberstr = member.name + "#" + member.discriminator
timeonserver = now - member.joined_at
logs = await member.guild.audit_logs(limit=1, action=discord.AuditLogAction.kick).flatten()
logs = logs[0]
if not(logs.reason):
logs.reason = "No reason specified."
if logs.user.id != bot.user.id and logs.target.id == member.id:
embed=discord.Embed(title= "manual kick", description= "**Offender:** " + member.mention + "\n**Reason:** " + logs.reason + "\n**Responsible moderator: **" + logs.user.mention,color= 0xff0000)
await modlog.send(embed= embed)
timestr = " joined "
if timeonserver.days:
if timeonserver.days >= 365:
if timeonserver.days / 365 < 2:
timestrAux = "1 year, " + str(timeonserver.days % 365) + " days, "
timestr += timestrAux
else:
timestrAux = str(math.floor(timeonserver.days/365)) + " years, " + str(timeonserver.days % 365) + " days, "
timestr += timestrAux
else:
if timeonserver.days == 1:
timestr += "1 day, "
else:
timestrAux = str(timeonserver.days) + " days, "
timestr += timestrAux
if timeonserver.seconds:
if timeonserver.seconds / 60 >= 60:
if timeonserver.seconds / 3600 < 2:
rest = timeonserver.seconds % 3600
minutes = math.floor(rest / 60)
seconds = rest % 60
timestrAux = "1 hour, "
if minutes:
if minutes == 1:
timestrAux += "1 minute, "
else:
timestrAuxAux = str(minutes) + " minutes, "
timestrAux += timestrAuxAux
if seconds:
if seconds == 1:
timestrAux += "1 second, "
else:
timestrAuxAux = str(seconds) + " seconds"
timestrAux += timestrAuxAux
timestr += timestrAux
else:
rest = timeonserver.seconds % 3600
minutes = math.floor(rest / 60)
seconds = rest % 60
timestrAux = str(math.floor(timeonserver.seconds / 3600)) + " hours, "
if minutes:
if minutes == 1:
timestrAux += "1 minute, "
else:
timestrAuxAux = str(minutes) + " minutes, "
timestrAux += timestrAuxAux
if seconds:
if seconds == 1:
timestrAux += "1 second, "
else:
timestrAuxAux = str(seconds) + " seconds"
timestrAux += timestrAuxAux
timestr += timestrAux
else:
minutes = math.floor(timeonserver.seconds / 60)
seconds = timeonserver.seconds % 60
timestrAux = ""
if minutes:
if minutes == 1:
timestrAux += "1 minute, "
else:
timestrAuxAux = str(minutes) + " minutes, "
timestrAux += timestrAuxAux
if seconds:
if seconds == 1:
timestrAux += "1 second, "
else:
timestrAuxAux = str(seconds) + " seconds"
timestrAux += timestrAuxAux
timestr += timestrAux
if timestr[-2:] == ", ":
timestr = timestr[:-2] + " ago."
else:
timestr += " ago."
rolestr = ""
for role in member.roles[1:]:
rolestr += role.mention + ", "
if rolestr[-2:] == ", ":
rolestr = rolestr[:-2]
if member.avatar:
avatarurl = "https://cdn.discordapp.com/avatars/" + str(member.id) + "/" + member.avatar + ".webp"
else:
avatarurl = "https://cdn.discordapp.com/avatars/774402228084670515/5ef539d5f3e8d576c4854768727bc75a.png"
embed = discord.Embed(title = "Member left", description = member.mention + timestr + "\n**Roles:** " + rolestr, color=0xff0000)
embed.set_author(name=memberstr, icon_url=avatarurl)
await modlog.send(embed= embed)
@bot.event
async def on_member_update(before, after):
if after.id == 697891299080142919 and before.status != after.status:
embed = discord.Embed(color=0xff0000)
if after.status == discord.Status.online:
embed.set_author(name="A wild BEEJ appeared!")
await after.guild.get_channel(int(config['GENERAL_ID'])).send(embed= embed)
elif after.status == discord.Status.offline:
embed.set_author(name="BEEJ has fled.")
await after.guild.get_channel(int(config['GENERAL_ID'])).send(embed= embed)
bot.run(config['BOT_TOKEN'])