mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
modernize language
This commit is contained in:
parent
033d84cc70
commit
80cdf0598a
@ -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) {
|
||||
@ -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'], '✅');
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ 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];
|
||||
|
||||
@ -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 : '<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));
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
@ -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'], '✅');
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user