add dynamic asset cache
This commit is contained in:
@@ -57,6 +57,8 @@ export async function importRegex(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bestMatchCache = new Map<string, string>()
|
||||||
|
|
||||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1){
|
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1){
|
||||||
let db = get(DataBase)
|
let db = get(DataBase)
|
||||||
let emoChanged = false
|
let emoChanged = false
|
||||||
@@ -212,11 +214,17 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
|||||||
for(const match of matches){
|
for(const match of matches){
|
||||||
const type = match[1]
|
const type = match[1]
|
||||||
const assetName = match[2]
|
const assetName = match[2]
|
||||||
if(!assetNames.includes(assetName)){
|
if(type !== 'emotion' && type !== 'source'){
|
||||||
const searched = await processer.similaritySearch(assetName)
|
if(bestMatchCache.has(assetName)){
|
||||||
const bestMatch = searched[0]
|
data = data.replaceAll(match[0], `{{${type}::${bestMatchCache.get(assetName)}}}`)
|
||||||
if(bestMatch){
|
}
|
||||||
data = data.replaceAll(match[0], `{{${type}::${bestMatch}}}`)
|
else if(!assetNames.includes(assetName)){
|
||||||
|
const searched = await processer.similaritySearch(assetName)
|
||||||
|
const bestMatch = searched[0]
|
||||||
|
if(bestMatch){
|
||||||
|
data = data.replaceAll(match[0], `{{${type}::${bestMatch}}}`)
|
||||||
|
bestMatchCache.set(assetName, bestMatch)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user