Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modern language #513

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/DeactivateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { RichReply } from "matrix-bot-sdk";

// !mjolnir deactivate <user ID>
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) {
Expand All @@ -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'], '✅');
}
12 changes: 6 additions & 6 deletions src/commands/KickCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/SetPowerLevelCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import { extractRequestError, LogLevel, LogService } from "matrix-bot-sdk";

// !mjolnir powerlevel <user ID> <level> [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];

let targetRooms = inRoom ? [await mjolnir.client.resolveRoom(inRoom)] : mjolnir.protectedRoomsTracker.getProtectedRooms();

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 : '<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));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ShutdownRoomCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { RichReply } from "matrix-bot-sdk";

// !mjolnir shutdown room <room> [<message>]
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();
Expand All @@ -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'], '✅');
}
10 changes: 5 additions & 5 deletions src/commands/UnbanBanCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions synapse_antispam/mjolnir/list_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ def __init__(self, entity, action, reason, kind):
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)
Loading