Drew Short
5 years ago
4 changed files with 86 additions and 80 deletions
-
74bot/bot.js
-
61bot/engine.js
-
16bot/utility.js
-
7index.js
@ -0,0 +1,61 @@ |
|||||
|
let sdk = require('matrix-js-sdk'); |
||||
|
let { logger } = require('./logging'); |
||||
|
|
||||
|
function init(bot) { |
||||
|
logger.info("Initializing modules"); |
||||
|
bot.initModules(); |
||||
|
|
||||
|
logger.info("Creating Matrix Client") |
||||
|
bot.client = sdk.createClient({ |
||||
|
baseUrl: bot.config.baseUrl, |
||||
|
accessToken: bot.config.accessToken, |
||||
|
userId: bot.config.userId |
||||
|
}); |
||||
|
|
||||
|
bot.client.on("sync", (state, previousState, data) => { |
||||
|
switch (state) { |
||||
|
case "PREPARED": |
||||
|
bot.connected = true; |
||||
|
bot.sendStatusStartup(); |
||||
|
break; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
bot.client.on("RoomMember.membership", (event, member) => { |
||||
|
if (member.membership === "invite" |
||||
|
&& bot.config.admin.indexOf(ember.userId) >= 0) { |
||||
|
bot.client.joinRoom(member.roomId).done(() => { |
||||
|
logger.info("Auto-joined %s", member.roomId); |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
/* Capture Exit Conditions */ |
||||
|
|
||||
|
["SIGINT", "SIGTERM"].forEach((signature) => { |
||||
|
process.on(signature, async () => { |
||||
|
await bot.sendStatusShutdown() |
||||
|
.then(() => { |
||||
|
logger.info("Gracefully stopping Matrix SDK Client") |
||||
|
bot.client.stopClient(); |
||||
|
}); |
||||
|
process.exit(0); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
process.on('exit', () => { |
||||
|
logger.info("Shutting Down"); |
||||
|
}); |
||||
|
|
||||
|
return bot; |
||||
|
} |
||||
|
|
||||
|
function run(bot) { |
||||
|
// logger.info("Initializing Crypto");
|
||||
|
// await bot.client.initCrypto();
|
||||
|
logger.info("Starting Matrix SDK Client"); |
||||
|
bot.client.startClient(); |
||||
|
} |
||||
|
|
||||
|
exports.init = init; |
||||
|
exports.run = run; |
@ -1,6 +1,7 @@ |
|||||
let bot = require('./bot/bot.js'); |
|
||||
bot.run( |
|
||||
bot.init( |
|
||||
|
let bot = require('./bot/bot'); |
||||
|
let engine = require('./bot/engine') |
||||
|
engine.run( |
||||
|
engine.init( |
||||
bot.create("../data/config.json") |
bot.create("../data/config.json") |
||||
) |
) |
||||
); |
); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue