-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
1825 lines (1609 loc) · 85.9 KB
/
main.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
# CastleMiner Discord bot, made by Zennara#8377
# This is a custom discord bot. It is written to work on only one server.
# imports
import discord
import os
import asyncio
import json
from datetime import datetime
import math
import requests
import random
from discord import Webhook
import aiohttp
import json
from discord.ext import tasks
# declare client
intents = discord.Intents.all()
client = discord.Client(intents=intents)
# json config data
f = open('config.json', encoding="utf-8") # open json file
config = json.load(f) # load file into dict
f.close() # close file
# server-specific ids
guild_id = str(config["guild_id"])
guild = client.get_guild(int(guild_id))
# print(data["566984586618470411434547908415586311"]["invites"])
# database functions
data = {}
# function to re-read data again from json database
def read_data():
f = open('database.json', encoding="utf-8") # open json
global data
data = json.load(f) # read data
f.close() # close
# function to write json data
def write_data(data):
# Serializing json
json_object = json.dumps(data, indent=2)
# Writing to sample.json
with open("database.json", "w", encoding="utf-8") as outfile:
outfile.write(json_object)
read_data()
def update_data():
global data
read_data()
write_data(data)
# delete database
CLEAR = False
if CLEAR:
count = 0
for key in data:
del data[key]
count += 1
print(count)
update_data()
# dump data in database.json
DUMP = False
if DUMP:
data2 = {}
count = 0
for key in data:
data2[str(key)] = data[str(key)]
count += 1
print(str(count))
with open("database.json", 'w') as f:
json.dump(str(data2), f)
DBFIX = True
if DBFIX:
# data["admin684524717167607837"] = {"server": "684524717167607837", "role": "684535492619927587"}
data["prefix"] = "cm/"
invites = {}
@client.event
async def on_invite_create(invite):
# write cache
invites[invite.guild.id] = await invite.guild.invites()
@client.event
async def on_invite_delete(invite):
# write cache
invites[invite.guild.id] = await invite.guild.invites()
# check invites and compare
# invites = {}
# last = ""
# async def getInvites():
# global last
# global invites
# global codeOwner
# global joinCode
# await client.wait_until_ready()
# gld = client.get_guild(int(guild_id))
# while True:
# invs = await gld.invites()
# tmp = []
# for i in invs:
# for s in invites:
# if s[0] == i.code:
# if int(i.uses) > s[1]:
# #get inviter id
# codeOwner = str(i.inviter.id)
# joinCode = str(i.code)
# tmp.append(tuple((i.code, i.uses)))
# invites = tmp
# await asyncio.sleep(1)
@tasks.loop(seconds = 10) # repeat after every 10 seconds
async def checkCounters():
while True:
# discord API limits rates to twice every 10m for channel edits
await asyncio.sleep(600)
# update channels
for guild in client.guilds:
# steam
header = {"Client-ID": "F07D7ED5C43A695B3EBB01C28B6A18E5"}
game_players_url = 'https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?format=json&appid='
# get amount of bots
bots = 0
for member in guild.members:
if member.bot:
bots += 1
for channel in guild.voice_channels:
if channel.name.startswith("Members"):
if (channel.name != "Members: " + str(guild.member_count - bots)):
await channel.edit(name="Members: " + str(guild.member_count - bots))
if channel.name.startswith("Bots"):
if (channel.name != "Bots: " + str(bots)):
await channel.edit(name="Bots: " + str(bots))
if channel.name.startswith("Channels"):
if (channel.name != "Channels: " + str(
len(guild.text_channels) + len(guild.voice_channels) - len(guild.categories))):
await channel.edit(name="Channels: " + str(
len(guild.text_channels) + len(guild.voice_channels) - len(guild.categories)))
if channel.name.startswith("Text Channels"):
if (channel.name != "Text Channels: " + str(len(guild.text_channels))):
await channel.edit(name="Text Channels: " + str(len(guild.text_channels)))
if channel.name.startswith("Voice Channels"):
if (channel.name != "Voice Channels: " + str(len(guild.voice_channels))):
await channel.edit(name="Voice Channels: " + str(len(guild.voice_channels)))
if channel.name.startswith("Categories"):
if (channel.name != "Categories: " + str(len(guild.categories))):
await channel.edit(name="Categories: " + str(len(guild.categories)))
if channel.name.startswith("Roles"):
if (channel.name != "Roles: " + str(len(guild.roles))):
await channel.edit(name="Roles: " + str(len(guild.roles)))
if channel.name.startswith("Bans"):
if (channel.name != "Bans: " + str(len(await guild.bans()))):
await channel.edit(name="Bans: " + str(len(await guild.bans())))
if channel.name.startswith("Messages"):
if (channel.name != "Messages: " + str(data['messages'])):
await channel.edit(name="Messages: " + str(data['messages']))
if channel.name.startswith("CMZ Players"):
game_players = requests.get(game_players_url + "253430", headers=header)
if (channel.name != "CMZ Players: " + str(game_players.json()['response']['player_count'])):
await channel.edit(name="CMZ Players: " + str(game_players.json()['response']['player_count']))
if channel.name.startswith("CMW Players"):
game_players = requests.get(game_players_url + "675210", headers=header)
if (channel.name != "CMW Players: " + str(game_players.json()['response']['player_count'])):
await channel.edit(name="CMW Players: " + str(game_players.json()['response']['player_count']))
# header = {"Client-ID": "F07D7ED5C43A695B3EBB01C28B6A18E5"}
# appIDs = ["253430", "675210", "414550"]
# game_players = [0,0,0]
# for i in range(0, 3):
# game_players_url = 'https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?format=json&appid=' + appIDs[i]
# game_players[i] = requests.get(game_players_url, headers=header)
# print("CMZ: " + str(game_players[0].json()['response']['player_count']))
# print("CMW: " + str(game_players[1].json()['response']['player_count']))
# print("Death Toll: " + str(game_players[2].json()['response']['player_count']))
def find_invite_by_code(invite_list, code):
# Simply looping through each invite in an
# invite list which we will get using guild.invites()
for inv in invite_list:
# Check if the invite code in this element
# of the list is the one we're looking for
if inv.code == code:
# If it is, we return it.
return inv
async def incorrectServer(message):
embed = discord.Embed(color=0x593695, description="Command not available in " + message.guild.name + ".")
embed.set_author(name="❌ | @" + client.user.name)
await message.channel.send(embed=embed)
async def incorrectRank(message):
embed = discord.Embed(color=0x593695, description="insufficient role in the server heirarchy.")
embed.set_author(name="❌ | @" + client.user.name)
await message.channel.send(embed=embed)
def checkRole(message, data):
if message.author.top_role >= message.guild.get_role(
int(data["admin" + str(message.guild.id)]['role'])) or message.author == message.guild.owner or str(
message.author.id) == "427968672980533269":
return True
else:
return False
@client.event
async def on_ready():
global bumped
bumped = False
print("\nZennInvites Ready\n")
await client.change_presence(
activity=discord.Streaming(name=" | " + data["prefix"] + "help", url="https://www.twitch.tv/xzennara/about"))
# Getting all the guilds our bot is in
for guild in client.guilds:
# Adding each guild's invites to our dict
invites[guild.id] = await guild.invites()
# gg = client.get_guild(566984586618470411)
# for ban in await gg.bans():
# if ban.user.name.lower().startswith("scatman"):
# print(f"{ban.user.id} | {ban.user.name}")
await checkCounters.start()
# channel and category IDs restricted for starboard
noStarboard = ["591135975355187200", "759976154479984650", "572774759331397632", "706953196425314820",
"738634279357251586", "812692775895957574"]
@client.event
async def on_raw_reaction_add(payload):
# STARBOARD
# check not restricted category
guild = client.get_guild(int(guild_id))
channel = guild.get_channel(payload.channel_id)
starchannel = guild.get_channel(812692775895957574)
if str(channel.category.id) not in noStarboard and str(channel.id) not in noStarboard:
# check for star
if payload.emoji.name == "⭐":
message = await channel.fetch_message(payload.message_id)
count = {react.emoji: react.count for react in message.reactions}
print(count)
# check star count
if count['⭐'] >= 6:
# check msg already in starchannel
done = False
async for msg in starchannel.history(limit=None):
if msg.content.startswith(message.jump_url):
done = True
if not done:
embed = discord.Embed(color=0xFFD700, description=message.content)
embed.set_author(name=message.author.name + "#" + message.author.discriminator,
icon_url=message.author.avatar.url)
# get all files
files = []
for ach in message.attachments:
files.append(await ach.to_file())
# get all non-link embeds
doEmbeds = True
for emb in message.embeds:
if str(emb.provider) != "EmbedProxy()":
doEmbeds = False
# define webhook
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(config["starboard_webhook_url"], session=session)
await webhook.send(username=message.author.display_name, avatar_url=message.author.avatar.url,
content=message.jump_url + "\n\n" + message.content, files=files)
# if all non-link embeds
if doEmbeds:
try:
await webhook.send(username=message.author.name, avatar_url=message.author.avatar.url,
embeds=message.embeds)
except:
pass
# make sure its not initial reaction
if payload.member != client.user:
# check if key exists in database
if "role" + str(payload.guild_id) + str(payload.channel_id) + str(payload.message_id) in data:
# check if it is correct reaction emoji
if str(payload.emoji.name) == str(
data["role" + str(payload.guild_id) + str(payload.channel_id) + str(payload.message_id)][
'reaction']):
# give role
role = payload.member.guild.get_role(int(
data["role" + str(payload.guild_id) + str(payload.channel_id) + str(payload.message_id)]['role']))
await payload.member.add_roles(role, atomic=True)
@client.event
async def on_raw_reaction_remove(payload):
if "role" + str(payload.guild_id) + str(payload.channel_id) + str(payload.message_id) in data:
# check if it is correct reaction emoji
if str(payload.emoji.name) == str(
data["role" + str(payload.guild_id) + str(payload.channel_id) + str(payload.message_id)]['reaction']):
# give role
role = client.get_guild(int(payload.guild_id)).get_role(
int(data["role" + str(payload.guild_id) + str(payload.channel_id) + str(payload.message_id)]['role']))
await client.get_guild(int(payload.guild_id)).get_member(int(payload.user_id)).remove_roles(role,
atomic=True)
@client.event
async def on_member_update(before, after):
# anti zalgo etc
percentbad = 0
characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 `+_-~=[]\\{}|;:\"\',<.>/?!@#$%^&*()"
if before.nick != after.nick:
for char in after.nick:
if char not in characters:
percentbad += 1
percentbad = (percentbad / len(after.nick)) * 100
if percentbad > 50:
await after.edit(nick=before.nick)
embed = discord.Embed(color=0x593695,
description="Can not change nickname. Contains more that 50 percent of non-allowed characters. Please only use the standard english keyboard.")
embed.set_author(name="❌ | @" + client.user.name)
await after.send(embed=embed)
@client.event
async def on_message(message):
global user
global bumped
# get prefix
prefix = data["prefix"]
# if str(message.guild.id) == guild_id:
# get messages and add
# data["messages"] += 1
# set message content to lowercase
messagecontent = message.content.lower().replace('<', '').replace('>', '').replace('!', '').replace('#',
'').replace('@',
'').replace(
'&', '')
# split current datetime
nowDT = str(datetime.now()).split()
nowDate = nowDT[0]
nowTime = str(datetime.strptime(str(nowDT[1][0: len(nowDT[1]) - 7]), "%H:%M:%S").strftime("%I:%M %p"))
if str(message.guild.id) == guild_id:
# put users in database
if str(message.author.id) not in data:
data[str(message.author.id)] = {'server': str(message.guild.id),
'name': str(message.author.name) + "#" + str(message.author.discriminator),
'invites': 0, 'leaves': 0, 'bumps': 0, 'joinCode': "null",
'inviter': "null"}
try:
if str(message.guild.get_member(message.mentions[0].id).id) not in data:
data[str(message.guild.get_member(message.mentions[0].id).id)] = {'server': str(message.guild.id),
'name': str(message.guild.get_member(
message.mentions[
0].id).name) + "#" + str(
message.guild.get_member(
message.mentions[
0].id).discriminator),
'invites': 0, 'leaves': 0, 'bumps': 0,
'joinCode': "null", 'inviter': "null"}
except:
pass
# grab for-digitaldna
if messagecontent == prefix + "grab memos":
if checkRole(message, data):
guild = client.get_guild(int(guild_id))
forddna = message.guild.get_channel(671495633051451397)
messageData = {}
# loop through messages in channel
async for m in forddna.history(limit=None):
# write content
messageData[str(m.author.id)] = {"name": str(m.author.name + "#" + m.author.discriminator),
"content": m.content,
"pfp": str(m.author.avatar.url)}
# load to json
obj = json.dumps(messageData, indent=4)
with open("For_DDNA_Responses.json", "w") as outfile:
outfile.write(obj)
# generate file
file = discord.File("For_DDNA_Responses.json")
# send message
await message.channel.send("**Below is the** `.json`** file of all the responses in** " + forddna.mention,
file=file)
else:
await incorrectRank(message)
# grab signatures
if messagecontent == prefix + "grab signatures":
if checkRole(message, data):
guild = client.get_guild(int(guild_id))
sigs = message.guild.get_channel(933608307170623498)
messageData = {}
# loop through messages in channel
async for m in sigs.history(limit=None):
# write content
if m.attachments: # check if there is attachment
messageData[str(m.author.id)] = {"name": m.author.name + "#" + m.author.discriminator,
"signature": str(m.attachments[0].url)}
else: # no attachments
messageData[str(m.author.id)] = {"name": m.author.name + "#" + m.author.discriminator,
"signature": m.content}
# load to json
obj = json.dumps(messageData, indent=4)
with open("Signatures.json", "w") as outfile:
outfile.write(obj)
# generate file
file = discord.File("Signatures.json")
# send message
await message.channel.send("**Below is the** `.json`** file of all the signatures in** " + sigs.mention,
file=file)
else:
await incorrectRank(message)
# fake ban
if messagecontent.startswith(prefix + "ban"):
if checkRole(message, data):
memberName = message.guild.get_member(int(messagecontent.split()[1])).mention
embed = discord.Embed(color=0x593695, description=memberName + "*** has been banned! F.***")
embed.set_author(name="✔️ | @" + client.user.name)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
else:
await incorrectRank(message)
# custom message
if messagecontent.startswith(prefix + "custom"):
if checkRole(message, data):
embed = discord.Embed(color=0x593695, description=str(messagecontent.split(maxsplit=1)[1]))
embed.set_author(name="✔️ | @" + client.user.name)
embed.set_footer(
text="Made by " + message.author.name + "#" + message.author.discriminator + "\n" + nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
await message.delete()
else:
await incorrectRank(message)
# giveaway
if messagecontent.startswith(prefix + "giveaway"):
if checkRole(message, data):
try:
channel = message.guild.get_channel(int(messagecontent.split()[1]))
event = await channel.fetch_message(int(messagecontent.split()[2]))
reaction = event.reactions[0]
users = await reaction.users().flatten()
# users is now a list of User...
winner = random.choice(users)
await message.channel.send(':cupcake: ***{}*** **has won the giveaway!**'.format(winner))
except:
embed = discord.Embed(color=0x593695, description="Invalid Syntax")
embed.set_author(name="❌ | @" + client.user.name)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
else:
await incorrectRank(message)
# cross
if messagecontent == prefix + "cross":
server = 0
count = 0
i = 0
players = [""]
# main server
if message.guild.id == 566984586618470411:
server = 684524717167607837
# modding
if message.guild.id == 684524717167607837:
server = 566984586618470411
embed = discord.Embed(color=0x593695, description="")
for member in message.guild.members:
if member not in client.get_guild(server).members:
if message.guild.id == 566984586618470411:
memberName = str(member.name) + "#" + str(member.discriminator)
else:
memberName = str(member.mention)
players[i] += "`" + str(count + 1) + " |` " + memberName + "\n";
count += 1
if count >= 50 * (i + 1):
players.append("")
embed.description = players[i]
embed.set_author(name="✔️ | @" + client.user.name)
await message.channel.send(embed=embed)
i += 1
embed.description = players[i]
embed.set_author(name="✔️ | @" + client.user.name)
await message.channel.send(embed=embed)
embed.description = "**" + str(count) + " members not in " + client.get_guild(
server).name + "**\n*Offline members may not tag correctly*"
embed.set_author(name="✔️ | @" + client.user.name)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
print(count)
# if len(players) == 1:
# embed.add_field(name="1", value=str(players[0]))
# setup server
if messagecontent == prefix + "setup":
if str(message.guild.id) == guild_id:
if message.author == message.guild.owner or str(message.author.id) == "427968672980533269":
if "admin" + str(message.guild.id) not in data:
# loading message
embed = discord.Embed(color=0x593695, description="**Loading Users Into Database...**")
embed.set_author(name="⌛ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
message2 = await message.channel.send(embed=embed)
# members
for member in message.guild.members:
# add member to database
if str(member.id) not in data:
data[str(member.id)] = {'server': str(message.guild.id),
'name': str(member.name) + "#" + str(member.discriminator),
'invites': 0, 'leaves': 0, 'bumps': 0, 'joinCode': "null",
'inviter': "null"}
await asyncio.sleep(0.1)
# invites
embed = discord.Embed(color=0x593695, description="**Loading Previous Invites**")
embed.set_author(name="⌛ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
for member in message.guild.members:
totalInvites = 0
for i in await message.guild.invites():
if i.inviter == member:
totalInvites += i.uses
tmp = data[str(member.id)];
del data[str(member.id)]
tmp['invites'] = totalInvites
data[str(member.id)] = tmp
update_data()
while True:
embed = discord.Embed(color=0x593695,
description="**Please enter the ID of your Disboard bumping channel.**\nEnter 0 to stop adding channels.")
embed.set_author(name="📝 | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
global done
global test
done = False
def check(m):
global done
global test
# check if user is done inputting channels
if m.content == "0":
done = True
passed = True
else:
# define check for disboard bumping channel
try:
test = message.guild.get_channel(int(m.content))
if test != None:
passed = True
else:
passed = False
except:
passed = False
return passed == True and m.channel == message.channel
# wait for user input
msg = await client.wait_for('message', check=check)
# check if user is done inputting channels
if done:
break
# disboard bumps
embed = discord.Embed(color=0x593695,
description="**Loading Previous Disboard Bumps**\nThis could take a while.")
embed.set_author(name="⌛ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
bumped = False
bumpedAuthor = ""
for messages in await test.history(limit=None, oldest_first=True).flatten():
# check if previous message was bump
if bumped == True:
# check if bump was from Disboard bot
if str(messages.author.id) == "302050872383242240": # disboard bot ID
# check if succesful bump (blue color)
if str(messages.embeds[0].colour) == "#24b7b7":
if str(bumpedAuthor.id) not in data:
data[str(bumpedAuthor.id)] = {'server': str(message.guild.id),
'name': str(bumpedAuthor.name) + "#" + str(
bumpedAuthor.discriminator), 'invites': 0,
'leaves': 0, 'bumps': 0, 'joinCode': "null",
'inviter': "null"}
tmp = data[str(bumpedAuthor.id)]
del data[str(bumpedAuthor.id)]
tmp['bumps'] += 1
data[str(bumpedAuthor.id)] = tmp
update_data()
bumped = False
# check if message was bump
if messages.content == "!d bump":
bumped = True
bumpedAuthor = messages.author
# code admin role
embed = discord.Embed(color=0x593695,
description="**Please enter the ID of the lowest role in the hierarchy able to do server-managing bot commands.**")
embed.set_author(name="📝 | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
def check(m):
# define check for role
try:
test = message.guild.get_role(int(m.content))
if test != None:
passed = True
else:
passed = False
except:
passed = False
return passed == True and m.channel == message.channel
msg = await client.wait_for('message', check=check)
# write to data
data["admin" + str(message.guild.id)] = {"server": str(message.guild.id), "role": str(msg.content)}
embed = discord.Embed(color=0x593695,
description="**" + str(message.guild.name) + " Setup Complete**")
embed.set_author(name="✔️ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
else:
embed = discord.Embed(color=0x593695, description="**Setup has already been completed.**")
embed.set_author(name="❌ | @" + client.user.name)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
else:
await incorrectRank(message)
else:
await incorrectServer(message)
# poll
if message.content.startswith(prefix + "poll"):
numemojis = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣"]
try:
msg = message.content.split("\"")
await message.delete()
count = 0
print(len(msg))
if len(msg) > 3:
options = ""
for i in range(len(msg)):
if i > 1 and i % 2 != 0:
options = options + "\n" + numemojis[count] + " " + msg[i]
count += 1
else:
options = ""
embed = discord.Embed(color=0x593695, description="**📊 | " + msg[1] + "**\n\n" + options)
embed.set_footer(text=nowDate + " at " + nowTime)
pollmsg = await message.channel.send(embed=embed)
if len(msg) < 4:
await pollmsg.add_reaction('👍')
await pollmsg.add_reaction('👎')
else:
for i in range(0, int((len(msg) - 3) / 2)):
await pollmsg.add_reaction(numemojis[i])
except:
embed = discord.Embed(color=0x593695,
description="**Invalid Poll Usage**\nRefer to syntax at cm/help polls")
embed.set_author(name="❌ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
# reports
if messagecontent == prefix + "report":
def check(m):
if (message.author.id == m.author.id and m.guild == None):
return True
else:
return False
async def reportmsg():
embed = discord.Embed(color=0x593695,
description="**Report started**\nUse cm/cancel in DM to cancel the report.")
embed.set_author(name="✅ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.author.send(embed=embed)
embed = discord.Embed(color=0x593695, description="**In-game name of attacker:**")
embed.set_author(name="📝 | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
message2 = await message.author.send(embed=embed)
inGameName = await client.wait_for('message', check=check)
if inGameName.content == "cm/cancel":
print("test123")
return
embed.description = "**Steam Name or Link:**\nType *NA* if unavailable."
await message2.edit(embed=embed)
steamName = await client.wait_for('message', check=check)
if steamName.content == "cm/cancel":
return
embed.description = "**Discord Name and Tag:**\nType *NA* if unavailable."
await message2.edit(embed=embed)
discordName = await client.wait_for('message', check=check)
if discordName.content == "cm/cancel":
return
embed.description = "**What game did the event take place?**"
await message2.edit(embed=embed)
game = await client.wait_for('message', check=check)
if game.content == "cm/cancel":
return
embed.description = "**Description of the event:**"
await message2.edit(embed=embed)
description = await client.wait_for('message', check=check)
if description.content == "cm/cancel":
return
embed.description = "**Were you using a mod?**\nIf so, which one?"
await message2.edit(embed=embed)
modName = await client.wait_for('message', check=check)
if modName.content == "cm/cancel":
return
embed = discord.Embed(color=0x593695, description="**Thank you for your report.**")
embed.set_author(name="✅ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
embed = discord.Embed(color=0x593695,
description="**IGN: **" + inGameName.content + "\n**Steam: **" + steamName.content + "\n**Discord: **" + discordName.content)
embed.add_field(name="Game", value=game.content)
embed.add_field(name="Mod", value=modName.content)
embed.add_field(name="Description", value=description.content, inline=False)
embed.set_author(name="✖ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(
text=nowDate + " at " + nowTime + "\nReport by: " + message.author.name + "#" + message.author.discriminator)
await message.author.send(embed=embed)
if "report" in data:
channel = message.guild.get_channel(int(data["report"]["channel"]))
await channel.send(embed=embed)
else:
embed = discord.Embed(color=0x593695,
description="**Failed to send report**\nContact an admin if you think this is a mistake.")
embed.set_author(name="❌ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
await reportmsg()
# create report channel
if messagecontent.startswith(prefix + "reportchannel"):
if checkRole(message, data):
try:
# get role
reportChannel = message.guild.get_channel(int(messagecontent.split()[1]))
# write to database
if "report" in data:
del data["report"]
data["report"] = {"server": str(message.guild.id), "channel": str(reportChannel.id)}
update_data()
# print embed
embed = discord.Embed(color=0x593695, description="Reports will now go to " + reportChannel.mention)
embed.set_author(name="✔️ | @" + client.user.name)
await message.channel.send(embed=embed)
except:
pass
else:
await incorrectRank(message)
# fetch invites
if messagecontent == prefix + "fetch invites":
if str(message.guild.id) == guild_id:
if checkRole(message, data):
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '✅'
embed = discord.Embed(color=0x593695,
description="**WARNING: Doing so may result in data loss. Continue?**\nReact with ✅ or wait 30s")
embed.set_author(name="❔ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
message2 = await message.channel.send(embed=embed)
await message2.add_reaction('✅')
try:
reaction, user = await client.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await message2.delete()
else:
# invites
embed = discord.Embed(color=0x593695, description="**Loading Previous Invites**")
embed.set_author(name="⌛ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
count = 0
for member in message.guild.members:
totalInvites = 0
if str(member.id) not in data:
data[str(member.id)] = {'server': str(message.guild.id),
'name': str(member.name) + "#" + str(member.discriminator),
'invites': 0, 'leaves': 0, 'bumps': 0, 'joinCode': "null",
'inviter': "null"}
count += 1
print("member passed | " + str(member.id) + " | " + str(count));
for i in await message.guild.invites():
if i.inviter == member:
totalInvites += i.uses
try:
tmp = data[str(member.id)]
del data[str(member.id)]
tmp['invites'] = totalInvites
data[str(member.id)] = tmp
update_data()
except:
embed = discord.Embed(color=0x593695, description="<@!" + str(member.id) + ">")
embed.set_author(name="❌ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message.channel.send(embed=embed)
embed = discord.Embed(color=0x593695, description="**Previous Invites Fetched**")
embed.set_author(name="✔️ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
else:
await incorrectRank(message)
else:
await incorrectServer(message)
# fetch disboard bumps
if messagecontent == prefix + "fetch bumps":
if str(message.guild.id) == guild_id:
tmp2 = {}
tmp2 = dict(data)
if checkRole(message, data):
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '✅'
embed = discord.Embed(color=0x593695,
description="**WARNING: Doing so may result in data loss. Continue?**\nReact with ✅ or wait 30s")
embed.set_author(name="❔ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
message2 = await message.channel.send(embed=embed)
await message2.add_reaction('✅')
try:
reaction, user = await client.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await message2.delete()
else:
embed = discord.Embed(color=0x593695, description="**Clearing Bumps...**")
embed.set_author(name="⌛ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
# clear bumps
for key in data:
try:
tmp = data[key]
del data[key]
tmp['bumps'] = 0
data[key] = tmp
update_data()
except:
pass
while True:
embed = discord.Embed(color=0x593695,
description="**Please enter the ID of your Disboard bumping channel.**\nEnter 0 to stop adding channels.")
embed.set_author(name="📝 | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
done = False
def check(m):
global done
global test
# check if user is done inputting channels
if m.content == "0":
done = True
passed = True
else:
# define check for disboard bumping channel
try:
test = message.guild.get_channel(int(m.content))
if test != None:
passed = True
else:
passed = False
except:
passed = False
return passed == True and m.channel == message.channel
# wait for user input
msg = await client.wait_for('message', check=check)
# check if user is done inputting channels
if done:
break
# disboard bumps
embed = discord.Embed(color=0x593695,
description="**Loading Previous Disboard Bumps**\nThis could take a while.")
embed.set_author(name="⌛ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
bumped = False
bumpedAuthor = ""
for messages in await test.history(limit=None, oldest_first=True).flatten():
# check if previous message was bump
if bumped == True:
# check if bump was from Disboard bot
if str(messages.author.id) == "302050872383242240": # disboard bot ID
# check if succesful bump (blue color)
if str(messages.embeds[0].colour) == "#24b7b7":
if str(bumpedAuthor.id) not in data:
data[str(bumpedAuthor.id)] = {'server': str(message.guild.id),
'name': str(bumpedAuthor.name) + "#" + str(
bumpedAuthor.discriminator), 'invites': 0,
'leaves': 0, 'bumps': 0, 'joinCode': "null",
'inviter': "null"}
tmp = data[str(bumpedAuthor.id)]
del data[str(bumpedAuthor.id)]
tmp['bumps'] += 1
data[str(bumpedAuthor.id)] = tmp
update_data()
bumped = False
# check if message was bump
if messages.content == "!d bump":
bumped = True
bumpedAuthor = messages.author
embed = discord.Embed(color=0x593695, description="**Previous Bumps Fetched**")
embed.set_author(name="✔️ | @" + client.user.name, icon_url=client.user.avatar.url)
embed.set_footer(text=nowDate + " at " + nowTime)
await message2.edit(embed=embed)
else:
await incorrectRank(message)
else:
await incorrectServer(message)
# add code admin
if messagecontent.startswith(prefix + "codeadmin"):
if checkRole(message, data):
try:
# get role
codeRole = message.guild.get_role(int(messagecontent.split()[1]))
# write to database
data["admin" + str(message.guild.id)] = {"server": str(message.guild.id), "role": str(codeRole.id)}
# print embed
embed = discord.Embed(color=0x593695,