ensure joined user is facilitator before uninviting other facilitators
This commit is contained in:
parent
4cddeae508
commit
f8a1698c56
49
src/bot.js
49
src/bot.js
@ -106,7 +106,7 @@ class OcrccBot {
|
|||||||
|
|
||||||
async inviteFacilitators(roomId) {
|
async inviteFacilitators(roomId) {
|
||||||
this.localStorage.setItem(`${roomId}-waiting`, 'true')
|
this.localStorage.setItem(`${roomId}-waiting`, 'true')
|
||||||
let chatOffline = true;
|
let invitations = []
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const roomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
|
const roomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
|
||||||
@ -116,15 +116,17 @@ class OcrccBot {
|
|||||||
const user = this.client.getUser(memberId);
|
const user = this.client.getUser(memberId);
|
||||||
if (
|
if (
|
||||||
user &&
|
user &&
|
||||||
(user.presence === "online") &&
|
(user.presence !== "offline") &&
|
||||||
memberId !== this.config.BOT_USERID
|
memberId !== this.config.BOT_USERID
|
||||||
) {
|
) {
|
||||||
chatOffline = false;
|
invitations.push(memberId)
|
||||||
this.inviteUserToRoom(roomId, memberId);
|
this.inviteUserToRoom(roomId, memberId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (chatOffline) {
|
if (invitations.length > 0) {
|
||||||
|
this.localStorage.setItem(`${roomId}-invitations`, invitations)
|
||||||
|
} else {
|
||||||
logger.log('info', "NO FACILITATORS ONLINE")
|
logger.log('info', "NO FACILITATORS ONLINE")
|
||||||
this.sendNotice(roomId, "CHAT_OFFLINE")
|
this.sendNotice(roomId, "CHAT_OFFLINE")
|
||||||
}
|
}
|
||||||
@ -388,23 +390,30 @@ class OcrccBot {
|
|||||||
try {
|
try {
|
||||||
const room = await this.client.joinRoom(member.roomId)
|
const room = await this.client.joinRoom(member.roomId)
|
||||||
logger.log("info", "AUTO JOINED ROOM => " + room.roomId)
|
logger.log("info", "AUTO JOINED ROOM => " + room.roomId)
|
||||||
this.sendTextMessage(
|
const currentDate = new Date()
|
||||||
this.config.FACILITATOR_ROOM_ID,
|
const chatDate = currentDate.toLocaleDateString()
|
||||||
`A support seeker requested a chat (Room ID: ${room.roomId})`
|
const chatTime = currentDate.toLocaleTimeString()
|
||||||
);
|
const roomId = room.roomId.split(':')[0]
|
||||||
|
const notification = `Incoming support chat at ${chatTime} (room ID: ${roomId})`
|
||||||
|
this.sendTextMessage(this.config.FACILITATOR_ROOM_ID, notification);
|
||||||
this.inviteFacilitators(room.roomId)
|
this.inviteFacilitators(room.roomId)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
logger.log("error", "ERROR JOINING ROOM => " + err)
|
logger.log("error", "ERROR JOINING ROOM => " + err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a facilitator joins a support session, make them a moderator
|
|
||||||
// revoke the other invitations
|
|
||||||
if (
|
if (
|
||||||
member.membership === "join" &&
|
member.membership === "join" &&
|
||||||
member.userId !== this.config.BOT_USERID &&
|
member.userId !== this.config.BOT_USERID &&
|
||||||
this.localStorage.getItem(`${member.roomId}-waiting`)
|
this.localStorage.getItem(`${member.roomId}-waiting`)
|
||||||
) {
|
) {
|
||||||
|
// make sure it's a facilitator joining
|
||||||
|
const roomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
|
||||||
|
const members = Object.keys(roomMembers["joined"]);
|
||||||
|
const isFacilitator = members.includes(member.userId)
|
||||||
|
|
||||||
|
if (isFacilitator) {
|
||||||
|
// made facilitator a moderator in the room
|
||||||
this.localStorage.setItem(`${member.roomId}-facilitator`, member.userId)
|
this.localStorage.setItem(`${member.roomId}-facilitator`, member.userId)
|
||||||
const event = {
|
const event = {
|
||||||
getType: () => {
|
getType: () => {
|
||||||
@ -420,15 +429,24 @@ class OcrccBot {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.client.setPowerLevel(member.roomId, member.userId, 50, event);
|
this.client.setPowerLevel(member.roomId, member.userId, 50, event);
|
||||||
|
|
||||||
|
// send notification to Support Chat Notifications room
|
||||||
|
const currentDate = new Date()
|
||||||
|
const chatTime = currentDate.toLocaleTimeString()
|
||||||
|
const roomId = member.roomId.split(':')[0]
|
||||||
|
const notification = `${member.name} joined the chat at ${chatTime} (room ID: ${roomId})`
|
||||||
|
this.sendTextMessage(this.config.FACILITATOR_ROOM_ID, notification);
|
||||||
|
|
||||||
|
// send notification to chat room
|
||||||
this.sendTextMessage(
|
this.sendTextMessage(
|
||||||
member.roomId,
|
member.roomId,
|
||||||
`${member.name} has joined the chat.`
|
`${member.name} has joined the chat.`
|
||||||
);
|
);
|
||||||
this.sendTextMessage(
|
|
||||||
this.config.FACILITATOR_ROOM_ID,
|
// revoke the other invitations
|
||||||
`${member.name} joined the chat (Room ID: ${member.roomId})`
|
|
||||||
);
|
|
||||||
this.uninviteFacilitators(member.roomId);
|
this.uninviteFacilitators(member.roomId);
|
||||||
|
|
||||||
|
// set transcript file
|
||||||
if (this.config.CAPTURE_TRANSCRIPTS) {
|
if (this.config.CAPTURE_TRANSCRIPTS) {
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const dateOpts = {
|
const dateOpts = {
|
||||||
@ -445,6 +463,7 @@ class OcrccBot {
|
|||||||
this.localStorage.setItem(`${member.roomId}-transcript`, filepath)
|
this.localStorage.setItem(`${member.roomId}-transcript`, filepath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
member.membership === "leave" &&
|
member.membership === "leave" &&
|
||||||
@ -472,7 +491,7 @@ class OcrccBot {
|
|||||||
this.client.leave(member.roomId)
|
this.client.leave(member.roomId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async setMessageListeners() {
|
async setMessageListeners() {
|
||||||
|
Loading…
Reference in New Issue
Block a user