[feat] added calc

This commit is contained in:
kwaroran
2023-07-07 17:02:14 +09:00
parent 4650fe2d95
commit 4d4bee4df8
2 changed files with 9 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import { downloadFile } from "../storage/globalApi";
import { alertError, alertNormal } from "../alert";
import { language } from "src/lang";
import { findCharacterbyId, selectSingleFile } from "../util";
import { calcString } from "./infunctions";
const dreg = /{{data}}/g
const randomness = /\|\|\|/g
@@ -110,6 +111,7 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
}
}
else{
let mOut = outScript.replace(dreg, "$&")
if(chatID !== -1){
const selchar = db.characters[get(selectedCharID)]
const chat = selchar.chats[selchar.chatPage]
@@ -134,6 +136,10 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
}
return selchar.firstMsgIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[selchar.firstMsgIndex]
}
if(p1.startsWith('calc')){
const v = p1.split("::")[1]
return calcString(v).toString()
}
return v
})
}
@@ -141,7 +147,7 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
const list = data.split('|||')
data = list[Math.floor(Math.random()*list.length)];
}
data = data.replace(reg, outScript.replace(dreg, "$&"))
data = data.replace(reg, mOut)
}
}
}