diff --git a/src/protections/BasicFlooding.ts b/src/protections/BasicFlooding.ts index 873bc38..42c04ba 100644 --- a/src/protections/BasicFlooding.ts +++ b/src/protections/BasicFlooding.ts @@ -18,6 +18,7 @@ import { IProtection } from "./IProtection"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, LogService } from "matrix-bot-sdk"; 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 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 // Redact all the things the user said too - for (const eventId of forUser.map(e => e.eventId)) { - await mjolnir.client.redactEvent(roomId, eventId, "spam"); + if (!config.noop) { + 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 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 forUser = forRoom[event['sender']] = []; // reset the user's list diff --git a/src/protections/FirstMessageIsImage.ts b/src/protections/FirstMessageIsImage.ts index 7d5ed13..695f76b 100644 --- a/src/protections/FirstMessageIsImage.ts +++ b/src/protections/FirstMessageIsImage.ts @@ -18,6 +18,7 @@ import { IProtection } from "./IProtection"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, LogService } from "matrix-bot-sdk"; import { logMessage } from "../LogProxy"; +import config from "../config"; export class FirstMessageIsImage implements IProtection { @@ -63,10 +64,18 @@ export class FirstMessageIsImage implements IProtection { this.recentlyBanned.push(event['sender']); // flag to reduce spam // 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 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`); + } } } diff --git a/src/queues/AutomaticRedactionQueue.ts b/src/queues/AutomaticRedactionQueue.ts index 4b965dc..b2fec7d 100644 --- a/src/queues/AutomaticRedactionQueue.ts +++ b/src/queues/AutomaticRedactionQueue.ts @@ -16,6 +16,7 @@ limitations under the License. import { LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk"; import { logMessage } from "../LogProxy"; +import config from "../config"; export class AutomaticRedactionQueue { private usersToRedact: Set = new Set(); @@ -36,7 +37,11 @@ export class AutomaticRedactionQueue { const permalink = Permalinks.forEvent(roomId, event['event_id']); try { 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) { logMessage(LogLevel.WARN, "AutomaticRedactionQueue", `Unable to redact message: ${permalink}`); LogService.warn("AutomaticRedactionQueue", e);