mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Respect no-op in more places
This commit is contained in:
parent
f9e3c33935
commit
7de3744875
@ -18,6 +18,7 @@ import { IProtection } from "./IProtection";
|
|||||||
import { Mjolnir } from "../Mjolnir";
|
import { Mjolnir } from "../Mjolnir";
|
||||||
import { LogLevel, LogService } from "matrix-bot-sdk";
|
import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||||
import { logMessage } from "../LogProxy";
|
import { logMessage } from "../LogProxy";
|
||||||
|
import config from "../config";
|
||||||
|
|
||||||
export const MAX_PER_MINUTE = 10; // if this is exceeded, we'll ban the user for spam and redact their messages
|
export const MAX_PER_MINUTE = 10; // if this is exceeded, we'll ban the user for spam and redact their messages
|
||||||
const TIMESTAMP_THRESHOLD = 30000; // 30s out of phase
|
const TIMESTAMP_THRESHOLD = 30000; // 30s out of phase
|
||||||
@ -63,12 +64,20 @@ export class BasicFlooding implements IProtection {
|
|||||||
this.recentlyBanned.push(event['sender']); // flag to reduce spam
|
this.recentlyBanned.push(event['sender']); // flag to reduce spam
|
||||||
|
|
||||||
// Redact all the things the user said too
|
// Redact all the things the user said too
|
||||||
for (const eventId of forUser.map(e => e.eventId)) {
|
if (!config.noop) {
|
||||||
await mjolnir.client.redactEvent(roomId, eventId, "spam");
|
for (const eventId of forUser.map(e => e.eventId)) {
|
||||||
|
await mjolnir.client.redactEvent(roomId, eventId, "spam");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await logMessage(LogLevel.WARN, "BasicFlooding", `Tried to redact messages for ${event['sender']} in ${roomId} but Mjolnir is running in no-op mode`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await logMessage(LogLevel.WARN, "BasicFlooding", `Banning ${event['sender']} in ${roomId} for flooding (${messageCount} messages in the last minute)`);
|
await logMessage(LogLevel.WARN, "BasicFlooding", `Banning ${event['sender']} in ${roomId} for flooding (${messageCount} messages in the last minute)`);
|
||||||
await mjolnir.client.banUser(event['sender'], roomId, "spam");
|
if (!config.noop) {
|
||||||
|
await mjolnir.client.banUser(event['sender'], roomId, "spam");
|
||||||
|
} else {
|
||||||
|
await logMessage(LogLevel.WARN, "BasicFlooding", `Tried to ban ${event['sender']} in ${roomId} but Mjolnir is running in no-op mode`);
|
||||||
|
}
|
||||||
|
|
||||||
// Free up some memory now that we're ready to handle it elsewhere
|
// Free up some memory now that we're ready to handle it elsewhere
|
||||||
forUser = forRoom[event['sender']] = []; // reset the user's list
|
forUser = forRoom[event['sender']] = []; // reset the user's list
|
||||||
|
@ -18,6 +18,7 @@ import { IProtection } from "./IProtection";
|
|||||||
import { Mjolnir } from "../Mjolnir";
|
import { Mjolnir } from "../Mjolnir";
|
||||||
import { LogLevel, LogService } from "matrix-bot-sdk";
|
import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||||
import { logMessage } from "../LogProxy";
|
import { logMessage } from "../LogProxy";
|
||||||
|
import config from "../config";
|
||||||
|
|
||||||
export class FirstMessageIsImage implements IProtection {
|
export class FirstMessageIsImage implements IProtection {
|
||||||
|
|
||||||
@ -63,10 +64,18 @@ export class FirstMessageIsImage implements IProtection {
|
|||||||
this.recentlyBanned.push(event['sender']); // flag to reduce spam
|
this.recentlyBanned.push(event['sender']); // flag to reduce spam
|
||||||
|
|
||||||
// Redact the event
|
// Redact the event
|
||||||
await mjolnir.client.redactEvent(roomId, event['event_id'], "spam");
|
if (!config.noop) {
|
||||||
|
await mjolnir.client.redactEvent(roomId, event['event_id'], "spam");
|
||||||
|
} else {
|
||||||
|
await logMessage(LogLevel.WARN, "FirstMessageIsImage", `Tried to redact ${event['event_id']} in ${roomId} but Mjolnir is running in no-op mode`);
|
||||||
|
}
|
||||||
|
|
||||||
await logMessage(LogLevel.WARN, "FirstMessageIsImage", `Banning ${event['sender']} for posting an image as the first thing after joining in ${roomId}.`);
|
await logMessage(LogLevel.WARN, "FirstMessageIsImage", `Banning ${event['sender']} for posting an image as the first thing after joining in ${roomId}.`);
|
||||||
await mjolnir.client.banUser(event['sender'], roomId, "spam");
|
if (!config.noop) {
|
||||||
|
await mjolnir.client.banUser(event['sender'], roomId, "spam");
|
||||||
|
} else {
|
||||||
|
await logMessage(LogLevel.WARN, "FirstMessageIsImage", `Tried to ban ${event['sender']} in ${roomId} but Mjolnir is running in no-op mode`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import { LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk";
|
import { LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk";
|
||||||
import { logMessage } from "../LogProxy";
|
import { logMessage } from "../LogProxy";
|
||||||
|
import config from "../config";
|
||||||
|
|
||||||
export class AutomaticRedactionQueue {
|
export class AutomaticRedactionQueue {
|
||||||
private usersToRedact: Set<string> = new Set<string>();
|
private usersToRedact: Set<string> = new Set<string>();
|
||||||
@ -36,7 +37,11 @@ export class AutomaticRedactionQueue {
|
|||||||
const permalink = Permalinks.forEvent(roomId, event['event_id']);
|
const permalink = Permalinks.forEvent(roomId, event['event_id']);
|
||||||
try {
|
try {
|
||||||
LogService.info("AutomaticRedactionQueue", `Redacting event because the user is listed as bad: ${permalink}`)
|
LogService.info("AutomaticRedactionQueue", `Redacting event because the user is listed as bad: ${permalink}`)
|
||||||
await mjolnirClient.redactEvent(roomId, event['event_id']);
|
if (!config.noop) {
|
||||||
|
await mjolnirClient.redactEvent(roomId, event['event_id']);
|
||||||
|
} else {
|
||||||
|
await logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Tried to redact ${permalink} but Mjolnir is running in no-op mode`);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Unable to redact message: ${permalink}`);
|
logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Unable to redact message: ${permalink}`);
|
||||||
LogService.warn("AutomaticRedactionQueue", e);
|
LogService.warn("AutomaticRedactionQueue", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user