Browse Source

Adding admin module and changing startup to notice

pull/10/head
Drew Short 5 years ago
parent
commit
c6b4d7d3c4
  1. 18
      bot/bot.js
  2. 10
      bot/message.js
  3. 13
      bot/module/admin.js
  4. 8
      bot/module/index.js

18
bot/bot.js

@ -6,10 +6,17 @@ let { logger } = require('./logging');
let { modules } = require('./module/index')
class Bot {
constructor(config, buildInfo) {
constructor(config, buildInfo, modules) {
this.config = config;
this.buildInfo = buildInfo;
this.connected = false;
this.modules = modules;
}
initModules() {
modules.forEach((module) => {
logger.info("Loading module: %s", module.name);
});
}
sendStatusStartup() {
@ -18,7 +25,7 @@ class Bot {
this.config.statusRooms.forEach(roomId => {
logger.debug("Notifying %s of startup", roomId);
promises.push(this.client.sendMessage(
roomId, message.createBasic("Started with version: " + this.buildInfo)
roomId, message.createBasic("Started with version: " + this.buildInfo, message.types.NOTICE)
).then(() => {
logger.debug("Notified %s of startup", roomId);
}));
@ -35,7 +42,7 @@ class Bot {
this.config.statusRooms.forEach(roomId => {
logger.debug("Notifying %s of shutdown", roomId);
promises.push(this.client.sendMessage(
roomId, message.createBasic("Shutting down")
roomId, message.createBasic("Shutting down", message.types.NOTICE)
).then(() => {
logger.debug("Notified %s of shutdown", roomId);
}));
@ -71,10 +78,13 @@ function create(configFile) {
logger.debug("%o", sanitizeConfig(config));
let buildInfo = getBuildInfo("../build.info")
logger.info("Running version: %s", buildInfo);
return new Bot(config, buildInfo);
return new Bot(config, buildInfo, modules);
}
function init(bot) {
logger.info("Initializing modules");
bot.initModules();
logger.info("Creating Matrix Client")
bot.client = sdk.createClient({
baseUrl: bot.config.baseUrl,

10
bot/message.js

@ -1,8 +1,14 @@
function createBasicMessage(body) {
let messageTypes = {
TEXT: 'm.text',
NOTICE: 'm.notice'
}
function createBasicMessage(body, msgtype=messageTypes.TEXT) {
return {
"body": body,
"msgtype": "m.text"
"msgtype": msgtype
}
}
exports.types = messageTypes;
exports.createBasic = createBasicMessage;

13
bot/module/admin.js

@ -0,0 +1,13 @@
/**
* Administration module
*/
class AdminModule {
constructor() {
this.name = "Administration"
this.description = "Support administration tasks"
this.command = "admin"
}
}
exports.module = new AdminModule();

8
bot/module/index.js

@ -1,5 +1,11 @@
/**
* Manage the registered modules
*/
let adminModule = require('./admin');
function getModules() {
return [];
return [adminModule.module];
}
exports.modules = getModules();
Loading…
Cancel
Save