help.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. import { tryDo } from "../../../shared/lib/src/common/async_utils";
  6. @Plugin
  7. export class Help {
  8. @Command({
  9. type: "mention",
  10. pattern: "help",
  11. allowDM: true
  12. })
  13. async showHelp({ message }: ICommandData): Promise<void> {
  14. const isAuthed = await isAuthorisedAsync(message.member ?? message.author);
  15. let baseCommands = "\n";
  16. let modCommands = "\n";
  17. let prefixCommands = "\n";
  18. for (const doc of plgMgr.documentation) {
  19. if (isAuthed && doc.auth) {
  20. if (doc.type == "prefix")
  21. prefixCommands = `${prefixCommands}${COMMAND_PREFIX}${doc.example} - ${doc.doc}\n`;
  22. else if (doc.type == "mention")
  23. modCommands = `${modCommands}${doc.example} - ${doc.doc}\n`;
  24. }
  25. else if (!doc.auth)
  26. baseCommands = `${baseCommands}${doc.example} - ${doc.doc}\n`;
  27. }
  28. 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}\`\`\``;
  29. if (isAuthed)
  30. msg = `${msg}\n👑**Moderator commands**👑\n\`\`\`${modCommands}\`\`\`\n**Prefix commands**\`\`\`${prefixCommands}\`\`\``;
  31. const dmResult = await tryDo(message.author.createDM());
  32. if (dmResult.ok) {
  33. await tryDo(message.delete());
  34. const result = await tryDo(dmResult.result.send(msg));
  35. if (result.ok)
  36. return;
  37. }
  38. message.reply(msg);
  39. }
  40. }