Skip to content

Commit b578c45

Browse files
authored
Include proper security practices (#48)
1 parent 86309ff commit b578c45

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

bot/cogs/admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def reload_lib_modules(self, module: str) -> list[tuple[str, str]]:
104104
# To learn more about it, see the link below (and ?tag ass on the dpy server):
105105
# https://about.abstractumbra.dev/discord.py/2023/01/29/sync-command-example.html
106106
@commands.guild_only()
107-
@commands.command(name="sync")
107+
@commands.command(name="sync", hidden=True)
108108
async def sync(
109109
self,
110110
ctx: RoboContext,

bot/cogs/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ async def config(self, ctx: GuildContext) -> None:
127127
if ctx.invoked_subcommand is None:
128128
await ctx.send_help(ctx.command)
129129

130+
@commands.cooldown(1, 20, commands.BucketType.guild)
130131
@config.command(name="setup", usage="ticket_name: <str> log_name: <str>")
131132
async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
132133
"""First-time setup for Rodhaj
@@ -278,6 +279,7 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
278279
msg = f"Rodhaj channels successfully created! The ticket channel can be found under {ticket_channel.mention}"
279280
await ctx.send(msg)
280281

282+
@commands.cooldown(1, 20, commands.BucketType.guild)
281283
@config.command(name="delete")
282284
async def delete(self, ctx: GuildContext) -> None:
283285
"""Permanently deletes Rodhaj channels and tickets."""

bot/cogs/tickets.py

+5
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def get_solved_tag(
320320
### Feature commands
321321

322322
@is_ticket_or_dm()
323+
@commands.cooldown(1, 20, commands.BucketType.channel)
323324
@commands.hybrid_command(name="close", aliases=["solved", "closed", "resolved"])
324325
async def close(self, ctx: RoboContext) -> None:
325326
"""Closes the thread"""
@@ -356,7 +357,11 @@ async def close(self, ctx: RoboContext) -> None:
356357
self.get_ticket_owner_id.cache_invalidate(closed_ticket.id)
357358
await self.notify_finished_ticket(ctx, owner_id)
358359

360+
# 10 command invocations per 12 seconds for each member
361+
# These values should not be tripped unless someone is spamming
362+
# https://github.com/Rapptz/RoboDanny/blob/rewrite/cogs/mod.py#L524C9-L524C74
359363
@is_ticket_thread()
364+
@commands.cooldown(10, 12, commands.BucketType.member)
360365
@commands.command(name="reply", aliases=["r"])
361366
async def reply(
362367
self, ctx: GuildContext, *, message: Annotated[str, commands.clean_content]

bot/libs/utils/errors.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ def create_premade_embed(title: str, description: str) -> ErrorEmbed:
2929
return embed
3030

3131

32+
def build_cooldown_embed(error: commands.CommandOnCooldown) -> ErrorEmbed:
33+
embed = ErrorEmbed()
34+
embed.timestamp = discord.utils.utcnow()
35+
embed.title = "Command On Cooldown"
36+
embed.description = (
37+
f"This command is on cooldown. Try again in {error.retry_after:.2f}s"
38+
)
39+
return embed
40+
41+
3242
async def send_error_embed(ctx: commands.Context, error: commands.CommandError) -> None:
33-
if isinstance(error, commands.CommandInvokeError) or isinstance(
43+
if isinstance(error, commands.CommandOnCooldown):
44+
await ctx.send(embed=build_cooldown_embed(error))
45+
elif isinstance(error, commands.CommandInvokeError) or isinstance(
3446
error, commands.HybridCommandError
3547
):
3648
await ctx.send(embed=produce_error_embed(error))
37-
elif isinstance(error, commands.CommandNotFound):
38-
await ctx.send(
49+
elif isinstance(error, commands.NoPrivateMessage):
50+
await ctx.author.send(
3951
embed=create_premade_embed(
40-
"Command not found",
41-
"The command you were looking for could not be found",
42-
)
43-
)
44-
elif isinstance(error, commands.NotOwner):
45-
# Basically completely silence it making people not know what happened
46-
return
47-
elif isinstance(error, commands.MissingPermissions):
48-
missing_perms = ", ".join(error.missing_permissions).rstrip(",")
49-
await ctx.send(
50-
embed=create_premade_embed(
51-
"Missing Permissions",
52-
f"You are missing the following permissions: {missing_perms}",
52+
"Guild Only", "This command cannot be used in private messages"
5353
)
5454
)
5555
elif isinstance(error, commands.MissingRequiredArgument):
@@ -59,5 +59,3 @@ async def send_error_embed(ctx: commands.Context, error: commands.CommandError)
5959
f"You are missing the following argument(s): {error.param.name}",
6060
)
6161
)
62-
else:
63-
await ctx.send(embed=produce_error_embed(error))

0 commit comments

Comments
 (0)