diff --git a/src/appservice/bot/AccessCommands.tsx b/src/appservice/bot/AccessCommands.tsx index 25f96d3a..6854c50a 100644 --- a/src/appservice/bot/AccessCommands.tsx +++ b/src/appservice/bot/AccessCommands.tsx @@ -18,6 +18,7 @@ defineInterfaceCommand({ { name: 'user', acceptor: findPresentationType('UserID'), + description: 'The user that should be allowed to provision a bot' } ]), command: async function (this: AppserviceContext, _keywords: ParsedKeywords, user: UserID): Promise> { @@ -39,6 +40,7 @@ defineInterfaceCommand({ { name: 'user', acceptor: findPresentationType('UserID'), + description: 'The user which shall not be allowed to provision bots anymore' } ]), command: async function (this: AppserviceContext, _keywords: ParsedKeywords, user: UserID): Promise> { diff --git a/src/appservice/bot/AppserviceCommandHandler.ts b/src/appservice/bot/AppserviceCommandHandler.ts index 2853a745..887c53fd 100644 --- a/src/appservice/bot/AppserviceCommandHandler.ts +++ b/src/appservice/bot/AppserviceCommandHandler.ts @@ -5,9 +5,9 @@ import { WeakEvent } from 'matrix-appservice-bridge'; import { readCommand } from '../../commands/interface-manager/CommandReader'; -import { defineCommandTable, defineInterfaceCommand, findCommandTable } from '../../commands/interface-manager/InterfaceCommand'; +import { defineCommandTable, defineInterfaceCommand, findCommandTable, findTableCommand } from '../../commands/interface-manager/InterfaceCommand'; import { defineMatrixInterfaceAdaptor, findMatrixInterfaceAdaptor, MatrixContext } from '../../commands/interface-manager/MatrixInterfaceAdaptor'; -import { ArgumentStream, parameters } from '../../commands/interface-manager/ParameterParsing'; +import { ArgumentStream, RestDescription, findPresentationType, parameters } from '../../commands/interface-manager/ParameterParsing'; import { MjolnirAppService } from '../AppService'; import { CommandResult } from '../../commands/interface-manager/Validation'; import { renderHelp } from '../../commands/interface-manager/MatrixHelpRenderer'; @@ -26,23 +26,23 @@ import './AccessCommands'; import { AppserviceBotEmitter } from './AppserviceBotEmitter'; -const helpCommand = defineInterfaceCommand({ - parameters: parameters([]), +defineInterfaceCommand({ + parameters: parameters([], new RestDescription('command parts', findPresentationType("any"))), table: "appservice bot", - command: async function() { return CommandResult.Ok(findCommandTable("appservice bot").getAllCommands()) }, + command: async function () { return CommandResult.Ok(findCommandTable("appservice bot")) }, designator: ["help"], summary: "Display this message" }) defineMatrixInterfaceAdaptor({ - interfaceCommand: helpCommand, + interfaceCommand: findTableCommand("appservice bot", "help"), renderer: renderHelp }) export class AppserviceCommandHandler { private readonly commandTable = findCommandTable("appservice bot"); - constructor ( + constructor( private readonly appservice: MjolnirAppService ) { diff --git a/src/appservice/bot/ListCommand.tsx b/src/appservice/bot/ListCommand.tsx index 10cb4191..1d6035ef 100644 --- a/src/appservice/bot/ListCommand.tsx +++ b/src/appservice/bot/ListCommand.tsx @@ -28,7 +28,7 @@ const listUnstarted = defineInterfaceCommand({ designator: ["list", "unstarted"], table: "appservice bot", parameters: parameters([]), - command: async function() { + command: async function () { return CommandResult.Ok(this.appservice.mjolnirManager.getUnstartedMjolnirs()); }, summary: "List any Mjolnir that failed to start." @@ -38,7 +38,7 @@ const listUnstarted = defineInterfaceCommand({ // and be used similar to like #=1 and #1. defineMatrixInterfaceAdaptor({ interfaceCommand: listUnstarted, - renderer: async function(this: MatrixInterfaceAdaptor, client: MatrixSendClient, commandRoomId: string, event: any, result: CommandResult) { + renderer: async function (this: MatrixInterfaceAdaptor, client: MatrixSendClient, commandRoomId: string, event: any, result: CommandResult) { tickCrossRenderer.call(this, client, commandRoomId, event, result); // don't await, it doesn't really matter. if (result.isErr()) { return; // just let the default handler deal with it. @@ -53,7 +53,7 @@ defineMatrixInterfaceAdaptor({ {mjolnir.mjolnirRecord.owner}, {mjolnir.mxid.toString()} {mjolnir.failCode}: -
+
{mjolnir.cause} })} @@ -77,9 +77,10 @@ const restart = defineInterfaceCommand({ { name: "mjolnir", acceptor: findPresentationType("UserID"), + description: 'The userid of the mjolnir to restart' } ]), - command: async(context, _keywords, mjolnirId: UserID): Promise> => { + command: async (context, _keywords, mjolnirId: UserID): Promise> => { const mjolnirManager = context.appservice.mjolnirManager; const mjolnir = mjolnirManager.findUnstartedMjolnir(mjolnirId.localpart); if (mjolnir?.mjolnirRecord === undefined) { diff --git a/src/commands/interface-manager/MatrixHelpRenderer.tsx b/src/commands/interface-manager/MatrixHelpRenderer.tsx index fe39b7d1..9a91cbc1 100644 --- a/src/commands/interface-manager/MatrixHelpRenderer.tsx +++ b/src/commands/interface-manager/MatrixHelpRenderer.tsx @@ -3,7 +3,7 @@ */ import { MatrixSendClient } from "../../MatrixEmitter"; -import { BaseFunction, InterfaceCommand } from "./InterfaceCommand"; +import { BaseFunction, CommandTable, InterfaceCommand } from "./InterfaceCommand"; import { MatrixContext, MatrixInterfaceAdaptor } from "./MatrixInterfaceAdaptor"; import { ArgumentParseError, ParameterDescription, RestDescription } from "./ParameterParsing"; import { CommandError, CommandResult } from "./Validation"; @@ -29,17 +29,17 @@ function restArgument(rest: RestDescription): string { export function renderParameterDescription(description: ParameterDescription): DocumentNode { return - {description.name} - {description.description ?? 'no description'}
+ {description.name} - {description.description ?? 'no description'}
} export function renderCommandSummary(command: InterfaceCommand): DocumentNode { return
- {renderCommandHelp(command)} - {command.summary} + {renderCommandHelp(command)} - {command.summary} {command.description - ? Description:
{command.description}
+ ? Description:
{command.description}
: [] } {command.argumentListParser.descriptions.length > 0 @@ -63,13 +63,30 @@ export function renderCommandHelp(command: InterfaceCommand): stri ].join(' '); } -export async function renderHelp(client: MatrixSendClient, commandRoomId: string, event: any, result: CommandResult[], CommandError>): Promise { - const commands = result.ok; - let text = '' - for (const command of commands) { - text += `${renderCommandHelp(command)}\n`; +function renderTableHelp(table: CommandTable): DocumentNode { + let tableName = table.name; + if (typeof table.name === 'string') { + tableName = table.name.charAt(0).toUpperCase() + table.name.slice(1); } - await client.replyNotice(commandRoomId, event, text); + return +
+ {tableName} commands: + {table.getExportedCommands().map(renderCommandSummary)} + {table.getImportedTables().map(renderTableHelp)} +
+
+} + +export async function renderHelp(client: MatrixSendClient, commandRoomId: string, event: any, result: CommandResult): Promise { + if (result.isErr()) { + throw new TypeError("This command isn't supposed to fail"); + } + await renderMatrixAndSend( + renderTableHelp(result.ok), + commandRoomId, + event, + client + ); } export async function tickCrossRenderer(this: MatrixInterfaceAdaptor, client: MatrixSendClient, commandRoomId: string, event: any, result: CommandResult): Promise { @@ -122,17 +139,17 @@ function formattedArgumentHint(command: InterfaceCommand, error: A function renderArgumentParseError(command: InterfaceCommand, error: ArgumentParseError): DocumentNode { return - There was a problem when parsing the {error.parameter.name} parameter for this command.
- {renderCommandHelp(command)}
- {error.message}
+ There was a problem when parsing the {error.parameter.name} parameter for this command.
+ {renderCommandHelp(command)}
+ {error.message}
{formattedArgumentHint(command, error)}
} function renderCommandException(command: InterfaceCommand, error: CommandException): DocumentNode { return - There was an unexpected error when processing this command:
- {error.message}
+ There was an unexpected error when processing this command:
+ {error.message}
Details can be found by providing the reference {error.uuid} to an administrator.