[feat] change emotion on script

This commit is contained in:
kwaroran
2023-05-07 23:56:05 +09:00
parent 517e66db7a
commit 2b33ea45a7
2 changed files with 43 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ import { loadLoreBookPrompt } from "../lorebook";
import { findCharacterbyId, replacePlaceholders } from "../util";
import { requestChatData } from "./request";
import { stableDiff } from "./stableDiff";
import { processScript } from "./scripts";
import { processScript, processScriptFull } from "./scripts";
export interface OpenAIChat{
role: 'system'|'user'|'assistant'
@@ -282,23 +282,26 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
}, 'model')
let result = ''
let emoChanged = false
if(req.type === 'fail'){
alertError(req.result)
return false
}
else{
result = reformatContent(req.result)
const result2 = processScriptFull(currentChar, reformatContent(req.result), 'editoutput')
result = result2.data
emoChanged = result2.emoChanged
db.characters[selectedChar].chats[selectedChat].message.push({
role: 'char',
data: result,
saying: processScript(currentChar,currentChar.chaId, 'editoutput')
saying: currentChar.chaId
})
setDatabase(db)
}
if(currentChar.viewScreen === 'emotion'){
if(currentChar.viewScreen === 'emotion' && (!emoChanged)){
let currentEmotion = currentChar.emotionImages

View File

@@ -1,15 +1,49 @@
import { get } from "svelte/store";
import { CharEmotion, selectedCharID } from "../stores";
import type { character } from "../database";
const dreg = /{{data}}/g
export function processScript(char:character, data:string, mode:'editinput'|'editoutput'|'editprocess'){
type ScriptMode = 'editinput'|'editoutput'|'editprocess'
export function processScript(char:character, data:string, mode:ScriptMode){
return processScriptFull(char, data, mode).data
}
export function processScriptFull(char:character, data:string, mode:ScriptMode){
let emoChanged = false
for (const script of char.customscript){
if(script.type === mode){
const reg = new RegExp(script.in,'g')
data = data.replace(reg, (v) => {
if(script.out.startsWith('@@emo ')){
if(char.viewScreen !== 'emotion'){
return v
}
const emoName = script.out.substring(6).trim()
let charemotions = get(CharEmotion)
let tempEmotion = charemotions[char.chaId]
if(!tempEmotion){
tempEmotion = []
}
if(tempEmotion.length > 4){
tempEmotion.splice(0, 1)
}
for(const emo of char.emotionImages){
if(emo[0] === emoName){
const emos:[string, string,number] = [emo[0], emo[1], Date.now()]
tempEmotion.push(emos)
charemotions[char.chaId] = tempEmotion
CharEmotion.set(charemotions)
emoChanged = true
break
}
}
return v
}
return script.out.replace(dreg, v)
})
}
}
return data
return {data, emoChanged}
}