diff --git a/bot/bot.js b/bot/bot.js index 67681bf..d8d5b7f 100644 --- a/bot/bot.js +++ b/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, diff --git a/bot/message.js b/bot/message.js index a748109..9c936bf 100644 --- a/bot/message.js +++ b/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; \ No newline at end of file diff --git a/bot/module/admin.js b/bot/module/admin.js new file mode 100644 index 0000000..729e000 --- /dev/null +++ b/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(); \ No newline at end of file diff --git a/bot/module/index.js b/bot/module/index.js index 15cad4b..1c36a30 100644 --- a/bot/module/index.js +++ b/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(); \ No newline at end of file