|
|
@ -2,7 +2,7 @@ let fs = require('fs'); |
|
|
|
let sdk = require('matrix-js-sdk'); |
|
|
|
let message = require('./message.js'); |
|
|
|
let utility = require('./utility.js'); |
|
|
|
let logging = require('./logging'); |
|
|
|
let { logger } = require('./logging'); |
|
|
|
|
|
|
|
class Bot { |
|
|
|
constructor(config, buildInfo) { |
|
|
@ -15,15 +15,15 @@ class Bot { |
|
|
|
let promises = [Promise.resolve(true)] |
|
|
|
if (this.connected) { |
|
|
|
this.config.statusRooms.forEach(roomId => { |
|
|
|
logging.logger.debug("Notifying %s", roomId, "of startup"); |
|
|
|
logger.debug("Notifying %s of startup", roomId); |
|
|
|
promises.push(this.client.sendMessage( |
|
|
|
roomId, message.createBasic("Started with version: " + this.buildInfo) |
|
|
|
).then(function () { |
|
|
|
logging.logger.debug("Notified %s", roomId, "of startup"); |
|
|
|
logger.debug("Notified %s of startup", roomId); |
|
|
|
})); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
logging.logger.warn("Attempting to send startup message while disconnected"); |
|
|
|
logger.warn("Attempting to send startup message while disconnected"); |
|
|
|
} |
|
|
|
return Promise.all(promises); |
|
|
|
} |
|
|
@ -32,15 +32,15 @@ class Bot { |
|
|
|
let promises = [Promise.resolve(true)] |
|
|
|
if (this.connected) { |
|
|
|
this.config.statusRooms.forEach(roomId => { |
|
|
|
logging.logger.debug("Notifying %s", roomId, "of Shutdown"); |
|
|
|
logger.debug("Notifying %s of shutdown", roomId); |
|
|
|
promises.push(this.client.sendMessage( |
|
|
|
roomId, message.createBasic("Shutting down") |
|
|
|
).then(function () { |
|
|
|
logging.logger.debug("Notified %s", roomId, "of shutdown"); |
|
|
|
logger.debug("Notified %s of shutdown", roomId); |
|
|
|
})); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
logging.logger.warn("Attempting to send shutdown message while disconnected"); |
|
|
|
logger.warn("Attempting to send shutdown message while disconnected"); |
|
|
|
} |
|
|
|
return Promise.all(promises); |
|
|
|
} |
|
|
@ -53,7 +53,7 @@ function getBuildInfo(buildInfoPath) { |
|
|
|
if (err.code === 'ENOENT') { |
|
|
|
return "UNKNOWN_" + utility.toISODateString(new Date()); |
|
|
|
} else { |
|
|
|
logging.logger.error("Unexpected Error! " + err); |
|
|
|
logger.error("Unexpected Error!", err); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -66,15 +66,15 @@ function sanitizeConfig(config) { |
|
|
|
|
|
|
|
function create(configFile) { |
|
|
|
let config = require(configFile); |
|
|
|
logging.logger.info("Running with config:"); |
|
|
|
logging.logger.debug(sanitizeConfig(config)); |
|
|
|
logger.info("Running with config:"); |
|
|
|
logger.debug("%o", sanitizeConfig(config)); |
|
|
|
let buildInfo = getBuildInfo("../build.info") |
|
|
|
logging.logger.info("Running version:", buildInfo); |
|
|
|
logger.info("Running version: %s", buildInfo); |
|
|
|
return new Bot(config, buildInfo); |
|
|
|
} |
|
|
|
|
|
|
|
function init(bot) { |
|
|
|
logging.logger.info("Creating Matrix Client") |
|
|
|
logger.info("Creating Matrix Client") |
|
|
|
bot.client = sdk.createClient({ |
|
|
|
baseUrl: bot.config.baseUrl, |
|
|
|
accessToken: bot.config.accessToken, |
|
|
@ -94,7 +94,7 @@ function init(bot) { |
|
|
|
if (member.membership === "invite" |
|
|
|
&& bot.config.admin.indexOf(ember.userId) >= 0) { |
|
|
|
bot.client.joinRoom(member.roomId).done(function () { |
|
|
|
logging.logger.info("Auto-joined %s", member.roomId); |
|
|
|
logger.info("Auto-joined %s", member.roomId); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
@ -105,7 +105,7 @@ function init(bot) { |
|
|
|
process.on(signature, async () => { |
|
|
|
await bot.sendStatusShutdown() |
|
|
|
.then(function () { |
|
|
|
logging.logger.info("Gracefully stopping Matrix SDK Client") |
|
|
|
logger.info("Gracefully stopping Matrix SDK Client") |
|
|
|
bot.client.stopClient(); |
|
|
|
}); |
|
|
|
process.exit(0); |
|
|
@ -113,16 +113,16 @@ function init(bot) { |
|
|
|
}); |
|
|
|
|
|
|
|
process.on('exit', async function () { |
|
|
|
logging.logger.info("Shutting Down"); |
|
|
|
logger.info("Shutting Down"); |
|
|
|
}); |
|
|
|
|
|
|
|
return bot; |
|
|
|
} |
|
|
|
|
|
|
|
function run(bot) { |
|
|
|
// logging.logger.info("Initializing Crypto");
|
|
|
|
// logger.info("Initializing Crypto");
|
|
|
|
// await bot.client.initCrypto();
|
|
|
|
logging.logger.info("Starting Matrix SDK Client"); |
|
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
|
bot.client.startClient(); |
|
|
|
} |
|
|
|
|
|
|
|