From 03382ce70c1cc66f3e9a70cac50efc615835c470 Mon Sep 17 00:00:00 2001 From: Randshot Date: Sat, 1 Feb 2020 10:30:23 +0100 Subject: [PATCH 1/2] Fix unban command Signed-off-by: Randshot --- src/commands/UnbanBanCommand.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/UnbanBanCommand.ts b/src/commands/UnbanBanCommand.ts index 12d0c76..5040245 100644 --- a/src/commands/UnbanBanCommand.ts +++ b/src/commands/UnbanBanCommand.ts @@ -87,7 +87,7 @@ export async function parseArguments(roomId: string, event: any, mjolnir: Mjolni let replyMessage = null; if (!list) replyMessage = "No ban list matching that shortcode was found"; else if (!ruleType) replyMessage = "Please specify the type as either 'user', 'room', or 'server'"; - else if (!entity) replyMessage = "No entity found to ban"; + else if (!entity) replyMessage = "No entity found to (un)ban"; if (replyMessage) { const reply = RichReply.createFor(roomId, event, replyMessage, replyMessage); @@ -131,15 +131,16 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol await mjolnir.client.sendStateEvent(bits.list.roomId, bits.ruleType, stateKey, ruleContent); - if (USER_RULE_TYPES.includes(bits.ruleType) && parts.length > 5 && parts[5] === 'true') { + if (USER_RULE_TYPES.includes(bits.ruleType) && bits.reason === 'true') { const rule = new MatrixGlob(bits.entity); await logMessage(LogLevel.INFO, "UnbanBanCommand", "Unbanning users that match glob: " + bits.entity); let unbannedSomeone = false; for (const protectedRoomId of Object.keys(mjolnir.protectedRooms)) { const members = await mjolnir.client.getRoomMembers(protectedRoomId, null, ['ban'], null); + await logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Found ${members.length} banned user(s)`); for (const member of members) { - const victim = member['state_key']; - if (!member['content'] || member['content']['membership'] !== 'ban') continue; + const victim = member.membershipFor; + if (member.membership !== 'ban') continue; if (rule.test(victim)) { await logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Unbanning ${victim} in ${protectedRoomId}`); From bef99297f9a9f9a8e82c23fa6f66f2744f7033ea Mon Sep 17 00:00:00 2001 From: Randshot Date: Mon, 3 Feb 2020 17:37:27 +0100 Subject: [PATCH 2/2] Remove scary text... Signed-off-by: Randshot --- src/commands/UnbanBanCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/UnbanBanCommand.ts b/src/commands/UnbanBanCommand.ts index 5040245..efe1a86 100644 --- a/src/commands/UnbanBanCommand.ts +++ b/src/commands/UnbanBanCommand.ts @@ -87,7 +87,7 @@ export async function parseArguments(roomId: string, event: any, mjolnir: Mjolni let replyMessage = null; if (!list) replyMessage = "No ban list matching that shortcode was found"; else if (!ruleType) replyMessage = "Please specify the type as either 'user', 'room', or 'server'"; - else if (!entity) replyMessage = "No entity found to (un)ban"; + else if (!entity) replyMessage = "No entity found"; if (replyMessage) { const reply = RichReply.createFor(roomId, event, replyMessage, replyMessage);