mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 05:36:06 +00:00
Add a command to shut down a room
Fixes https://github.com/matrix-org/mjolnir/issues/21
This commit is contained in:
parent
8465a1ed78
commit
dea6f8cbf1
@ -574,4 +574,11 @@ export class Mjolnir {
|
|||||||
const endpoint = `/_synapse/admin/v1/deactivate/${userId}`;
|
const endpoint = `/_synapse/admin/v1/deactivate/${userId}`;
|
||||||
return await this.client.doRequest("POST", endpoint);
|
return await this.client.doRequest("POST", endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async shutdownSynapseRoom(roomId: string): Promise<any> {
|
||||||
|
const endpoint = `/_synapse/admin/v1/shutdown_room/${roomId}`;
|
||||||
|
return await this.client.doRequest("POST", endpoint, null, {
|
||||||
|
new_room_user_id: await this.client.getUserId(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import { execAddProtectedRoom, execRemoveProtectedRoom } from "./AddRemoveProtec
|
|||||||
import { execMoveAliasCommand } from "./MoveAliasCommand";
|
import { execMoveAliasCommand } from "./MoveAliasCommand";
|
||||||
import { execAddRoomToDirectoryCommand, execRemoveRoomFromDirectoryCommand } from "./AddRemoveRoomFromDirectoryCommand";
|
import { execAddRoomToDirectoryCommand, execRemoveRoomFromDirectoryCommand } from "./AddRemoveRoomFromDirectoryCommand";
|
||||||
import { execSetPowerLevelCommand } from "./SetPowerLevelCommand";
|
import { execSetPowerLevelCommand } from "./SetPowerLevelCommand";
|
||||||
|
import { execShutdownRoomCommand } from "./ShutdownRoomCommand";
|
||||||
|
|
||||||
export const COMMAND_PREFIX = "!mjolnir";
|
export const COMMAND_PREFIX = "!mjolnir";
|
||||||
|
|
||||||
@ -88,6 +89,8 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
|||||||
return await execRemoveRoomFromDirectoryCommand(roomId, event, mjolnir, parts);
|
return await execRemoveRoomFromDirectoryCommand(roomId, event, mjolnir, parts);
|
||||||
} else if (parts[1] === 'powerlevel' && parts.length > 3) {
|
} else if (parts[1] === 'powerlevel' && parts.length > 3) {
|
||||||
return await execSetPowerLevelCommand(roomId, event, mjolnir, parts);
|
return await execSetPowerLevelCommand(roomId, event, mjolnir, parts);
|
||||||
|
} else if (parts[1] === 'shutdown' && parts[2] === 'room' && parts.length > 3) {
|
||||||
|
return await execShutdownRoomCommand(roomId, event, mjolnir, parts);
|
||||||
} else {
|
} else {
|
||||||
// Help menu
|
// Help menu
|
||||||
const menu = "" +
|
const menu = "" +
|
||||||
@ -114,6 +117,7 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
|||||||
"!mjolnir move <room alias> <room alias/ID> - Moves a <room alias> to a new <room ID>\n" +
|
"!mjolnir move <room alias> <room alias/ID> - Moves a <room alias> to a new <room ID>\n" +
|
||||||
"!mjolnir directory add <room alias/ID> - Publishes a room in the server's room directory\n" +
|
"!mjolnir directory add <room alias/ID> - Publishes a room in the server's room directory\n" +
|
||||||
"!mjolnir directory remove <room alias/ID> - Removes a room from the server's room directory\n" +
|
"!mjolnir directory remove <room alias/ID> - Removes a room from the server's room directory\n" +
|
||||||
|
"!mjolnir shutdown room <room alias/ID> - Uses the bot's account to shut down a room, preventing access to the room on this server\n" +
|
||||||
"!mjolnir powerlevel <user ID> <power level> [room alias/ID] - Sets the power level of the user in the specified room (or all protected rooms)\n" +
|
"!mjolnir powerlevel <user ID> <power level> [room alias/ID] - Sets the power level of the user in the specified room (or all protected rooms)\n" +
|
||||||
"!mjolnir help - This menu\n";
|
"!mjolnir help - This menu\n";
|
||||||
const html = `<b>Mjolnir help:</b><br><pre><code>${htmlEscape(menu)}</code></pre>`;
|
const html = `<b>Mjolnir help:</b><br><pre><code>${htmlEscape(menu)}</code></pre>`;
|
||||||
|
34
src/commands/ShutdownRoomCommand.ts
Normal file
34
src/commands/ShutdownRoomCommand.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Mjolnir } from "../Mjolnir";
|
||||||
|
import { RichReply } from "matrix-bot-sdk";
|
||||||
|
|
||||||
|
// !mjolnir shutdown room <room>
|
||||||
|
export async function execShutdownRoomCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||||
|
const victim = parts[3];
|
||||||
|
|
||||||
|
const isAdmin = await mjolnir.isSynapseAdmin();
|
||||||
|
if (!isAdmin) {
|
||||||
|
const message = "I am not a Synapse administrator, or the endpoint is blocked";
|
||||||
|
const reply = RichReply.createFor(roomId, event, message, message);
|
||||||
|
reply['msgtype'] = "m.notice";
|
||||||
|
return mjolnir.client.sendMessage(roomId, reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(victim));
|
||||||
|
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user