From cee8ce308b928e66cf414840e1493eb51cd838d4 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Wed, 24 Jul 2024 12:00:48 -0700 Subject: [PATCH] requested changes --- src/Mjolnir.ts | 2 +- src/commands/CommandHandler.ts | 10 ++++------ src/commands/SuspendCommand.ts | 6 +++--- .../{unSuspendCommand.ts => UnsuspendCommand.ts} | 8 ++++---- 4 files changed, 12 insertions(+), 14 deletions(-) rename src/commands/{unSuspendCommand.ts => UnsuspendCommand.ts} (86%) diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts index 73dfbf4..8224147 100644 --- a/src/Mjolnir.ts +++ b/src/Mjolnir.ts @@ -485,7 +485,7 @@ export class Mjolnir { return await this.client.doRequest("PUT", endpoint, null, body); } - public async unSuspendSynapseUser(userId: string): Promise { + public async unsuspendSynapseUser(userId: string): Promise { const endpoint = `/_synapse/admin/v1/suspend/${userId}`; const body = {"suspend": false} return await this.client.doRequest("PUT", endpoint, null, body); diff --git a/src/commands/CommandHandler.ts b/src/commands/CommandHandler.ts index 53381cc..420bc09 100644 --- a/src/commands/CommandHandler.ts +++ b/src/commands/CommandHandler.ts @@ -44,7 +44,7 @@ import { parse as tokenize } from "shell-quote"; import { execSinceCommand } from "./SinceCommand"; import { execSetupProtectedRoom } from "./SetupDecentralizedReportingCommand"; import {execSuspendCommand} from "./SuspendCommand"; -import {execUnSuspendCommand} from "./unSuspendCommand"; +import {execUnsuspendCommand} from "./UnsuspendCommand"; export const COMMAND_PREFIX = "!mjolnir"; @@ -133,7 +133,7 @@ export async function handleCommand(roomId: string, event: { content: { body: st } else if (parts[1] === 'suspend' && parts.length > 2) { return await execSuspendCommand(roomId, event, mjolnir, parts); } else if (parts[1] === 'unsuspend' && parts.length > 2) { - return await execUnSuspendCommand(roomId, event, mjolnir, parts) + return await execUnsuspendCommand(roomId, event, mjolnir, parts) } else { // Help menu const menu = "" + @@ -176,10 +176,8 @@ export async function handleCommand(roomId: string, event: { content: { body: st "!mjolnir shutdown room [message] - Uses the bot's account to shut down a room, preventing access to the room on this server\n" + "!mjolnir powerlevel [room alias/ID] - Sets the power level of the user in the specified room (or all protected rooms)\n" + "!mjolnir make admin [user alias/ID] - Make the specified user or the bot itself admin of the room\n" + - "!mjolnir suspend - Suspend the specified user" - + - "!mjolnir unsuspend - Unsuspend the specified user" - + + "!mjolnir suspend - Suspend the specified user" + + "!mjolnir unsuspend - Unsuspend the specified user" + "!mjolnir help - This menu\n" const html = `Mjolnir help:
${htmlEscape(menu)}
`; const text = `Mjolnir help:\n${menu}`; diff --git a/src/commands/SuspendCommand.ts b/src/commands/SuspendCommand.ts index 11a0f5f..db74e32 100644 --- a/src/commands/SuspendCommand.ts +++ b/src/commands/SuspendCommand.ts @@ -18,7 +18,7 @@ import {Mjolnir} from "../Mjolnir"; import {RichReply} from "matrix-bot-sdk"; export async function execSuspendCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { - const victim = parts[2]; + const target = parts[2]; const isAdmin = await mjolnir.isSynapseAdmin(); if (!isAdmin) { @@ -29,8 +29,8 @@ export async function execSuspendCommand(roomId: string, event: any, mjolnir: Mj return; } - await mjolnir.suspendSynapseUser(victim); - const msg = `User ${victim} has been suspended.` + await mjolnir.suspendSynapseUser(target); + const msg = `User ${target} has been suspended.` const confirmation = RichReply.createFor(roomId, event, msg, msg); confirmation['msgtype'] = "m.notice"; await mjolnir.client.sendMessage(roomId, confirmation) diff --git a/src/commands/unSuspendCommand.ts b/src/commands/UnsuspendCommand.ts similarity index 86% rename from src/commands/unSuspendCommand.ts rename to src/commands/UnsuspendCommand.ts index 37cb84f..fbb06d1 100644 --- a/src/commands/unSuspendCommand.ts +++ b/src/commands/UnsuspendCommand.ts @@ -17,8 +17,8 @@ limitations under the License. import {Mjolnir} from "../Mjolnir"; import {RichReply} from "matrix-bot-sdk"; -export async function execUnSuspendCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { - const victim = parts[2]; +export async function execUnsuspendCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) { + const target = parts[2]; const isAdmin = await mjolnir.isSynapseAdmin(); if (!isAdmin) { @@ -29,8 +29,8 @@ export async function execUnSuspendCommand(roomId: string, event: any, mjolnir: return; } - await mjolnir.unSuspendSynapseUser(victim); - const msg = `User ${victim}'s suspension has been reversed.` + await mjolnir.unsuspendSynapseUser(target); + const msg = `User ${target}'s suspension has been reversed.` const confirmation = RichReply.createFor(roomId, event, msg, msg); confirmation['msgtype'] = "m.notice"; mjolnir.client.sendMessage(roomId, confirmation)