Skip to content

Commit

Permalink
Merge pull request #117 from matrix-org/yoric/delete-rooms-api
Browse files Browse the repository at this point in the history
Replace shutdown_room API with DELETE /_synapse/admin/v1/rooms/<room_…
  • Loading branch information
turt2live authored Aug 17, 2021
2 parents f09fd5d + dd6c06e commit 3703176
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 25 deletions.
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>]
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

0 comments on commit 3703176

Please sign in to comment.