help.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { isAuthorisedAsync } from "../util";
  2. import { plgMgr, COMMAND_PREFIX } from "src/main";
  3. import { Command, ICommandData, Plugin } from "src/model/plugin";
  4. import { client } from "src/client";
  5. @Plugin
  6. export class Help {
  7. @Command({
  8. type: "mention",
  9. pattern: "help"
  10. })
  11. async showHelp({ message }: ICommandData): Promise<void> {
  12. const isAuthed = await isAuthorisedAsync(message.member);
  13. let baseCommands = "\n";
  14. let modCommands = "\n";
  15. let prefixCommands = "\n";
  16. for (const doc of plgMgr.documentation) {
  17. if (isAuthed && doc.auth) {
  18. if (doc.type == "prefix")
  19. prefixCommands = `${prefixCommands}${COMMAND_PREFIX}${doc.example} - ${doc.doc}\n`;
  20. else if (doc.type == "mention")
  21. modCommands = `${modCommands}${doc.example} - ${doc.doc}\n`;
  22. }
  23. else if (!doc.auth)
  24. baseCommands = `${baseCommands}${doc.example} - ${doc.doc}\n`;
  25. }
  26. 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}\`\`\``;
  27. if (isAuthed)
  28. msg = `${msg}\n👑**Moderator commands**👑\n\`\`\`${modCommands}\`\`\`\n**Prefix commands**\`\`\`${prefixCommands}\`\`\``;
  29. message.reply(msg);
  30. }
  31. }