latest build
This commit is contained in:
parent
666f2361c8
commit
6c882a44cc
109
dist/bot.js
vendored
109
dist/bot.js
vendored
@ -112,14 +112,6 @@ class OcrccBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteUserToRoom(roomId, member) {
|
|
||||||
try {
|
|
||||||
this.client.invite(roomId, member);
|
|
||||||
} catch (err) {
|
|
||||||
this.handleBotCrash(roomId, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kickUserFromRoom(roomId, member) {
|
kickUserFromRoom(roomId, member) {
|
||||||
try {
|
try {
|
||||||
this.client.kick(roomId, member, this.config.kickReason);
|
this.client.kick(roomId, member, this.config.kickReason);
|
||||||
@ -130,27 +122,50 @@ class OcrccBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async inviteFacilitatorIfOnline(roomId, memberId) {
|
||||||
|
const user = this.client.getUser(memberId);
|
||||||
|
|
||||||
|
if (user && user.presence !== "offline" && memberId !== this.config.botUserId) {
|
||||||
|
try {
|
||||||
|
this.client.invite(roomId, memberId);
|
||||||
|
|
||||||
|
_logger.default.log("info", `CHAT INVITATION SENT TO ${memberId} FOR ROOM ${roomId}`);
|
||||||
|
|
||||||
|
return memberId;
|
||||||
|
} catch (err) {
|
||||||
|
this.handleBotCrash(roomId, err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async inviteFacilitators(roomId) {
|
async inviteFacilitators(roomId) {
|
||||||
try {
|
try {
|
||||||
this.localStorage.setItem(`${roomId}-waiting`, 'true');
|
this.localStorage.setItem(`${roomId}-waiting`, 'true');
|
||||||
let invitations = [];
|
let invitations = [];
|
||||||
const roomMembers = await this.client.getJoinedRoomMembers(this.config.facilitatorRoomId);
|
const roomMembers = await this.client.getJoinedRoomMembers(this.config.facilitatorRoomId);
|
||||||
const members = Object.keys(roomMembers["joined"]);
|
const members = Object.keys(roomMembers["joined"]);
|
||||||
members.forEach(memberId => {
|
|
||||||
const user = this.client.getUser(memberId);
|
|
||||||
|
|
||||||
if (user && user.presence !== "offline" && memberId !== this.config.botUserId) {
|
for (const memberId of members) {
|
||||||
invitations.push(memberId);
|
const invited = await this.inviteFacilitatorIfOnline(roomId, memberId);
|
||||||
this.inviteUserToRoom(roomId, memberId);
|
invitations.push(invited);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (invitations.length > 0) {
|
if (invitations.filter(i => i).length > 0) {
|
||||||
this.localStorage.setItem(`${roomId}-invitations`, invitations);
|
this.localStorage.setItem(`${roomId}-invitations`, invitations);
|
||||||
} else {
|
} else {
|
||||||
_logger.default.log('info', "NO FACILITATORS ONLINE");
|
this.sendBotSignal(roomId, BOT_SIGNAL_CHAT_OFFLINE); // send notification to Support Chat Notifications room
|
||||||
|
|
||||||
this.sendBotSignal(roomId, BOT_SIGNAL_CHAT_OFFLINE);
|
const currentDate = new Date();
|
||||||
|
const closedTime = currentDate.toLocaleTimeString();
|
||||||
|
const roomRef = roomId.split(':')[0];
|
||||||
|
const notification = `No facilitators were online, chat closed at ${closedTime} (room ID: ${roomRef})`;
|
||||||
|
|
||||||
|
_logger.default.log('info', `NO FACILITATORS ONLINE, CHAT CLOSED AT ${closedTime} (room ID: ${roomRef})`);
|
||||||
|
|
||||||
|
this.sendTextMessage(this.config.facilitatorRoomId, notification);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.handleBotCrash(roomId, err);
|
this.handleBotCrash(roomId, err);
|
||||||
@ -182,6 +197,7 @@ class OcrccBot {
|
|||||||
handleBotCrash(roomId, error) {
|
handleBotCrash(roomId, error) {
|
||||||
if (roomId) {
|
if (roomId) {
|
||||||
this.sendTextMessage(roomId, this.config.botErrorMessage);
|
this.sendTextMessage(roomId, this.config.botErrorMessage);
|
||||||
|
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendTextMessage(this.config.facilitatorRoomId, `${this.config.botDisplayName} ran into an error: ${error}. Please verify that the chat service is working.`);
|
this.sendTextMessage(this.config.facilitatorRoomId, `${this.config.botDisplayName} ran into an error: ${error}. Please verify that the chat service is working.`);
|
||||||
@ -510,16 +526,31 @@ class OcrccBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (member.membership === "leave" && member.userId !== this.config.botUserId) {
|
if (member.membership === "leave" && member.userId !== this.config.botUserId) {
|
||||||
|
// notify room if the facilitator has left
|
||||||
|
try {
|
||||||
|
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`);
|
||||||
|
|
||||||
|
if (member.userId === facilitatorId) {
|
||||||
|
this.sendTextMessage(member.roomId, `${member.name} has left the chat.`); // 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} left the chat at ${chatTime} (room ID: ${roomId})`;
|
||||||
|
await this.sendTextMessage(this.config.facilitatorRoomId, notification);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
_logger.default.log("error", `ERROR NOTIFYING THAT FACLITATOR HAS LEFT THE ROOM ==> ${err}`);
|
||||||
|
}
|
||||||
|
|
||||||
const room = this.client.getRoom(member.roomId);
|
const room = this.client.getRoom(member.roomId);
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
const roomMembers = await room.getJoinedMembers(); // array
|
const roomMembers = await room.getJoinedMembers(); // array
|
||||||
|
// leave if there is nobody in the room
|
||||||
const facilitatorRoomMembers = await this.client.getJoinedRoomMembers(this.config.facilitatorRoomId); // object
|
|
||||||
|
|
||||||
const isBotInRoom = Boolean(roomMembers.find(member => member.userId === this.config.botUserId)); // leave if there is nobody in the room
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const memberCount = roomMembers.length;
|
const memberCount = roomMembers.length;
|
||||||
|
const isBotInRoom = Boolean(roomMembers.find(member => member.userId === this.config.botUserId));
|
||||||
|
|
||||||
if (memberCount === 1 && isBotInRoom) {
|
if (memberCount === 1 && isBotInRoom) {
|
||||||
// just the bot left
|
// just the bot left
|
||||||
@ -533,27 +564,12 @@ class OcrccBot {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return _logger.default.log("error", `ERROR LEAVING EMPTY ROOM ==> ${err}`);
|
return _logger.default.log("error", `ERROR LEAVING EMPTY ROOM ==> ${err}`);
|
||||||
} // notify room if the facilitator has left
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`);
|
|
||||||
|
|
||||||
if (isBotInRoom && member.userId === facilitatorId) {
|
|
||||||
this.sendTextMessage(member.roomId, `${member.name} has left the chat.`); // 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} left the chat at ${chatTime} (room ID: ${roomId})`;
|
|
||||||
await this.sendTextMessage(this.config.facilitatorRoomId, notification);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
_logger.default.log("error", `ERROR NOTIFYING THAT FACLITATOR HAS LEFT THE ROOM ==> ${err}`);
|
|
||||||
} // 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 facilitatorRoomMembers = await this.client.getJoinedRoomMembers(this.config.facilitatorRoomId); // object
|
||||||
|
|
||||||
const facilitators = facilitatorRoomMembers['joined'];
|
const facilitators = facilitatorRoomMembers['joined'];
|
||||||
let facilitatorInRoom = false;
|
let facilitatorInRoom = false;
|
||||||
roomMembers.forEach(member => {
|
roomMembers.forEach(member => {
|
||||||
@ -579,12 +595,18 @@ class OcrccBot {
|
|||||||
const stillWaiting = this.localStorage.getItem(`${roomId}-waiting`);
|
const stillWaiting = this.localStorage.getItem(`${roomId}-waiting`);
|
||||||
|
|
||||||
if (stillWaiting) {
|
if (stillWaiting) {
|
||||||
_logger.default.log("info", `FACILITATOR DID NOT JOIN CHAT WITHIN TIME LIMIT, SENDING SIGNAL TO END CHAT`);
|
|
||||||
|
|
||||||
await this.sendTextMessage(roomId, this.config.chatNotAvailableMessage);
|
await this.sendTextMessage(roomId, this.config.chatNotAvailableMessage);
|
||||||
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT);
|
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT); // send notification to Support Chat Notifications room
|
||||||
|
|
||||||
|
const currentDate = new Date();
|
||||||
|
const closedTime = currentDate.toLocaleTimeString();
|
||||||
|
const roomRef = roomId.split(':')[0];
|
||||||
|
const notification = `No facilitators joined the chat within the maximum wait time, chat closed at ${closedTime} (room ID: ${roomRef})`;
|
||||||
|
this.sendTextMessage(this.config.facilitatorRoomId, notification);
|
||||||
|
|
||||||
|
_logger.default.log("info", `NO FACILITATORS JOINED THE CHAT WITHIN THE MAXIMUM WAIT TIME, CHAT CLOSED AT ${closedTime} (room ID: ${roomRef})`);
|
||||||
}
|
}
|
||||||
}, this.config.maxWaitTime);
|
}, this.config.maxWaitTime * 1000); // convert seconds to milliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
setInactivityTimeout(roomId) {
|
setInactivityTimeout(roomId) {
|
||||||
@ -599,7 +621,8 @@ class OcrccBot {
|
|||||||
|
|
||||||
await this.sendTextMessage(roomId, this.config.chatInactiveMessage);
|
await this.sendTextMessage(roomId, this.config.chatInactiveMessage);
|
||||||
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT);
|
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT);
|
||||||
}, this.config.maxInactiveTime);
|
}, this.config.maxInactiveTime * 1000); // convert seconds to milliseconds
|
||||||
|
|
||||||
this.inactivityTimers[roomId] = newTimeout;
|
this.inactivityTimers[roomId] = newTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
dist/setup.js
vendored
2
dist/setup.js
vendored
@ -24,7 +24,7 @@ const getSettings = async () => {
|
|||||||
return Object.entries(fields).reduce((settingsObj, [k, v]) => {
|
return Object.entries(fields).reduce((settingsObj, [k, v]) => {
|
||||||
const [scope, key] = k.split('_');
|
const [scope, key] = k.split('_');
|
||||||
|
|
||||||
if (scope === 'platfrom') {
|
if (scope === 'platform') {
|
||||||
settingsObj[key] = v;
|
settingsObj[key] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user