import { isAuthorisedAsync } from "../util"; import { plgMgr, COMMAND_PREFIX } from "src/main"; import { Command, ICommandData, Plugin } from "src/model/plugin"; import { client } from "src/client"; import { tryDo } from "../../../shared/lib/src/common/async_utils"; @Plugin export class Help { @Command({ type: "mention", pattern: "help", allowDM: true }) async showHelp({ message }: ICommandData): Promise { const isAuthed = await isAuthorisedAsync(message.member ?? message.author); let baseCommands = "\n"; let modCommands = "\n"; let prefixCommands = "\n"; for (const doc of plgMgr.documentation) { if (isAuthed && doc.auth) { if (doc.type == "prefix") prefixCommands = `${prefixCommands}${COMMAND_PREFIX}${doc.example} - ${doc.doc}\n`; else if (doc.type == "mention") modCommands = `${modCommands}${doc.example} - ${doc.doc}\n`; } else if (!doc.auth) baseCommands = `${baseCommands}${doc.example} - ${doc.doc}\n`; } let msg = `Hello! I am ${client.botUser.username}! My job is to help with C(O)M-related problems!\nPing me with one of the following commands:\n\`\`\`${baseCommands}\`\`\``; if (isAuthed) msg = `${msg}\nšŸ‘‘**Moderator commands**šŸ‘‘\n\`\`\`${modCommands}\`\`\`\n**Prefix commands**\`\`\`${prefixCommands}\`\`\``; const dmResult = await tryDo(message.author.createDM()); if (dmResult.ok) { await tryDo(message.delete()); const result = await tryDo(dmResult.result.send(msg)); if (result.ok) return; } message.reply({ content: msg, failIfNotExists: false }); } }