[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.
This commit is contained in:
PredaaA 2019-11-23 00:54:01 +01:00 committed by Michael H
parent a3140b6659
commit 77742179c0
2 changed files with 56 additions and 1 deletions

View File

@ -0,0 +1 @@
Adds a command to list disabled commands globally or per guild.

View File

@ -33,7 +33,14 @@ from . import (
) )
from .utils import create_backup from .utils import create_backup
from .utils.predicates import MessagePredicate 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 from .commands.requires import PrivilegeLevel
@ -1877,6 +1884,53 @@ class Core(commands.Cog, CoreLogic):
"""Manage the bot's commands.""" """Manage the bot's commands."""
pass 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) @command_manager.group(name="disable", invoke_without_command=True)
async def command_disable(self, ctx: commands.Context, *, command: str): async def command_disable(self, ctx: commands.Context, *, command: str):
"""Disable a command. """Disable a command.