simplify and proper NOT check fix

This commit is contained in:
Bronya Rand 2023-12-04 15:57:04 -06:00
parent ce1fb8a888
commit 085daaeff7

View File

@ -1759,53 +1759,44 @@ async function checkWorldInfo(chat, maxContext) {
if (Array.isArray(entry.key) && entry.key.length) { //check for keywords existing if (Array.isArray(entry.key) && entry.key.length) { //check for keywords existing
// If selectiveLogic isn't found, assume it's AND, only do this once per entry // If selectiveLogic isn't found, assume it's AND, only do this once per entry
const selectiveLogic = entry.selectiveLogic ?? 0; const selectiveLogic = entry.selectiveLogic ?? 0;
let notFlag = true;
primary: for (let key of entry.key) { primary: for (let key of entry.key) {
const substituted = substituteParams(key); const substituted = substituteParams(key);
console.debug(`${entry.uid}: ${substituted}`); console.debug(`${entry.uid}: ${substituted}`);
if (substituted && matchKeys(textToScan, substituted.trim())) { if (substituted && matchKeys(textToScan, substituted.trim())) {
console.debug(`${entry.uid}: got primary match`); console.debug(`WI UID ${entry.uid} found by primary match: ${substituted}.`);
//selective logic begins //selective logic begins
if ( if (
entry.selective && //all entries are selective now entry.selective && //all entries are selective now
Array.isArray(entry.keysecondary) && //always true Array.isArray(entry.keysecondary) && //always true
entry.keysecondary.length //ignore empties entry.keysecondary.length //ignore empties
) { ) {
console.debug(`uid:${entry.uid}: checking logic: ${entry.selectiveLogic}`); console.debug(`WI UID:${entry.uid} found. Checking logic: ${entry.selectiveLogic}`);
secondary: for (let keysecondary of entry.keysecondary) { secondary: for (let keysecondary of entry.keysecondary) {
const secondarySubstituted = substituteParams(keysecondary); const secondarySubstituted = substituteParams(keysecondary);
console.debug(`uid:${entry.uid}: filtering ${secondarySubstituted}`); console.debug(`WI UID:${entry.uid}: Filtering for secondary keyword - "${secondarySubstituted}".`);
//AND operator
if (selectiveLogic === 0) { if (selectiveLogic === 0 && secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim()) ||
console.debug('saw AND logic, checking..'); selectiveLogic === 1 && !(secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim()))) {
if (secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim())) { if (selectiveLogic === 0) {
console.debug(`activating entry ${entry.uid} with AND found`); console.debug(`(AND Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
activatedNow.add(entry); } else {
break secondary; console.debug(`(NOT Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
}
}
//NOT operator
if (selectiveLogic === 1) {
console.debug(`uid ${entry.uid}: checking NOT logic for ${secondarySubstituted}`);
if (secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim())) {
console.debug(`uid ${entry.uid}: canceled; filtered out by ${secondarySubstituted}`);
notFlag = false;
break primary;
} }
activatedNow.add(entry);
break secondary;
} }
} }
//handle cases where secondary is empty // Handle cases where secondary is empty
} else { } else {
console.debug(`uid ${entry.uid}: activated without filter logic`); console.debug(`WI UID ${entry.uid}: Activated without filter logic.`);
activatedNow.add(entry); activatedNow.add(entry);
break primary; break primary;
} }
} else { console.debug('no active entries for logic checks yet'); } } else { console.debug(`No active entries for logic checks for word: ${substituted}.`); }
}
//for a NOT all entries must be checked, a single match invalidates activation
if (selectiveLogic === 1 && notFlag) {
console.debug(`${entry.uid}: activated; passed NOT filter`);
activatedNow.add(entry);
} }
} }
} }