From 00e86527ced902a7ebd96fe8e323bcabad1d55f1 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 28 Mar 2024 18:37:32 +0900 Subject: [PATCH] fix trigger variable handling in triggers.ts --- src/ts/process/triggers.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ts/process/triggers.ts b/src/ts/process/triggers.ts index d01af730..5065c564 100644 --- a/src/ts/process/triggers.ts +++ b/src/ts/process/triggers.ts @@ -1,5 +1,5 @@ import { cloneDeep } from "lodash"; -import { getVarChat, risuChatParser } from "../parser"; +import { risuChatParser } from "../parser"; import type { Chat, character } from "../storage/database"; import { tokenize } from "../tokenizer"; import { getModuleTriggers } from "./modules"; @@ -74,8 +74,18 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{ if((!triggers) || (triggers.length === 0)){ return null } - let varValues = getVarChat(-1, char) + const charVars = chat.scriptstate + let varValues:{[key:string]:string} = {} let varValuesChanged = false + + for(const key in charVars){ + if(!key.startsWith('$')){ + continue + } + varValues[key] = charVars[key.substring(1)].toString() + } + + for(const trigger of triggers){ if(mode !== trigger.type){ continue @@ -193,6 +203,11 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{ if(additonalSysPrompt.promptend){ caculatedTokens += await tokenize(additonalSysPrompt.promptend) } + if(varValuesChanged){ + for(const key in varValues){ + chat.scriptstate['$' + key] = varValues[key] + } + } return {additonalSysPrompt, chat, tokens:caculatedTokens}