From 0879cd58a0bb47a8520366c327a7cc2d8450e5b7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 4 Dec 2019 19:25:46 -0700 Subject: [PATCH] Actually fix ban command not always applying Fixes https://github.com/matrix-org/mjolnir/issues/13 --- src/Mjolnir.ts | 14 ++++++++------ src/commands/UnbanBanCommand.ts | 4 ---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts index 508d5b53..ede9013b 100644 --- a/src/Mjolnir.ts +++ b/src/Mjolnir.ts @@ -379,6 +379,14 @@ export class Mjolnir { } } + // Check for updated ban lists before checking protected rooms - the ban lists might be protected + // themselves. + if (this.banLists.map(b => b.roomId).includes(roomId)) { + if (ALL_RULE_TYPES.includes(event['type'])) { + await this.syncListForRoom(roomId); + } + } + if (Object.keys(this.protectedRooms).includes(roomId)) { if (event['sender'] === await this.client.getUserId()) return; // Ignore ourselves @@ -424,12 +432,6 @@ export class Mjolnir { await this.printActionResult(errors); } } - - if (this.banLists.map(b => b.roomId).includes(roomId)) { - if (ALL_RULE_TYPES.includes(event['type'])) { - await this.syncListForRoom(roomId); - } - } } private async printActionResult(errors: RoomUpdateError[], title: string = null, logAnyways = false) { diff --git a/src/commands/UnbanBanCommand.ts b/src/commands/UnbanBanCommand.ts index 89433254..12d0c76b 100644 --- a/src/commands/UnbanBanCommand.ts +++ b/src/commands/UnbanBanCommand.ts @@ -119,10 +119,6 @@ export async function execBanCommand(roomId: string, event: any, mjolnir: Mjolni await mjolnir.client.sendStateEvent(bits.list.roomId, bits.ruleType, stateKey, ruleContent); await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); - - // Just sync the lists to apply the ban as it might not always come down /sync for some reason - await logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Syncing lists to ensure the ban is applied`); - await mjolnir.syncLists(config.verboseLogging); } // !mjolnir unban [apply:t/f]