Status command can distinguish between protected and watched lists.

https://github.com/matrix-org/mjolnir/issues/370
This commit is contained in:
gnuxie 2022-10-14 20:01:26 +01:00 committed by Gnuxie
parent 5c2e4ab0bb
commit cea6944c92
2 changed files with 29 additions and 13 deletions

View File

@ -335,6 +335,15 @@ export class Mjolnir {
this.reportPoller?.stop(); 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. * Explicitly protect this room, adding it to the account data.
* Should NOT be used to protect a room to implement e.g. `config.protectAllJoinedRooms`, * Should NOT be used to protect a room to implement e.g. `config.protectAllJoinedRooms`,

View File

@ -18,6 +18,7 @@ import { Mjolnir, STATE_CHECKING_PERMISSIONS, STATE_NOT_STARTED, STATE_RUNNING,
import { RichReply } from "matrix-bot-sdk"; import { RichReply } from "matrix-bot-sdk";
import { htmlEscape, parseDuration } from "../utils"; import { htmlEscape, parseDuration } from "../utils";
import { HumanizeDurationLanguage, HumanizeDuration } from "humanize-duration-ts"; import { HumanizeDurationLanguage, HumanizeDuration } from "humanize-duration-ts";
import PolicyList from "../models/PolicyList";
const HUMANIZE_LAG_SERVICE: HumanizeDurationLanguage = new HumanizeDurationLanguage(); const HUMANIZE_LAG_SERVICE: HumanizeDurationLanguage = new HumanizeDurationLanguage();
const HUMANIZER: HumanizeDuration = new HumanizeDuration(HUMANIZE_LAG_SERVICE); const HUMANIZER: HumanizeDuration = new HumanizeDuration(HUMANIZE_LAG_SERVICE);
@ -67,22 +68,28 @@ async function showMjolnirStatus(roomId: string, event: any, mjolnir: Mjolnir) {
break; break;
} }
html += `<b>Protected rooms: </b> ${Object.keys(mjolnir.protectedRooms).length}<br/>`; html += `<b>Protected rooms: </b> ${mjolnir.protectedRoomsTracker.getProtectedRooms().length}<br/>`;
text += `Protected rooms: ${Object.keys(mjolnir.protectedRooms).length}\n`; text += `Protected rooms: ${mjolnir.protectedRoomsTracker.getProtectedRooms().length}\n`;
// Append list information // Append list information
html += "<b>Subscribed ban lists:</b><br><ul>"; const renderPolicyLists = (header: string, lists: PolicyList[]) => {
text += "Subscribed ban lists:\n"; html += `<b>${header}:</b><br><ul>`;
for (const list of mjolnir.lists) { text += `${header}:\n`;
const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`; for (const list of lists) {
html += `<li>${htmlEscape(list.listShortcode)} @ <a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`; const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`;
text += `* ${list.listShortcode} @ ${list.roomRef} (${ruleInfo})\n`; html += `<li>${htmlEscape(list.listShortcode)} @ <a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`;
text += `* ${list.listShortcode} @ ${list.roomRef} (${ruleInfo})\n`;
}
if (lists.length === 0) {
html += "<li><i>None</i></li>";
text += "* None\n";
}
html += "</ul>";
} }
if (mjolnir.lists.length === 0) { const subscribedLists = mjolnir.lists.filter(list => !mjolnir.explicitlyProtectedRooms.includes(list.roomId));
html += "<li><i>None</i></li>"; renderPolicyLists("Subscribed policy lists", subscribedLists);
text += "* None\n"; const subscribedAndProtectedLists = mjolnir.lists.filter(list => mjolnir.explicitlyProtectedRooms.includes(list.roomId));
} renderPolicyLists("Subscribed and protected policy lists", subscribedAndProtectedLists);
html += "</ul>";
const reply = RichReply.createFor(roomId, event, text, html); const reply = RichReply.createFor(roomId, event, text, html);
reply["msgtype"] = "m.notice"; reply["msgtype"] = "m.notice";