Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f838637d7a | ||
|
|
404f440f48 | ||
|
|
14ed711b6a |
@@ -11,7 +11,6 @@ BOT_USERNAME=
|
||||
BOT_PASSWORD=
|
||||
BOT_USERID=
|
||||
FACILITATOR_ROOM_ID=
|
||||
FACILITATOR_GROUP_ID=
|
||||
CHAT_OFFLINE_MESSAGE=
|
||||
CAPTURE_TRANSCRIPTS=
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "private-safesupport-bot",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"description": "Chatbot to manage interactions on Safe Support Chat",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
||||
43
src/bot.js
43
src/bot.js
@@ -81,7 +81,7 @@ class OcrccBot {
|
||||
});
|
||||
await this.sendMessage(roomId, content);
|
||||
default:
|
||||
logger.log("error", `ERROR SENDING MESSAGE: ${err}`);
|
||||
logger.log("error", `ERROR SENDING MESSAGE ${content.body}: ${err}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -474,26 +474,31 @@ class OcrccBot {
|
||||
member.membership === "leave" &&
|
||||
member.userId !== this.config.BOT_USERID
|
||||
) {
|
||||
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`)
|
||||
if (member.userId === facilitatorId) {
|
||||
this.sendTextMessage(
|
||||
member.roomId,
|
||||
`${member.name} has left the chat.`
|
||||
);
|
||||
}
|
||||
// ensure bot is still in the room
|
||||
const roomData = await this.client.getJoinedRooms()
|
||||
const joinedRooms = roomData["joined_rooms"]
|
||||
const isBotInRoom = joinedRooms.includes(member.roomId)
|
||||
|
||||
// leave if there is nobody in the room
|
||||
const room = this.client.getRoom(member.roomId)
|
||||
if (!room) return
|
||||
|
||||
// leave if there is nobody in the room
|
||||
const memberCount = room.getJoinedMemberCount()
|
||||
|
||||
if (memberCount === 1) { // just the bot left
|
||||
if (memberCount === 1 && isBotInRoom) { // just the bot left
|
||||
logger.log("info", `LEAVING EMPTY ROOM ==> ${member.roomId}`);
|
||||
this.deleteTranscript(member.userId, member.roomId);
|
||||
this.localStorage.removeItem(`${member.roomId}-facilitator`)
|
||||
this.localStorage.removeItem(`${member.roomId}-transcript`)
|
||||
this.client.leave(member.roomId)
|
||||
return this.client.leave(member.roomId)
|
||||
}
|
||||
|
||||
// notify room if the facilitator has left
|
||||
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`)
|
||||
if (isBotInRoom && member.userId === facilitatorId) {
|
||||
this.sendTextMessage(
|
||||
member.roomId,
|
||||
`${member.name} has left the chat.`
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -551,12 +556,18 @@ class OcrccBot {
|
||||
};
|
||||
|
||||
this.client = matrix.createClient(opts);
|
||||
await this.deleteOldDevices()
|
||||
await this.trackJoinedRooms()
|
||||
await this.client.initCrypto()
|
||||
await this.setMembershipListeners();
|
||||
await this.setMessageListeners();
|
||||
this.client.startClient({ initialSyncLimit: 0 })
|
||||
|
||||
this.client.once('sync', async (state, prevState, data) => {
|
||||
logger.log("info", `SYNC STATUS: ${state}`)
|
||||
if (state === 'PREPARED') {
|
||||
await this.deleteOldDevices()
|
||||
await this.trackJoinedRooms()
|
||||
await this.setMembershipListeners();
|
||||
await this.setMessageListeners();
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
this.handleBotCrash(undefined, err);
|
||||
logger.log("error", `ERROR INITIALIZING CLIENT: ${err}`);
|
||||
|
||||
Reference in New Issue
Block a user