mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
[V3 Core] Command group automatic help (#1790)
* decorator inheritence * black format * add autohelp * modify commands to use autohelp
This commit is contained in:
@@ -97,7 +97,27 @@ class Group(Command, commands.Group):
|
||||
in.
|
||||
"""
|
||||
|
||||
pass
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.autohelp = kwargs.pop("autohelp", False)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
async def invoke(self, ctx):
|
||||
|
||||
view = ctx.view
|
||||
previous = view.index
|
||||
view.skip_ws()
|
||||
trigger = view.get_word()
|
||||
if trigger:
|
||||
ctx.subcommand_passed = trigger
|
||||
ctx.invoked_subcommand = self.all_commands.get(trigger, None)
|
||||
view.index = previous
|
||||
view.previous = previous
|
||||
|
||||
if ctx.invoked_subcommand is None or self == ctx.invoked_subcommand:
|
||||
if self.autohelp and not self.invoke_without_command:
|
||||
await ctx.send_help()
|
||||
|
||||
await super().invoke(ctx)
|
||||
|
||||
|
||||
# decorators
|
||||
|
||||
@@ -321,7 +321,7 @@ class Core(CoreLogic):
|
||||
|
||||
return fmt.format(d=days, h=hours, m=minutes, s=seconds)
|
||||
|
||||
@commands.group()
|
||||
@commands.group(autohelp=True)
|
||||
async def embedset(self, ctx: commands.Context):
|
||||
"""
|
||||
Commands for toggling embeds on or off.
|
||||
@@ -341,7 +341,6 @@ class Core(CoreLogic):
|
||||
user_setting = await self.bot.db.user(ctx.author).embeds()
|
||||
text += "User setting: {}".format(user_setting)
|
||||
await ctx.send(box(text))
|
||||
await ctx.send_help()
|
||||
|
||||
@embedset.command(name="global")
|
||||
@checks.is_owner()
|
||||
@@ -528,7 +527,7 @@ class Core(CoreLogic):
|
||||
formed = self._get_package_strings(not_found, fmt, ("was", "were"))
|
||||
await ctx.send(formed)
|
||||
|
||||
@commands.group()
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
async def unload(self, ctx, *, cog_name: str):
|
||||
"""Unloads packages"""
|
||||
@@ -599,7 +598,7 @@ class Core(CoreLogic):
|
||||
pass
|
||||
await ctx.bot.shutdown(restart=True)
|
||||
|
||||
@commands.group(name="set")
|
||||
@commands.group(name="set", autohelp=True)
|
||||
async def _set(self, ctx):
|
||||
"""Changes Red's settings"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
@@ -625,7 +624,6 @@ class Core(CoreLogic):
|
||||
f"Locale: {locale}"
|
||||
)
|
||||
await ctx.send(box(settings))
|
||||
await ctx.send_help()
|
||||
|
||||
@_set.command()
|
||||
@checks.guildowner()
|
||||
@@ -983,12 +981,11 @@ class Core(CoreLogic):
|
||||
ctx.bot.disable_sentry()
|
||||
await ctx.send(_("Done. Sentry logging is now disabled."))
|
||||
|
||||
@commands.group()
|
||||
@commands.group(autohelp=True)
|
||||
@checks.is_owner()
|
||||
async def helpset(self, ctx: commands.Context):
|
||||
"""Manage settings for the help command."""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
pass
|
||||
|
||||
@helpset.command(name="pagecharlimit")
|
||||
async def helpset_pagecharlimt(self, ctx: commands.Context, limit: int):
|
||||
@@ -1269,14 +1266,13 @@ class Core(CoreLogic):
|
||||
else:
|
||||
await ctx.send(_("Message delivered to {}").format(destination))
|
||||
|
||||
@commands.group()
|
||||
@commands.group(autohelp=True)
|
||||
@checks.is_owner()
|
||||
async def whitelist(self, ctx):
|
||||
"""
|
||||
Whitelist management commands.
|
||||
"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
pass
|
||||
|
||||
@whitelist.command(name="add")
|
||||
async def whitelist_add(self, ctx, user: discord.User):
|
||||
@@ -1328,14 +1324,13 @@ class Core(CoreLogic):
|
||||
await ctx.bot.db.whitelist.set([])
|
||||
await ctx.send(_("Whitelist has been cleared."))
|
||||
|
||||
@commands.group()
|
||||
@commands.group(autohelp=True)
|
||||
@checks.is_owner()
|
||||
async def blacklist(self, ctx):
|
||||
"""
|
||||
blacklist management commands.
|
||||
"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
pass
|
||||
|
||||
@blacklist.command(name="add")
|
||||
async def blacklist_add(self, ctx, user: discord.User):
|
||||
|
||||
Reference in New Issue
Block a user