diff --git a/README.md b/README.md
index a067dbc..2eea357 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,8 @@ Phase 2:
* [x] Pantalaimon support
* [ ] No-op mode (for verifying behaviour)
* [ ] Redact messages on ban (optionally)
-* [ ] Less spam in management room (or more, by request)
+* [x] More useful spam in management room
+* [ ] Command to import ACLs, etc from rooms
* [ ] Vet rooms on startup option
* [ ] Room upgrade handling (both protected+list rooms)
* [ ] Command to actually unban users (instead of leaving them stuck)
diff --git a/config/default.yaml b/config/default.yaml
index 2a61f29..7c864fd 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -27,8 +27,12 @@ autojoin: true
# The room ID where people can use the bot. The bot has no access controls, so
# anyone in this room can use the bot - secure your room!
# This should be a room alias or room ID - not a matrix.to URL.
+# Note: Mjolnir is fairly verbose - expect a lot of messages from it.
managementRoom: "#moderators:example.org"
+# Set to false to make the management room a bit quieter.
+verboseLogging: true
+
# The room ID or alias where the bot's own personal ban list is kept. This is
# where the commands to manage a ban list end up being routed to. Note that
# this room is NOT automatically added to the banLists list below - you will
diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts
index eae5f68..12da537 100644
--- a/src/Mjolnir.ts
+++ b/src/Mjolnir.ts
@@ -72,11 +72,23 @@ export class Mjolnir {
await list.updateList();
}
- let errors = await applyServerAcls(this.banLists, Object.keys(this.protectedRooms), this.client);
- await this.printActionResult(errors);
+ let hadErrors = false;
- errors = await applyUserBans(this.banLists, Object.keys(this.protectedRooms), this.client);
- await this.printActionResult(errors);
+ const aclErrors = await applyServerAcls(this.banLists, Object.keys(this.protectedRooms), this);
+ const banErrors = await applyUserBans(this.banLists, Object.keys(this.protectedRooms), this);
+ hadErrors = hadErrors || await this.printActionResult(aclErrors, "Errors updating server ACLs:");
+ hadErrors = hadErrors || await this.printActionResult(banErrors, "Errors updating member bans:");
+
+ if (!hadErrors) {
+ const html = `Done updating rooms - no errors`;
+ const text = "Updated all protected rooms with new rules successfully";
+ await this.client.sendMessage(this.managementRoomId, {
+ msgtype: "m.notice",
+ body: text,
+ format: "org.matrix.custom.html",
+ formatted_body: html,
+ });
+ }
}
public async syncListForRoom(roomId: string) {
@@ -88,11 +100,23 @@ export class Mjolnir {
}
if (!updated) return;
- let errors = await applyServerAcls(this.banLists, Object.keys(this.protectedRooms), this.client);
- await this.printActionResult(errors);
+ let hadErrors = false;
- errors = await applyUserBans(this.banLists, Object.keys(this.protectedRooms), this.client);
- await this.printActionResult(errors);
+ const aclErrors = await applyServerAcls(this.banLists, Object.keys(this.protectedRooms), this);
+ const banErrors = await applyUserBans(this.banLists, Object.keys(this.protectedRooms), this);
+ hadErrors = hadErrors || await this.printActionResult(aclErrors, "Errors updating server ACLs:");
+ hadErrors = hadErrors || await this.printActionResult(banErrors, "Errors updating member bans:");
+
+ if (!hadErrors) {
+ const html = `Done updating rooms - no errors`;
+ const text = "Done updating rooms - no errors";
+ await this.client.sendMessage(this.managementRoomId, {
+ msgtype: "m.notice",
+ body: text,
+ format: "org.matrix.custom.html",
+ formatted_body: html,
+ });
+ }
}
private async handleEvent(roomId: string, event: any) {
@@ -101,29 +125,33 @@ export class Mjolnir {
if (ALL_RULE_TYPES.includes(event['type'])) {
await this.syncListForRoom(roomId);
} else if (event['type'] === "m.room.member") {
- const errors = await applyUserBans(this.banLists, Object.keys(this.protectedRooms), this.client);
- await this.printActionResult(errors);
- }
+ const errors = await applyUserBans(this.banLists, Object.keys(this.protectedRooms), this);
+ const hadErrors = await this.printActionResult(errors);
-
- const html = `Updated all protected rooms with new rules successfully.`;
- const text = "Updated all protected rooms with new rules successfully";
- await this.client.sendMessage(this.managementRoomId, {
- msgtype: "m.notice",
- body: text,
- format: "org.matrix.custom.html",
- formatted_body: html,
- });
+ if (!hadErrors) {
+ const html = `Done updating rooms - no errors`;
+ const text = "Done updating rooms - no errors";
+ await this.client.sendMessage(this.managementRoomId, {
+ msgtype: "m.notice",
+ body: text,
+ format: "org.matrix.custom.html",
+ formatted_body: html,
+ });
+ }
+ } else return; // Not processed
}
- private async printActionResult(errors: RoomUpdateError[]) {
- if (errors.length <= 0) return;
+ private async printActionResult(errors: RoomUpdateError[], title: string=null) {
+ if (errors.length <= 0) return false;
let html = "";
let text = "";
- html += `${errors.length} errors updating protected rooms!