Add CommandConverter and CogConverter + add usage in Core (#5037)

* add commands, cog converter

* properly use type_checking

* make core commands use command converter

* update commands to use cogconverter

* fix undefined variable name, style

* Update redbot/core/commands/converter.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/commands/converter.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* update cog argument names

* update documentation arg names

* update more docs

* This new Sphinx is annoying about this...

* I'm questioning my skills

* Fix name error in `[p]embedset showsettings` when command is not given

* Do not use the new cog converter in `[p]command enablecog`

This is needed so that a cog that isn't loaded but was disabled
can be enabled back.

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
PhenoM4n4n
2021-09-07 14:43:29 -07:00
committed by GitHub
parent 63fd7cc95f
commit e5b236fb1c
4 changed files with 95 additions and 115 deletions

View File

@@ -45,6 +45,8 @@ __all__ = [
"parse_relativedelta",
"parse_timedelta",
"Literal",
"CommandConverter",
"CogConverter",
]
_ = Translator("commands.converter", __file__)
@@ -526,3 +528,29 @@ if not TYPE_CHECKING:
return cls(k)
else:
return cls((k,))
if TYPE_CHECKING:
CommandConverter = dpy_commands.Command
CogConverter = dpy_commands.Cog
else:
class CommandConverter(dpy_commands.Converter):
"""Converts a command name to the matching `redbot.core.commands.Command` object."""
async def convert(self, ctx: "Context", argument: str):
arg = argument.strip()
command = ctx.bot.get_command(arg)
if not command:
raise BadArgument(_('Command "{arg}" not found.').format(arg=arg))
return command
class CogConverter(dpy_commands.Converter):
"""Converts a cog name to the matching `redbot.core.commands.Cog` object."""
async def convert(self, ctx: "Context", argument: str):
arg = argument.strip()
cog = ctx.bot.get_cog(arg)
if not cog:
raise BadArgument(_('Cog "{arg}" not found.').format(arg=arg))
return cog