From e776d82d89691aaba133b6a9a364b66644f13a7d Mon Sep 17 00:00:00 2001 From: Shay Date: Wed, 24 Jul 2024 15:53:19 -0700 Subject: [PATCH] modernize language (#513) --- src/commands/DeactivateCommand.ts | 4 ++-- src/commands/KickCommand.ts | 12 ++++++------ src/commands/SetPowerLevelCommand.ts | 6 +++--- src/commands/ShutdownRoomCommand.ts | 4 ++-- src/commands/UnbanBanCommand.ts | 10 +++++----- src/utils.ts | 8 ++++---- synapse_antispam/mjolnir/list_rule.py | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/commands/DeactivateCommand.ts b/src/commands/DeactivateCommand.ts index 39743f4..14a6ee0 100644 --- a/src/commands/DeactivateCommand.ts +++ b/src/commands/DeactivateCommand.ts @@ -19,7 +19,7 @@ import { RichReply } from "matrix-bot-sdk"; // !mjolnir deactivate export async function execDeactivateCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { - const victim = parts[2]; + const target = parts[2]; const isAdmin = await mjolnir.isSynapseAdmin(); if (!isAdmin) { @@ -30,6 +30,6 @@ export async function execDeactivateCommand(roomId: string, event: any, mjolnir: return; } - await mjolnir.deactivateSynapseUser(victim); + await mjolnir.deactivateSynapseUser(target); await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } diff --git a/src/commands/KickCommand.ts b/src/commands/KickCommand.ts index 8a5c85e..f7649f4 100644 --- a/src/commands/KickCommand.ts +++ b/src/commands/KickCommand.ts @@ -54,21 +54,21 @@ export async function execKickCommand(roomId: string, event: any, mjolnir: Mjoln const members = await mjolnir.client.getRoomMembers(protectedRoomId, undefined, ["join"], ["ban", "leave"]); for (const member of members) { - const victim = member.membershipFor; + const target = member.membershipFor; - if (kickRule.test(victim)) { - await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "KickCommand", `Removing ${victim} in ${protectedRoomId}`, protectedRoomId); + if (kickRule.test(target)) { + await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "KickCommand", `Removing ${target} in ${protectedRoomId}`, protectedRoomId); if (!mjolnir.config.noop) { try { await mjolnir.taskQueue.push(async () => { - return mjolnir.client.kickUser(victim, protectedRoomId, reason); + return mjolnir.client.kickUser(target, protectedRoomId, reason); }); } catch (e) { - await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "KickCommand", `An error happened while trying to kick ${victim}: ${e}`); + await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "KickCommand", `An error happened while trying to kick ${target}: ${e}`); } } else { - await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "KickCommand", `Tried to kick ${victim} in ${protectedRoomId} but the bot is running in no-op mode.`, protectedRoomId); + await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "KickCommand", `Tried to kick ${target} in ${protectedRoomId} but the bot is running in no-op mode.`, protectedRoomId); } } } diff --git a/src/commands/SetPowerLevelCommand.ts b/src/commands/SetPowerLevelCommand.ts index 58553eb..1b096db 100644 --- a/src/commands/SetPowerLevelCommand.ts +++ b/src/commands/SetPowerLevelCommand.ts @@ -19,7 +19,7 @@ import { extractRequestError, LogLevel, LogService } from "matrix-bot-sdk"; // !mjolnir powerlevel [room] export async function execSetPowerLevelCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { - const victim = parts[2]; + const target = parts[2]; const level = Math.round(Number(parts[3])); const inRoom = parts[4]; @@ -27,10 +27,10 @@ export async function execSetPowerLevelCommand(roomId: string, event: any, mjoln for (const targetRoomId of targetRooms) { try { - await mjolnir.client.setUserPowerLevel(victim, targetRoomId, level); + await mjolnir.client.setUserPowerLevel(target, targetRoomId, level); } catch (e) { const message = e.message || (e.body ? e.body.error : ''); - await mjolnir.managementRoomOutput.logMessage(LogLevel.ERROR, "SetPowerLevelCommand", `Failed to set power level of ${victim} to ${level} in ${targetRoomId}: ${message}`, targetRoomId); + await mjolnir.managementRoomOutput.logMessage(LogLevel.ERROR, "SetPowerLevelCommand", `Failed to set power level of ${target} to ${level} in ${targetRoomId}: ${message}`, targetRoomId); LogService.error("SetPowerLevelCommand", extractRequestError(e)); } } diff --git a/src/commands/ShutdownRoomCommand.ts b/src/commands/ShutdownRoomCommand.ts index edfb424..098c7ba 100644 --- a/src/commands/ShutdownRoomCommand.ts +++ b/src/commands/ShutdownRoomCommand.ts @@ -19,7 +19,7 @@ import { RichReply } from "matrix-bot-sdk"; // !mjolnir shutdown room [] export async function execShutdownRoomCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { - const victim = parts[3]; + const target = parts[3]; const reason = parts.slice(4).join(" ") || undefined; const isAdmin = await mjolnir.isSynapseAdmin(); @@ -31,6 +31,6 @@ export async function execShutdownRoomCommand(roomId: string, event: any, mjolni return; } - await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(victim), reason); + await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(target), reason); await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } diff --git a/src/commands/UnbanBanCommand.ts b/src/commands/UnbanBanCommand.ts index e751de5..c6285ba 100644 --- a/src/commands/UnbanBanCommand.ts +++ b/src/commands/UnbanBanCommand.ts @@ -137,15 +137,15 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol const members = await mjolnir.client.getRoomMembers(protectedRoomId, undefined, ['ban'], undefined); await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Found ${members.length} banned user(s)`); for (const member of members) { - const victim = member.membershipFor; + const target = member.membershipFor; if (member.membership !== 'ban') continue; - if (rule.test(victim)) { - await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Unbanning ${victim} in ${protectedRoomId}`, protectedRoomId); + if (rule.test(target)) { + await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Unbanning ${target} in ${protectedRoomId}`, protectedRoomId); if (!mjolnir.config.noop) { - await mjolnir.client.unbanUser(victim, protectedRoomId); + await mjolnir.client.unbanUser(target, protectedRoomId); } else { - await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "UnbanBanCommand", `Attempted to unban ${victim} in ${protectedRoomId} but Mjolnir is running in no-op mode`, protectedRoomId); + await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "UnbanBanCommand", `Attempted to unban ${target} in ${protectedRoomId} but Mjolnir is running in no-op mode`, protectedRoomId); } unbannedSomeone = true; diff --git a/src/utils.ts b/src/utils.ts index c3c5991..5e9899b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -87,12 +87,12 @@ export async function redactUserMessagesIn(client: MatrixSendClient, managementR await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Fetching sent messages for ${userIdOrGlob} in ${targetRoomId} to redact...`, targetRoomId); await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => { - for (const victimEvent of eventsToRedact) { - await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${victimEvent['event_id']} in ${targetRoomId}`, targetRoomId); + for (const targetEvent of eventsToRedact) { + await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${targetEvent['event_id']} in ${targetRoomId}`, targetRoomId); if (!noop) { - await client.redactEvent(targetRoomId, victimEvent['event_id']); + await client.redactEvent(targetRoomId, targetEvent['event_id']); } else { - await managementRoom.logMessage(LogLevel.WARN, "utils#redactUserMessagesIn", `Tried to redact ${victimEvent['event_id']} in ${targetRoomId} but Mjolnir is running in no-op mode`, targetRoomId); + await managementRoom.logMessage(LogLevel.WARN, "utils#redactUserMessagesIn", `Tried to redact ${targetEvent['event_id']} in ${targetRoomId} but Mjolnir is running in no-op mode`, targetRoomId); } } }); diff --git a/synapse_antispam/mjolnir/list_rule.py b/synapse_antispam/mjolnir/list_rule.py index ad0ca3f..13f2c41 100644 --- a/synapse_antispam/mjolnir/list_rule.py +++ b/synapse_antispam/mjolnir/list_rule.py @@ -50,5 +50,5 @@ class ListRule(object): self.reason = reason self.kind = rule_type_to_stable(kind) - def matches(self, victim): - return self.regex.match(victim) + def matches(self, target): + return self.regex.match(target)