mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Regex: Upgrade engine
If the extension is disabled, don't use any regex formatting. In addition, wrap all foreach logic into its own function which reduces the size of all regex injections. This commit also removes the need for working around static imports as UI is separate from the engine and is therefore imported at the same time as other non-static extensions. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
import { substituteParams } from "../../../script.js";
|
||||
import { extension_settings } from "../../extensions.js";
|
||||
export {
|
||||
regex_placement,
|
||||
getRegexedString,
|
||||
runRegexScript
|
||||
}
|
||||
|
||||
const regex_placement = {
|
||||
MD_DISPLAY: 0,
|
||||
USER_INPUT: 1,
|
||||
AI_OUTPUT: 2,
|
||||
SYSTEM: 3,
|
||||
SENDAS: 4
|
||||
}
|
||||
|
||||
// From: https://github.com/IonicaBizau/regex-parser.js/blob/master/lib/index.js
|
||||
function regexFromString(input) {
|
||||
// Parse input
|
||||
@@ -17,6 +28,21 @@ function regexFromString(input) {
|
||||
return new RegExp(m[2], m[3]);
|
||||
}
|
||||
|
||||
function getRegexedString(rawString, placement) {
|
||||
if (extension_settings.disabledExtensions.includes("regex") || !rawString || placement === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
let finalString;
|
||||
extension_settings.regex.forEach((script) => {
|
||||
if (script.placement.includes(placement)) {
|
||||
finalString = runRegexScript(script, rawString);
|
||||
}
|
||||
});
|
||||
|
||||
return finalString;
|
||||
}
|
||||
|
||||
// Runs the provided regex script on the given string
|
||||
function runRegexScript(regexScript, rawString) {
|
||||
if (!!(regexScript.disabled)) {
|
||||
|
Reference in New Issue
Block a user