Update help

This commit is contained in:
Declan Chidlow 2024-07-12 19:09:54 +08:00
parent 0cd5a4e21c
commit 4bc049064b

View file

@ -3,115 +3,108 @@ import { commands, DEFAULT_PREFIX, ownerIDs } from "../../modules/command_handle
import MessageCommandContext from "../../../struct/MessageCommandContext"; import MessageCommandContext from "../../../struct/MessageCommandContext";
import CommandCategory from "../../../struct/commands/CommandCategory"; import CommandCategory from "../../../struct/commands/CommandCategory";
const categories: { [key in CommandCategory]: { const categories: {
friendlyName: string, [key in CommandCategory]: {
description: string, friendlyName: string;
aliases: string[], description: string;
} } = { aliases: string[];
[CommandCategory.Moderation]: { };
friendlyName: 'Moderation', } = {
description: 'Moderation-focused commands', [CommandCategory.Moderation]: {
aliases: [ 'mod' ], friendlyName: "Moderation",
}, description: "Moderation-focused commands",
[CommandCategory.Config]: { aliases: ["moderation", "mod"],
friendlyName: 'Configuration', },
description: 'Configure AutoMod', [CommandCategory.Config]: {
aliases: [ 'conf', 'config' ], friendlyName: "Configuration",
}, description: "Configure AutoMod",
[CommandCategory.Owner]: { aliases: ["configuration", "config", "conf"],
friendlyName: 'Owner', },
description: 'Owner-only commands for managing AutoMod', [CommandCategory.Owner]: {
aliases: [], friendlyName: "Owner",
}, description: "Owner-only commands for managing AutoMod",
[CommandCategory.Miscellaneous]: { aliases: [ "owner" ],
friendlyName: 'Miscellaneous', },
description: 'Assorted extras', [CommandCategory.Miscellaneous]: {
aliases: [ 'misc' ], friendlyName: "Miscellaneous",
}, description: "Assorted extras",
[CommandCategory.None]: { aliases: ["miscellaneous", "misc"],
friendlyName: 'Uncategorized', },
description: 'Uncategorized commands', [CommandCategory.None]: {
aliases: [], friendlyName: "Uncategorized",
}, description: "Uncategorized commands",
aliases: [],
},
}; };
export default { export default {
name: 'help', name: "help",
aliases: null, aliases: null,
description: 'Help command.', description: "Help command.",
removeEmptyArgs: true, removeEmptyArgs: true,
category: CommandCategory.Miscellaneous, category: CommandCategory.Miscellaneous,
run: async (message: MessageCommandContext, args: string[]) => { run: async (message: MessageCommandContext, args: string[]) => {
const isBotOwner = ownerIDs.includes(message.authorId!); const isBotOwner = ownerIDs.includes(message.authorId!);
const prefix = DEFAULT_PREFIX; // TODO: fetch prefix from server config const prefix = DEFAULT_PREFIX; // TODO: fetch prefix from server config
let searchInput = args.shift()?.toLowerCase(); let searchInput = args.shift()?.toLowerCase();
if (!searchInput) { if (!searchInput) {
let msg = `## AutoMod Help\n` + let msg =
`Type **${prefix}help [category]** to view see all commands or **${prefix}help [command]** to learn more about a command.\n\n` `## AutoMod Help\n` +
+ `### [Open Server Settings]` `Type **${prefix}help [category]** to view see all commands or **${prefix}help [command]** to learn more about a command.\n\n` +
+ `(<${process.env.WEB_UI_URL || 'https://automod.vale.rocks'}/dashboard/${message.channel?.serverId}>)\n\n`; `### [Open Server Settings]` +
`(<${process.env.WEB_UI_URL || "https://automod.vale.rocks"}/dashboard/${message.channel?.serverId}>)\n\n`;
let total = 0; let total = 0;
for (const categoryName in CommandCategory) { for (const categoryName in CommandCategory) {
let cmdCount = commands.filter( let cmdCount = commands.filter((cmd) => cmd.category == categoryName && (cmd.restrict == "BOTOWNER" ? isBotOwner : true)).length;
cmd => (cmd.category == categoryName) &&
(cmd.restrict == 'BOTOWNER' ? isBotOwner : true) // Ensure owner commands are only shown to bot owner
).length;
if (cmdCount > 0) { if (cmdCount > 0) {
total++; total++;
const category = (categories as any)[categoryName]; const category = (categories as any)[categoryName];
msg += `**${category.friendlyName}**\n` + msg += `**${category.friendlyName}**\n` + ` \u200b \u200b ↳ ${category.description} \u200b $\\big |$ \u200b **${cmdCount}** command${cmdCount == 1 ? "" : "s"}\n`;
` \u200b \u200b ↳ ${(category.description)} \u200b $\\big |$ \u200b **${cmdCount}** command${cmdCount == 1 ? '' : 's'}\n`; }
} }
}
msg += `\n##### Categories: ${total}`; msg += `\n##### Categories: ${total}`;
await message.reply(msg); await message.reply(msg);
} else { } else {
let [ categoryName, category ] = Object.entries(categories).find( let [categoryName, category] =
c => c[1].friendlyName.toLowerCase() == searchInput Object.entries(categories).find((c) => c[1].friendlyName.toLowerCase() == searchInput || c[0].toLowerCase() == searchInput) ||
|| c[0].toLowerCase() == searchInput Object.entries(categories).find((c) => c[1].aliases.find((k) => k.toLowerCase() == searchInput)) ||
) || Object.entries(categories).find( [];
c => c[1].aliases.find(k => k.toLowerCase() == searchInput) if (category && !searchInput.startsWith(prefix)) {
) || []; let msg = `**AutoMod Help** - Category: ${category.friendlyName}\n` + `${category.description}\n\n` + `Type **${prefix}help [command]** to learn more about a command.\n\n`;
if (category && !searchInput.startsWith(prefix)) {
let msg = `**AutoMod Help** - Category: ${category.friendlyName}\n`
+ `${category.description}\n\n`
+ `Type **${prefix}help [command]** to learn more about a command.\n\n`;
let cmdList = commands.filter(c => (c.category || 'uncategorized') == categoryName); let cmdList = commands.filter((c) => (c.category || "uncategorized") == categoryName);
if (cmdList.length > 0) { if (cmdList.length > 0) {
for (const cmd of cmdList) { for (const cmd of cmdList) {
msg += `**${prefix}${cmd.name}** \u200b $\\big |$ \u200b ${cmd.description}\n`; msg += `**${prefix}${cmd.name}** \u200b $\\big |$ \u200b ${cmd.description}\n`;
msg += '\n'; msg += "\n";
} }
msg += `##### Total: ${cmdList.length}`; msg += `##### Total: ${cmdList.length}`;
} else msg += `### This category is empty.`; } else msg += `### This category is empty.`;
await message.reply(msg); await message.reply(msg);
} else { } else {
if (searchInput.startsWith(prefix)) searchInput = searchInput.substring(prefix.length); if (searchInput.startsWith(prefix)) searchInput = searchInput.substring(prefix.length);
let cmd = commands.find(c => c.name.toLowerCase() == searchInput) let cmd = commands.find((c) => c.name.toLowerCase() == searchInput) || commands.find((c) => c.aliases && c.aliases.find((k) => k.toLowerCase() == searchInput));
|| commands.find(c => c.aliases && c.aliases.find(k => k.toLowerCase() == searchInput));
if (!cmd) { if (!cmd) {
return message.reply(`I can't find any command or category matching \`${searchInput}\`.`); return message.reply(`I can't find any command or category matching \`${searchInput}\`.`);
} else { } else {
let msg = `**AutoMod Help** - Command: ${cmd.name}\n` let msg = `**AutoMod Help** - Command: ${cmd.name}\n` + `${cmd.description}\n\n`;
+ `${cmd.description}\n\n`;
if (cmd.syntax) msg += `Syntax: \`${cmd.syntax}\`\n`; if (cmd.syntax) msg += `Syntax: \`${cmd.syntax}\`\n`;
msg += 'Aliases: ' + (cmd.aliases ? `\`${cmd.aliases.join(`\`, \``)}\`` : 'None') + '\n'; msg += "Aliases: " + (cmd.aliases ? `\`${cmd.aliases.join(`\`, \``)}\`` : "None") + "\n";
message.reply(msg); message.reply(msg);
} }
} }
} }
} },
} as Command; } as Command;