From bca21ec9b69b4c8b4a85988a1120b572b990dfa0 Mon Sep 17 00:00:00 2001 From: nonenothingnada <150897918+nonenothingnada@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:11:09 +0100 Subject: [PATCH] Bugfix: World Info - NOT operator only considers first secondary key Small fix to correct the behavior of the World Info NOT operator with a list of secondary keys to what was (hopefully) intended. Previously only the first secondary key was ever checked. Now each primary key should be checked against each secondary key with a single match invalidating the entry activation. --- public/scripts/world-info.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 7c4c0ef6f..720be4ccc 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1526,6 +1526,9 @@ async function checkWorldInfo(chat, maxContext) { } 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 + const selectiveLogic = entry.selectiveLogic ?? 0; + let notFlag = true; primary: for (let key of entry.key) { const substituted = substituteParams(key); console.debug(`${entry.uid}: ${substituted}`) @@ -1541,10 +1544,6 @@ async function checkWorldInfo(chat, maxContext) { secondary: for (let keysecondary of entry.keysecondary) { const secondarySubstituted = substituteParams(keysecondary); console.debug(`uid:${entry.uid}: filtering ${secondarySubstituted}`); - - // If selectiveLogic isn't found, assume it's AND - const selectiveLogic = entry.selectiveLogic ?? 0; - //AND operator if (selectiveLogic === 0) { console.debug('saw AND logic, checking..') @@ -1559,11 +1558,8 @@ async function checkWorldInfo(chat, maxContext) { 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; - } else { - console.debug(`${entry.uid}: activated; passed NOT filter`) - activatedNow.add(entry); - break secondary; } } } @@ -1575,6 +1571,11 @@ async function checkWorldInfo(chat, maxContext) { } } else { console.debug('no active entries for logic checks yet') } } + //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); + } } }