-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BotCommands.py
111 lines (91 loc) · 6.16 KB
/
BotCommands.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
from CommandHelpers import TargetIdTransformer
from discord import app_commands, Interaction, Member, User, Embed
from ScamReportModal import SubmitScamReport
from BotServerSettings import ServerSettingsView
from Config import Config
@app_commands.guild_only()
class GlobalScamCommands(app_commands.Group):
def GetInstance(self):
return self.extras["instance"]
def IsActivated(self, InteractionId:int) -> bool:
return (self.GetInstance().Database.IsActivatedInServer(InteractionId))
@app_commands.command(name="check", description="Checks to see if a discord id is banned")
@app_commands.checks.has_permissions(ban_members=True)
@app_commands.checks.cooldown(1, 3.0)
async def ScamCheck_Global(self, interaction:Interaction, target:app_commands.Transform[int, TargetIdTransformer]):
if (target <= -1):
await interaction.response.send_message("Invalid id!", ephemeral=True, delete_after=5.0)
return
if (self.IsActivated(interaction.guild_id)):
ResponseEmbed:Embed = await self.GetInstance().CreateBanEmbed(target)
await interaction.response.send_message(embed = ResponseEmbed)
else:
await interaction.response.send_message("Your server must be activated in order to run scam check!")
@app_commands.command(name="report", description="Report an User ID")
@app_commands.checks.has_permissions(ban_members=True)
@app_commands.checks.cooldown(1, 5.0)
async def ReportScam_Global(self, interaction:Interaction, target:app_commands.Transform[int, TargetIdTransformer]):
if (interaction.guild_id == Config()["ControlServer"]):
await interaction.response.send_message("You cannot make remote reports from this server!", ephemeral=True, delete_after=5.0)
return
# Block any usages of the commands if the server is not activated.
if (not self.IsActivated(interaction.guild_id)):
await interaction.response.send_message("You must activate your server to report users", ephemeral=True, delete_after=10.0)
return
UserToSend:Member|User|None = await self.GetInstance().LookupUser(target, ServerToInspect=interaction.guild)
# If the user is no longer in said server, then do a global lookup
if (UserToSend is None):
UserToSend = await self.GetInstance().LookupUser(target)
# If the user is still invalid, then ask for a manual report.
if (UserToSend is None):
await interaction.response.send_message("Unable to look up the given user for a report, you'll have to make a report manually.", ephemeral=True)
return
await interaction.response.send_modal(SubmitScamReport(UserToSend))
@app_commands.command(name="reportuser", description="Report a user by a mention selector")
@app_commands.checks.has_permissions(ban_members=True)
@app_commands.checks.cooldown(1, 5.0)
async def ReportScamUser_Global(self, interaction:Interaction, user:Member):
if (interaction.guild_id == Config()["ControlServer"]):
await interaction.response.send_message("This command cannot be used in the control server", ephemeral=True, delete_after=5.0)
return
# Block any usages of the commands if the server is not activated.
if (not self.IsActivated(interaction.guild_id)):
await interaction.response.send_message("You must activate your server to report users", ephemeral=True, delete_after=10.0)
return
await interaction.response.send_modal(SubmitScamReport(user))
@app_commands.command(name="setup", description="Set up ScamGuard")
@app_commands.checks.has_permissions(ban_members=True)
@app_commands.checks.cooldown(1, 5.0)
async def SetupScamGuard_Global(self, interaction:Interaction):
if (interaction.guild_id == Config()["ControlServer"]):
await interaction.response.send_message("This command cannot be used in the control server", ephemeral=True, delete_after=5.0)
return
# Block any usages of the setup command if the server is activated.
if (not self.IsActivated(interaction.guild_id)):
await self.GetInstance().ServerSetupHelper.OpenServerSetupModel(interaction)
else:
await interaction.response.send_message("This server is already activated with ScamGuard!", ephemeral=True, delete_after=15.0)
@app_commands.command(name="config", description="Set ScamGuard Settings")
@app_commands.checks.has_permissions(ban_members=True)
@app_commands.checks.cooldown(1, 5.0)
async def ConfigScamGuard_Global(self, interaction:Interaction):
if (interaction.guild_id == Config()["ControlServer"]):
await interaction.response.send_message("This command cannot be used in the control server", ephemeral=True, delete_after=5.0)
return
if (not self.IsActivated(interaction.guild_id)):
await interaction.response.send_message("You must run `/scamguard setup` and activate first before proceeding", ephemeral=True, delete_after=30.0)
else:
await interaction.response.defer(thinking=True)
BotInstance = self.GetInstance()
ResponseEmbed:Embed = BotInstance.CreateBaseEmbed("ScamGuard Settings")
BotInstance.AddSettingsEmbedInfo(ResponseEmbed)
SettingsView:ServerSettingsView = ServerSettingsView(interaction.client.ApplySettings, interaction)
await SettingsView.Send(interaction, [ResponseEmbed])
@app_commands.command(name="info", description="Info & Stats about ScamGuard")
@app_commands.checks.cooldown(1, 5.0)
async def HelpScamGuard_Global(self, interaction:Interaction):
if (interaction.guild_id == Config()["ControlServer"]):
await interaction.response.send_message("This command cannot be used in the control server", ephemeral=True, delete_after=5.0)
return
ResponseEmbed:Embed = self.GetInstance().CreateInfoEmbed()
await interaction.response.send_message(embed=ResponseEmbed, silent=True)