mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Add a command to deactivate a user
This commit is contained in:
parent
417673aeef
commit
778f9c3459
@ -387,4 +387,21 @@ export class Mjolnir {
|
||||
await this.client.sendMessage(config.managementRoom, message);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async isSynapseAdmin(): Promise<boolean> {
|
||||
try {
|
||||
const endpoint = `/_synapse/admin/v1/users/${await this.client.getUserId()}/admin`;
|
||||
const response = await this.client.doRequest("GET", endpoint);
|
||||
return response['admin'];
|
||||
} catch (e) {
|
||||
LogService.error("Mjolnir", "Error determining if Mjolnir is a server admin:");
|
||||
LogService.error("Mjolnir", e);
|
||||
return false; // assume not
|
||||
}
|
||||
}
|
||||
|
||||
public async deactivateSynapseUser(userId: string): Promise<any> {
|
||||
const endpoint = `/_synapse/admin/v1/deactivate/${userId}`;
|
||||
return await this.client.doRequest("POST", endpoint);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import { execUnwatchCommand, execWatchCommand } from "./WatchUnwatchCommand";
|
||||
import { execRedactCommand } from "./RedactCommand";
|
||||
import { execImportCommand } from "./ImportCommand";
|
||||
import { execSetDefaultListCommand } from "./SetDefaultBanListCommand";
|
||||
import { execDeactivateCommand } from "./DeactivateCommand";
|
||||
|
||||
export const COMMAND_PREFIX = "!mjolnir";
|
||||
|
||||
@ -59,6 +60,8 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
||||
return await execImportCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'default' && parts.length > 2) {
|
||||
return await execSetDefaultListCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'deactivate' && parts.length > 2) {
|
||||
return await execDeactivateCommand(roomId, event, mjolnir, parts);
|
||||
} else {
|
||||
// Help menu
|
||||
const menu = "" +
|
||||
@ -75,6 +78,7 @@ export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir
|
||||
"!mjolnir unwatch <room alias/ID> - Unwatches a ban list\n" +
|
||||
"!mjolnir import <room alias/ID> <list shortcode> - Imports bans and ACLs into the given list\n" +
|
||||
"!mjolnir default <shortcode> - Sets the default list for commands\n" +
|
||||
"!mjolnir deactivate <user ID> - Deactivates a user ID\n" +
|
||||
"!mjolnir help - This menu\n";
|
||||
const html = `<b>Mjolnir help:</b><br><pre><code>${htmlEscape(menu)}</code></pre>`;
|
||||
const text = `Mjolnir help:\n${menu}`;
|
||||
|
34
src/commands/DeactivateCommand.ts
Normal file
34
src/commands/DeactivateCommand.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 2019 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 deactivate <user ID>
|
||||
export async function execDeactivateCommand(roomId: string, event: any, mjolnir: Mjolnir, parts: string[]) {
|
||||
const victim = parts[2];
|
||||
|
||||
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.deactivateSynapseUser(victim);
|
||||
await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
|
||||
}
|
Loading…
Reference in New Issue
Block a user