|
@ -10,29 +10,19 @@ class Engine { |
|
|
init() { |
|
|
init() { |
|
|
logger.info("Initializing modules"); |
|
|
logger.info("Initializing modules"); |
|
|
this.initModules(); |
|
|
this.initModules(); |
|
|
|
|
|
|
|
|
this.bot.init(); |
|
|
|
|
|
|
|
|
|
|
|
this.bot.client.on("sync", (state, previousState, data) => { |
|
|
|
|
|
switch (state) { |
|
|
|
|
|
case "PREPARED": |
|
|
|
|
|
this.bot.connected = true; |
|
|
|
|
|
this.bot.sendStatusStartup(); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.bot.client.on("RoomMember.membership", (event, member) => { |
|
|
|
|
|
if (member.membership === "invite" |
|
|
|
|
|
&& this.bot.config.admin.indexOf(ember.userId) >= 0) { |
|
|
|
|
|
this.bot.client.joinRoom(member.roomId).done(() => { |
|
|
|
|
|
logger.info("Auto-joined %s", member.roomId); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Bind Message Parsing */ |
|
|
|
|
|
let handleMessages = function (event, room, toStartOfTimeline) { |
|
|
|
|
|
if (event.getType() !== "m.room.message") { |
|
|
|
|
|
return; // only use messages
|
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("[%s] %s", room.name, event.event.content.body); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.bot.init(handleMessages); |
|
|
|
|
|
|
|
|
/* Capture Exit Conditions */ |
|
|
/* Capture Exit Conditions */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
["SIGINT", "SIGTERM"].forEach((signature) => { |
|
|
["SIGINT", "SIGTERM"].forEach((signature) => { |
|
|
process.on(signature, async () => { |
|
|
process.on(signature, async () => { |
|
|
await this.bot.sendStatusShutdown() |
|
|
await this.bot.sendStatusShutdown() |
|
@ -43,11 +33,11 @@ class Engine { |
|
|
process.exit(0); |
|
|
process.exit(0); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.on('exit', () => { |
|
|
process.on('exit', () => { |
|
|
logger.info("Shutting Down"); |
|
|
logger.info("Shutting Down"); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -58,10 +48,7 @@ class Engine { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
run() { |
|
|
run() { |
|
|
// logger.info("Initializing Crypto");
|
|
|
|
|
|
// await bot.client.initCrypto();
|
|
|
|
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
|
|
|
this.bot.client.startClient(); |
|
|
|
|
|
|
|
|
this.bot.connect(); |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|