Skip to content

Commit

Permalink
Merge branch 'main' into noelle/perms
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Jan 21, 2024
2 parents 7fb19c8 + b578c45 commit c37a634
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bot/cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def reload_lib_modules(self, module: str) -> list[tuple[str, str]]:
# To learn more about it, see the link below (and ?tag ass on the dpy server):
# https://about.abstractumbra.dev/discord.py/2023/01/29/sync-command-example.html
@commands.guild_only()
@commands.command(name="sync")
@commands.command(name="sync", hidden=True)
async def sync(
self,
ctx: RoboContext,
Expand Down
2 changes: 2 additions & 0 deletions bot/cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ async def config(self, ctx: GuildContext) -> None:
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)

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

@commands.cooldown(1, 20, commands.BucketType.guild)
@config.command(name="delete")
async def delete(self, ctx: GuildContext) -> None:
"""Permanently deletes Rodhaj channels and tickets."""
Expand Down
5 changes: 5 additions & 0 deletions bot/cogs/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def get_solved_tag(
### Feature commands

@is_ticket_or_dm()
@commands.cooldown(1, 20, commands.BucketType.channel)
@commands.hybrid_command(name="close", aliases=["solved", "closed", "resolved"])
async def close(self, ctx: RoboContext) -> None:
"""Closes a ticket
Expand Down Expand Up @@ -347,7 +348,11 @@ async def close(self, ctx: RoboContext) -> None:
self.get_ticket_owner_id.cache_invalidate(closed_ticket.id)
await self.notify_finished_ticket(ctx, owner_id)

# 10 command invocations per 12 seconds for each member
# These values should not be tripped unless someone is spamming
# https://github.com/Rapptz/RoboDanny/blob/rewrite/cogs/mod.py#L524C9-L524C74
@is_ticket_thread()
@commands.cooldown(10, 12, commands.BucketType.member)
@commands.command(name="reply", aliases=["r"])
async def reply(
self, ctx: GuildContext, *, message: Annotated[str, commands.clean_content]
Expand Down
34 changes: 16 additions & 18 deletions bot/libs/utils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ def create_premade_embed(title: str, description: str) -> ErrorEmbed:
return embed


def build_cooldown_embed(error: commands.CommandOnCooldown) -> ErrorEmbed:
embed = ErrorEmbed()
embed.timestamp = discord.utils.utcnow()
embed.title = "Command On Cooldown"
embed.description = (
f"This command is on cooldown. Try again in {error.retry_after:.2f}s"
)
return embed


async def send_error_embed(ctx: commands.Context, error: commands.CommandError) -> None:
if isinstance(error, commands.CommandInvokeError) or isinstance(
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(embed=build_cooldown_embed(error))
elif isinstance(error, commands.CommandInvokeError) or isinstance(
error, commands.HybridCommandError
):
await ctx.send(embed=produce_error_embed(error))
elif isinstance(error, commands.CommandNotFound):
await ctx.send(
elif isinstance(error, commands.NoPrivateMessage):
await ctx.author.send(
embed=create_premade_embed(
"Command not found",
"The command you were looking for could not be found",
)
)
elif isinstance(error, commands.NotOwner):
# Basically completely silence it making people not know what happened
return
elif isinstance(error, commands.MissingPermissions):
missing_perms = ", ".join(error.missing_permissions).rstrip(",")
await ctx.send(
embed=create_premade_embed(
"Missing Permissions",
f"You are missing the following permissions: {missing_perms}",
"Guild Only", "This command cannot be used in private messages"
)
)
elif isinstance(error, commands.MissingRequiredArgument):
Expand All @@ -59,5 +59,3 @@ async def send_error_embed(ctx: commands.Context, error: commands.CommandError)
f"You are missing the following argument(s): {error.param.name}",
)
)
else:
await ctx.send(embed=produce_error_embed(error))

0 comments on commit c37a634

Please sign in to comment.