Skip to content

Commit

Permalink
Revert 0f91bce
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Dec 17, 2024
1 parent 3ae6a4e commit 800d572
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 161 deletions.
4 changes: 0 additions & 4 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ recordIgnoredInvites: false
# (see verboseLogging to adjust this a bit.)
managementRoom: "#moderators:example.org"

# Forward any messages mentioning the bot user to the mangement room. Repeated mentions within
# a 10 minute period are ignored.
forwardMentionsToManagementRoom: false

# Whether Mjolnir should log a lot more messages in the room,
# mainly involves "all-OK" messages, and debugging messages for when mjolnir checks bans in a room.
verboseLogging: true
Expand Down
39 changes: 3 additions & 36 deletions src/Mjolnir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2024 The Matrix.org Foundation C.I.C.
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,14 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import {
extractRequestError,
LogLevel,
LogService,
MembershipEvent,
Permalinks,
UserID,
} from "@vector-im/matrix-bot-sdk";
import { extractRequestError, LogLevel, LogService, MembershipEvent } from "@vector-im/matrix-bot-sdk";

import { ALL_RULE_TYPES as ALL_BAN_LIST_RULE_TYPES } from "./models/ListRule";
import { COMMAND_PREFIX, handleCommand } from "./commands/CommandHandler";
Expand All @@ -41,7 +34,6 @@ import { RoomMemberManager } from "./RoomMembers";
import ProtectedRoomsConfig from "./ProtectedRoomsConfig";
import { MatrixEmitter, MatrixSendClient } from "./MatrixEmitter";
import { OpenMetrics } from "./webapis/OpenMetrics";
import { LRUCache } from "lru-cache";
import { ModCache } from "./ModCache";

export const STATE_NOT_STARTED = "not_started";
Expand Down Expand Up @@ -90,11 +82,6 @@ export class Mjolnir {

public readonly policyListManager: PolicyListManager;

public readonly lastBotMentionForRoomId = new LRUCache<string, true>({
ttl: 1000 * 60 * 8, // 8 minutes
ttlAutopurge: true,
});

/**
* Members of the moderator room and others who should not be banned, ACL'd etc.
*/
Expand Down Expand Up @@ -220,29 +207,9 @@ export class Mjolnir {

matrixEmitter.on("room.message", async (roomId, event) => {
const eventContent = event.content;
if (roomId !== this.managementRoomId) return;
if (typeof eventContent !== "object") return;

if (this.config.forwardMentionsToManagementRoom && this.protectedRoomsTracker.isProtectedRoom(roomId)) {
if (eventContent?.["m.mentions"]?.user_ids?.includes(this.clientUserId)) {
LogService.info("Mjolnir", `Bot mentioned ${roomId} by ${event.sender}`);
// Bot mentioned in a public room.
if (this.lastBotMentionForRoomId.has(roomId)) {
// Mentioned too recently, ignore.
return;
}
this.lastBotMentionForRoomId.set(roomId, true);
const permalink = Permalinks.forEvent(roomId, event.event_id, [
new UserID(this.clientUserId).domain,
]);
await this.managementRoomOutput.logMessage(
LogLevel.INFO,
"Mjolnir",
`Bot mentioned ${roomId} by ${event.sender} in ${permalink}`,
roomId,
);
}
}

const { msgtype, body: originalBody, sender } = eventContent;
const eventId = event.event_id;
if (msgtype !== "m.text" || typeof originalBody !== "string") {
Expand Down
2 changes: 0 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export interface IConfig {
acceptInvitesFromSpace: string;
recordIgnoredInvites: boolean;
managementRoom: string;
forwardMentionsToManagementRoom: boolean;
verboseLogging: boolean;
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
syncOnStartup: boolean;
Expand Down Expand Up @@ -210,7 +209,6 @@ const defaultConfig: IConfig = {
autojoinOnlyIfManager: true,
recordIgnoredInvites: false,
managementRoom: "!noop:example.org",
forwardMentionsToManagementRoom: false,
verboseLogging: false,
logLevel: "INFO",
syncOnStartup: true,
Expand Down
117 changes: 0 additions & 117 deletions test/integration/forwardedMentionsTest.ts

This file was deleted.

3 changes: 2 additions & 1 deletion test/integration/protectedRoomsConfigTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { MatrixSendClient } from "../../src/MatrixEmitter";
import { Mjolnir } from "../../src/Mjolnir";
import PolicyList from "../../src/models/PolicyList";
import { newTestUser } from "./clientHelper";
import { createBanList } from "./commands/commandUtils";
import { createBanList, getFirstReaction } from "./commands/commandUtils";

async function createPolicyList(client: MatrixClient): Promise<PolicyList> {
const serverName = new UserID(await client.getUserId()).domain;
const policyListId = await client.createRoom({ preset: "public_chat" });
return new PolicyList(policyListId, Permalinks.forRoom(policyListId), client);
}
Expand Down
5 changes: 4 additions & 1 deletion test/integration/standardConsequenceTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { strict as assert } from "assert";

import { Mjolnir } from "../../src/Mjolnir";
import { Protection } from "../../src/protections/IProtection";
import { newTestUser } from "./clientHelper";
import { newTestUser, noticeListener } from "./clientHelper";
import { matrixClient, mjolnir } from "./mjolnirSetupUtils";
import { ConsequenceBan, ConsequenceRedact } from "../../src/protections/consequence";

describe("Test: standard consequences", function () {
Expand Down

0 comments on commit 800d572

Please sign in to comment.