Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace shutdown_room API with DELETE /_synapse/admin/v1/rooms/<room_… #117

Merged
merged 3 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "ts-mocha --project ./tsconfig.json test/**/*.ts"
},
"devDependencies": {
"@types/mocha": "^8.2.2",
"@types/mocha": "^9.0.0",
"@types/node": "11",
"expect": "^27.0.6",
"mocha": "^9.0.1",
Expand Down
8 changes: 5 additions & 3 deletions src/Mjolnir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,12 @@ export class Mjolnir {
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, {
public async shutdownSynapseRoom(roomId: string, message?: string): Promise<any> {
const endpoint = `/_synapse/admin/v1/rooms/${roomId}`;
return await this.client.doRequest("DELETE", endpoint, null, {
new_room_user_id: await this.client.getUserId(),
block: true,
message: message /* If `undefined`, we'll use Synapse's default message. */
});
}
}
2 changes: 1 addition & 1 deletion src/commands/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
"!mjolnir alias add <room alias> <target room alias/ID> - Adds <room alias> to <target room>\n" +
"!mjolnir alias remove <room alias> - Deletes the room alias from whatever room it is attached to\n" +
"!mjolnir resolve <room alias> - Resolves a room alias to a room ID\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 shutdown room <room alias/ID> [message] - 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 help - This menu\n";
const html = `<b>Mjolnir help:</b><br><pre><code>${htmlEscape(menu)}</code></pre>`;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ShutdownRoomCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import { Mjolnir } from "../Mjolnir";
import { RichReply } from "matrix-bot-sdk";

// !mjolnir shutdown room <room>
// !mjolnir shutdown room <room> [<message>]
Yoric marked this conversation as resolved.
Show resolved Hide resolved
export async function execShutdownRoomCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
const victim = parts[3];

Expand All @@ -30,6 +30,6 @@ export async function execShutdownRoomCommand(roomId: string, event: any, mjolni
return;
}

await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(victim));
await mjolnir.shutdownSynapseRoom(await mjolnir.client.resolveRoom(victim), parts[4]);
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
}
Loading