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.

53 lines
1.6 KiB

  1. /**
  2. * Administration module
  3. */
  4. let { AbstractModule } = require('./abstract');
  5. let { logger } = require('../logging');
  6. let { sanitizeConfig } = require('../config');
  7. let message = require('../message');
  8. class AdminModule extends AbstractModule {
  9. constructor() {
  10. super(
  11. "Administration",
  12. "Support administration tasks",
  13. "admin"
  14. );
  15. this.hidden = true;
  16. this.helpAndUsage = `Usage: admin <command>
  17. admin config - print the bot configuration`;
  18. this.needGlobalConfig = true;
  19. }
  20. /**
  21. * Override to only permit recognized admin users to access the plugin
  22. */
  23. handleMessage(event, room, callback) {
  24. if (this.getGlobal("admins", []).includes(event.sender.userId)) {
  25. logger.debug("Authorized %s for admin action", event.sender.userId);
  26. super.handleMessage(event, room, callback);
  27. } else {
  28. logger.warn("User %s tried to access admin functionality", event.sender.userId);
  29. return event.sender.userId + " is not a recognized admin!"
  30. }
  31. }
  32. /* Commands
  33. * All methods starting with cmd_ will be parsed at initialization to expose those methods as commdands to the user
  34. */
  35. /**
  36. * Print the current config information
  37. *
  38. * @param {...any} args
  39. */
  40. cmd_config(...args) {
  41. if (this._global_config != null) {
  42. let configBody = JSON.stringify(sanitizeConfig(this._global_config), null, 2)
  43. return message.createMarkdown(configBody, "```" + configBody + "```");
  44. }
  45. return null;
  46. }
  47. }
  48. exports.module = new AdminModule();