From 102c3f097bc9b510800b803f762b51448f452851 Mon Sep 17 00:00:00 2001 From: murm Date: Sat, 18 Mar 2023 20:00:37 -0400 Subject: [PATCH] added help cmd, and helper function to misc --- commands/general/help.js | 28 ++++++++++++++++++++++++---- utils/misc.js | 13 +++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/commands/general/help.js b/commands/general/help.js index 20ac6e8..1bbadfa 100644 --- a/commands/general/help.js +++ b/commands/general/help.js @@ -1,15 +1,35 @@ // import { Constants } from "oceanic.js"; // import database from "../../utils/database.js"; -// import * as collections from "../../utils/collections.js"; -// import { random } from "../../utils/misc.js"; +import * as collections from "../../utils/collections.js"; +import { htmlescape } from "../../utils/misc.js"; // import paginator from "../../utils/pagination/pagination.js"; -// import * as help from "../../utils/help.js"; +import * as help from "../../utils/help.js"; import Command from "../../classes/command.js"; // const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://esmbot.net/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem"]; class HelpCommand extends Command { async run() { - return { html: "

There are no mrmBot Docs Yet

In the meantime, please refer to https://esmbot.net/help.html" }; + let html; + if (this.args.length !== 0) { + if (collections.commands.has(this.args[0].toLowerCase())) { + const command = collections.aliases.get(this.args[0].toLowerCase()) ?? this.args[0].toLowerCase(); + const info = collections.info.get(command); + // TODO: room-specific prefix + const prefix = htmlescape(process.env.PREFIX); + html = `

mrmBot Help

${prefix}${command}
${htmlescape(info.description)}` + return { html: html } + } + if (help.categories[this.args[0].toLowerCase()]) { + } + } + html = `

mrmBot Help

` + for (const [command] of collections.commands) { + const description = collections.info.get(command).description; + html = html + `` + } + html = html + "
CommandDescription
${command}${description}
" + return { html: html } + // return { html: "

There are no mrmBot Docs Yet

In the meantime, please refer to https://esmbot.net/help.html" }; } diff --git a/utils/misc.js b/utils/misc.js index d2c40fb..497c5d7 100644 --- a/utils/misc.js +++ b/utils/misc.js @@ -20,6 +20,8 @@ const optionalReplace = (token) => { return token === undefined || token === "" ? "" : (token === "true" || token === "false" ? token : ""); }; + + // clean(text) to clean message of any private info or mentions export function clean(text) { if (typeof text !== "string") @@ -63,6 +65,17 @@ export async function activityChanger(bot) { setTimeout(() => activityChanger(bot), 900000); } +export function htmlescape (s) { + let lookup = { + '&': "&", + '"': """, + '\'': "'", + '<': "<", + '>': ">" + }; + return s.replace( /[&"'<>]/g, c => lookup[c] ); +} + export async function checkBroadcast(bot) { if (!db) { return;