mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 17:07:07 +01:00
Port #3031 onto new engine
This commit is contained in:
parent
5c90c8b1f6
commit
48d8e6e2c3
@ -1,4 +1,4 @@
|
|||||||
import { characters, substituteParams, this_chid } from '../../../script.js';
|
import { characters, substituteParams, substituteParamsExtended, this_chid } from '../../../script.js';
|
||||||
import { extension_settings } from '../../extensions.js';
|
import { extension_settings } from '../../extensions.js';
|
||||||
import { regexFromString } from '../../utils.js';
|
import { regexFromString } from '../../utils.js';
|
||||||
export {
|
export {
|
||||||
@ -22,6 +22,28 @@ const regex_placement = {
|
|||||||
WORLD_INFO: 5,
|
WORLD_INFO: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function sanitizeRegexMacro(x) {
|
||||||
|
return (x && typeof x === 'string') ?
|
||||||
|
x.replaceAll(/[\n\r\t\v\f\0.^$*+?{}[\]\\/|()]/gs, function (s) {
|
||||||
|
switch (s) {
|
||||||
|
case '\n':
|
||||||
|
return '\\n';
|
||||||
|
case '\r':
|
||||||
|
return '\\r';
|
||||||
|
case '\t':
|
||||||
|
return '\\t';
|
||||||
|
case '\v':
|
||||||
|
return '\\v';
|
||||||
|
case '\f':
|
||||||
|
return '\\f';
|
||||||
|
case '\0':
|
||||||
|
return '\\0';
|
||||||
|
default:
|
||||||
|
return '\\' + s;
|
||||||
|
}
|
||||||
|
}) : x;
|
||||||
|
}
|
||||||
|
|
||||||
function getScopedRegex() {
|
function getScopedRegex() {
|
||||||
const isAllowed = extension_settings?.character_allowed_regex?.includes(characters?.[this_chid]?.avatar);
|
const isAllowed = extension_settings?.character_allowed_regex?.includes(characters?.[this_chid]?.avatar);
|
||||||
|
|
||||||
@ -109,7 +131,10 @@ function runRegexScript(regexScript, rawString, { characterOverride } = {}) {
|
|||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
|
|
||||||
const findRegex = regexFromString(regexScript.substituteRegex ? substituteParams(regexScript.findRegex) : regexScript.findRegex);
|
const regexString = regexScript.substituteRegex
|
||||||
|
? substituteParamsExtended(regexScript.findRegex, {}, sanitizeRegexMacro)
|
||||||
|
: regexScript.findRegex;
|
||||||
|
const findRegex = regexFromString(regexString);
|
||||||
|
|
||||||
// The user skill issued. Return with nothing.
|
// The user skill issued. Return with nothing.
|
||||||
if (!findRegex) {
|
if (!findRegex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user