mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Compare commits
5 Commits
279a28fdb8
...
213c07f928
Author | SHA1 | Date | |
---|---|---|---|
|
213c07f928 | ||
|
d3f8c033b1 | ||
|
4f73da38b8 | ||
|
0c375992ea | ||
|
ec0c8b7484 |
@ -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])}`);
|
||||
|
@ -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}`);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user