Browse Source

Add module scaffold and anonymous function cleanup

pull/10/head
Drew Short 5 years ago
parent
commit
e92ebf6208
  1. 21
      bot/bot.js
  2. 5
      bot/module/index.js

21
bot/bot.js

@ -1,8 +1,9 @@
let fs = require('fs');
let sdk = require('matrix-js-sdk');
let message = require('./message.js');
let utility = require('./utility.js');
let message = require('./message');
let utility = require('./utility');
let { logger } = require('./logging');
let { modules } = require('./module/index')
class Bot {
constructor(config, buildInfo) {
@ -18,7 +19,7 @@ class Bot {
logger.debug("Notifying %s of startup", roomId);
promises.push(this.client.sendMessage(
roomId, message.createBasic("Started with version: " + this.buildInfo)
).then(function () {
).then(() => {
logger.debug("Notified %s of startup", roomId);
}));
});
@ -35,7 +36,7 @@ class Bot {
logger.debug("Notifying %s of shutdown", roomId);
promises.push(this.client.sendMessage(
roomId, message.createBasic("Shutting down")
).then(function () {
).then(() => {
logger.debug("Notified %s of shutdown", roomId);
}));
});
@ -81,19 +82,19 @@ function init(bot) {
userId: bot.config.userId
});
bot.client.on("sync", async function (state, previousState, data) {
bot.client.on("sync", (state, previousState, data) => {
switch (state) {
case "PREPARED":
bot.connected = true;
await bot.sendStatusStartup();
bot.sendStatusStartup();
break;
}
});
bot.client.on("RoomMember.membership", function (event, member) {
bot.client.on("RoomMember.membership", (event, member) => {
if (member.membership === "invite"
&& bot.config.admin.indexOf(ember.userId) >= 0) {
bot.client.joinRoom(member.roomId).done(function () {
bot.client.joinRoom(member.roomId).done(() => {
logger.info("Auto-joined %s", member.roomId);
});
}
@ -104,7 +105,7 @@ function init(bot) {
["SIGINT", "SIGTERM"].forEach((signature) => {
process.on(signature, async () => {
await bot.sendStatusShutdown()
.then(function () {
.then(() => {
logger.info("Gracefully stopping Matrix SDK Client")
bot.client.stopClient();
});
@ -112,7 +113,7 @@ function init(bot) {
});
});
process.on('exit', async function () {
process.on('exit', () => {
logger.info("Shutting Down");
});

5
bot/module/index.js

@ -0,0 +1,5 @@
function getModules() {
return [];
}
exports.modules = getModules();
Loading…
Cancel
Save