From 177bd0ff54d40f5a8fbe8333d50376bbaebc8fe4 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 11 Jan 2025 23:30:09 +0000 Subject: [PATCH] Log an error when sending the ban reason fails Signed-off-by: nexy7574 --- src/protections/WordList.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/protections/WordList.ts b/src/protections/WordList.ts index 4f68fddb..44fca4de 100644 --- a/src/protections/WordList.ts +++ b/src/protections/WordList.ts @@ -26,6 +26,7 @@ import { UserConsequences, Value, describeProtection, + isError, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; import { @@ -33,6 +34,7 @@ import { StringRoomID, MatrixRoomID, } from "@the-draupnir-project/matrix-basic-types"; +import { resultifyBotSDKRequestError } from "matrix-protection-suite-for-matrix-bot-sdk"; const log = new Logger("WordList"); @@ -199,10 +201,22 @@ export class WordListProtection event.sender, reason ); - await this.draupnir.client.sendMessage(this.draupnir.managementRoomID, { - msgtype: "m.notice", - body: `Banned ${event.sender} in ${roomID} for saying '${match[0]}'.`, - }); + // await this.draupnir.client.sendMessage(this.draupnir.managementRoomID, { + // msgtype: "m.notice", + // body: `Banned ${event.sender} in ${roomID} for saying '${match[0]}'.`, + // }); + const messageResult = await this.draupnir.client + .sendMessage(this.draupnir.managementRoomID, { + msgtype: "m.notice", + body: `Banned ${event.sender} in ${roomID} for saying '${match[0]}'.`, + }) + .then((_) => Ok(undefined), resultifyBotSDKRequestError); + if (isError(messageResult)) { + log.error( + `Failed to send a message to the management room after banning ${event.sender} in ${roomID} for saying '${match[0]}'.`, + messageResult.error + ); + } await this.eventConsequences.consequenceForEvent( roomID, event.event_id,