send whole channel shutdown reason, not just the first word

This commit is contained in:
jesopo 2022-02-28 19:35:24 +00:00 committed by Jess Porter
parent eb7f5f6b3e
commit 65af82d46f
2 changed files with 57 additions and 1 deletions

View File

@ -20,6 +20,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 reason = parts.slice(4).join(" ") || undefined;
const isAdmin = await mjolnir.isSynapseAdmin();
if (!isAdmin) {
@ -30,6 +31,6 @@ export async function execShutdownRoomCommand(roomId: string, event: any, mjolni
return;
}
await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(victim), parts[4]);
await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(victim), reason);
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
}

View File

@ -0,0 +1,55 @@
import { strict as assert } from "assert";
import { newTestUser } from "../clientHelper";
describe("Test: shutdown command", function() {
let client;
this.beforeEach(async function () {
client = await newTestUser({ name: { contains: "shutdown-command" }});
await client.start();
})
this.afterEach(async function () {
await client.stop();
})
it("Mjolnir asks synapse to shut down a channel", async function() {
this.timeout(20000);
const badRoom = await client.createRoom();
await client.joinRoom(this.mjolnir.managementRoomId);
let reply1 = new Promise(async (resolve, reject) => {
const msgid = await client.sendMessage(this.mjolnir.managementRoomId, {msgtype: "m.text", body: `!mjolnir shutdown room ${badRoom} closure test`});
client.on('room.event', (roomId, event) => {
if (
roomId === this.mjolnir.managementRoomId
&& event?.type === "m.reaction"
&& event.sender === this.mjolnir.client.userId
&& event.content?.["m.relates_to"]?.event_id === msgid
) {
resolve(event);
}
});
});
const reply2 = new Promise((resolve, reject) => {
this.mjolnir.client.on('room.event', (roomId, event) => {
if (
roomId !== this.mjolnir.managementRoomId
&& roomId !== badRoom
&& event?.type === "m.room.message"
&& event.sender === this.mjolnir.client.userId
&& event.content?.body === "closure test"
) {
resolve(event);
}
});
});
await reply1
await reply2
await assert.rejects(client.joinRoom(badRoom), e => {
return e.message.endsWith('{"errcode":"M_UNKNOWN","error":"This room has been blocked on this server"}');
});
});
});