mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Prevent / being used in bot or server prefixes (#5693)
* Update `[p]set prefix`/`[p]set serverprefix` * Update cli * style * update __main__ * style * improve checks * Raise in Red.set_prefixes, update responses * uniform responses * Fixes * Keep generator variable names consistent across files
This commit is contained in:
parent
febc503df1
commit
ae80e62a13
@ -138,6 +138,11 @@ async def _edit_prefix(red, prefix, no_prompt):
|
|||||||
if not prefixes:
|
if not prefixes:
|
||||||
print("You need to pass at least one prefix!")
|
print("You need to pass at least one prefix!")
|
||||||
continue
|
continue
|
||||||
|
if any(prefix.startswith("/") for prefix in prefixes):
|
||||||
|
print(
|
||||||
|
"Prefixes cannot start with '/', as it conflicts with Discord's slash commands."
|
||||||
|
)
|
||||||
|
continue
|
||||||
prefixes = sorted(prefixes, reverse=True)
|
prefixes = sorted(prefixes, reverse=True)
|
||||||
await red._config.prefix.set(prefixes)
|
await red._config.prefix.set(prefixes)
|
||||||
print("Prefixes updated.\n")
|
print("Prefixes updated.\n")
|
||||||
|
|||||||
@ -70,6 +70,11 @@ async def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
|||||||
if len(prefix) > 10:
|
if len(prefix) > 10:
|
||||||
if not confirm("Your prefix seems overly long. Are you sure that it's correct?"):
|
if not confirm("Your prefix seems overly long. Are you sure that it's correct?"):
|
||||||
prefix = ""
|
prefix = ""
|
||||||
|
if prefix.startswith("/"):
|
||||||
|
print(
|
||||||
|
"Prefixes cannot start with '/', as it conflicts with Discord's slash commands."
|
||||||
|
)
|
||||||
|
prefix = ""
|
||||||
if prefix:
|
if prefix:
|
||||||
await red._config.prefix.set([prefix])
|
await red._config.prefix.set([prefix])
|
||||||
|
|
||||||
|
|||||||
@ -3536,6 +3536,11 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
|||||||
**Arguments:**
|
**Arguments:**
|
||||||
- `<prefixes...>` - The prefixes the bot will respond to globally.
|
- `<prefixes...>` - The prefixes the bot will respond to globally.
|
||||||
"""
|
"""
|
||||||
|
if any(prefix.startswith("/") for prefix in prefixes):
|
||||||
|
await ctx.send(
|
||||||
|
_("Prefixes cannot start with '/', as it conflicts with Discord's slash commands.")
|
||||||
|
)
|
||||||
|
return
|
||||||
if any(len(x) > MAX_PREFIX_LENGTH for x in prefixes):
|
if any(len(x) > MAX_PREFIX_LENGTH for x in prefixes):
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
_(
|
_(
|
||||||
@ -3584,6 +3589,11 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
|||||||
await ctx.bot.set_prefixes(guild=ctx.guild, prefixes=[])
|
await ctx.bot.set_prefixes(guild=ctx.guild, prefixes=[])
|
||||||
await ctx.send(_("Server prefixes have been reset."))
|
await ctx.send(_("Server prefixes have been reset."))
|
||||||
return
|
return
|
||||||
|
if any(prefix.startswith("/") for prefix in prefixes):
|
||||||
|
await ctx.send(
|
||||||
|
_("Prefixes cannot start with '/', as it conflicts with Discord's slash commands.")
|
||||||
|
)
|
||||||
|
return
|
||||||
if any(len(x) > MAX_PREFIX_LENGTH for x in prefixes):
|
if any(len(x) > MAX_PREFIX_LENGTH for x in prefixes):
|
||||||
await ctx.send(_("You cannot have a prefix longer than 25 characters."))
|
await ctx.send(_("You cannot have a prefix longer than 25 characters."))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -45,6 +45,10 @@ class PrefixManager:
|
|||||||
prefixes = prefixes or []
|
prefixes = prefixes or []
|
||||||
if not isinstance(prefixes, list) and not all(isinstance(pfx, str) for pfx in prefixes):
|
if not isinstance(prefixes, list) and not all(isinstance(pfx, str) for pfx in prefixes):
|
||||||
raise TypeError("Prefixes must be a list of strings")
|
raise TypeError("Prefixes must be a list of strings")
|
||||||
|
if any(prefix.startswith("/") for prefix in prefixes):
|
||||||
|
raise ValueError(
|
||||||
|
"Prefixes cannot start with '/', as it conflicts with Discord's slash commands."
|
||||||
|
)
|
||||||
prefixes = sorted(prefixes, reverse=True)
|
prefixes = sorted(prefixes, reverse=True)
|
||||||
if gid is None:
|
if gid is None:
|
||||||
if not prefixes:
|
if not prefixes:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user