[feat] lorebook regex
This commit is contained in:
@@ -51,8 +51,8 @@ export function addLorebook(type:number) {
|
||||
}
|
||||
|
||||
interface formatedLore{
|
||||
keys:string[]|'always',
|
||||
secondKey:string[]
|
||||
keys:string[]|'always'|{type:'regex',regex:string},
|
||||
secondKey:string[]|{type:'regex',regex:string}
|
||||
content: string
|
||||
order: number
|
||||
activatied: boolean
|
||||
@@ -91,12 +91,14 @@ export async function loadLoreBookPrompt(){
|
||||
}
|
||||
|
||||
formatedLore.push({
|
||||
keys: lore.alwaysActive ? 'always' : (lore.key ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
|
||||
return a.length > 1
|
||||
}),
|
||||
secondKey: lore.selective ? (lore.secondkey ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
|
||||
return a.length > 1
|
||||
}) : [],
|
||||
keys: lore.alwaysActive ? 'always' : (lore.key?.startsWith("regex:")) ? ({type:'regex',regex:lore.key.replace('regex:','')}) :
|
||||
(lore.key ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
|
||||
return a.length > 1
|
||||
}),
|
||||
secondKey: lore.selective ? ((lore.secondkey?.startsWith("regex:")) ? ({type:'regex',regex:lore.secondkey.replace('regex:','')}) :
|
||||
(lore.secondkey ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
|
||||
return a.length > 1
|
||||
})) : [],
|
||||
content: lore.content,
|
||||
order: lore.insertorder,
|
||||
activatied: false
|
||||
@@ -136,28 +138,42 @@ export async function loadLoreBookPrompt(){
|
||||
}
|
||||
|
||||
let firstKeyActivation = false
|
||||
for(const key of lore.keys){
|
||||
if(key){
|
||||
if(formatedChat.includes(key)){
|
||||
firstKeyActivation = true
|
||||
break
|
||||
if(Array.isArray(lore.keys)){
|
||||
for(const key of lore.keys){
|
||||
if(key){
|
||||
if(formatedChat.includes(key)){
|
||||
firstKeyActivation = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(formatedChat.match(new RegExp(lore.keys.regex,'g'))){
|
||||
firstKeyActivation = true
|
||||
}
|
||||
}
|
||||
|
||||
if(firstKeyActivation){
|
||||
if(lore.secondKey.length === 0){
|
||||
activatiedPrompt.push(lore.content)
|
||||
lore.activatied = true
|
||||
loreListUpdated = true
|
||||
continue
|
||||
}
|
||||
for(const key of lore.secondKey){
|
||||
if(formatedChat.includes(key)){
|
||||
if(Array.isArray(lore.secondKey)){
|
||||
if(lore.secondKey.length === 0){
|
||||
activatiedPrompt.push(lore.content)
|
||||
lore.activatied = true
|
||||
loreListUpdated = true
|
||||
break
|
||||
continue
|
||||
}
|
||||
for(const key of lore.secondKey){
|
||||
if(formatedChat.includes(key)){
|
||||
activatiedPrompt.push(lore.content)
|
||||
lore.activatied = true
|
||||
loreListUpdated = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(formatedChat.match(new RegExp(lore.secondKey.regex,'g'))){
|
||||
firstKeyActivation = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user