diff --git a/documentation/Extension-howto.md b/documentation/Extension-howto.md index 586620ec3..74641cbbc 100644 --- a/documentation/Extension-howto.md +++ b/documentation/Extension-howto.md @@ -159,15 +159,11 @@ Even though it executes no code, we add an automatic help trigger that is called description="Long-description", ) async def command-group-name(): - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return ``` This defines a command group that is called using `.command-group-name `. The help is included and called if it is called by itself, should be included unless the command group itself serves a purpose. -Note: The help call uses `self.module[11:]` since that is the most reliable way to get the actual extension name, since it always contains `extensions:` - ## Command definition diff --git a/techsupport_bot/commands/chatgpt.py b/techsupport_bot/commands/chatgpt.py index 8628af51b..1784956f3 100644 --- a/techsupport_bot/commands/chatgpt.py +++ b/techsupport_bot/commands/chatgpt.py @@ -187,9 +187,7 @@ async def gptutil(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): Context of the invokation """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @gptutil.command( diff --git a/techsupport_bot/commands/commandcontrol.py b/techsupport_bot/commands/commandcontrol.py index cb42bf0a5..c3cf9b074 100644 --- a/techsupport_bot/commands/commandcontrol.py +++ b/techsupport_bot/commands/commandcontrol.py @@ -45,9 +45,7 @@ async def command_group(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @command_group.command( diff --git a/techsupport_bot/commands/config.py b/techsupport_bot/commands/config.py index 0da600ffd..a7571297c 100644 --- a/techsupport_bot/commands/config.py +++ b/techsupport_bot/commands/config.py @@ -41,9 +41,7 @@ async def config_command(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): the context object for the message """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @commands.has_permissions(administrator=True) @commands.guild_only() diff --git a/techsupport_bot/commands/duck.py b/techsupport_bot/commands/duck.py index 2552b1a67..f7433e5e3 100644 --- a/techsupport_bot/commands/duck.py +++ b/techsupport_bot/commands/duck.py @@ -478,9 +478,7 @@ async def duck(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @commands.guild_only() diff --git a/techsupport_bot/commands/echo.py b/techsupport_bot/commands/echo.py index b83ad8a62..92f585774 100644 --- a/techsupport_bot/commands/echo.py +++ b/techsupport_bot/commands/echo.py @@ -44,9 +44,7 @@ async def echo(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @echo.command( diff --git a/techsupport_bot/commands/emoji.py b/techsupport_bot/commands/emoji.py index 56d496d79..536c79e0a 100644 --- a/techsupport_bot/commands/emoji.py +++ b/techsupport_bot/commands/emoji.py @@ -174,7 +174,7 @@ async def emoji(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @emoji.command( diff --git a/techsupport_bot/commands/extension.py b/techsupport_bot/commands/extension.py index 80fdf9daa..7cd53ef11 100644 --- a/techsupport_bot/commands/extension.py +++ b/techsupport_bot/commands/extension.py @@ -127,9 +127,7 @@ async def extension_group(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @extension_group.command( diff --git a/techsupport_bot/commands/factoids.py b/techsupport_bot/commands/factoids.py index 0cb415e9c..5490f7f6d 100644 --- a/techsupport_bot/commands/factoids.py +++ b/techsupport_bot/commands/factoids.py @@ -1291,9 +1291,7 @@ async def factoid(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @commands.check(has_manage_factoids_role) diff --git a/techsupport_bot/commands/gate.py b/techsupport_bot/commands/gate.py index d36d8151a..48c921b2c 100644 --- a/techsupport_bot/commands/gate.py +++ b/techsupport_bot/commands/gate.py @@ -184,9 +184,7 @@ async def gate_command(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @commands.has_permissions(manage_messages=True) @commands.guild_only() diff --git a/techsupport_bot/commands/google.py b/techsupport_bot/commands/google.py index 79ffb2e00..259e222b3 100644 --- a/techsupport_bot/commands/google.py +++ b/techsupport_bot/commands/google.py @@ -90,9 +90,7 @@ async def google(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @commands.guild_only() diff --git a/techsupport_bot/commands/grab.py b/techsupport_bot/commands/grab.py index 1d278a858..fcdb9c60d 100644 --- a/techsupport_bot/commands/grab.py +++ b/techsupport_bot/commands/grab.py @@ -160,8 +160,7 @@ async def grabs(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @commands.guild_only() diff --git a/techsupport_bot/commands/hangman.py b/techsupport_bot/commands/hangman.py index 555acba30..aafef1522 100644 --- a/techsupport_bot/commands/hangman.py +++ b/techsupport_bot/commands/hangman.py @@ -332,9 +332,7 @@ async def hangman(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return hangman_app_group: app_commands.Group = app_commands.Group( name="hangman", description="Command Group for the Hangman Extension" diff --git a/techsupport_bot/commands/listen.py b/techsupport_bot/commands/listen.py index 30b218ac0..ac962defa 100644 --- a/techsupport_bot/commands/listen.py +++ b/techsupport_bot/commands/listen.py @@ -265,9 +265,7 @@ async def listen(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): the context object for the message """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @listen.command( description="Starts a listening job", usage="[src-channel] [dst-channel]" diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 86f6301ae..027a9e9dd 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -1283,9 +1283,7 @@ async def modmail(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return def modmail_commands_list(self: Self) -> list[tuple[str, str, str, str]]: """ diff --git a/techsupport_bot/commands/poll.py b/techsupport_bot/commands/poll.py index 27b1c381b..84a87b0eb 100644 --- a/techsupport_bot/commands/poll.py +++ b/techsupport_bot/commands/poll.py @@ -135,9 +135,7 @@ async def poll(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @poll.command( @@ -335,9 +333,7 @@ async def strawpoll(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @strawpoll.command( diff --git a/techsupport_bot/commands/relay.py b/techsupport_bot/commands/relay.py index 7680e03c7..4aee8d976 100644 --- a/techsupport_bot/commands/relay.py +++ b/techsupport_bot/commands/relay.py @@ -155,7 +155,7 @@ async def irc_base(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run """ - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @irc_base.command(name="maps", description="List all the maps for IRC") async def irc_maps(self: Self, ctx: commands.Context) -> None: diff --git a/techsupport_bot/commands/rules.py b/techsupport_bot/commands/rules.py index 246644faa..620295627 100644 --- a/techsupport_bot/commands/rules.py +++ b/techsupport_bot/commands/rules.py @@ -44,9 +44,7 @@ async def rule_group(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return async def get_guild_rules(self: Self, guild: discord.Guild) -> munch.Munch: """Gets the munchified rules for a given guild. diff --git a/techsupport_bot/commands/set.py b/techsupport_bot/commands/set.py index dee397730..eb25d5130 100644 --- a/techsupport_bot/commands/set.py +++ b/techsupport_bot/commands/set.py @@ -46,9 +46,7 @@ async def set_group(self: Self, ctx: commands.Context) -> None: Args: ctx (commands.Context): The context in which the command was run in """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return @auxiliary.with_typing @set_group.command( diff --git a/techsupport_bot/commands/xkcd.py b/techsupport_bot/commands/xkcd.py index 987d3ffa5..e68018f7b 100644 --- a/techsupport_bot/commands/xkcd.py +++ b/techsupport_bot/commands/xkcd.py @@ -53,9 +53,6 @@ async def xkcd( """ if number: await self.numbered_comic(ctx, number) - else: - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) @xkcd.command( name="random", @@ -116,7 +113,7 @@ async def shadow_number(self: Self, ctx: commands.Context, *, _: int) -> None: Args: ctx (commands.Context): The context generate by this command """ - await auxiliary.extension_help(self, ctx, self.__module__[9:]) + return async def numbered_comic(self: Self, ctx: commands.Context, number: int) -> None: """Gets the comic from XKCD by number diff --git a/techsupport_bot/core/auxiliary.py b/techsupport_bot/core/auxiliary.py index c724cbfbd..5c187c7d5 100644 --- a/techsupport_bot/core/auxiliary.py +++ b/techsupport_bot/core/auxiliary.py @@ -11,7 +11,6 @@ import discord import munch -import ui from discord import app_commands from discord.ext import commands @@ -492,62 +491,6 @@ def get_help_embed_for_extension( return embed -async def extension_help( - cog: cogs.BaseCog, ctx: commands.Context, extension_name: str -) -> None: - """Automatically prompts for help if improper syntax for an extension is called. - - The format for extension_name that's used is `self.__module__[11:]`, because - all extensions have the value set to extension., it's the most reliable - way to get the extension name regardless of aliases - - Args: - cog (cogs.BaseCog): The cog that needs the commands put into a help menu - ctx (commands.Context): context of the message - extension_name (str): the name of the extension to show the help for - """ - - # Checks whether the first given argument is valid if an argument is supplied - if len(ctx.message.content.split()) > 1: - arg = ctx.message.content.split().pop(1) - valid_commands = [] - valid_args = [] - # Loops through each command for said extension - for command in cog.bot.get_cog(cog.qualified_name).walk_commands(): - valid_commands.append(command.name) - valid_args.append(command.aliases) - - # Flatmaps nested lists, because aliases are returned as lists. - valid_args = [item for sublist in valid_args for item in sublist] - - # If argument isn't a valid command or alias, wait for confirmation to show help page - if arg not in valid_args and arg not in valid_commands: - view = ui.Confirm() - await view.send( - message="Invalid argument! Show help command?", - channel=ctx.channel, - author=ctx.author, - timeout=10, - ) - await view.wait() - if view.value != ui.ConfirmResponse.CONFIRMED: - return - - await ctx.send( - embed=get_help_embed_for_extension( - cog, extension_name, await cog.bot.get_prefix(ctx.message) - ) - ) - - # Executed if no arguments were supplied - elif len(ctx.message.content.split()) == 1: - await ctx.send( - embed=get_help_embed_for_extension( - cog, extension_name, await cog.bot.get_prefix(ctx.message) - ) - ) - - async def bot_admin_check_context(ctx: commands.Context) -> bool: """A simple check to put on a prefix command function to ensure that the caller is an admin