feat: add triggercode
This commit is contained in:
@@ -663,4 +663,7 @@ export const languageEnglish = {
|
||||
doNotTranslate: "Do Not Translate",
|
||||
includePersonaName: "Include Persona Name",
|
||||
hidePersonaName: "Hide Persona Name",
|
||||
triggerSwitchWarn: "If you change the trigger type, current triggers will be lost. do you want to continue?",
|
||||
codeMode: "Code Mode",
|
||||
blockMode: "Block Mode",
|
||||
}
|
||||
@@ -580,7 +580,44 @@
|
||||
}}><PlusIcon /></button>
|
||||
|
||||
<span class="text-textcolor mt-4">{language.triggerScript} <Help key="triggerScript"/></span>
|
||||
<TriggerList bind:value={currentChar.data.triggerscript} lowLevelAble={currentChar.data.lowLevelAccess} />
|
||||
<div class="flex items-start mt-2 gap-2">
|
||||
<button class="bg-bgcolor py-2 rounded-lg px-4" class:ring-1={currentChar.data?.triggerscript?.[0]?.effect?.[0]?.type !== 'triggercode'} on:click|stopPropagation={async () => {
|
||||
if(currentChar.type === 'character' && currentChar.data?.triggerscript?.[0]?.effect?.[0]?.type === 'triggercode'){
|
||||
const codeTrigger = currentChar.data?.triggerscript?.[0]?.effect?.[0]?.code
|
||||
if(codeTrigger){
|
||||
const t = await alertConfirm(language.triggerSwitchWarn)
|
||||
if(!t){
|
||||
return
|
||||
}
|
||||
}
|
||||
currentChar.data.triggerscript = []
|
||||
}
|
||||
}}>{language.blockMode}</button>
|
||||
<button class="bg-bgcolor py-2 rounded-lg px-4" class:ring-1={currentChar.data?.triggerscript?.[0]?.effect?.[0]?.type === 'triggercode'} on:click|stopPropagation={async () => {
|
||||
if(currentChar.type === 'character' && currentChar.data?.triggerscript?.[0]?.effect?.[0]?.type !== 'triggercode'){
|
||||
if(currentChar.data?.triggerscript && currentChar.data?.triggerscript.length > 0){
|
||||
const t = await alertConfirm(language.triggerSwitchWarn)
|
||||
if(!t){
|
||||
return
|
||||
}
|
||||
}
|
||||
currentChar.data.triggerscript = [{
|
||||
comment: "",
|
||||
type: "start",
|
||||
conditions: [],
|
||||
effect: [{
|
||||
type: "triggercode",
|
||||
code: ""
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}}>{language.codeMode}</button>
|
||||
</div>
|
||||
{#if currentChar.data?.triggerscript?.[0]?.effect?.[0]?.type === 'triggercode'}
|
||||
<TextAreaInput highlight margin="both" autocomplete="off" bind:value={currentChar.data.triggerscript[0].effect[0].code}></TextAreaInput>
|
||||
{:else}
|
||||
<TriggerList bind:value={currentChar.data.triggerscript} lowLevelAble={currentChar.data.lowLevelAccess} />
|
||||
{/if}
|
||||
<button class="font-medium cursor-pointer hover:text-green-500 mb-2" on:click={() => {
|
||||
if(currentChar.type === 'character'){
|
||||
let script = currentChar.data.triggerscript
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
onInput()
|
||||
}}
|
||||
translate="no"
|
||||
|
||||
>{value ?? ''}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -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} = {}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user