Update help
This commit is contained in:
parent
0cd5a4e21c
commit
4bc049064b
1 changed files with 88 additions and 95 deletions
|
@ -3,42 +3,44 @@ 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]: {
|
[CommandCategory.Moderation]: {
|
||||||
friendlyName: 'Moderation',
|
friendlyName: "Moderation",
|
||||||
description: 'Moderation-focused commands',
|
description: "Moderation-focused commands",
|
||||||
aliases: [ 'mod' ],
|
aliases: ["moderation", "mod"],
|
||||||
},
|
},
|
||||||
[CommandCategory.Config]: {
|
[CommandCategory.Config]: {
|
||||||
friendlyName: 'Configuration',
|
friendlyName: "Configuration",
|
||||||
description: 'Configure AutoMod',
|
description: "Configure AutoMod",
|
||||||
aliases: [ 'conf', 'config' ],
|
aliases: ["configuration", "config", "conf"],
|
||||||
},
|
},
|
||||||
[CommandCategory.Owner]: {
|
[CommandCategory.Owner]: {
|
||||||
friendlyName: 'Owner',
|
friendlyName: "Owner",
|
||||||
description: 'Owner-only commands for managing AutoMod',
|
description: "Owner-only commands for managing AutoMod",
|
||||||
aliases: [],
|
aliases: [ "owner" ],
|
||||||
},
|
},
|
||||||
[CommandCategory.Miscellaneous]: {
|
[CommandCategory.Miscellaneous]: {
|
||||||
friendlyName: 'Miscellaneous',
|
friendlyName: "Miscellaneous",
|
||||||
description: 'Assorted extras',
|
description: "Assorted extras",
|
||||||
aliases: [ 'misc' ],
|
aliases: ["miscellaneous", "misc"],
|
||||||
},
|
},
|
||||||
[CommandCategory.None]: {
|
[CommandCategory.None]: {
|
||||||
friendlyName: 'Uncategorized',
|
friendlyName: "Uncategorized",
|
||||||
description: 'Uncategorized commands',
|
description: "Uncategorized commands",
|
||||||
aliases: [],
|
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[]) => {
|
||||||
|
@ -47,24 +49,21 @@ export default {
|
||||||
|
|
||||||
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`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,23 +71,19 @@ export default {
|
||||||
|
|
||||||
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)) {
|
if (category && !searchInput.startsWith(prefix)) {
|
||||||
let msg = `**AutoMod Help** - Category: ${category.friendlyName}\n`
|
let msg = `**AutoMod Help** - Category: ${category.friendlyName}\n` + `${category.description}\n\n` + `Type **${prefix}help [command]** to learn more about a command.\n\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}`;
|
||||||
|
@ -97,21 +92,19 @@ export default {
|
||||||
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;
|
||||||
|
|
Loading…
Reference in a new issue