-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathowner.py
executable file
·910 lines (755 loc) · 29.8 KB
/
owner.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
# This project is licensed under the terms of the GPL v3.0 license. Copyright 2024 Cyteon
import discord
import ast
import os
import sys
import pymongo
from datetime import datetime
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
from utils import CONSTANTS, DBClient, Checks, CachedDB
client = DBClient.client
db = client.potatobot
def insert_returns(body):
# insert return stmt if the last expression is a expression statement
if isinstance(body[-1], ast.Expr):
body[-1] = ast.Return(body[-1].value)
ast.fix_missing_locations(body[-1])
# for if statements, we insert returns into the body and the orelse
if isinstance(body[-1], ast.If):
insert_returns(body[-1].body)
insert_returns(body[-1].orelse)
# for with blocks, again we insert returns into the body
if isinstance(body[-1], ast.With):
insert_returns(body[-1].body)
class Owner(commands.Cog, name="owner"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_group(
name="dev",
description="Commands for devs",
usage="dev <subcommand> [args]",
)
@commands.check(Checks.is_not_blacklisted)
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def dev(self, context: Context) -> None:
prefix = await self.bot.get_prefix(context)
cmds = "\n".join([f"{prefix}dev {cmd.name} - {cmd.description}" for cmd in self.dev.walk_commands()])
embed = discord.Embed(
title=f"Help: Dev", description="List of available commands:", color=0xBEBEFE
)
embed.add_field(
name="Commands", value=f"```{cmds}```", inline=False
)
await context.send(embed=embed)
@dev.command(
name="sync",
description="Sync the slash commands.",
usage="dev sync guild/global"
)
@app_commands.describe(scope="The scope of the sync. Can be `global` or `guild`")
@commands.is_owner()
async def sync(self, context: Context, scope: str) -> None:
await context.defer()
if scope == "global":
await context.bot.tree.sync()
embed = discord.Embed(
description="Slash commands have been globally synchronized.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
elif scope == "guild":
context.bot.tree.copy_global_to(guild=context.guild)
await context.bot.tree.sync(guild=context.guild)
embed = discord.Embed(
description="Slash commands have been synchronized in this guild.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
embed = discord.Embed(
description="The scope must be `global` or `guild`.", color=0xE02B2B
)
await context.send(embed=embed)
@dev.command(
name="unsync",
description="Unsync the slash commands",
usage="dev unsync guild/global"
)
@commands.is_owner()
async def unsync(self, context: Context, scope: str) -> None:
await context.defer()
if scope == "global":
context.bot.tree.clear_commands(guild=None)
await context.bot.tree.sync()
embed = discord.Embed(
description="Slash commands have been globally unsynchronized.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
elif scope == "guild":
context.bot.tree.clear_commands(guild=context.guild)
await context.bot.tree.sync(guild=context.guild)
embed = discord.Embed(
description="Slash commands have been unsynchronized in this guild.",
color=0xBEBEFE,
)
await context.send(embed=embed)
return
embed = discord.Embed(
description="The scope must be `global` or `guild`.", color=0xE02B2B
)
await context.send(embed=embed)
@dev.command(
name="sudo",
description="sus",
usage="dev sudo <user> <command> [args...]",
)
@commands.is_owner()
async def sudo(self, context: Context, user: discord.Member, *, command: str) -> None:
message = context.message
message.author = user
message.content = context.prefix + command
await self.bot.process_commands(message)
@dev.command(
name="load",
description="Load a cog",
usage="dev load <cog>",
)
@commands.is_owner()
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def load(self, context: Context, cog: str) -> None:
try:
await self.bot.load_extension(f"cogs.{cog}")
except Exception:
embed = discord.Embed(
description=f"Could not load the `{cog}` cog.", color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
description=f"Successfully loaded the `{cog}` cog.", color=0xBEBEFE
)
await context.send(embed=embed)
@dev.command(
name="unload",
description="Unloads a cog.",
usage="dev unload <cog>",
)
@commands.is_owner()
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def unload(self, context: Context, cog: str) -> None:
try:
await self.bot.unload_extension(f"cogs.{cog}")
except Exception:
embed = discord.Embed(
description=f"Could not unload the `{cog}` cog.", color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
description=f"Successfully unloaded the `{cog}` cog.", color=0xBEBEFE
)
await context.send(embed=embed)
@dev.command(
name="reload",
description="Reloads a cog",
usage="dev reload <cog>",
)
@app_commands.describe(cog="The name of the cog to reload")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
@commands.is_owner()
async def reload(self, context: Context, cog: str) -> None:
try:
await self.bot.reload_extension(f"cogs.{cog}")
except Exception:
embed = discord.Embed(
description=f"Could not reload the `{cog}` cog.", color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
description=f"Successfully reloaded the `{cog}` cog.", color=0xBEBEFE
)
await context.send(embed=embed)
@dev.command(
name="shutdown",
description="bye",
usage="dev shutdown"
)
@commands.is_owner()
async def shutdown(self, context: Context) -> None:
embed = discord.Embed(description="Shutting down. Bye! :wave:", color=0xBEBEFE)
await context.send(embed=embed)
sys.exit(0)
@dev.command(
name="say",
description="talk",
usage="dev say <message>",
)
@commands.is_owner()
async def say(self, context: Context, *, message: str) -> None:
await context.channel.send(message)
@commands.command(
name="embed",
description="say smth in embed",
usage="embed <title> <description> [footer]",
)
@commands.is_owner()
async def embed(self, context: Context, description: str = "", title: str = "", footer: str = "") -> None:
embed = discord.Embed(
title=title, description=description, color=0xBEBEFE
)
embed.set_footer(text=footer)
await context.channel.send(embed=embed)
@dev.command(
name="reply",
description="Reply to a message",
usage="dev reply <message_url> <content>",
)
@commands.is_owner()
async def reply(self, context: Context, message: discord.Message, *, reply: str) -> None:
await message.reply(reply)
@dev.command(
name="eval",
description=":D",
usage="eval <code>",
)
@commands.is_owner()
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def eval(self, context, *, cmd: str):
fn_name = "_eval_expr"
cmd = cmd.strip("` ")
# add a layer of indentation
cmd = "\n".join(f" {i}" for i in cmd.splitlines())
# wrap in async def body
body = f"async def {fn_name}():\n{cmd}"
parsed = ast.parse(body)
body = parsed.body[0].body
insert_returns(body)
env = {
'bot': context.bot,
'discord': discord,
'commands': commands,
'context': context,
'db': db,
'__import__': __import__
}
exec(compile(parsed, filename="<ast>", mode="exec"), env)
result = (await eval(f"{fn_name}()", env))
await context.send(result)
@dev.command(
name="enable-ai",
description="Give server AI access",
usage="dev enable-ai [optional: server id]",
)
@commands.is_owner()
async def enable_ai(self, context, server: int = 0):
c = db["guilds"]
data = c.find_one(
{
"id": server if server != 0 else context.guild.id
}
)
if not data:
data = CONSTANTS.guild_data_template(context.guild.id)
c.insert_one(data)
newdata = { "$set": { "ai_access": True } }
c.update_one({"id": context.guild.id}, newdata)
await context.send("AI access have been enabled in this server")
@dev.command(
name="disable-ai",
description="Disable server AI access",
usage="dev disable-ai [optional: server id]",
)
@commands.is_owner()
async def disable_ai(self, context, server_id: int = 0):
c = db["guilds"]
data = c.find_one(
{
"id": server_id if server_id != 0 else context.guild.id
}
)
if not data:
data = CONSTANTS.guild_data_template(context.guild.id)
c.insert_one(data)
newdata = { "$set": { "ai_access": False } }
c.update_one({"id": context.guild.id}, newdata)
await context.send("AI access have been disabled in this server")
@dev.command(
name="blacklist",
description="Blacklist a user",
usage="dev blacklist <user> [reason: optional]",
)
@commands.is_owner()
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def blacklist(self, context, user: discord.User, *, reason: str = "No reason provided"):
users_global = db["users_global"]
user_data = users_global.find_one({"id": user.id})
if user is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users_global.insert_one(user_data)
newdata = {
"$set": {
"blacklisted": True,
"blacklist_reason": reason
}
}
await CachedDB.update_one(users_global, {"id": user.id}, newdata)
await context.send(f"{user} has been blacklisted.")
embed = discord.Embed(
title=f"You have been blacklisted from using the bot",
color=0xE02B2B,
description=f"Reason: {reason}"
)
try:
await user.send(embed=embed)
except Exception as e:
await context.send(f"Could not send message to {user.mention} due to: {e}")
@dev.command(
name="unblacklist",
description="Unblacklist a user",
usage="dev unblacklist <user>",
)
@commands.is_owner()
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def unblacklist(self, context, user: discord.User):
users_global = db["users_global"]
user_data = users_global.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users_global.insert_one(user_data)
newdata = {
"$set": {
"blacklisted": False,
"blacklist_reason": ""
}
}
await CachedDB.update_one(users_global, {"id": user.id}, newdata)
await context.send(f"{user} has been unblacklisted.")
embed = discord.Embed(
title=f"You have been unblacklisted from using the bot",
color=0xBEBEFE,
)
try:
await user.send(embed=embed)
except Exception as e:
await context.send(f"Could not send message to {user.mention} due to: {e}")
@commands.hybrid_command(
name="ai-ignore",
description="Make the AI ignore someone",
usage="ai_ignore <user> [reason: optional]",
)
@commands.is_owner()
async def ai_ignore(self, context, user: discord.User, *, reason: str = "No reason provided"):
users_global = db["users_global"]
user_data = users_global.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
user_data.insert_one(user_data)
newdata = {
"$set": {
"ai_ignore": True,
"ai_ignore_reason": reason
}
}
await CachedDB.update_one(users_global, {"id": user.id}, newdata)
await context.send(f"{user} will now be ignored by the AI.")
@commands.hybrid_command(
name="ai-unignore",
description="Make the AI not ignore someone",
usage="ai-unignore <user>",
)
@commands.is_owner()
async def ai_unignore(self, context, user: discord.User):
users_global = db["users_global"]
user_data = users_global.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users_global.insert_one(user_data)
newdata = {
"$set": {
"ai_ignore": False,
"ai_ignore_reason": ""
}
}
await CachedDB.update_one(users_global, {"id": user.id}, newdata)
await context.send(f"{user} will no longer be ignored by the AI")
@commands.command(
name="inspect",
description="Inspect a user",
usage="inspect <user>",
)
@commands.is_owner()
async def inspect(self, context, user: discord.User):
users_global = db["users_global"]
user_data = users_global.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users_global.insert_one(user_data)
embed = discord.Embed(
title=f"Inspecting {user}",
color=0xBEBEFE
)
embed.add_field(name="Total Commands", value=user_data["inspect"]["total_commands"])
embed.add_field(name="Times Flagged", value=user_data["inspect"]["times_flagged"])
embed.add_field(name="NSFW Requests", value=user_data["inspect"]["nsfw_requests"])
# STUFF THAT MIGHT NOT BE FOUND
if "ai_requests" in user_data["inspect"]:
embed.add_field(name="AI Requests", value=user_data["inspect"]["ai_requests"])
if user_data["blacklisted"]:
embed.add_field(name="Blacklist Reason", value=user_data["blacklist_reason"])
if user_data["ai_ignore"]:
embed.add_field(name="AI Ignore Reason", value=user_data["ai_ignore_reason"])
await context.send(embed=embed)
@commands.command(
name="inspect-clear",
description="Clear someones inspect data",
usage="inspect-clear <user>",
)
@commands.is_owner()
async def inspect_clear(self, context: Context, user: discord.Member):
users_global = db["users_global"]
newdata = {
"$set": {"inspect.total_commands": 0, "inspect.times_flagged": 0, "inspect.nsfw_requests": 0, "inspect.ai_requests": 0}
}
users_global.update_one({"id": user.id}, newdata)
user_new = users_global.find_one({"id": user.id})
await context.send(f"Cleared inspect info for {user.mention}")
@commands.command(
name="top-flagged",
description="Get the top flagged users",
usage="top-flagged"
)
@commands.is_owner()
async def top_flagged(self, context):
users_global = db["users_global"]
users = users_global.find().sort("inspect.times_flagged", -1).limit(10)
embed = discord.Embed(
title="Top Flagged Users",
color=0xBEBEFE
)
for user in users:
discord_user = self.bot.get_user(user["id"])
if not discord_user:
continue
embed.add_field(name=f"{str(discord_user).capitalize()} ({discord_user.id})", value= f"Flagged **{user['inspect']['times_flagged']}** times", inline=False)
await context.send(embed=embed)
@commands.command(
name="top-nsfw",
description="Get the top NSFW requesters",
usage="top-nsfw"
)
@commands.is_owner()
async def top_nsfw(self, context):
users_global = db["users_global"]
users = users_global.find().sort("inspect.nsfw_requests", -1).limit(10)
embed = discord.Embed(
title="Top NSFW Requesters",
color=0xBEBEFE
)
for user in users:
discord_user = self.bot.get_user(user["id"])
if not discord_user:
continue
embed.add_field(name=f"{str(discord_user).capitalize()} ({discord_user.id})", value= f"**{user['inspect']['nsfw_requests']}** NSFW requests", inline=False)
await context.send(embed=embed)
@commands.command(
name="ai-announce",
description="Announce smth",
usage="ai-announce <message>"
)
@commands.is_owner()
async def ai_announce(self, context, *, message: str):
channels = db["ai_channels"]
listOfChannels = channels.find_one({"listOfChannels": True})
embed = discord.Embed(description=message)
for channel_id in listOfChannels["ai_channels"]:
channel = self.bot.get_channel(channel_id)
if channel:
if channel.permissions_for(channel.guild.me).send_messages:
await channel.send(embed=embed)
await context.send("Announced")
@dev.command(
name="copy-db-to-backup",
description="Copy the database to a backup",
usage="dev copy-db-to-backup"
)
@commands.is_owner()
async def copy_db_to_backup(self, context):
backup_db = pymongo.MongoClient(os.getenv("MONGODB_BACKUP_URL")).potatobot
message = await context.send("""
Status:
Removing old data: :tools:
Copying guilds: :x:
Copying ai_channels: :x:
Copying users: :x:
Copying AI convos: :x:
Copying global user data: :x:
Copying starboard: :x:
Copying reaction roles: :x:
""")
backup_db["ai_convos"].drop()
backup_db["guilds"].drop()
backup_db["ai_channels"].drop()
backup_db["users"].drop()
backup_db["starboard"].drop()
backup_db["users_global"].drop()
backup_db["reactionroles"].drop()
for guild in db["guilds"].find():
backup_db["guilds"].insert_one(guild)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :tools:
Copying ai_channels: :x:
Copying users: :x:
Copying AI convos: :x:
Copying global user data: :x:
Copying starboard: :x:
Copying reaction roles: :x:
""")
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :tools:
Copying users: :x:
Copying AI convos: :x:
Copying global user data: :x:
Copying starboard: :x:
Copying reaction roles: :x:
""")
for channel in db["ai_channels"].find():
backup_db["ai_channels"].insert_one(channel)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :white_check_mark:
Copying users: :tools:
Copying AI convos: :x:
Copying global user data: :x:
Copying starboard: :x:
Copying reaction roles: :x:
""")
for user in db["users"].find():
backup_db["users"].insert_one(user)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :white_check_mark:
Copying users: :white_check_mark:
Copying AI convos: :tools:
Copying global user data: :x:
Copying starboard: :x:
Copying reaction roles: :x:
""")
for convo in db["ai_convos"].find():
backup_db["ai_convos"].insert_one(convo)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :white_check_mark:
Copying users: :white_check_mark:
Copying AI convos: :white_check_mark:
Copying global user data: :tools:
Copying starboard: :x:
Copying reaction roles: :x:
""")
for user in db["users_global"].find():
backup_db["users_global"].insert_one(user)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :white_check_mark:
Copying users: :white_check_mark:
Copying AI convos: :white_check_mark:
Copying global user data: :white_check_mark:
Copying starboard: :tools:
Copying reaction roles: :x:
""")
for starboard in db["starboard"].find():
backup_db["starboard"].insert_one(starboard)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :white_check_mark:
Copying users: :white_check_mark:
Copying AI convos: :white_check_mark:
Copying global user data: :white_check_mark:
Copying starboard: :white_check_mark:
Copying reaction roles: :tools:
""")
for starboard in db["reactionroles"].find():
backup_db["reactionroles"].insert_one(starboard)
await message.edit(content="""
Status:
Removing old data: :white_check_mark:
Copying guilds: :white_check_mark:
Copying ai_channels: :white_check_mark:
Copying users: :white_check_mark:
Copying AI convos: :white_check_mark:
Copying global user data: :white_check_mark:
Copying starboard: :white_check_mark:
Copying reaction roles: :white_check_mark:
**Backup Done!!!**
""")
@commands.command(
name="force_system_prompt",
description="Set the system prompt for the AI",
)
@commands.is_owner()
async def force_system_prompt(self, context: Context, *, prompt: str) -> None:
c = db["guilds"]
data = c.find_one({"id": context.guild.id})
newdata = {
"$set": { "system_prompt": prompt }
}
c.update_one(
{ "id": context.guild.id }, newdata
)
await context.send("System prompt set to: " + prompt)
@commands.hybrid_group(
name="strikes",
description="Stuff for striking users"
)
async def strikes(self, context: Context):
prefix = await self.bot.get_prefix(context)
cmds = "\n".join([f"{prefix}strikes {cmd.name} - {cmd.description}" for cmd in self.strikes.walk_commands()])
embed = discord.Embed(
title=f"Help: Strikes", description="List of available commands:", color=0xBEBEFE
)
embed.add_field(
name="Commands", value=f"```{cmds}```", inline=False
)
await context.send(embed=embed)
@strikes.command(
name="add",
description="Strike a user"
)
@commands.is_owner()
async def add(self, context: Context, user: discord.User, *, reason: str):
users = db["users_global"]
user_data = users.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users.insert_one(user_data)
if not "strikes" in user_data:
user_data["strikes"] = []
user_data["strikes"].append({"reason": reason, "time": datetime.now().strftime("%d.%m.%Y %H:%M:%S")})
newdata = {"$set": {"strikes": user_data["strikes"]}}
users.update_one({"id": user.id}, newdata)
await context.send(f"{user.mention} has been striked for **{reason}** | This is strike {len(user_data['strikes'])}")
embed = discord.Embed(
title=f"You have received a global strike",
color=0xE02B2B,
description=f"Reason: {reason}"
)
embed.set_footer(text="Time: " + datetime.now().strftime("%d.%m.%Y %H:%M:%S"))
try:
await user.send(embed=embed)
except Exception as e:
await context.send(f"Could not send message to {user.mention} due to: {e}")
@strikes.command(
name="remove",
description="Remove a strike from a user"
)
@commands.is_owner()
async def remove(self, context: Context, user: discord.User, id: int):
users = db["users_global"]
user_data = users.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users.insert_one(user_data)
if not "strikes" in user_data:
user_data["strikes"] = []
if id > len(user_data["strikes"]):
await context.send("That strike does not exist")
return
reason = user_data["strikes"][id]["reason"]
user_data["strikes"].pop(id)
newdata = {"$set": {"strikes": user_data["strikes"]}}
users.update_one({"id": user.id}, newdata)
await context.send(f"Strike **{id}** has been removed from {user.mention}")
embed = discord.Embed(
title=f"Globally removed strike | ID: {id}",
color=0xBEBEFE,
description=f"Reason: {reason}"
)
embed.set_footer(text="Time: " + datetime.now().strftime("%d.%m.%Y %H:%M:%S"))
try:
await user.send(embed=embed)
except Exception as e:
await context.send(f"Could not send message to {user.mention} due to: {e}")
@strikes.command(
name="list",
description="Lists a users strikes"
)
@commands.is_owner()
async def list(self, context: Context, user: discord.User):
users = db["users_global"]
user_data = users.find_one({"id": user.id})
if user_data is None:
user_data = CONSTANTS.user_global_data_template(user.id)
users.insert_one(user_data)
if not "strikes" in user_data:
user_data["strikes"] = []
embed = discord.Embed(
title=f"Strikes for {user}",
color=0xBEBEFE
)
for i, strike in enumerate(user_data["strikes"]):
embed.add_field(name=f"Strike at {strike['time']} | ID: {i}", value=strike["reason"], inline=False)
await context.send(embed=embed)
@commands.command(
name="dm",
description="DM a user",
usage="dev dm <user> <message>"
)
@commands.is_owner()
async def dm(self, context: Context, user: discord.User, *, message: str) -> None:
try:
await user.send(message)
await context.send(f"Sent message to {user.mention}")
except Exception as e:
await context.send(f"Could not send message to {user.mention} due to: {e}")
@dev.command(
name="simulate-level-up",
description="",
usage="dev simulate-level-up"
)
@commands.is_owner()
async def simulate_level_up(self, context: Context):
author = context.author
c = db["users"]
data = await CachedDB.find_one(c, {"id": author.id, "guild_id": context.guild.id})
guilds = db["guilds"]
guild_data = await CachedDB.find_one(guilds, {"id": context.guild.id})
if data:
channel = context.channel
if guild_data:
if "level_announce_channel" in guild_data:
if guild_data["level_announce_channel"] != 0:
channel = context.guild.get_channel(guild_data["level_announce_channel"])
if "should_announce_levelup" in guild_data:
if guild_data["should_announce_levelup"]:
await channel.send(f"{author.mention} leveled up to level {data['level']}!")
else:
await channel.send(f"{author.mention} leveled up to level {data['level']}!")
async def setup(bot) -> None:
await bot.add_cog(Owner(bot))