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.
 
 
 
 
 

54 lines
1.6 KiB

/**
* Administration module
*/
let { AbstractModule } = require('./abstract');
let { logger } = require('../logging');
let { sanitizeConfig } = require('../config');
let message = require('../message');
class AdminModule extends AbstractModule {
constructor() {
super(
"Administration",
"Support administration tasks",
"admin"
);
this.hidden = true;
this.helpAndUsage = `Usage: admin <command>
admin config - print the bot configuration`;
this.needGlobalConfig = true;
}
/**
* Override to only permit recognized admin users to access the plugin
*/
handleMessage(event, room, callback) {
if (this.getGlobal("admins", []).includes(event.sender.userId)) {
logger.debug("Authorized %s for admin action", event.sender.userId);
super.handleMessage(event, room, callback);
} else {
logger.warn("User %s tried to access admin functionality", event.sender.userId);
return event.sender.userId + " is not a recognized admin!"
}
}
/* Commands
* All methods starting with cmd_ will be parsed at initialization to expose those methods as commdands to the user
*/
/**
* Print the current config information
*
* @param {...any} args
*/
cmd_config(event, ...args) {
if (this._global_config != null) {
let configBody = JSON.stringify(sanitizeConfig(this._global_config), null, 2)
return message.createMarkdown(configBody, "```" + configBody + "```");
}
return null;
}
}
exports.module = new AdminModule();