From cea6944c92e81d74722bf6ba9a8a429989fd7137 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Fri, 14 Oct 2022 20:01:26 +0100 Subject: [PATCH] Status command can distinguish between protected and watched lists. https://github.com/matrix-org/mjolnir/issues/370 --- src/Mjolnir.ts | 9 +++++++++ src/commands/StatusCommand.ts | 33 ++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts index 1fe15ea..227125f 100644 --- a/src/Mjolnir.ts +++ b/src/Mjolnir.ts @@ -335,6 +335,15 @@ export class Mjolnir { this.reportPoller?.stop(); } + /** + * Rooms that mjolnir is configured to explicitly protect. + * Do not use to access all of the rooms that mjolnir protects. + * FIXME: In future ProtectedRoomsSet on this mjolnir should not be public and should also be accessed via a delegator method. + */ + public get explicitlyProtectedRooms(): string[] { + return this.protectedRoomsConfig.getExplicitlyProtectedRooms() + } + /** * Explicitly protect this room, adding it to the account data. * Should NOT be used to protect a room to implement e.g. `config.protectAllJoinedRooms`, diff --git a/src/commands/StatusCommand.ts b/src/commands/StatusCommand.ts index 6e597ec..5eb69a7 100644 --- a/src/commands/StatusCommand.ts +++ b/src/commands/StatusCommand.ts @@ -18,6 +18,7 @@ import { Mjolnir, STATE_CHECKING_PERMISSIONS, STATE_NOT_STARTED, STATE_RUNNING, import { RichReply } from "matrix-bot-sdk"; import { htmlEscape, parseDuration } from "../utils"; import { HumanizeDurationLanguage, HumanizeDuration } from "humanize-duration-ts"; +import PolicyList from "../models/PolicyList"; const HUMANIZE_LAG_SERVICE: HumanizeDurationLanguage = new HumanizeDurationLanguage(); const HUMANIZER: HumanizeDuration = new HumanizeDuration(HUMANIZE_LAG_SERVICE); @@ -67,22 +68,28 @@ async function showMjolnirStatus(roomId: string, event: any, mjolnir: Mjolnir) { break; } - html += `Protected rooms: ${Object.keys(mjolnir.protectedRooms).length}
`; - text += `Protected rooms: ${Object.keys(mjolnir.protectedRooms).length}\n`; + html += `Protected rooms: ${mjolnir.protectedRoomsTracker.getProtectedRooms().length}
`; + text += `Protected rooms: ${mjolnir.protectedRoomsTracker.getProtectedRooms().length}\n`; // Append list information - html += "Subscribed ban lists:
"; + const subscribedLists = mjolnir.lists.filter(list => !mjolnir.explicitlyProtectedRooms.includes(list.roomId)); + renderPolicyLists("Subscribed policy lists", subscribedLists); + const subscribedAndProtectedLists = mjolnir.lists.filter(list => mjolnir.explicitlyProtectedRooms.includes(list.roomId)); + renderPolicyLists("Subscribed and protected policy lists", subscribedAndProtectedLists); const reply = RichReply.createFor(roomId, event, text, html); reply["msgtype"] = "m.notice";