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 => `
Slash commands: