|
|
@ -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, |
|
|
|