-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commands for managing appservice users.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |