mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#629 Random list select substitution
This commit is contained in:
@@ -1496,9 +1496,25 @@ function substituteParams(content, _name1, _name2, _original) {
|
|||||||
content = content.replace(/<BOT>/gi, _name2);
|
content = content.replace(/<BOT>/gi, _name2);
|
||||||
content = content.replace(/{{time}}/gi, moment().format('LT'));
|
content = content.replace(/{{time}}/gi, moment().format('LT'));
|
||||||
content = content.replace(/{{date}}/gi, moment().format('LL'));
|
content = content.replace(/{{date}}/gi, moment().format('LL'));
|
||||||
|
content = randomReplace(content);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function randomReplace(input, emptyListPlaceholder = '') {
|
||||||
|
const randomPattern = /{{random:([^}]+)}}/g;
|
||||||
|
|
||||||
|
return input.replace(randomPattern, (match, listString) => {
|
||||||
|
const list = listString.split(',').map(item => item.trim()).filter(item => item.length > 0);
|
||||||
|
|
||||||
|
if (list.length === 0) {
|
||||||
|
return emptyListPlaceholder;
|
||||||
|
}
|
||||||
|
|
||||||
|
const randomIndex = Math.floor(Math.random() * list.length);
|
||||||
|
return list[randomIndex];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getStoppingStrings(isImpersonate, addSpace) {
|
function getStoppingStrings(isImpersonate, addSpace) {
|
||||||
const charString = `\n${name2}:`;
|
const charString = `\n${name2}:`;
|
||||||
const youString = `\nYou:`;
|
const youString = `\nYou:`;
|
||||||
@@ -1600,7 +1616,7 @@ export function extractMessageBias(message) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const forbiddenMatches = ['user', 'char', 'time', 'date'];
|
const forbiddenMatches = ['user', 'char', 'time', 'date', 'random'];
|
||||||
const found = [];
|
const found = [];
|
||||||
const rxp = /\{\{([\s\S]+?)\}\}/gm;
|
const rxp = /\{\{([\s\S]+?)\}\}/gm;
|
||||||
//const rxp = /{([^}]+)}/g;
|
//const rxp = /{([^}]+)}/g;
|
||||||
@@ -1609,7 +1625,12 @@ export function extractMessageBias(message) {
|
|||||||
while ((curMatch = rxp.exec(message))) {
|
while ((curMatch = rxp.exec(message))) {
|
||||||
const match = curMatch[1].trim();
|
const match = curMatch[1].trim();
|
||||||
|
|
||||||
if (forbiddenMatches.includes(match)) {
|
// Ignore random pattern matches
|
||||||
|
if (/^random:.+/i.test(match)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forbiddenMatches.includes(match.toLowerCase())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -333,7 +333,7 @@ function switchSpoilerMode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function peekSpoilerMode(){
|
function peekSpoilerMode() {
|
||||||
$("#description_div").toggle();
|
$("#description_div").toggle();
|
||||||
$("#description_textarea").toggle();
|
$("#description_textarea").toggle();
|
||||||
$("#firstmessage_textarea").toggle();
|
$("#firstmessage_textarea").toggle();
|
||||||
|
Reference in New Issue
Block a user