Skip to content

Commit

Permalink
Prohibit zero-length prefixes in [p]set [server]prefix (#6013)
Browse files Browse the repository at this point in the history
Co-authored-by: Kreusada Ignad Amredes <[email protected]>
  • Loading branch information
japandotorg and Kreusada authored Feb 27, 2024
1 parent 9345b69 commit 9dc7462
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def entity_transformer(statement: str) -> str:
TokenConverter = commands.get_dict_converter(delims=[" ", ",", ";"])

MAX_PREFIX_LENGTH = 25
MINIMUM_PREFIX_LENGTH = 1


class CoreLogic:
Expand Down Expand Up @@ -4052,6 +4053,24 @@ async def _set_prefix(self, ctx: commands.Context, *prefixes: str):
_("Prefixes cannot start with '/', as it conflicts with Discord's slash commands.")
)
return
if any(len(x) < MINIMUM_PREFIX_LENGTH for x in prefixes):
await ctx.send(
_(
"Warning: A prefix is below the recommended length (1 character).\n"
"Do you want to continue?"
)
+ " (yes/no)"
)
pred = MessagePredicate.yes_or_no(ctx)
try:
await self.bot.wait_for("message", check=pred, timeout=30)
except asyncio.TimeoutError:
await ctx.send(_("Response timed out."))
return
else:
if pred.result is False:
await ctx.send(_("Cancelled."))
return
if any(len(x) > MAX_PREFIX_LENGTH for x in prefixes):
await ctx.send(
_(
Expand Down Expand Up @@ -4111,6 +4130,9 @@ async def _set_serverprefix(
_("Prefixes cannot start with '/', as it conflicts with Discord's slash commands.")
)
return
if any(len(x) < MINIMUM_PREFIX_LENGTH for x in prefixes):
await ctx.send(_("You cannot have a prefix shorter than 1 character."))
return
if any(len(x) > MAX_PREFIX_LENGTH for x in prefixes):
await ctx.send(_("You cannot have a prefix longer than 25 characters."))
return
Expand Down

0 comments on commit 9dc7462

Please sign in to comment.