feat: add triggercode

This commit is contained in:
kwaroran
2024-06-29 00:45:57 +09:00
parent 39e7a8df8b
commit 8a94ef938e
5 changed files with 67 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { risuChatParser } from "../parser";
import { risuChatParser, risuCommandParser } from "../parser";
import { DataBase, type Chat, type character } from "../storage/database";
import { tokenize } from "../tokenizer";
import { getModuleTriggers } from "./modules";
@@ -23,7 +23,7 @@ export interface triggerscript{
export type triggerCondition = triggerConditionsVar|triggerConditionsExists|triggerConditionsChatIndex
export type triggerEffect = triggerEffectCutChat|triggerEffectModifyChat|triggerEffectImgGen|triggerEffectRegex|triggerEffectRunLLM|triggerEffectCheckSimilarity|triggerEffectSendAIprompt|triggerEffectShowAlert|triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger
export type triggerEffect = triggerCode|triggerEffectCutChat|triggerEffectModifyChat|triggerEffectImgGen|triggerEffectRegex|triggerEffectRunLLM|triggerEffectCheckSimilarity|triggerEffectSendAIprompt|triggerEffectShowAlert|triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger
export type triggerConditionsVar = {
type:'var'|'value'
@@ -32,6 +32,11 @@ export type triggerConditionsVar = {
operator:'='|'!='|'>'|'<'|'>='|'<='|'null'|'true'
}
export type triggerCode = {
type: 'triggercode',
code: string
}
export type triggerConditionsChatIndex = {
type:'chatindex'
value:string
@@ -202,7 +207,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
continue
}
}
else if(mode !== trigger.type){
else if(mode !== trigger.type && trigger.effect[0]?.type !== 'triggercode'){
continue
}
@@ -518,6 +523,20 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
setVar(effect.inputVar, res)
break
}
case 'triggercode':{
const triggerCodeResult = await risuCommandParser(effect.code,{
chara:char,
lowLevelAccess: trigger.lowLevelAccess,
funcName: mode
})
if(triggerCodeResult['__stop_chat__'] === '1'){
stopSending = true
}
break
}
}
}
}