mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Resolve variables in /fuzzy
This commit is contained in:
@ -37,7 +37,7 @@ import { autoSelectPersona } from "./personas.js";
|
|||||||
import { getContext } from "./extensions.js";
|
import { getContext } from "./extensions.js";
|
||||||
import { hideChatMessage, unhideChatMessage } from "./chats.js";
|
import { hideChatMessage, unhideChatMessage } from "./chats.js";
|
||||||
import { delay, isFalseBoolean, isTrueBoolean, stringToRange } from "./utils.js";
|
import { delay, isFalseBoolean, isTrueBoolean, stringToRange } from "./utils.js";
|
||||||
import { registerVariableCommands } from "./variables.js";
|
import { registerVariableCommands, resolveVariable } from "./variables.js";
|
||||||
export {
|
export {
|
||||||
executeSlashCommands,
|
executeSlashCommands,
|
||||||
registerSlashCommand,
|
registerSlashCommand,
|
||||||
@ -272,7 +272,7 @@ function fuzzyCallback(args, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const list = JSON.parse(args.list);
|
const list = JSON.parse(resolveVariable(args.list));
|
||||||
if (!Array.isArray(list)) {
|
if (!Array.isArray(list)) {
|
||||||
console.warn('WARN: Invalid list argument provided for /fuzzy command');
|
console.warn('WARN: Invalid list argument provided for /fuzzy command');
|
||||||
return '';
|
return '';
|
||||||
|
@ -69,6 +69,18 @@ function addGlobalVariable(name, value) {
|
|||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resolveVariable(name) {
|
||||||
|
if (existsLocalVariable(name)) {
|
||||||
|
return getLocalVariable(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existsGlobalVariable(name)) {
|
||||||
|
return getGlobalVariable(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
export function replaceVariableMacros(str) {
|
export function replaceVariableMacros(str) {
|
||||||
// Replace {{getvar::name}} with the value of the variable name
|
// Replace {{getvar::name}} with the value of the variable name
|
||||||
str = str.replace(/{{getvar::([^}]+)}}/gi, (_, name) => {
|
str = str.replace(/{{getvar::([^}]+)}}/gi, (_, name) => {
|
||||||
|
Reference in New Issue
Block a user