-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
1820 lines (1560 loc) · 75.1 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
"""
____ _ _ ___ ____ ___ ____
| _ \ _ __ ___ (_) ___ ___| |_ |_ _| _ \|_ _/ ___|
| |_) | '__/ _ \| |/ _ \/ __| __| | || |_) || |\___ \
| __/| | | (_) | | __/ (__| |_ | || _ < | | ___) |
|_| |_| \___// |\___|\___|\__| |___|_| \_\___|____/
|__/
When I wrote this code,
only God and I knew how it worked.
Now, only God knows.
Last Edited: 04 February 2023
Version: v2.2.1
"""
IRIS_version = "2.2.1"
# Discord Modules
import discord
from discord import app_commands
from discord.ext import commands, tasks
# Utility Modules
import os
import sys
import time
import json
import shutil
import random
import asyncio
import traceback
from pathlib import Path
from itertools import cycle
from datetime import datetime
from io import StringIO, BytesIO
# Client Settings
intents = discord.Intents.all()
client = commands.AutoShardedBot(command_prefix=".", help_command=None, intents=intents)
path = os.path.dirname(__file__)
# Log Settings
user_join = True
deleted_message = True
edited_message = True
censored_message = True
voice_events = True
# Opening Config JSON file
with open("config.json") as configjson:
# Load the existing JSON data
configs = json.load(configjson)
# Accessing configs - channel ID
channel_id = configs.get("channel_id", {})
user_join = channel_id.get("user_join")
deleted_message = channel_id.get("deleted_message")
edited_message = channel_id.get("edited_message")
voice_events = channel_id.get("voice_events")
watched_message = channel_id.get("watched_message")
feedback_channel = channel_id.get("feedback_channel")
report_channel = channel_id.get("report_channel")
file_logger = channel_id.get("file_logger")
# Accessing configs - Log Settings
log_settings = configs.get("log_settings", {})
log_user_join = log_settings.get("user_join")
log_deleted_message = log_settings.get("deleted_message")
log_edited_message = log_settings.get("edited_message")
log_watched_message = log_settings.get("watched_message")
log_voice_events = log_settings.get("voice_events")
file_log_extensions = log_settings.get("file_log_extension", [])
# Watched Words
with open("watchedWords.txt") as watchWordsFile:
watchedWords = [line.rstrip() for line in watchWordsFile]
# Dictionaries & Lists
voice_timers = {}
space = " "
Watchlist = [0]
ownerID = [638342719592202251, 729854914812968991]
cooldowns = {}
# Utils
now = datetime.now()
login_time = now.strftime("%Z %d/%b/%Y %H:%M:%S")
logfile = Path("D:\\IRIS.log")
# Colour Code Functions
def prRed(skk): print("\033[91m {}\033[00m" .format(skk))
def prGreen(skk): print("\033[92m {}\033[00m" .format(skk))
def prYellow(skk): print("\033[93m {}\033[00m" .format(skk))
def prLightPurple(skk): print("\033[94m {}\033[00m" .format(skk))
def prPurple(skk): print("\033[95m {}\033[00m" .format(skk))
def prCyan(skk): print("\033[96m {}\033[00m" .format(skk))
def prLightGray(skk): print("\033[97m {}\033[00m" .format(skk))
def prBlack(skk): print("\033[98m {}\033[00m" .format(skk))
os.system('title ProjectIRIS Central Controller')
# Connect
@client.event
async def on_ready():
logfile = Path("D:\\IRIS.log")
if logfile.is_file():
logfile = open(r"D:\\IRIS.log", "a")
prYellow(f"[{login_time}] [INFO] Log file exists in file path.")
else:
logfile = open(r"D:\\IRIS.log", "a")
logfile.write(f"Project IRIS Console Log \nCreated on {login_time} \n<->=============================<->")
prYellow(f"[{login_time}] [INFO] Log file does not exist.")
prYellow(f"[{login_time}] [INFO] New log file created.")
for server in client.guilds:
await client.tree.sync(guild=discord.Object(id=server.id))
change_status.start()
usercount.start()
prYellow(f"[{login_time}] [INFO] Iris has logged in.")
logfile.write(f"\n[{login_time}] [INFO] Iris has logged in.")
prRed('<=>--------------------------------<=>')
prLightGray(f"{space}Logged in as {client.user}")
prLightGray(f"{space}User ID: {client.user.id}")
prLightGray(f"{space}Logged in at {login_time}")
prLightGray(f"{space}Iris Version: {IRIS_version}")
prLightGray(f"{space}Discord Version: {discord.__version__}")
prLightGray(f"{space}Python Version: {sys.version}")
prRed('<=>--------------------------------<=>')
server = len(client.guilds)
server_count = int(server)
with open("profiles.json") as userjson:
userlist = json.load(userjson)
user_count = 0
for user in userlist.get("users", []):
user_count += 1
prLightGray(f"{space}Connected to")
prLightGray(f"{space}{server_count} Discord Guilds")
prLightGray(f"{space}{user_count} Iris Users")
prRed('<=>--------------------------------<=>')
guild_number = 0
for guild in client.guilds:
guild_number = guild_number + 1
prLightGray(f"{space}[{guild_number}] {guild} | ID:{guild.id} | {guild.owner}")
prRed('<=>--------------------------------<=>')
channel = client.get_channel(1193155470186266754)
message = await channel.fetch_message(1193237727144054865)
restartTimes = int(message.content) + 1
await message.edit(content=f"{restartTimes}")
restimemsg = await channel.fetch_message(1193237749596180480)
await restimemsg.edit(content=f"**Last Restart:**{login_time}\n**Iris Version:** {IRIS_version}\n**Discord Version:** {discord.__version__}\n**Python Version:** {sys.version}")
# Bot Status
status_cycle = ["with papa", "Minecraft"]
status = cycle(status_cycle)
@tasks.loop(seconds=5)
async def change_status():
await client.change_presence(activity=discord.Game(next(status)))
# Functions
# Check if user exists in customResponses.json
def user_exists(user_id):
# Opening JSON file
userjson = open("customResponses.json", encoding="UTF-8")
userlist = json.load(userjson)
# Load the existing JSON data
with open("customResponses.json") as userjson:
userlist = json.load(userjson)
# Access the "users" array
users = userlist.get("users", [])
# Check if the user ID exists in the "users" array
return any(user['ID'] == user_id for user in users)
# Create new log object
def create_log(guildName, guildID, channelName, channelID, authorName, authorID, messageID, eventTime, wordDetected, messageContent):
# Opening JSON file
logjson = open("watchedWords_log.json")
# Load the existing JSON data
with open("watchedWords_log.json") as logjson:
data = json.load(logjson)
# Create a new log object
new_log = {
"info": [
{
"guildName": guildName,
"guildID": guildID
},
{
"channelName": channelName,
"channelID": channelID
},
{
"authorName": authorName,
"authorID": authorID
},
{
"messageID": messageID,
"eventTime": eventTime
}
],
"wordDetected": wordDetected,
"messageContent": messageContent
}
# Add the new log to the "messages" array
data["messages"].append(new_log)
# Save the updated data back to the JSON file
with open("watchedWords_log.json", "w", encoding="UTF-8") as logjson:
json.dump(data, logjson, indent=4)
# Register new user
def register_user(user_id, wallet, bank, bio, badges, user_number, total_earned, total_spent, total_transfered, total_received, peak_wealth, commands_issued, inventory):
# Opening JSON file
userjson = open("profiles.json")
# Load the existing JSON data
with open("profiles.json") as userjson:
data = json.load(userjson)
# Create a new user object
new_user = {
"ID": user_id,
"wallet": wallet,
"bank": bank,
"bio": bio,
"badges": badges,
"user_number": user_number,
"total_earned": total_earned,
"total_spent": total_spent,
"total_transfered": total_transfered,
"total_received": total_received,
"peak_wealth": peak_wealth,
"commands_issued": commands_issued,
"inventory": inventory
}
# Add the new user to the "users" array
data["users"].append(new_user)
# Save the updated data back to the JSON file
with open("profiles.json", "w") as userjson:
json.dump(data, userjson, indent=4)
# Check if user exists in profiles.json
def user_exists(user_id):
# Opening JSON file
userjson = open("profiles.json")
userlist = json.load(userjson)
# Load the existing JSON data
with open("profiles.json") as userjson:
userlist = json.load(userjson)
# Access the "users" array
users = userlist.get("users", [])
# Check if the user ID exists in the "users" array
return any(user['ID'] == user_id for user in users)
# Commands Issued Counter
def commands_issued(user_id):
# Opening JSON file
userjson = open("profiles.json")
userlist = json.load(userjson)
# Load the existing JSON data
with open("profiles.json") as userjson:
userlist = json.load(userjson)
# Get user
userid_to_find = user_id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Rewrite data
user_commands_issued = user["commands_issued"]
new_user_commands_issued = user_commands_issued + 1
user["commands_issued"] = new_user_commands_issued
# Get Iris
userid_to_find = 902720782503907358
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Rewrite data
user_commands_issued = user["commands_issued"]
new_user_commands_issued = user_commands_issued + 1
user["commands_issued"] = new_user_commands_issued
# Save the modified data back to the JSON file
with open("profiles.json", "w") as userjson:
json.dump(userlist, userjson, indent=4)
# Function to get a random outcome based on probability distribution
def get_random_outcome(outcomes):
rand_num = random.uniform(0, 1)
cumulative_probability = 0
for outcome in outcomes:
cumulative_probability += outcome["probability"]
if rand_num < cumulative_probability:
# Return a random value within the specified range
return random.choice(outcome["range"])
# Update Peak Wealth
def update_peak_wealth(user_id):
# Opening JSON file
with open("profiles.json", "r") as userjson:
userlist = json.load(userjson)
# Get user
userid_to_find = user_id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
current_wealth = user['wallet'] + user['bank']
# Check if the current wealth is higher than the recorded peak wealth
if current_wealth > user['peak_wealth']:
user['peak_wealth'] = current_wealth
# Save the modified data back to the JSON file
with open("profiles.json", "w") as userjson:
json.dump(userlist, userjson, indent=4)
# Deleted Message Log
@client.event
async def on_message_delete(message: str):
if message.author.id == client.user.id:
return
else:
user = message.author
channel = message.channel
embed = discord.Embed(title=f"{user} deleted a message in {message.guild}",description=(f"{user.mention} **|** {channel.mention}"),colour=discord.Colour.purple())
embed.add_field(name=f"Content", value=f"{message.content}", inline=False)
embed.add_field(name=f"ID", value=f"```\n Channel = {channel.id} \n User = {user.id} \n Message = {message.id} \n```", inline=False)
embed.timestamp = message.created_at
channel = client.get_channel(deleted_message)
await channel.send(embed=embed)
now = datetime.now()
event_time = now.strftime("%Z %d/%b/%Y %H:%M:%S")
log = f"[{event_time}] [LOG] Message Deleted\nUser: {user}({user.id})\nServer: {message.guild}({message.guild.id})\nContent: {message.content}"
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
# Edited Message Log
@client.event
async def on_message_edit(message_before, message_after):
if message_before.author.bot:
return
if message_before.content == message_after.content:
return
else:
msg = message_after
user = msg.author
channel = msg.channel
server = msg.guild
msg_link = f"https://discord.com/channels/{server.id}/{channel.id}/{msg.id}"
embed = discord.Embed(title=f"{user} edited a message in {server}",description=(f"{user.mention} **|** {channel.mention} **|** {msg_link}"),colour=discord.Colour.purple())
embed.add_field(name=f"Original Message", value=f"{message_before.content}", inline=False)
embed.add_field(name=f"Edited Message", value=f"{message_after.content}", inline=False)
embed.add_field(name=f"ID", value=f"```\n Channel = {channel.id} \n User = {user.id} \n Message = {msg.id} \n```", inline=False)
embed.timestamp = msg.created_at
channel = client.get_channel(edited_message)
await channel.send(embed=embed)
now = datetime.now()
event_time = now.strftime("%Z %d/%b/%Y %H:%M:%S")
log = f"[{event_time}] [LOG] Message Edited\nUser: {user}({user.id})\nServer: {server}({server.id})\nContent: {message_before.content}\nEdited Content: {message_after.content}"
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
# Message Detection
@client.event
async def on_message(message):
guildName = message.guild.name
guildID = message.guild.id
channelName = message.channel.name
channelID = message.channel.id
authorName = message.author.name
authorID = message.author.id
messageContent = message.content
messageID = message.id
now = datetime.now()
event_time = now.strftime("%Z %d/%b/%Y %H:%M:%S")
if message.author.id == client.user.id:
return
## Watched Words
if any(word.casefold() in message.content.casefold() for word in watchedWords):
matching_words = [word for word in watchedWords if word.casefold() in messageContent.casefold()]
for matching_word in matching_words:
wordDetected = matching_word
now = datetime.now()
eventTime = now.strftime("%Z %d/%b/%Y %H:%M:%S")
create_log(guildName, guildID, channelName, channelID, authorName, authorID, messageID, eventTime, wordDetected, messageContent)
msg_link = f"https://discord.com/channels/{guildID}/{channelID}/{messageID}"
embed = discord.Embed(title=f"Watched Word Detected from {authorName} in {guildName}",description=(f"{message.author.mention} **|** {msg_link}"),colour=discord.Colour.purple())
embed.add_field(name=f"Content", value=f"{message.content}", inline=False)
embed.add_field(name=f"ID", value=f"```\n Guild = {guildID} \n Channel = {channelID} \n User = {authorID} \n Message = {messageID} \n```", inline=False)
embed.timestamp = message.created_at
channel = client.get_channel(watched_message)
await channel.send(embed=embed)
## Bot Mentions
if client.user.mentioned_in(message):
if "@everyone" in message.content:
return
else:
log = f"[{event_time}] [LOG] Iris pinged by {message.author}({message.author.id})"
# Opening JSON file
userjson = open("customResponses.json", encoding="UTF-8")
userlist = json.load(userjson)
# Check if user ID exists
userid_to_check = message.author.id
if user_exists(userid_to_check):
# Get User
userid_to_find = message.author.id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Get responses
responses = user["responses"]
responses = random.choice(responses)
await message.reply(responses)
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
if not user_exists(userid_to_check):
log = f"[{event_time}] [LOG] Iris pinged by {message.author}({message.author.id})"
# Opening JSON file
userjson = open("customResponses.json", encoding="UTF-8")
userlist = json.load(userjson)
# Get User
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == 0:
# Get responses
responses = user["responses"]
responses = random.choice(responses)
await message.reply(responses)
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
## File Logger
if message.attachments:
# Check if there are attachments in the message
for attachment in message.attachments:
msg_link = f"https://discord.com/channels/{guildID}/{channelID}/{messageID}"
if any(attachment.filename.lower().endswith(ext) for ext in file_log_extensions):
file_log_channel = client.get_channel(file_logger)
content = await attachment.read()
# Text Files
if attachment.filename.lower().endswith("txt"):
txt_file_like = StringIO(content.decode('utf-8'))
txtfile = discord.File(txt_file_like, filename=attachment.filename)
# Check word count
word_count = len(content.decode('utf-8').split())
# Check if word count is more than 300
if word_count > 300:
await file_log_channel.send(f"**{authorName}** `{authorID}`\n**{guildName}** `{guildID}`\n`{attachment.filename}` [source]({msg_link})\n```\nToo many characters\n```", file=txtfile)
else:
# Send the content normally
await file_log_channel.send(f"**{authorName}** `{authorID}`\n**{guildName}** `{guildID}`\n`{attachment.filename}` [source]({msg_link})\n```\n{content.decode('utf-8')}\n```", file=txtfile)
# Images
image_extensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "webp", "svg"]
image_file_like = BytesIO(content)
imgfile = discord.File(image_file_like, filename='your_image_filename.png')
if any(attachment.filename.lower().endswith(ext) for ext in image_extensions):
await file_log_channel.send(f"**{authorName}** `{authorID}`\n**{guildName}** `{guildID}`\n`{attachment.filename}` [source]({msg_link})", file=imgfile)
# Voice Channel Log
@client.event
async def on_voice_state_update(user, before, after):
now = datetime.now()
event_time = now.strftime("%Z %d/%b/%Y %H:%M:%S")
# Channel Join Log
if before.channel is None and after.channel is not None:
voice_timers[user.id] = now
embed = discord.Embed(title=f"{user} joined :speaker:{after.channel}",
description=(f"{user.mention} **|** {after.channel.guild} **|** {after.channel.mention}"),
colour=discord.Colour.green())
embed.add_field(name=f"ID", value=f"```\n Channel = {after.channel.id} \n User = {user.id} \n```", inline=False)
channel = client.get_channel(voice_events)
await channel.send(embed=embed)
log = f"[{event_time}] [LOG] Channel Join\nUser: {user}({user.id})\nServer: {after.channel.guild}({after.channel.guild.id})\nChannel: {after.channel}({after.channel.id})"
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
# Channel Leave Log
elif before.channel is not None and after.channel is None:
if user.id in voice_timers:
start_time = voice_timers.pop(user.id)
duration = now - start_time
inthours = duration.seconds // 3600
hours = str(inthours)
intminutes = (duration.seconds // 60) % 60
minutes = str(intminutes)
intseconds = duration.seconds % 60
seconds = str(intseconds)
duration_str = f"{hours.zfill(2)}:{minutes.zfill(2)}:{seconds.zfill(2)}"
embed = discord.Embed(title=f"{user} left :speaker:{before.channel}",
description=(f"{user.mention} **|** {before.channel.guild} **|** {before.channel.mention}\n"
f"Duration: {duration_str}"),
colour=discord.Colour.red())
embed.add_field(name=f"ID", value=f"```\n Channel = {before.channel.id} \n User = {user.id} \n```",
inline=False)
channel = client.get_channel(voice_events)
await channel.send(embed=embed)
log = f"[{event_time}] [LOG] Channel Leave\nUser: {user}({user.id})\nServer: {before.channel.guild}({before.channel.guild.id})\nChannel: {before.channel}({before.channel.id})\nDuration: {duration_str}"
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
# Channel Switch Log
elif before.channel != after.channel:
if before.channel is not None and after.channel is not None:
embed = discord.Embed(
title=f"{user} switched from :speaker:{before.channel} to :speaker:{after.channel}",
description=(f"{user.mention} **|** {after.channel.guild}"),
colour=discord.Colour.orange())
embed.add_field(name=f"ID",
value=f"```\n Before_Channel = {before.channel.id} \n After_Channel = {after.channel.id} \n User = {user.id} \n```",
inline=False)
channel = client.get_channel(voice_events)
await channel.send(embed=embed)
log = f"[{event_time}] [LOG] Channel Switch\nUser: {user}({user.id})\nServer: {after.channel.guild}({after.channel.guild.id})\nBefore Channel: {before.channel}({before.channel.id}) | After Channel: {after.channel}({after.channel.id})"
logfile = open(r"D:\\IRIS.log", "a", encoding="utf-8")
logfile.write(f"\n\n{log}")
print(log)
else:
return
# Hello Command
@client.tree.command(name = "hello", description = "Says hello to Iris.")
async def hello(ctx):
commands_issued(ctx.user.id)
await ctx.response.send_message("Hello!")
# Iris Choice
@client.tree.command(name = "choose", description = "Lets Iris choose for you.")
@app_commands.describe(choice1 = "Enter first choice.")
@app_commands.describe(choice2 = "Enter second choice.")
async def choose(ctx: discord.Interaction, choice1: str, choice2: str):
commands_issued(ctx.user.id)
choice1 = choice1
choice2 = choice2
choices = [choice1, choice2]
IRISchoose = random.choice(choices)
await ctx.response.send_message(f"**[** {choice1} **|** {choice2} **]** \n{IRISchoose}")
# Ping Check
@client.tree.command(name = "ping", description = "Checks Iris' latency.")
async def ping(ctx):
commands_issued(ctx.user.id)
latency = round(client.latency * 1000)
await ctx.response.send_message(f"{latency}ms")
# User Status Count
@tasks.loop(seconds=10)
async def usercount():
now = datetime.now()
refresh_time = now.strftime("%H:%M:%S")
# Count members
server = client.get_guild(863253117684678658) #學術寶庫
online_members = []
offline_members = []
idle_members = []
dnd_members = []
for member in server.members:
if member.status == discord.Status.online:
online_members.append(member.name)
if member.status == discord.Status.offline:
offline_members.append(member.name)
if member.status == discord.Status.idle:
idle_members.append(member.name)
if member.status == discord.Status.dnd:
dnd_members.append(member.name)
online = len(online_members)
offline = len(offline_members)
idle = len(idle_members)
dnd = len(dnd_members)
# Live Status Message Edit
channel = client.get_channel(1193155470186266754)
message = await channel.fetch_message(1193484403574325278)
newmsg = f"**{server} Member Status**\n**Total Members: {server.member_count}**\n*Refreshes every 10 seconds* **|** *Last Refresh: {refresh_time}*\n:green_circle: {online}\n:orange_circle: {idle}\n:red_circle: {dnd}\n:white_circle: {offline}"
await message.edit(content=newmsg)
# Join Voice
@client.tree.command(name = "join", description = "Joins VC.")
async def join(ctx: discord.Interaction):
commands_issued(ctx.user.id)
channel = ctx.user.voice.channel
await channel.connect()
await ctx.response.send_message("Connected to {channel.mention}")
# Leave Voice
@client.tree.command(name = "leave", description = "Leaves VC.")
async def leave(ctx: discord.Interaction):
commands_issued(ctx.user.id)
await ctx.guild.voice_client.disconnect()
await ctx.response.send_message("Disconnected from {channel.mention}")
# [Console] Say Command
@client.tree.command(name = "say", description = "Console Command", guild=discord.Object(id=952892062552981526))
@app_commands.describe(say_text = "Enter message.")
@app_commands.describe(say_channel = "Enter channel ID.")
async def say(ctx: discord.Interaction, say_channel: str, say_text: str):
commands_issued(ctx.user.id)
if ctx.user.id in ownerID:
channel = client.get_channel(int(say_channel))
message = await channel.send(say_text)
embed = discord.Embed(title=f"[Console] Say Command",description=(f"Message successfully sent."),colour=discord.Colour.dark_red())
embed.add_field(name=f"User", value=f"{ctx.user.mention}", inline=False)
embed.add_field(name=f"Channel", value=f"{channel.mention}", inline=False)
embed.add_field(name=f"Message", value=f"https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id}", inline=False)
embed.add_field(name=f"Content", value=f"{message.content}", inline=False)
await ctx.response.send_message(embed=embed)
else:
await ctx.response.send_message("Only papa can use this command!")
# [Console] Sync Command Tree
@client.tree.command(name="sync", description="Syncs the command tree", guild=discord.Object(id=952892062552981526))
async def sync(ctx: discord.Interaction):
if ctx.user.id in ownerID:
commands_issued(ctx.user.id)
await client.tree.sync()
await ctx.response.send_message(f"Command tree synced.<:OuroKronii_cheers:940254772395655218>")
else:
await ctx.response.send_message("Only papa can use this command!")
# [Console] Developer Info
## Guild List
@client.tree.command(name = "guilds", description = "Console Command", guild=discord.Object(id=952892062552981526))
async def devinfo(ctx: discord.Interaction):
if ctx.user.id in ownerID:
commands_issued(ctx.user.id)
page = 0
# Guilds
for i in range(0, len(client.guilds), 9):
page = page + 1
server_list = discord.Embed(title="Project IRIS Guild List",
description=f"***Page {page}***",
colour=discord.Colour.dark_red())
guilds = client.guilds[i:i + 9]
for guild in guilds:
server_list.add_field(
name=guild.name,
value=
f"`{guild.id}` \n ***{guild.member_count} members***")
server_list.set_footer(
text=f"Developer Info requested by {ctx.user}")
await ctx.user.send(embed=server_list)
await ctx.response.send_message(
f"I'm currently connected to **{len(client.guilds)} servers** <:anime_brighteyes:943480188195442758> More detailed information has been sent to your DMs! <a:UruhaRushia_happy:940254774094364694>")
else:
await ctx.response.send_message("Only papa can use this command!")
## Members List
@client.tree.command(name = "members", description = "Console Command", guild=discord.Object(id=952892062552981526))
@app_commands.describe(guild = "Enter guild ID.")
async def devinfo(ctx: discord.Interaction, guild: str):
guild_id = int(guild)
server = client.get_guild(guild_id)
if ctx.user.id in ownerID:
commands_issued(ctx.user.id)
page = 0
for i in range(0, len(server.members), 50):
page = page + 1
type_bot = 0
type_user = 0
member_list = discord.Embed(
title=f"{server}",
description=f"***Page {page} | Guild ID: `{server.id}` ***",
colour=discord.Colour.dark_red())
members = server.members[i:i + 50]
for member in members:
if member.bot:
bot = "Bot"
type_bot += 1
else:
bot = ""
type_user += 1
member_list.add_field(name=f"{member} {bot}",
value=f"`{member.id}`",
inline=True)
member_list.set_footer(
text=f"{type_user} Users | {type_bot} Bots")
await ctx.user.send(embed=member_list)
await ctx.response.send_message(
f"**{server}** currently has **{len(server.members)} members** <:anime_brighteyes:943480188195442758> More detailed information has been sent to your DMs! <a:UruhaRushia_happy:940254774094364694>")
else:
await ctx.response.send_message("Only papa can use this command!")
## Channels List
@client.tree.command(name = "channels", description = "Console Command", guild=discord.Object(id=952892062552981526))
@app_commands.describe(guild = "Enter guild ID.")
async def devinfo(ctx: discord.Interaction, guild: str):
guild_id = int(guild)
server = client.get_guild(guild_id)
if ctx.user.id in ownerID:
commands_issued(ctx.user.id)
page = 0
# Text Channels
for i in range(0, len(server.text_channels), 25):
page = page + 1
text_channel_list = discord.Embed(
title=f"{server}",
description=
f"***Page {page} | Guild ID: `{server.id}` | Text Channels ***",
colour=discord.Colour.dark_red())
channels = server.text_channels[i:i + 25]
for channel in channels:
text_channel_list.add_field(name=f"#{channel.name}",
value=f"`{channel.id}`",
inline=True)
text_channel_list.set_footer(
text=f"{len(server.text_channels)} Text Channels",)
await ctx.user.send(embed=text_channel_list)
# Voice Channels
for i in range(0, len(server.voice_channels), 25):
page = page + 1
voice_channel_list = discord.Embed(
title=f"{server}",
description=
f"***Page {page} | Guild ID: `{server.id}` | Voice Channels ***",
colour=discord.Colour.dark_red())
channels = server.voice_channels[i:i + 25]
for channel in channels:
voice_channel_list.add_field(
name=f":speaker:{channel.name}",
value=f"`{channel.id}`",
inline=True)
voice_channel_list.set_footer(
text=f"{len(server.voice_channels)} voice Channels",)
await ctx.user.send(embed=voice_channel_list)
await ctx.response.send_message(
f"**{server}** currently has **{len(server.text_channels)} text channels** and **{len(server.voice_channels)} voice channels** <:anime_brighteyes:943480188195442758> More detailed information has been sent to your DMs! <a:UruhaRushia_happy:940254774094364694>")
else:
await ctx.response.send_message("***Error*** You can't use that command.")
# [CONSOLE] Clear DM
@client.tree.command(name = "cls", description = "Clears your DM", guild=discord.Object(id=952892062552981526))
async def cls(ctx: discord.Interaction):
commands_issued(ctx.user.id)
deleted_messages_count = 0
await ctx.response.send_message("This might take a while.")
remove = 9999999999999999999999999999999999999999
remove = remove * remove * remove
async for message in ctx.user.history(limit=remove):
remove = remove + 1
if message.author.id == client.user.id:
await message.delete()
deleted_messages_count += 1
time.sleep(0.5)
await ctx.channel.send(f"{deleted_messages_count} messages has been deleted.")
# Feedback Command
@client.tree.command(name = "feedback", description = "Feedback about your experiences with Iris")
@app_commands.describe(feedback = "Enter your feedback.")
async def feedback(ctx: discord.Interaction, feedback: str):
commands_issued(ctx.user.id)
embed = discord.Embed(title=f"Feedback Received",description=(f"{feedback}"),colour=discord.Colour.dark_red())
embed.add_field(name=f"{ctx.guild}", value=f"{ctx.user.name} | {ctx.user.mention}", inline=False)
channel = client.get_channel(feedback_channel)
await channel.send(embed=embed)
await ctx.response.send_message("Your feedback has been received!")
# Report Command
@client.tree.command(name = "report", description = "Report a user")
@app_commands.describe(user_id = "Enter the user ID to be reported.")
@app_commands.describe(report_reason = "Enter your reason of reporting.")
async def report(ctx: discord.Interaction, user_id: str, report_reason: str):
commands_issued(ctx.user.id)
embed = discord.Embed(title=f"User Report Received",description=(f"{user_id}\n{report_reason}"),colour=discord.Colour.dark_red())
embed.add_field(name=f"{ctx.guild}", value=f"{ctx.user.name} | {ctx.user.mention}", inline=False)
channel = client.get_channel(report_channel)
await channel.send(embed=embed)
await ctx.response.send_message("User reported!")
# Info Command
@client.tree.command(name = "info", description = "More information about Iris")
async def info(ctx: discord.Interaction):
commands_issued(ctx.user.id)
embed = discord.Embed(title=f"Project IRIS Info",colour=discord.Colour.dark_red())
embed.add_field(name=f"**<=> Our Team <=>**", value=f"The people that made this Project IRIS possible", inline=False)
embed.add_field(name=f"Near `kuroyukinear`", value=f"Owner | Developer", inline=True)
embed.add_field(name=f"Skully `skull1fy`", value=f"Public Relations", inline=True)
embed.add_field(name=f"**<=> Links <=>**", value=f"Links related to Project IRIS", inline=False)
embed.add_field(name=f"Socials", value=f"[Twitter](https://twitter.com/KuroyukiNear)\n[Instagram](https://instagram.com/kuroyuki.near)", inline=True)
embed.add_field(name=f"Invites", value=f"[Bot Invite](https://discord.com/oauth2/authorize?client_id=902720782503907358&permissions=1644971949559&scope=bot)\n[Server Invite](https://discord.gg/9RUy6suKsy)", inline=True)
await ctx.response.send_message(embed=embed)
# Display Profile
@client.tree.command(name = "profile", description = "View a user's profile")
async def profile(ctx: discord.Interaction, member: discord.Member = None):
commands_issued(ctx.user.id)
# Opening JSON file
userjson = open("profiles.json")
userlist = json.load(userjson)
# If user is mentioned
if member == None:
user = ctx.user
username = ctx.user
else:
user = member
username = member
# Check if user ID exists
userid_to_check = user.id
if user_exists(userid_to_check):
# Get User
userid_to_find = user.id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Get RixCoins
wrix = user["wallet"]
brix = user["bank"]
rix = f"`{wrix + brix}`"
# Get bio and user number
bio = user["bio"]
user_number = user["user_number"]
# Get badges
user_badges = user.get("badges", [])
badges = ', '.join(map(str, user_badges))
# Embed Profile
info = discord.Embed(title=f"{username}'s Profile",
description=f"User #{user_number}",
colour=discord.Colour.dark_red())
info.add_field(name="Badges", value=f"{badges}", inline=False)
info.add_field(name="RixCoins", value=f"{rix}", inline=False)
info.add_field(name="Bio", value=f"{bio}", inline=False)
await ctx.response.send_message(embed=info)
# Register if user does not exist
else:
with open("profiles.json") as userjson:
userlist = json.load(userjson)
count = len(userlist.get("users", [])) # Does not need to add 1 to count as Iris will be User #0
register_user(
user_id=userid_to_check,
wallet=50,
bank=0,
bio="Use `/bio` to edit your bio",
badges=["`no badges`"],
user_number=count,
total_earned=0,
total_spent=0,
total_transfered=0,
total_received=0,
peak_wealth=0,
commands_issued=0,
inventory={}
)
await ctx.response.send_message("User has just been registered. Please use `/profile` again.")
# Edit Bio
@client.tree.command(name = "bio", description = "Edit your bio")
async def bio(ctx: discord.Interaction, newbio: str):
commands_issued(ctx.user.id)
# Opening JSON file
userjson = open("profiles.json")
userlist = json.load(userjson)
# Get user
userid_to_find = ctx.user.id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Edit bio
user["bio"] = newbio
# Save the modified data back to the JSON file
with open("profiles.json", "w") as userjson:
json.dump(userlist, userjson, indent=4)
await ctx.response.send_message(
"Your bio has been changed.\nNote: if `/profile` is not working after you changed your bio, you have probably exceeded the character limit."
)
# Balance
@client.tree.command(name = "balance", description = "View a user's balance")
async def profile(ctx: discord.Interaction, member: discord.Member = None):
commands_issued(ctx.user.id)
# Opening JSON file
userjson = open("profiles.json")
userlist = json.load(userjson)
# If user is mentioned
if member == None:
user = ctx.user
username = ctx.user
else:
user = member
username = member
# Check if user ID exists
userid_to_check = user.id
if user_exists(userid_to_check):
# Get User
userid_to_find = user.id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Get RixCoins
wrix = user["wallet"]
brix = user["bank"]
rix = f"`{wrix + brix}`"
# Embed Profile
info = discord.Embed(title=f"{username}'s Balance",
description=f"Networth: `{rix}`RC",
colour=discord.Colour.dark_red())
info.add_field(name="Wallet", value=f"`{wrix}`RC", inline=True)
info.add_field(name="Bank", value=f"`{brix}`RC", inline=True)
await ctx.response.send_message(embed=info)
# Reply if user does not exist
else:
await ctx.response.send_message("User has not been registered. Please use `/profile` to register.")
# Transfer RixCoins
@client.tree.command(name = "transfer", description = "Transfer RixCoins to another user")
async def transfer(ctx: discord.Interaction, member: discord.Member, amount: int):
commands_issued(ctx.user.id)
# Opening JSON file
userjson = open("profiles.json")
userlist = json.load(userjson)
# Users
transferer = ctx.user
receiver = member
# Check if the users are the same
if transferer.id == receiver.id:
await ctx.response.send_message(f"***ERROR*** You can't transfer to yourself.", ephemeral=True)
return
# Check if transferer ID exists
userid_to_check = transferer.id
if user_exists(userid_to_check):
# Get transferer
userid_to_find = transferer.id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Get data
transferer_rix = user["wallet"]
total_transfered = user["total_transfered"]
else:
await ctx.response.send_message(f"***ERROR*** User **{transferer.name}** not found.", ephemeral=True)
# Check if receiver ID exists
userid_to_check = receiver.id
if user_exists(userid_to_check):
# Get receiver
userid_to_find = receiver.id
users_list = userlist.get("users", [])
for user in users_list:
if user['ID'] == userid_to_find:
# Get data
receiver_rix = user["wallet"]