From 77742179c01bd820b6488ee3f7ce103c77c87614 Mon Sep 17 00:00:00 2001 From: PredaaA <46051820+PredaaA@users.noreply.github.com> Date: Sat, 23 Nov 2019 00:54:01 +0100 Subject: [PATCH] [Core] Add [p]listdisabled command (#3118) * Update core_commands.py * Create 3115.feature.rst * Rename 3115.feature.rst to 3118.feature.rst * Add a message if there's any disabled commands. * Use the same format as [p]command disable/enable * Make strings more i18n friendly. * Flame's requested changes. --- changelog.d/3118.feature.rst | 1 + redbot/core/core_commands.py | 56 +++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 changelog.d/3118.feature.rst diff --git a/changelog.d/3118.feature.rst b/changelog.d/3118.feature.rst new file mode 100644 index 000000000..dab83632a --- /dev/null +++ b/changelog.d/3118.feature.rst @@ -0,0 +1 @@ +Adds a command to list disabled commands globally or per guild. diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 218db18b1..f0362b230 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -33,7 +33,14 @@ from . import ( ) from .utils import create_backup from .utils.predicates import MessagePredicate -from .utils.chat_formatting import humanize_timedelta, pagify, box, inline, humanize_list +from .utils.chat_formatting import ( + box, + humanize_list, + humanize_number, + humanize_timedelta, + inline, + pagify, +) from .commands.requires import PrivilegeLevel @@ -1877,6 +1884,53 @@ class Core(commands.Cog, CoreLogic): """Manage the bot's commands.""" pass + @command_manager.group(name="listdisabled", invoke_without_command=True) + async def list_disabled(self, ctx: commands.Context): + """ + List disabled commands. + + If you're the bot owner, this will show global disabled commands by default. + """ + # Select the scope based on the author's privileges + if await ctx.bot.is_owner(ctx.author): + await ctx.invoke(self.list_disabled_global) + else: + await ctx.invoke(self.list_disabled_guild) + + @list_disabled.command(name="global") + async def list_disabled_global(self, ctx: commands.Context): + """List disabled commands globally.""" + disabled_list = await self.bot._config.disabled_commands() + if not disabled_list: + return await ctx.send(_("There aren't any globally disabled commands.")) + + if len(disabled_list) > 1: + header = _("{} commands are disabled globally.\n").format( + humanize_number(len(disabled_list)) + ) + else: + header = _("1 command is disabled globally.\n") + paged = [box(x) for x in pagify(humanize_list(disabled_list), page_length=1000)] + paged[0] = header + paged[0] + await ctx.send_interactive(paged) + + @list_disabled.command(name="guild") + async def list_disabled_guild(self, ctx: commands.Context): + """List disabled commands in this server.""" + disabled_list = await self.bot._config.guild(ctx.guild).disabled_commands() + if not disabled_list: + return await ctx.send(_("There aren't any disabled commands in {}.").format(ctx.guild)) + + if len(disabled_list) > 1: + header = _("{} commands are disabled in {}.\n").format( + humanize_number(len(disabled_list)), ctx.guild + ) + else: + header = _("1 command is disabled in {}.\n").format(ctx.guild) + paged = [box(x) for x in pagify(humanize_list(disabled_list), page_length=1000)] + paged[0] = header + paged[0] + await ctx.send_interactive(paged) + @command_manager.group(name="disable", invoke_without_command=True) async def command_disable(self, ctx: commands.Context, *, command: str): """Disable a command.