Compare commits

...

5 Commits

Author SHA1 Message Date
Will Hunt
213c07f928
Merge 0c375992ea into d3f8c033b1 2024-09-20 00:46:31 +02:00
Travis Ralston
d3f8c033b1
Merge pull request #526 from matrix-org/hs/await-redact
Fix NSFW protection not awaiting redaction
2024-09-20 00:46:28 +02:00
Will Hunt
4f73da38b8 await redact in nsfw protection 2024-09-19 22:41:51 +01:00
Will Hunt
0c375992ea fix typo 2024-09-19 22:33:15 +01:00
Will Hunt
ec0c8b7484 Move operator 2024-09-19 22:28:11 +01:00
3 changed files with 5 additions and 6 deletions

View File

@ -50,7 +50,7 @@ export class MentionSpam extends Protection {
let found = 0;
for (const word of body.split(/\s/)) {
if (USER_ID_REGEX.test(word.trim())) {
if (found++ > max) {
if (++found > max) {
return true;
}
}
@ -60,7 +60,7 @@ export class MentionSpam extends Protection {
let found = 0;
for (const word of htmlBody.split(/\s/)) {
if (USER_ID_REGEX.test(word.trim())) {
if (found++ > max) {
if (++found > max) {
return true;
}
}
@ -72,7 +72,7 @@ export class MentionSpam extends Protection {
public async handleEvent(mjolnir: Mjolnir, roomId: string, event: any): Promise<any> {
if (event['type'] === 'm.room.message') {
let content = event['content'] || {};
const explicitMentions = content["m.mentions"]?.["m.user_ids"];
const explicitMentions = content["m.mentions"]?.user_ids;
const hitLimit = this.checkMentions(content.body, content.formatted_body, explicitMentions);
if (hitLimit) {
await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "MentionSpam", `Redacting event from ${event['sender']} for spamming mentions. ${Permalinks.forEvent(roomId, event['event_id'], [new UserID(await mjolnir.client.getUserId()).domain])}`);

View File

@ -60,10 +60,9 @@ export class NsfwProtection extends Protection {
if (prediction["probability"] > mjolnir.config.nsfwSensitivity) {
await mjolnir.managementRoomOutput.logMessage(LogLevel.INFO, "NSFWProtection", `Redacting ${event["event_id"]} for inappropriate content.`);
try {
mjolnir.client.redactEvent(roomId, event["event_id"])
await mjolnir.client.redactEvent(roomId, event["event_id"]);
} catch (err) {
await mjolnir.managementRoomOutput.logMessage(LogLevel.ERROR, "NSFWProtection", `There was an error redacting ${event["event_id"]}: ${err}`);
}
}
}

View File

@ -71,7 +71,7 @@ describe("Test: Mention spam protection", function () {
});
// Also covers HTML mentions
const mentionUsers = Array.from({length: DEFAULT_MAX_MENTIONS+1}, (_, i) => `@user${i}:example.org`);
const messageWithTextMentions = await client.sendText(room, 'Hello world ' + mentionUsers.join(' '));
const messageWithTextMentions = await client.sendText(room, mentionUsers.join(' '));
const messageWithMMentions = await client.sendMessage(room, {
msgtype: 'm.text',
body: 'Hello world',