From 39903ee298f43f706dd565b41d5a4a3e5dc167d4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 19 Feb 2020 15:52:41 -0700 Subject: [PATCH] Don't explode if we fail to leave protected rooms when de-protecting --- src/commands/AddRemoveProtectedRoomsCommand.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/commands/AddRemoveProtectedRoomsCommand.ts b/src/commands/AddRemoveProtectedRoomsCommand.ts index 0dd70d5..b674b3a 100644 --- a/src/commands/AddRemoveProtectedRoomsCommand.ts +++ b/src/commands/AddRemoveProtectedRoomsCommand.ts @@ -15,7 +15,8 @@ limitations under the License. */ import { Mjolnir } from "../Mjolnir"; -import { RichReply } from "matrix-bot-sdk"; +import { LogLevel, LogService, RichReply } from "matrix-bot-sdk"; +import { logMessage } from "../LogProxy"; // !mjolnir rooms add export async function execAddProtectedRoom(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { @@ -28,6 +29,11 @@ export async function execAddProtectedRoom(roomId: string, event: any, mjolnir: export async function execRemoveProtectedRoom(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { const protectedRoomId = await mjolnir.client.resolveRoom(parts[3]); await mjolnir.removeProtectedRoom(protectedRoomId); - await mjolnir.client.leaveRoom(protectedRoomId); + try { + await mjolnir.client.leaveRoom(protectedRoomId); + } catch (e) { + LogService.warn("AddRemoveProtectedRoomsCommand", e); + await logMessage(LogLevel.WARN, "AddRemoveProtectedRoomsCommand", `Failed to leave ${protectedRoomId} - the room is no longer being protected, but the bot could not leave`); + } await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); }