mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-10-22 17:11:17 +00:00
Update CommandHandler and Help for migrated commands.
This commit is contained in:
1 parent
9b48a48c44
commit
a17625ac8f
2 files changed
+21
-79
No files matched your search
@@ -26,7 +26,6 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { LogService, RichReply } from "matrix-bot-sdk";
|
||||
import { parse as tokenize } from "shell-quote";
|
||||
import { readCommand } from "./interface-manager/CommandReader";
|
||||
import { BaseFunction, CommandTable, defineCommandTable, findCommandTable, findTableCommand } from "./interface-manager/InterfaceCommand";
|
||||
import { findMatrixInterfaceAdaptor, MatrixContext } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
@@ -42,21 +41,30 @@ export interface DraupnirContext extends MatrixContext {
|
||||
|
||||
export type DraupnirBaseExecutor = (this: DraupnirContext, ...args: any[]) => Promise<ActionResult<unknown>>;
|
||||
|
||||
// Plesae keep these in alphabetical order.
|
||||
defineCommandTable("synapse admin");
|
||||
import "./AliasCommands";
|
||||
import "./DeactivateCommand";
|
||||
import "./HijackRoomCommand";
|
||||
import "./ShutdownRoomCommand";
|
||||
import "./DeactivateCommand";
|
||||
import "./AliasCommands";
|
||||
|
||||
defineCommandTable("mjolnir").importTable(findCommandTable("synapse admin"));
|
||||
import "./Ban";
|
||||
import "./Unban";
|
||||
import "./StatusCommand";
|
||||
import "./CreateBanListCommand";
|
||||
import "./Help";
|
||||
import "./ImportCommand";
|
||||
import "./KickCommand";
|
||||
import "./PermissionCheckCommand";
|
||||
import "./ProtectionsCommands";
|
||||
import "./RedactCommand";
|
||||
import "./ResolveAlias";
|
||||
import "./Rooms";
|
||||
import "./Rules";
|
||||
import "./SetDisplayNameCommand"
|
||||
import "./SetPowerLevelCommand";
|
||||
import "./StatusCommand";
|
||||
import "./Unban";
|
||||
import "./WatchUnwatchCommand";
|
||||
import "./Help";
|
||||
import "./SetDisplayNameCommand";
|
||||
|
||||
export const COMMAND_PREFIX = "!draupnir";
|
||||
|
||||
@@ -68,46 +76,6 @@ export async function handleCommand(
|
||||
commandTable: CommandTable<BaseFunction>
|
||||
) {
|
||||
try {
|
||||
/**
|
||||
* TODO Delete these:
|
||||
|
||||
if (parts[1] === 'joins') {
|
||||
return await showJoinsStatus(roomID, event, mjolnir, parts.slice(2)); // joins
|
||||
} else if (parts[1] === 'sync') {
|
||||
return await execSyncCommand(roomID, event, mjolnir);
|
||||
} else if (parts[1] === 'verify') {
|
||||
return await execPermissionCheckCommand(roomID, event, mjolnir);
|
||||
} else if (parts.length >= 5 && parts[1] === 'list' && parts[2] === 'create') {
|
||||
return await execCreateListCommand(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'redact' && parts.length > 1) {
|
||||
return await execRedactCommand(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'import' && parts.length > 2) {
|
||||
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] === 'protections') {
|
||||
return await execListProtections(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'enable' && parts.length > 1) {
|
||||
return await execEnableProtection(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'disable' && parts.length > 1) {
|
||||
return await execDisableProtection(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'config' && parts[2] === 'set' && parts.length > 3) {
|
||||
return await execConfigSetProtection(roomID, event, mjolnir, parts.slice(3))
|
||||
} else if (parts[1] === 'config' && parts[2] === 'add' && parts.length > 3) {
|
||||
return await execConfigAddProtection(roomID, event, mjolnir, parts.slice(3))
|
||||
} else if (parts[1] === 'config' && parts[2] === 'remove' && parts.length > 3) {
|
||||
return await execConfigRemoveProtection(roomID, event, mjolnir, parts.slice(3))
|
||||
} else if (parts[1] === 'config' && parts[2] === 'get') {
|
||||
return await execConfigGetProtection(roomID, event, mjolnir, parts.slice(3))
|
||||
} else if (parts[1] === 'resolve' && parts.length > 2) {
|
||||
return await execResolveCommand(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'powerlevel' && parts.length > 3) {
|
||||
return await execSetPowerLevelCommand(roomID, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'since') {
|
||||
return await execSinceCommand(roomID, event, mjolnir, tokens);
|
||||
} else if (parts[1] === 'kick' && parts.length > 2) {
|
||||
return await execKickCommand(roomID, event, mjolnir, parts);
|
||||
*/
|
||||
const readItems = readCommand(normalisedCommand).slice(1); // remove "!mjolnir"
|
||||
const stream = new ArgumentStream(readItems);
|
||||
const command = commandTable.findAMatchingCommand(stream)
|
||||
|
||||
+6
-32
@@ -30,33 +30,9 @@ import { CommandTable, defineInterfaceCommand, findCommandTable, findTableComman
|
||||
import { renderCommandSummary } from "./interface-manager/MatrixHelpRenderer";
|
||||
import { JSXFactory } from "./interface-manager/JSXFactory";
|
||||
import { findPresentationType, parameters, RestDescription } from "./interface-manager/ParameterParsing";
|
||||
import { CommandResult } from "./interface-manager/Validation";
|
||||
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
|
||||
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
|
||||
|
||||
const oldHelpMenu = "" +
|
||||
"!mjolnir - Print status information\n" +
|
||||
"!mjolnir status - Print status information\n" +
|
||||
"!mjolnir status protection <protection> [subcommand] - Print status information for a protection\n" +
|
||||
"!mjolnir redact <user ID> [room alias/ID] [limit] - Redacts messages by the sender in the target room (or all rooms), up to a maximum number of events in the backlog (default 1000)\n" +
|
||||
"!mjolnir redact <event permalink> - Redacts a message by permalink\n" +
|
||||
"!mjolnir kick <glob> [room alias/ID] [reason] - Kicks a user or all of those matching a glob in a particular room or all protected rooms\n" +
|
||||
"!mjolnir sync - Force updates of all lists and re-apply rules\n" +
|
||||
"!mjolnir verify - Ensures Mjolnir can moderate all your rooms\n" +
|
||||
"!mjolnir list create <shortcode> <alias localpart> - Creates a new ban list with the given shortcode and alias\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 protections - List all available protections\n" +
|
||||
"!mjolnir enable <protection> - Enables a particular protection\n" +
|
||||
"!mjolnir disable <protection> - Disables a particular protection\n" +
|
||||
"!mjolnir config set <protection>.<setting> [value] - Change a protection setting\n" +
|
||||
"!mjolnir config add <protection>.<setting> [value] - Add a value to a list protection setting\n" +
|
||||
"!mjolnir config remove <protection>.<setting> [value] - Remove a value from a list protection setting\n" +
|
||||
"!mjolnir config get [protection] - List protection settings\n" +
|
||||
"!mjolnir resolve <room alias> - Resolves a room alias to a room ID\n" +
|
||||
"!mjolnir since <date>/<duration> <action> <limit> [rooms...] [reason] - Apply an action ('kick', 'ban', 'mute', 'unmute' or 'show') to all users who joined a room since <date>/<duration> (up to <limit> users)\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";
|
||||
import { ActionResult, Ok, isError } from "matrix-protection-suite";
|
||||
|
||||
function renderTableHelp(table: CommandTable): DocumentNode {
|
||||
// FIXME: is it possible to force case of table names?
|
||||
@@ -71,10 +47,6 @@ function renderTableHelp(table: CommandTable): DocumentNode {
|
||||
|
||||
function renderMjolnirHelp(mjolnirTable: CommandTable): DocumentNode {
|
||||
return <root>
|
||||
<details>
|
||||
<summary><b>Old Commands:</b></summary>
|
||||
<pre>{oldHelpMenu}</pre>
|
||||
</details>
|
||||
{renderTableHelp(mjolnirTable)}
|
||||
</root>
|
||||
}
|
||||
@@ -82,15 +54,17 @@ function renderMjolnirHelp(mjolnirTable: CommandTable): DocumentNode {
|
||||
defineInterfaceCommand({
|
||||
parameters: parameters([], new RestDescription('command parts', findPresentationType("any"))),
|
||||
table: "mjolnir",
|
||||
command: async function() { return CommandResult.Ok(findCommandTable("mjolnir")) },
|
||||
command: async function() {
|
||||
return Ok(findCommandTable("mjolnir"))
|
||||
},
|
||||
designator: ["help"],
|
||||
summary: "Display this message"
|
||||
})
|
||||
|
||||
defineMatrixInterfaceAdaptor({
|
||||
interfaceCommand: findTableCommand("mjolnir", "help"),
|
||||
renderer: async function(client, commandRoomId, event, result) {
|
||||
if (result.isErr()) {
|
||||
renderer: async function(client, commandRoomId, event, result: ActionResult<CommandTable>) {
|
||||
if (isError(result)) {
|
||||
throw new TypeError("This command isn't supposed to fail");
|
||||
}
|
||||
await renderMatrixAndSend(
|
||||
|
||||
Reference in new issue
Block a user