Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions documentation/Extension-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command>`.
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:<extension-name>`


## Command definition

Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/commandcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/duck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/factoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions techsupport_bot/commands/grab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/hangman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
"""
Expand Down
8 changes: 2 additions & 6 deletions techsupport_bot/commands/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion techsupport_bot/commands/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions techsupport_bot/commands/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions techsupport_bot/commands/xkcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
57 changes: 0 additions & 57 deletions techsupport_bot/core/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import discord
import munch
import ui
from discord import app_commands
from discord.ext import commands

Expand Down Expand Up @@ -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.<name>, 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

Expand Down
Loading