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.

72 lines
2.0 KiB

  1. let { logger } = require('./logging');
  2. let { modules } = require('./module/index')
  3. class Engine {
  4. constructor(bot, modules) {
  5. this.bot = bot;
  6. this.modules = modules;
  7. }
  8. init() {
  9. logger.info("Initializing modules");
  10. this.initModules();
  11. this.bot.init();
  12. this.bot.client.on("sync", (state, previousState, data) => {
  13. switch (state) {
  14. case "PREPARED":
  15. this.bot.connected = true;
  16. this.bot.sendStatusStartup();
  17. break;
  18. }
  19. });
  20. this.bot.client.on("RoomMember.membership", (event, member) => {
  21. if (member.membership === "invite"
  22. && this.bot.config.admin.indexOf(ember.userId) >= 0) {
  23. this.bot.client.joinRoom(member.roomId).done(() => {
  24. logger.info("Auto-joined %s", member.roomId);
  25. });
  26. }
  27. });
  28. /* Capture Exit Conditions */
  29. ["SIGINT", "SIGTERM"].forEach((signature) => {
  30. process.on(signature, async () => {
  31. await this.bot.sendStatusShutdown()
  32. .then(() => {
  33. logger.info("Gracefully stopping Matrix SDK Client")
  34. this.bot.client.stopClient();
  35. });
  36. process.exit(0);
  37. });
  38. });
  39. process.on('exit', () => {
  40. logger.info("Shutting Down");
  41. });
  42. return this;
  43. }
  44. initModules() {
  45. this.modules.forEach((module) => {
  46. logger.info("Loading module: %s", module.name);
  47. });
  48. }
  49. run() {
  50. // logger.info("Initializing Crypto");
  51. // await bot.client.initCrypto();
  52. logger.info("Starting Matrix SDK Client");
  53. this.bot.client.startClient();
  54. return this;
  55. }
  56. }
  57. function create(bot) {
  58. return new Engine(bot, modules)
  59. }
  60. exports.create = create;