mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Regex: allow multiple definitions in a single file
This commit is contained in:
@@ -459,19 +459,12 @@ async function toggleRegexCallback(args, scriptName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the import of the regex file.
|
* Performs the import of the regex object.
|
||||||
* @param {File} file Input file
|
* @param {Object} regexScript Input object
|
||||||
* @param {boolean} isScoped Is the script scoped to a character?
|
* @param {boolean} isScoped Is the script scoped to a character?
|
||||||
*/
|
*/
|
||||||
async function onRegexImportFileChange(file, isScoped) {
|
async function onRegexImportObjectChange(regexScript, isScoped) {
|
||||||
if (!file) {
|
|
||||||
toastr.error('No file provided.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fileText = await getFileText(file);
|
|
||||||
const regexScript = JSON.parse(fileText);
|
|
||||||
if (!regexScript.scriptName) {
|
if (!regexScript.scriptName) {
|
||||||
throw new Error('No script name provided.');
|
throw new Error('No script name provided.');
|
||||||
}
|
}
|
||||||
@@ -489,6 +482,33 @@ async function onRegexImportFileChange(file, isScoped) {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
await loadRegexScripts();
|
await loadRegexScripts();
|
||||||
toastr.success(`Regex script "${regexScript.scriptName}" imported.`);
|
toastr.success(`Regex script "${regexScript.scriptName}" imported.`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
toastr.error('Invalid regex object.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the import of the regex file.
|
||||||
|
* @param {File} file Input file
|
||||||
|
* @param {boolean} isScoped Is the script scoped to a character?
|
||||||
|
*/
|
||||||
|
async function onRegexImportFileChange(file, isScoped) {
|
||||||
|
if (!file) {
|
||||||
|
toastr.error('No file provided.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const regexScripts = JSON.parse(await getFileText(file));
|
||||||
|
if (Array.isArray(regexScripts)) {
|
||||||
|
for (const regexScript of regexScripts) {
|
||||||
|
await onRegexImportObjectChange(regexScript, isScoped);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await onRegexImportObjectChange(regexScripts, isScoped);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
toastr.error('Invalid JSON file.');
|
toastr.error('Invalid JSON file.');
|
||||||
|
Reference in New Issue
Block a user