Skip to content

Commit 9d80b44

Browse files
authored
Don't send the banned word in the ban reason (#665)
This change makes the ban reason when a user sends a banned word generic, and instead sends the banned word in the management room directly. This prevents the banned word from persisting in the room timeline after redacting the original event. Signed-off-by: nexy7574 <[email protected]>
1 parent c0d4627 commit 9d80b44

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/protections/WordList.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import {
2626
UserConsequences,
2727
Value,
2828
describeProtection,
29+
isError,
2930
} from "matrix-protection-suite";
3031
import { Draupnir } from "../Draupnir";
3132
import {
3233
StringUserID,
3334
StringRoomID,
3435
MatrixRoomID,
3536
} from "@the-draupnir-project/matrix-basic-types";
37+
import { resultifyBotSDKRequestError } from "matrix-protection-suite-for-matrix-bot-sdk";
3638

3739
const log = new Logger("WordList");
3840

@@ -193,12 +195,24 @@ export class WordListProtection
193195

194196
const match = this.badWords.exec(message);
195197
if (match) {
196-
const reason = `bad word: ${match[0]}`;
198+
const reason = `Said a bad word. Moderators, consult the management room for more information.`;
197199
await this.userConsequences.consequenceForUserInRoom(
198200
roomID,
199201
event.sender,
200202
reason
201203
);
204+
const messageResult = await this.draupnir.client
205+
.sendMessage(this.draupnir.managementRoomID, {
206+
msgtype: "m.notice",
207+
body: `Banned ${event.sender} in ${roomID} for saying '${match[0]}'.`,
208+
})
209+
.then((_) => Ok(undefined), resultifyBotSDKRequestError);
210+
if (isError(messageResult)) {
211+
log.error(
212+
`Failed to send a message to the management room after banning ${event.sender} in ${roomID} for saying '${match[0]}'.`,
213+
messageResult.error
214+
);
215+
}
202216
await this.eventConsequences.consequenceForEvent(
203217
roomID,
204218
event.event_id,

0 commit comments

Comments
 (0)