Core - #5891 Recovering Server Prefixes (#5918)

This commit is contained in:
AntonioNarra 2022-12-01 18:58:11 -05:00 committed by GitHub
parent bbb15924b9
commit b018a76b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3351,13 +3351,16 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
# -- End Set Ownernotifications Commands -- ### # -- End Set Ownernotifications Commands -- ###
@_set.command(name="showsettings") @_set.command(name="showsettings")
async def _set_showsettings(self, ctx: commands.Context): async def _set_showsettings(self, ctx: commands.Context, server: discord.Guild = None):
""" """
Show the current settings for [botname]. Show the current settings for [botname]. Accepts optional guild parameter if its prefix must be recovered.
""" """
if ctx.guild: if server is None:
guild_data = await ctx.bot._config.guild(ctx.guild).all() server = ctx.guild
guild = ctx.guild
if server:
guild_data = await ctx.bot._config.guild(server).all()
guild = server
admin_role_ids = guild_data["admin_role"] admin_role_ids = guild_data["admin_role"]
admin_role_names = [r.name for r in guild.roles if r.id in admin_role_ids] admin_role_names = [r.name for r in guild.roles if r.id in admin_role_ids]
admin_roles_str = ( admin_roles_str = (
@ -3367,9 +3370,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
mod_role_names = [r.name for r in guild.roles if r.id in mod_role_ids] mod_role_names = [r.name for r in guild.roles if r.id in mod_role_ids]
mod_roles_str = humanize_list(mod_role_names) if mod_role_names else _("Not Set.") mod_roles_str = humanize_list(mod_role_names) if mod_role_names else _("Not Set.")
guild_locale = await i18n.get_locale_from_guild(self.bot, ctx.guild) guild_locale = await i18n.get_locale_from_guild(self.bot, server)
guild_regional_format = ( guild_regional_format = (
await i18n.get_regional_format_from_guild(self.bot, ctx.guild) or guild_locale await i18n.get_regional_format_from_guild(self.bot, server) or guild_locale
) )
guild_settings = _( guild_settings = _(
@ -3386,7 +3389,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
else: else:
guild_settings = "" guild_settings = ""
prefixes = await ctx.bot._prefix_cache.get_prefixes(ctx.guild) prefixes = await ctx.bot._prefix_cache.get_prefixes(server)
global_data = await ctx.bot._config.all() global_data = await ctx.bot._config.all()
locale = global_data["locale"] locale = global_data["locale"]
regional_format = global_data["regional_format"] or locale regional_format = global_data["regional_format"] or locale
@ -3599,8 +3602,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
@_set.command(name="serverprefix", aliases=["serverprefixes"]) @_set.command(name="serverprefix", aliases=["serverprefixes"])
@checks.admin_or_permissions(manage_guild=True) @checks.admin_or_permissions(manage_guild=True)
@commands.guild_only() async def _set_serverprefix(
async def _set_serverprefix(self, ctx: commands.Context, *prefixes: str): self, ctx: commands.Context, server: Optional[discord.Guild], *prefixes: str
):
""" """
Sets [botname]'s server prefix(es). Sets [botname]'s server prefix(es).
@ -3613,12 +3617,16 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
- `[p]set serverprefix "! "` - Quotes are needed to use spaces in prefixes. - `[p]set serverprefix "! "` - Quotes are needed to use spaces in prefixes.
- `[p]set serverprefix "@[botname] "` - This uses a mention as the prefix. - `[p]set serverprefix "@[botname] "` - This uses a mention as the prefix.
- `[p]set serverprefix ! ? .` - Sets multiple prefixes. - `[p]set serverprefix ! ? .` - Sets multiple prefixes.
- `[p]set serverprefix "Red - Discord Bot" ? - Sets the prefix for a specific server. Quotes are needed to use spaces in the server name.
**Arguments:** **Arguments:**
- `[prefixes...]` - The prefixes the bot will respond to on this server. Leave blank to clear server prefixes. - `[prefixes...]` - The prefixes the bot will respond to on this server. Leave blank to clear server prefixes.
""" """
if server is None:
server = ctx.guild
if not prefixes: if not prefixes:
await ctx.bot.set_prefixes(guild=ctx.guild, prefixes=[]) await ctx.bot.set_prefixes(guild=server, 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): if any(prefix.startswith("/") for prefix in prefixes):
@ -3630,7 +3638,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
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
prefixes = sorted(prefixes, reverse=True) prefixes = sorted(prefixes, reverse=True)
await ctx.bot.set_prefixes(guild=ctx.guild, prefixes=prefixes) await ctx.bot.set_prefixes(guild=server, prefixes=prefixes)
if len(prefixes) == 1: if len(prefixes) == 1:
await ctx.send(_("Server prefix set.")) await ctx.send(_("Server prefix set."))
else: else: