bit of cleanup
This commit is contained in:
parent
6e71ba4b5b
commit
2983a14038
17
src/bot.js
17
src/bot.js
@ -530,16 +530,15 @@ class OcrccBot {
|
|||||||
member.membership === "leave" &&
|
member.membership === "leave" &&
|
||||||
member.userId !== this.config.BOT_USERID
|
member.userId !== this.config.BOT_USERID
|
||||||
) {
|
) {
|
||||||
// ensure bot is still in the room
|
|
||||||
const roomData = await this.client.getJoinedRooms()
|
|
||||||
const joinedRooms = roomData["joined_rooms"]
|
|
||||||
const isBotInRoom = joinedRooms.includes(member.roomId)
|
|
||||||
|
|
||||||
const room = this.client.getRoom(member.roomId)
|
const room = this.client.getRoom(member.roomId)
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
|
|
||||||
try {
|
const roomMembers = await room.getJoinedMembers() // array
|
||||||
|
const facilitatorRoomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID) // object
|
||||||
|
const isBotInRoom = roomMembers.find(member => member.userId === this.config.BOT_USERID)
|
||||||
|
|
||||||
// notify room if the facilitator has left
|
// notify room if the facilitator has left
|
||||||
|
try {
|
||||||
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`)
|
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`)
|
||||||
if (isBotInRoom && member.userId === facilitatorId) {
|
if (isBotInRoom && member.userId === facilitatorId) {
|
||||||
this.sendTextMessage(
|
this.sendTextMessage(
|
||||||
@ -553,7 +552,7 @@ class OcrccBot {
|
|||||||
|
|
||||||
// leave if there is nobody in the room
|
// leave if there is nobody in the room
|
||||||
try {
|
try {
|
||||||
const memberCount = room.getJoinedMemberCount()
|
const memberCount = roomMembers.length
|
||||||
if (memberCount === 1 && isBotInRoom) { // just the bot left
|
if (memberCount === 1 && isBotInRoom) { // just the bot left
|
||||||
logger.log("info", `LEAVING EMPTY ROOM ==> ${member.roomId}`);
|
logger.log("info", `LEAVING EMPTY ROOM ==> ${member.roomId}`);
|
||||||
this.deleteTranscript(member.userId, member.roomId);
|
this.deleteTranscript(member.userId, member.roomId);
|
||||||
@ -567,11 +566,9 @@ class OcrccBot {
|
|||||||
|
|
||||||
// send signal to close the chat if there are no facilitators in the room
|
// send signal to close the chat if there are no facilitators in the room
|
||||||
try {
|
try {
|
||||||
const roomMembers = await room.getJoinedMembers()
|
|
||||||
const facilitatorRoomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
|
|
||||||
const facilitators = facilitatorRoomMembers['joined']
|
const facilitators = facilitatorRoomMembers['joined']
|
||||||
|
|
||||||
let facilitatorInRoom = false;
|
let facilitatorInRoom = false;
|
||||||
|
|
||||||
roomMembers.forEach(member => {
|
roomMembers.forEach(member => {
|
||||||
if (member.userId !== this.config.BOT_USERID && Boolean(facilitators[member.userId])) {
|
if (member.userId !== this.config.BOT_USERID && Boolean(facilitators[member.userId])) {
|
||||||
facilitatorInRoom = true
|
facilitatorInRoom = true
|
||||||
|
Loading…
Reference in New Issue
Block a user