diff --git a/public/script.js b/public/script.js index b97fca2ce..aeec037ca 100644 --- a/public/script.js +++ b/public/script.js @@ -91,7 +91,7 @@ import { import { debounce, delay } from "./scripts/utils.js"; import { extension_settings, loadExtensionSettings } from "./scripts/extensions.js"; -import { executeSlashCommands } from "./scripts/slash-commands.js"; +import { executeSlashCommands, getSlashCommandsHelp } from "./scripts/slash-commands.js"; //exporting functions and vars for mods export { @@ -1067,6 +1067,10 @@ function sendSystemMessage(type, text) { newMessage.mes = text; } + if (type == system_message_types.HELP) { + newMessage.mes += getSlashCommandsHelp(); + } + if (!newMessage.extras) { newMessage.extras = {}; } diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 595e1b6a0..44bd54758 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -5,11 +5,13 @@ import { export { executeSlashCommands, registerSlashCommand, + getSlashCommandsHelp, } class SlashCommandParser { constructor() { this.commands = {}; + this.helpStrings = []; } addCommand(command, callback, aliases, helpString = '', interruptsGeneration = false, purgeFromMessage = true) { @@ -21,6 +23,13 @@ class SlashCommandParser { this.commands[alias] = fnObj; }); } + + let stringBuilder = `/${command} ${helpString} `; + if (Array.isArray(aliases) && aliases.length) { + let aliasesString = `(aliases: ${aliases.map(x => `/${x}`).join(', ')})`; + stringBuilder += aliasesString; + } + this.helpStrings.push(stringBuilder); } parse(text) { @@ -53,13 +62,19 @@ class SlashCommandParser { return false; } + + getHelpString() { + const listItems = this.helpStrings.map(x => `
  • ${x}
  • `).join('\n'); + return `

    Slash commands:

      ${listItems}
    `; + } } const parser = new SlashCommandParser(); const registerSlashCommand = parser.addCommand.bind(parser); +const getSlashCommandsHelp = parser.getHelpString.bind(parser); -parser.addCommand('help', helpCommandCallback, ['?'], 'Displays a help information', true, true); -parser.addCommand('bg', setBackgroundCallback, ['background'], 'Sets a background', false, true); +parser.addCommand('help', helpCommandCallback, ['?'], ' – displays a help information', true, true); +parser.addCommand('bg', setBackgroundCallback, ['background'], 'name – sets a background by file name', false, true); function helpCommandCallback() { sendSystemMessage(system_message_types.HELP); diff --git a/public/style.css b/public/style.css index e9a13e5a4..5e13a6887 100644 --- a/public/style.css +++ b/public/style.css @@ -2957,6 +2957,10 @@ label[for="extensions_autoconnect"] { color: lightgray; } +.monospace { + font-family: monospace; +} + .expander { flex-grow: 1; }