mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
send whole channel shutdown reason, not just the first word
This commit is contained in:
parent
eb7f5f6b3e
commit
65af82d46f
@ -20,6 +20,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 victim = parts[3];
|
||||||
|
const reason = parts.slice(4).join(" ") || undefined;
|
||||||
|
|
||||||
const isAdmin = await mjolnir.isSynapseAdmin();
|
const isAdmin = await mjolnir.isSynapseAdmin();
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
@ -30,6 +31,6 @@ export async function execShutdownRoomCommand(roomId: string, event: any, mjolni
|
|||||||
return;
|
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'], '✅');
|
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||||
}
|
}
|
||||||
|
55
test/integration/commands/shutdownCommandTest.ts
Normal file
55
test/integration/commands/shutdownCommandTest.ts
Normal 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"}');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user