Skip to content

Commit

Permalink
Don't send the banned word in the ban reason (#665)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nexy7574 authored Jan 11, 2025
1 parent c0d4627 commit 9d80b44
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/protections/WordList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import {
UserConsequences,
Value,
describeProtection,
isError,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
StringUserID,
StringRoomID,
MatrixRoomID,
} from "@the-draupnir-project/matrix-basic-types";
import { resultifyBotSDKRequestError } from "matrix-protection-suite-for-matrix-bot-sdk";

const log = new Logger("WordList");

Expand Down Expand Up @@ -193,12 +195,24 @@ export class WordListProtection

const match = this.badWords.exec(message);
if (match) {
const reason = `bad word: ${match[0]}`;
const reason = `Said a bad word. Moderators, consult the management room for more information.`;
await this.userConsequences.consequenceForUserInRoom(
roomID,
event.sender,
reason
);
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,
Expand Down

0 comments on commit 9d80b44

Please sign in to comment.