From 2c8e855385c2888f00daf02ca3b0ac7a70fc9dcf Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 24 Nov 2023 17:41:49 +0200 Subject: [PATCH] Resolve variables in /fuzzy --- public/scripts/slash-commands.js | 4 ++-- public/scripts/variables.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index a8fbc4622..bd23068a0 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -37,7 +37,7 @@ import { autoSelectPersona } from "./personas.js"; import { getContext } from "./extensions.js"; import { hideChatMessage, unhideChatMessage } from "./chats.js"; import { delay, isFalseBoolean, isTrueBoolean, stringToRange } from "./utils.js"; -import { registerVariableCommands } from "./variables.js"; +import { registerVariableCommands, resolveVariable } from "./variables.js"; export { executeSlashCommands, registerSlashCommand, @@ -272,7 +272,7 @@ function fuzzyCallback(args, value) { } try { - const list = JSON.parse(args.list); + const list = JSON.parse(resolveVariable(args.list)); if (!Array.isArray(list)) { console.warn('WARN: Invalid list argument provided for /fuzzy command'); return ''; diff --git a/public/scripts/variables.js b/public/scripts/variables.js index 8d30c361d..4ffe7b776 100644 --- a/public/scripts/variables.js +++ b/public/scripts/variables.js @@ -69,6 +69,18 @@ function addGlobalVariable(name, value) { return newValue; } +export function resolveVariable(name) { + if (existsLocalVariable(name)) { + return getLocalVariable(name); + } + + if (existsGlobalVariable(name)) { + return getGlobalVariable(name); + } + + return name; +} + export function replaceVariableMacros(str) { // Replace {{getvar::name}} with the value of the variable name str = str.replace(/{{getvar::([^}]+)}}/gi, (_, name) => {