From f122beadef0ca51fb1749bacc9fe8fdfe49fbaa1 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Tue, 21 Feb 2023 14:19:34 +0000 Subject: [PATCH] Help page. TODO: - Needs description adding into the detail rather than the summary - needs rich text - needs markdown detail/summary to not just be the HTML tags, unacceptable since it's supposed to be fallback - More commands --- src/commands/Help.tsx | 122 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/commands/Help.tsx diff --git a/src/commands/Help.tsx b/src/commands/Help.tsx new file mode 100644 index 00000000..dabd07bf --- /dev/null +++ b/src/commands/Help.tsx @@ -0,0 +1,122 @@ +/** + * Copyright (C) 2022 Gnuxie + * All rights reserved. + * + * This file is modified and is NOT licensed under the Apache License. + * This modified file incorperates work from mjolnir + * https://github.com/matrix-org/mjolnir + * which included the following license notice: + +Copyright 2019-2022 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. + * + * However, this file is modified and the modifications in this file + * are NOT distributed, contributed, committed, or licensed under the Apache License. + */ + +import { DocumentNode } from "./interface-manager/DeadDocument"; +import { CommandTable, defineInterfaceCommand, findCommandTable, findTableCommand } from "./interface-manager/InterfaceCommand"; +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 [subcommand] - Print status information for a protection\n" + +"!mjolnir redact [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 - Redacts a message by permalink\n" + +"!mjolnir kick [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 - Creates a new ban list with the given shortcode and alias\n" + +"!mjolnir watch - Watches a ban list\n" + +"!mjolnir unwatch - Unwatches a ban list\n" + +"!mjolnir import - Imports bans and ACLs into the given list\n" + +"!mjolnir default - Sets the default list for commands\n" + +"!mjolnir protections - List all available protections\n" + +"!mjolnir enable - Enables a particular protection\n" + +"!mjolnir disable - Disables a particular protection\n" + +"!mjolnir config set . [value] - Change a protection setting\n" + +"!mjolnir config add . [value] - Add a value to a list protection setting\n" + +"!mjolnir config remove . [value] - Remove a value from a list protection setting\n" + +"!mjolnir config get [protection] - List protection settings\n" + +"!mjolnir rooms - Lists all the protected rooms\n" + +"!mjolnir rooms add - Adds a protected room (may cause high server load)\n" + +"!mjolnir rooms remove - Removes a protected room\n" + +"!mjolnir resolve - Resolves a room alias to a room ID\n" + +"!mjolnir since / [rooms...] [reason] - Apply an action ('kick', 'ban', 'mute', 'unmute' or 'show') to all users who joined a room since / (up to users)\n" + +"!mjolnir powerlevel [room alias/ID] - Sets the power level of the user in the specified room (or all protected rooms)\n" + +"!mjolnir help - This menu\n"; + +function renderTableHelp(table: CommandTable): DocumentNode { + // FIXME: is it possible to force case of table names? + return +
+ {table.name} commands: + {table.getExportedCommands().map(renderCommandSummary)} + {table.getImportedTables().map(renderTableHelp)} +
+
+} + +function renderMjolnirHelp(mjolnirTable: CommandTable): DocumentNode { + return +
+ Old Commands: +
{oldHelpMenu}
+
+ {renderTableHelp(mjolnirTable)} +
+} + +defineInterfaceCommand({ + parameters: parameters([], new RestDescription('command parts', findPresentationType("any"))), + table: "mjolnir", + command: async function() { return CommandResult.Ok(findCommandTable("mjolnir")) }, + designator: ["help"], + summary: "Display this message" +}) + +defineMatrixInterfaceAdaptor({ + interfaceCommand: findTableCommand("mjolnir", "help"), + renderer: async function(client, commandRoomId, event, result) { + if (result.isErr()) { + throw new TypeError("This command isn't supposed to fail"); + } + await renderMatrixAndSend( + renderMjolnirHelp(result.ok), + commandRoomId, + event, + client + ); + } +}) + +// how to catagorise commands in help? +// one way is to have subcommand tables to group them by and then iterate over the subcommand tables +// what happens to the method that gets all the command in a table flat though? +// i guess there needs to be immediate commands and imported commands +// then we need to figure out how to render documentation, do we want to write that +// in markdown and import it or something? Not sure. +// but we need this because mjolnir-for-all etc. + +// alternatively we could just render the help page ourselves +// putting each category out by hand. + +// another thing to imagine is if you wanted to generate a link to a page +// where you can browse the documentation.