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
19 changes: 18 additions & 1 deletion techsupport_bot/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 53 additions & 24 deletions techsupport_bot/commands/modmail.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1242,19 +1242,58 @@ 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

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(),
Expand All @@ -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)

Expand Down