diff --git a/techsupport_bot/commands/help.py b/techsupport_bot/commands/help.py index e2449a725..b1e9a0c10 100644 --- a/techsupport_bot/commands/help.py +++ b/techsupport_bot/commands/help.py @@ -126,8 +126,25 @@ async def help_command(self, ctx: commands.Context, search_term: str = "") -> No ) ) + # Deal with special modmail commands, if this is the modmail guild + if self.bot.file_config.modmail_config.enable_modmail and ctx.guild.id == int( + self.bot.file_config.modmail_config.modmail_guild + ): + modmail_cog = ctx.bot.get_cog("Modmail") + if modmail_cog: + modmail_commands = modmail_cog.modmail_commands_list() + for command in modmail_commands: + all_command_list.append( + PrintableCommand( + prefix=command[0], + name=command[1], + usage=command[2].strip(), + description=f"Modmail only: {command[3]}", + ) + ) + # Sort and search the commands - sorted_commands = sorted(all_command_list, key=lambda x: x.name) + sorted_commands = sorted(all_command_list, key=lambda x: x.name.lower()) filtered_commands = [ command for command in sorted_commands diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 58ac3f605..0bc015a36 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -1,8 +1,8 @@ """ Runs a bot that can be messaged to create modmail threads Unit tests: False -Config: - File: enable_modmail, disable_thread_creation, modmail_auth_token, modmail_prefix, +Config: + File: enable_modmail, disable_thread_creation, modmail_auth_token, modmail_prefix, modmail_guild, modmail_forum_channel, modmail_log_channel Command: aliases, automatic_responses, modmail_roles, roles_to_ping, thread_creation_message API: None @@ -16,7 +16,7 @@ import asyncio import re from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Tuple import discord import expiringdict @@ -1242,12 +1242,50 @@ async def modmail(self, ctx): # Executed if there are no/invalid args supplied await auxiliary.extension_help(self, ctx, self.__module__[9:]) + def modmail_commands_list(self) -> list[Tuple[str, str, str, str]]: + """ + Builds a list of commands to allow both .modmail commands and .help to use them + Commands are sorted into a 4 part tuple: + [0] - prefix + [1] - command name + [2] - command usage + [3] - command description + """ + prefix = self.bot.file_config.modmail_config.modmail_prefix + commands_list = [ + (prefix, "reply", "[message]", "Sends a message"), + (prefix, "areply", "[message]", "Sends a message anonymously"), + (prefix, "send", "[factoid]", "Sends the user a factoid"), + ( + prefix, + "close", + "", + "Closes the thread, sends the user a closure message", + ), + ( + prefix, + "tclose", + "", + "Closes a thread in 5 minutes unless rerun or a message is sent", + ), + (prefix, "sclose", "", "Closes a thread without sending the user anything"), + ( + prefix, + "tsclose", + "", + ( + "Closes a thread in 5 minutes unless rerun or a message is sent, closes " + "without sending the user anything" + ), + ), + ] + return commands_list + @auxiliary.with_typing @commands.check(has_modmail_management_role) @modmail.command( name="commands", description="Lists all commands you can use in modmail threads", - usage="[user-to-ban]", ) async def modmail_commands(self, ctx: commands.Context): """Lists all commands usable in modmail threads @@ -1255,6 +1293,7 @@ async def modmail_commands(self, ctx: commands.Context): Args: ctx (commands.Context): Context of the command execution """ + list_of_modmail_commands = self.modmail_commands_list() prefix = self.bot.file_config.modmail_config.modmail_prefix embed = discord.Embed( color=discord.Color.green(), @@ -1263,26 +1302,16 @@ async def modmail_commands(self, ctx: commands.Context): ) embed.timestamp = datetime.utcnow() - # I hate this - embed.add_field(name="reply", value="Sends a message").add_field( - name="areply", value="Sends a message anonymously" - ).add_field(name="send", value="Sends the user a factoid").add_field( - # ZWSP used to separate the replies from closes, makes the fields a bit prettier - name="\u200B", - value="\u200B", - inline=False, - ).add_field( - name="close", value="Closes the thread, sends the user a closure message" - ).add_field( - name="tclose", - value="Closes a thread in 5 minutes unless rerun or a message " + "is sent", - ).add_field( - name="sclose", value="Closes a thread without sending the user anything" - ).add_field( - name="tsclose", - value="Closes a thread in 5 minutes unless rerun or a message" - + " is sent, closes without sending the user anything", - ) + # First three are reply commands + for command in list_of_modmail_commands[:3]: + embed.add_field(name=command[1], value=command[3]) + + # ZWSP used to separate the replies from closes, makes the fields a bit prettier + embed.add_field(name="\u200b", value="\u200b", inline=False) + + # Last four are closing commands + for command in list_of_modmail_commands[3:]: + embed.add_field(name=command[1], value=command[3]) await ctx.send(embed=embed)