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