[fix] genbots not work
This commit is contained in:
@@ -2,39 +2,44 @@ import { writeInlayImage } from "../image";
|
|||||||
import type { character } from "../storage/database";
|
import type { character } from "../storage/database";
|
||||||
import { generateAIImage } from "./stableDiff";
|
import { generateAIImage } from "./stableDiff";
|
||||||
|
|
||||||
|
const imggenRegex = [/<ImgGen="(.+?)">/gi, /{{ImgGen="(.+?)"}}/gi] as const
|
||||||
|
|
||||||
export function runInlayScreen(char:character, data:string):{text:string, promise?:Promise<string>} {
|
export function runInlayScreen(char:character, data:string):{text:string, promise?:Promise<string>} {
|
||||||
if(char.inlayViewScreen){
|
if(char.inlayViewScreen){
|
||||||
if(char.viewScreen === 'emotion'){
|
if(char.viewScreen === 'emotion'){
|
||||||
return {text: data.replace(/<Emotion="(.+?)">/g, '{{emotion::$1}}')}
|
return {text: data.replace(/<Emotion="(.+?)">/gi, '{{emotion::$1}}')}
|
||||||
}
|
}
|
||||||
if(char.viewScreen === 'imggen'){
|
if(char.viewScreen === 'imggen'){
|
||||||
return {
|
return {
|
||||||
text: data.replace(/<ImgGen="(.+?)">/g,'[Generating...]'),
|
text: data.replace(imggenRegex[0],'[Generating...]').replace(imggenRegex[1],'[Generating...]'),
|
||||||
promise : (async () => {
|
promise : (async () => {
|
||||||
const promises:Promise<string|false>[] = [];
|
for(const regex of imggenRegex){
|
||||||
const neg = char.newGenData.negative
|
const promises:Promise<string|false>[] = [];
|
||||||
data.replace(/<ImgGen="(.+?)">/g, (match, p1) => {
|
const neg = char.newGenData.negative
|
||||||
const prompt = char.newGenData.prompt.replaceAll('{{slot}}', p1)
|
data.replace(regex, (match, p1) => {
|
||||||
promises.push((async () => {
|
const prompt = char.newGenData.prompt.replaceAll('{{slot}}', p1)
|
||||||
const v = await generateAIImage(prompt, char, neg, 'inlay')
|
promises.push((async () => {
|
||||||
if(!v){
|
const v = await generateAIImage(prompt, char, neg, 'inlay')
|
||||||
|
if(!v){
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const imgHTML = new Image()
|
||||||
|
imgHTML.src = v
|
||||||
|
const inlay = await writeInlayImage(imgHTML)
|
||||||
|
return inlay
|
||||||
|
})())
|
||||||
|
return match
|
||||||
|
})
|
||||||
|
const d = await Promise.all(promises)
|
||||||
|
data = data.replace(regex, () => {
|
||||||
|
const result = d.shift()
|
||||||
|
if(result === false){
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
const imgHTML = new Image()
|
return result
|
||||||
imgHTML.src = v
|
})
|
||||||
const inlay = await writeInlayImage(imgHTML)
|
}
|
||||||
return inlay
|
return data
|
||||||
})())
|
|
||||||
return match
|
|
||||||
})
|
|
||||||
const d = await Promise.all(promises)
|
|
||||||
return data.replace(/<ImgGen="(.+?)">/g, () => {
|
|
||||||
const result = d.shift()
|
|
||||||
if(result === false){
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
})
|
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user