|
@ -13,13 +13,48 @@ class Bot { |
|
|
/** |
|
|
/** |
|
|
* Initialize the bot connection |
|
|
* Initialize the bot connection |
|
|
*/ |
|
|
*/ |
|
|
init() { |
|
|
|
|
|
|
|
|
init(messageCallback) { |
|
|
logger.info("Creating Matrix Client") |
|
|
logger.info("Creating Matrix Client") |
|
|
this.client = sdk.createClient({ |
|
|
this.client = sdk.createClient({ |
|
|
baseUrl: this.config.baseUrl, |
|
|
baseUrl: this.config.baseUrl, |
|
|
accessToken: this.config.accessToken, |
|
|
accessToken: this.config.accessToken, |
|
|
userId: this.config.userId |
|
|
userId: this.config.userId |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.client.on("sync", (state, previousState, data) => { |
|
|
|
|
|
switch (state) { |
|
|
|
|
|
case "PREPARED": |
|
|
|
|
|
this.connected = true; |
|
|
|
|
|
this.sendStatusStartup(); |
|
|
|
|
|
break; |
|
|
|
|
|
case "SYNCING": |
|
|
|
|
|
logger.debug("Syncing") |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
logger.error("Unexpected sync state: %s", state); |
|
|
|
|
|
process.exit(1); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.client.on("RoomMember.membership", (event, member) => { |
|
|
|
|
|
if (member.membership === "invite" |
|
|
|
|
|
&& this.config.admin.indexOf(ember.userId) >= 0) { |
|
|
|
|
|
this.client.joinRoom(member.roomId).done(() => { |
|
|
|
|
|
logger.info("Auto-joined %s", member.roomId); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.client.on("Room.timeline", messageCallback); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
connect() { |
|
|
|
|
|
// logger.info("Initializing Crypto");
|
|
|
|
|
|
// await bot.client.initCrypto();
|
|
|
|
|
|
logger.info("Starting Matrix SDK Client"); |
|
|
|
|
|
this.client.startClient(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sendStatusStartup() { |
|
|
sendStatusStartup() { |
|
|