Skip to content

Commit

Permalink
Commands for managing appservice users.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuxie committed Apr 1, 2023
1 parent 4ba052b commit a375715
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/appservice/bot/AccessCommands.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (C) 2022 Gnuxie <[email protected]>
* All rights reserved.
*/

import { defineInterfaceCommand, findTableCommand } from "../../commands/interface-manager/InterfaceCommand";
import { findPresentationType, parameters, ParsedKeywords } from "../../commands/interface-manager/ParameterParsing";
import { Permalinks } from "../../commands/interface-manager/Permalinks";
import { CommandResult } from "../../commands/interface-manager/Validation";
import { EntityType, Recommendation } from "../../models/ListRule";
import PolicyList from "../../models/PolicyList";
import { AppserviceContext } from "./AppserviceCommandHandler";
import { UserID } from "matrix-bot-sdk";
import { defineMatrixInterfaceAdaptor } from "../../commands/interface-manager/MatrixInterfaceAdaptor";
import { tickCrossRenderer } from "../../commands/interface-manager/MatrixHelpRenderer";

defineInterfaceCommand({
designator: ["allow"],
table: "appservice bot",
parameters: parameters([
{
name: 'user',
acceptor: findPresentationType('UserID'),
}
]),
command: async function (this: AppserviceContext, _keywords: ParsedKeywords, user: UserID): Promise<CommandResult<void>> {
const adminRoom = this.appservice.config.adminRoom;
const list = new PolicyList(adminRoom, Permalinks.forRoom(adminRoom), this.appservice.bridge.getBot().getClient());
await list.createPolicy(EntityType.RULE_USER, Recommendation.Allow, user.toString());
return CommandResult.Ok(undefined);
},
summary: "Allow a user to provision themselves a draupnir using the appservice."
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("appservice bot", "allow"),
renderer: tickCrossRenderer,
});

defineInterfaceCommand({
designator: ["remove"],
table: "appservice bot",
parameters: parameters([
{
name: 'user',
acceptor: findPresentationType('UserID'),
}
]),
command: async function (this: AppserviceContext, _keywords: ParsedKeywords, user: UserID): Promise<CommandResult<void>> {
const adminRoom = this.appservice.config.adminRoom;
const list = new PolicyList(adminRoom, Permalinks.forRoom(adminRoom), this.appservice.bridge.getBot().getClient());
await list.unbanEntity(EntityType.RULE_USER, user.toString());
return CommandResult.Ok(undefined);
},
summary: "Stop a user from using any provisioned draupnir in the appservice."
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("appservice bot", "remove"),
renderer: tickCrossRenderer,
});

0 comments on commit a375715

Please sign in to comment.