Baphomet is the dedicated bot for nulloctet matrix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

62 lines
1.6 KiB

let { logger } = require('./logging');
let { modules } = require('./module/index')
class Engine {
constructor(config, bot, modules) {
this.config = config
this.bot = bot;
this.modules = modules;
}
init() {
logger.info("Initializing modules");
this.initModules();
/* Bind Message Parsing */
let handleMessages = function (event, room, toStartOfTimeline) {
if (event.getType() !== "m.room.message") {
logger.debug("Recieved message of type: %s", event.getType());
return; // only use messages
}
logger.debug("[%s] %s", room.name, event.event.content.body);
}
this.bot.init(handleMessages);
/* Capture Exit Conditions */
["SIGINT", "SIGTERM"].forEach((signature) => {
process.on(signature, async () => {
await this.bot.sendStatusShutdown()
.then(() => {
logger.info("Gracefully stopping Matrix SDK Client")
this.bot.client.stopClient();
});
process.exit(0);
});
});
process.on('exit', () => {
logger.info("Shutting Down");
});
return this;
}
initModules() {
this.modules.forEach((module) => {
logger.info("Loading module: %s", module.name);
});
}
run() {
this.bot.connect();
return this;
}
}
function create(config, bot) {
return new Engine(config, bot, modules)
}
exports.create = create;