modernize language

This commit is contained in:
H. Shay 2024-07-24 12:06:08 -07:00
parent 033d84cc70
commit 80cdf0598a
7 changed files with 24 additions and 24 deletions

View File

@ -19,7 +19,7 @@ import { RichReply } from "matrix-bot-sdk";
// !mjolnir deactivate <user ID> // !mjolnir deactivate <user ID>
export async function execDeactivateCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { 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(); const isAdmin = await mjolnir.isSynapseAdmin();
if (!isAdmin) { if (!isAdmin) {
@ -30,6 +30,6 @@ export async function execDeactivateCommand(roomId: string, event: any, mjolnir:
return; return;
} }
await mjolnir.deactivateSynapseUser(victim); await mjolnir.deactivateSynapseUser(target);
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
} }

View File

@ -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"]); const members = await mjolnir.client.getRoomMembers(protectedRoomId, undefined, ["join"], ["ban", "leave"]);
for (const member of members) { for (const member of members) {
const victim = member.membershipFor; const target = member.membershipFor;
if (kickRule.test(victim)) { if (kickRule.test(target)) {
await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "KickCommand", `Removing ${victim} in ${protectedRoomId}`, protectedRoomId); await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "KickCommand", `Removing ${target} in ${protectedRoomId}`, protectedRoomId);
if (!mjolnir.config.noop) { if (!mjolnir.config.noop) {
try { try {
await mjolnir.taskQueue.push(async () => { await mjolnir.taskQueue.push(async () => {
return mjolnir.client.kickUser(victim, protectedRoomId, reason); return mjolnir.client.kickUser(target, protectedRoomId, reason);
}); });
} catch (e) { } 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 { } 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);
} }
} }
} }

View File

@ -19,7 +19,7 @@ import { extractRequestError, LogLevel, LogService } from "matrix-bot-sdk";
// !mjolnir powerlevel <user ID> <level> [room] // !mjolnir powerlevel <user ID> <level> [room]
export async function execSetPowerLevelCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { 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 level = Math.round(Number(parts[3]));
const inRoom = parts[4]; const inRoom = parts[4];
@ -27,10 +27,10 @@ export async function execSetPowerLevelCommand(roomId: string, event: any, mjoln
for (const targetRoomId of targetRooms) { for (const targetRoomId of targetRooms) {
try { try {
await mjolnir.client.setUserPowerLevel(victim, targetRoomId, level); await mjolnir.client.setUserPowerLevel(target, targetRoomId, level);
} catch (e) { } catch (e) {
const message = e.message || (e.body ? e.body.error : '<no message>'); const message = e.message || (e.body ? e.body.error : '<no message>');
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)); LogService.error("SetPowerLevelCommand", extractRequestError(e));
} }
} }

View File

@ -19,7 +19,7 @@ import { RichReply } from "matrix-bot-sdk";
// !mjolnir shutdown room <room> [<message>] // !mjolnir shutdown room <room> [<message>]
export async function execShutdownRoomCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { 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 reason = parts.slice(4).join(" ") || undefined;
const isAdmin = await mjolnir.isSynapseAdmin(); const isAdmin = await mjolnir.isSynapseAdmin();
@ -31,6 +31,6 @@ export async function execShutdownRoomCommand(roomId: string, event: any, mjolni
return; 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'], '✅'); await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
} }

View File

@ -137,15 +137,15 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol
const members = await mjolnir.client.getRoomMembers(protectedRoomId, undefined, ['ban'], undefined); const members = await mjolnir.client.getRoomMembers(protectedRoomId, undefined, ['ban'], undefined);
await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Found ${members.length} banned user(s)`); await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Found ${members.length} banned user(s)`);
for (const member of members) { for (const member of members) {
const victim = member.membershipFor; const target = member.membershipFor;
if (member.membership !== 'ban') continue; if (member.membership !== 'ban') continue;
if (rule.test(victim)) { if (rule.test(target)) {
await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Unbanning ${victim} in ${protectedRoomId}`, protectedRoomId); await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Unbanning ${target} in ${protectedRoomId}`, protectedRoomId);
if (!mjolnir.config.noop) { if (!mjolnir.config.noop) {
await mjolnir.client.unbanUser(victim, protectedRoomId); await mjolnir.client.unbanUser(target, protectedRoomId);
} else { } 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; unbannedSomeone = true;

View File

@ -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 managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Fetching sent messages for ${userIdOrGlob} in ${targetRoomId} to redact...`, targetRoomId);
await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => { await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => {
for (const victimEvent of eventsToRedact) { for (const targetEvent of eventsToRedact) {
await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${victimEvent['event_id']} in ${targetRoomId}`, targetRoomId); await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${targetEvent['event_id']} in ${targetRoomId}`, targetRoomId);
if (!noop) { if (!noop) {
await client.redactEvent(targetRoomId, victimEvent['event_id']); await client.redactEvent(targetRoomId, targetEvent['event_id']);
} else { } 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);
} }
} }
}); });

View File

@ -50,5 +50,5 @@ class ListRule(object):
self.reason = reason self.reason = reason
self.kind = rule_type_to_stable(kind) self.kind = rule_type_to_stable(kind)
def matches(self, victim): def matches(self, target):
return self.regex.match(victim) return self.regex.match(target)