diff --git a/src/bot.js b/src/bot.js index 9581973..f4f6f3a 100644 --- a/src/bot.js +++ b/src/bot.js @@ -39,6 +39,31 @@ class OcrccBot { this.sendMessage(roomId, content); } + + async sendNotice(roomId, message) { + logger.log("info", `SENDING *NOTICE*: ${message}`) + try { + await this.client.sendNotice(roomId, message) + } catch(err) { + switch (err["name"]) { + case "UnknownDeviceError": + Object.keys(err.devices).forEach(userId => { + Object.keys(err.devices[userId]).map(async deviceId => { + try { + await this.client.setDeviceVerified(userId, deviceId, true); + } catch(err) { + logger.log("error", `ERROR VERIFYING DEVICE: ${err}`); + } + }); + }); + await this.sendNotice(roomId, message); + default: + logger.log("error", `ERROR SENDING *NOTICE*: ${err}`); + break; + } + } + } + async sendMessage(roomId, content) { logger.log("info", `SENDING MESSAGE: ${content.body}`) try { @@ -104,6 +129,7 @@ class OcrccBot { if (chatOffline) { logger.log('info', "NO FACILITATORS ONLINE") this.sendTextMessage(roomId, this.config.CHAT_OFFLINE_MESSAGE); + this.sendNotice(roomId, "Chat is offline") } } catch(err) { @@ -112,6 +138,7 @@ class OcrccBot { } } + async uninviteFacilitators(roomId) { this.localStorage.removeItem(`${roomId}-waiting`)