mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Regex: fix multiple script bug
Multiple scripts were not running due to improper variable assingment. For efficiency's sake, do not do a string comparison before returning and instead do another variable assignment in the parent function. Doing this reduces the length of regex hooks in the parent calls, but also removes the need for unnecessary O(n) complexity of comparing two string variables. If there are errors, it would be advisable to add string comparison and revert back to the old logic in parent function calls. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@@ -39,14 +39,14 @@ function regexFromString(input) {
|
||||
|
||||
// Parent function to fetch a regexed version of a raw string
|
||||
function getRegexedString(rawString, placement, { characterOverride } = {}) {
|
||||
let finalString = rawString;
|
||||
if (extension_settings.disabledExtensions.includes("regex") || !rawString || placement === undefined) {
|
||||
return;
|
||||
return finalString;
|
||||
}
|
||||
|
||||
let finalString;
|
||||
extension_settings.regex.forEach((script) => {
|
||||
if (script.placement.includes(placement)) {
|
||||
finalString = runRegexScript(script, rawString, { characterOverride });
|
||||
finalString = runRegexScript(script, finalString, { characterOverride });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -55,17 +55,17 @@ function getRegexedString(rawString, placement, { characterOverride } = {}) {
|
||||
|
||||
// Runs the provided regex script on the given string
|
||||
function runRegexScript(regexScript, rawString, { characterOverride } = {}) {
|
||||
let newString = rawString;
|
||||
if (!regexScript || !!(regexScript.disabled) || !regexScript?.findRegex || !rawString) {
|
||||
return;
|
||||
return newString;
|
||||
}
|
||||
|
||||
let match;
|
||||
let newString;
|
||||
const findRegex = regexFromString(regexScript.substituteRegex ? substituteParams(regexScript.findRegex) : regexScript.findRegex);
|
||||
|
||||
// The user skill issued. Return with nothing.
|
||||
if (!findRegex) {
|
||||
return;
|
||||
return newString;
|
||||
}
|
||||
|
||||
while ((match = findRegex.exec(rawString)) !== null) {
|
||||
|
Reference in New Issue
Block a user