From 9dc7462d0f0fc6f7690c705cc652eaec9b2aadbb Mon Sep 17 00:00:00 2001 From: Lemon Rose <78662983+japandotorg@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:48:33 +0530 Subject: [PATCH] Prohibit zero-length prefixes in `[p]set [server]prefix` (#6013) Co-authored-by: Kreusada Ignad Amredes <67752638+Kreusada@users.noreply.github.com> --- redbot/core/core_commands.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 1b780b1ff7d..13c3d4c86b7 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -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: @@ -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( _( @@ -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