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