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

@@ -2026,6 +2026,7 @@ export async function risuCommandParser(da:string, arg:{
funcName?:string
passed?:string[],
recursiveCount?:number
lowLevelAccess?:boolean
} = {}):Promise<{[key:string]:string}>{
const db = arg.db ?? get(DataBase)
const aChara = arg.chara
@@ -2068,7 +2069,8 @@ export async function risuCommandParser(da:string, arg:{
consistantChar: false,
funcName: arg.funcName ?? null,
text: da,
recursiveCount: recursiveCount
recursiveCount: recursiveCount,
lowLevelAccess: arg.lowLevelAccess ?? false
}
let tempVar:{[key:string]:string} = {}

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
}
}
}
}