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.

51 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. /* Commands */
  25. cmd_help(...args) {
  26. logger.debug("%o", args)
  27. if (args.length < 1) {
  28. return this._default_help_message();
  29. } else {
  30. let command = args[0];
  31. logger.debug("Looking up help for %s from %o", command, this._commandMap);
  32. if (this._commandList.includes(command)) {
  33. return this._commandMap.get(command).cmd_help();
  34. } else {
  35. let help = command + " is an unrecognized module\n";
  36. help += this._default_help_message();
  37. return help;
  38. }
  39. }
  40. }
  41. }
  42. function create(commandMap) {
  43. return new HelpModule(commandMap);
  44. }
  45. exports.create = create;