Skip to content

Commit cea6944

Browse files
committed
Status command can distinguish between protected and watched lists.
#370
1 parent 5c2e4ab commit cea6944

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/Mjolnir.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ export class Mjolnir {
335335
this.reportPoller?.stop();
336336
}
337337

338+
/**
339+
* Rooms that mjolnir is configured to explicitly protect.
340+
* Do not use to access all of the rooms that mjolnir protects.
341+
* FIXME: In future ProtectedRoomsSet on this mjolnir should not be public and should also be accessed via a delegator method.
342+
*/
343+
public get explicitlyProtectedRooms(): string[] {
344+
return this.protectedRoomsConfig.getExplicitlyProtectedRooms()
345+
}
346+
338347
/**
339348
* Explicitly protect this room, adding it to the account data.
340349
* Should NOT be used to protect a room to implement e.g. `config.protectAllJoinedRooms`,

src/commands/StatusCommand.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Mjolnir, STATE_CHECKING_PERMISSIONS, STATE_NOT_STARTED, STATE_RUNNING,
1818
import { RichReply } from "matrix-bot-sdk";
1919
import { htmlEscape, parseDuration } from "../utils";
2020
import { HumanizeDurationLanguage, HumanizeDuration } from "humanize-duration-ts";
21+
import PolicyList from "../models/PolicyList";
2122

2223
const HUMANIZE_LAG_SERVICE: HumanizeDurationLanguage = new HumanizeDurationLanguage();
2324
const HUMANIZER: HumanizeDuration = new HumanizeDuration(HUMANIZE_LAG_SERVICE);
@@ -67,22 +68,28 @@ async function showMjolnirStatus(roomId: string, event: any, mjolnir: Mjolnir) {
6768
break;
6869
}
6970

70-
html += `<b>Protected rooms: </b> ${Object.keys(mjolnir.protectedRooms).length}<br/>`;
71-
text += `Protected rooms: ${Object.keys(mjolnir.protectedRooms).length}\n`;
71+
html += `<b>Protected rooms: </b> ${mjolnir.protectedRoomsTracker.getProtectedRooms().length}<br/>`;
72+
text += `Protected rooms: ${mjolnir.protectedRoomsTracker.getProtectedRooms().length}\n`;
7273

7374
// Append list information
74-
html += "<b>Subscribed ban lists:</b><br><ul>";
75-
text += "Subscribed ban lists:\n";
76-
for (const list of mjolnir.lists) {
77-
const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`;
78-
html += `<li>${htmlEscape(list.listShortcode)} @ <a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`;
79-
text += `* ${list.listShortcode} @ ${list.roomRef} (${ruleInfo})\n`;
80-
}
81-
if (mjolnir.lists.length === 0) {
82-
html += "<li><i>None</i></li>";
83-
text += "* None\n";
75+
const renderPolicyLists = (header: string, lists: PolicyList[]) => {
76+
html += `<b>${header}:</b><br><ul>`;
77+
text += `${header}:\n`;
78+
for (const list of lists) {
79+
const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`;
80+
html += `<li>${htmlEscape(list.listShortcode)} @ <a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`;
81+
text += `* ${list.listShortcode} @ ${list.roomRef} (${ruleInfo})\n`;
82+
}
83+
if (lists.length === 0) {
84+
html += "<li><i>None</i></li>";
85+
text += "* None\n";
86+
}
87+
html += "</ul>";
8488
}
85-
html += "</ul>";
89+
const subscribedLists = mjolnir.lists.filter(list => !mjolnir.explicitlyProtectedRooms.includes(list.roomId));
90+
renderPolicyLists("Subscribed policy lists", subscribedLists);
91+
const subscribedAndProtectedLists = mjolnir.lists.filter(list => mjolnir.explicitlyProtectedRooms.includes(list.roomId));
92+
renderPolicyLists("Subscribed and protected policy lists", subscribedAndProtectedLists);
8693

8794
const reply = RichReply.createFor(roomId, event, text, html);
8895
reply["msgtype"] = "m.notice";

0 commit comments

Comments
 (0)