feat: Require group prefix for hybrid commands

Added a _require_group_prefix check to all hybrid commands in each cog to ensure commands are only executed when invoked with the appropriate group prefix. Also updated error handling in bot.py to silently ignore CheckFailure errors. This improves command organization and prevents accidental command execution outside their intended context.
This commit is contained in:
neoarz
2025-09-29 09:59:56 -04:00
parent f8123b43a2
commit 3f4254dcdc
8 changed files with 154 additions and 0 deletions

View File

@@ -31,6 +31,16 @@ class Miscellaneous(commands.GroupCog, name="misc"):
else:
await context.send(f"Unknown miscellaneous command: {name}")
def _require_group_prefix(context: Context) -> bool:
if getattr(context, "interaction", None):
return True
group = getattr(getattr(context, "cog", None), "qualified_name", "").lower()
if not group:
return True
prefix = context.prefix or ""
content = context.message.content.strip().lower()
return content.startswith(f"{prefix}{group} ")
@miscellaneous_group.command(name="rr")
async def miscellaneous_group_rr(self, context: Context):
await self._invoke_hybrid(context, "rr")
@@ -51,6 +61,7 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def miscellaneous_group_keanu(self, context: Context):
await self._invoke_hybrid(context, "keanu")
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="rr",
description="Rickroll"
@@ -58,6 +69,7 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def rr(self, context):
return await rr_command()(self, context)
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="labubu",
description="Labubu ASCII art"
@@ -65,6 +77,7 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def labubu(self, context):
return await labubu_command()(self, context)
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="tryitandsee",
description="Try it and see"
@@ -72,6 +85,7 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def tryitandsee(self, context):
return await tryitandsee_command()(self, context)
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="piracy",
description="FBI Anti Piracy Warning"
@@ -79,6 +93,7 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def piracy(self, context):
return await piracy_command()(self, context)
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="keanu",
description="Reeves"