mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Status command can distinguish between protected and watched lists.
https://github.com/matrix-org/mjolnir/issues/370
This commit is contained in:
parent
5c2e4ab0bb
commit
cea6944c92
@ -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`,
|
||||||
|
@ -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`;
|
||||||
|
for (const list of lists) {
|
||||||
const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`;
|
const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`;
|
||||||
html += `<li>${htmlEscape(list.listShortcode)} @ <a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`;
|
html += `<li>${htmlEscape(list.listShortcode)} @ <a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`;
|
||||||
text += `* ${list.listShortcode} @ ${list.roomRef} (${ruleInfo})\n`;
|
text += `* ${list.listShortcode} @ ${list.roomRef} (${ruleInfo})\n`;
|
||||||
}
|
}
|
||||||
if (mjolnir.lists.length === 0) {
|
if (lists.length === 0) {
|
||||||
html += "<li><i>None</i></li>";
|
html += "<li><i>None</i></li>";
|
||||||
text += "* None\n";
|
text += "* None\n";
|
||||||
}
|
}
|
||||||
html += "</ul>";
|
html += "</ul>";
|
||||||
|
}
|
||||||
|
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);
|
const reply = RichReply.createFor(roomId, event, text, html);
|
||||||
reply["msgtype"] = "m.notice";
|
reply["msgtype"] = "m.notice";
|
||||||
|
Loading…
Reference in New Issue
Block a user