Baphomet is the dedicated bot for nulloctet matrix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. /**
  2. * Help module
  3. */
  4. let { AbstractModule } = require('./abstract');
  5. let { logger } = require('../logging');
  6. class HelpModule extends AbstractModule {
  7. constructor(commandMap) {
  8. super(
  9. "Help",
  10. "Provide helpful information about other modules.",
  11. "help"
  12. );
  13. this._commandMap = commandMap;
  14. this._commandList = Array.from(commandMap.keys()).sort();
  15. this.defaultCommand = 'help';
  16. }
  17. _default_help_message() {
  18. let help = `!help <command>`;
  19. for (let command of this._commandList) {
  20. help += "\n!help " + command + " : " + this._commandMap.get(command).description;
  21. }
  22. return help;
  23. }
  24. cmd_help(...args) {
  25. logger.debug("%o", args)
  26. if (args.length < 1) {
  27. return this._default_help_message();
  28. } else {
  29. let command = args[0];
  30. logger.debug("Looking up help for %s from %o", command, this._commandMap);
  31. if (this._commandList.includes(command)) {
  32. return this._commandMap.get(command).cmd_help();
  33. } else {
  34. let help = command + " is an unrecognized module\n";
  35. help += this._default_help_message();
  36. return help;
  37. }
  38. }
  39. }
  40. }
  41. function create(commandMap) {
  42. return new HelpModule(commandMap);
  43. }
  44. exports.create = create;