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:
@@ -101,9 +101,9 @@ import {
|
|||||||
nai_settings,
|
nai_settings,
|
||||||
} from "./scripts/nai-settings.js";
|
} from "./scripts/nai-settings.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createNewBookmark,
|
createNewBookmark,
|
||||||
showBookmarksButtons
|
showBookmarksButtons
|
||||||
} from "./scripts/bookmarks.js";
|
} from "./scripts/bookmarks.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3465,7 +3486,7 @@ function extractMessageFromData(data) {
|
|||||||
function cleanUpMessage(getMessage, isImpersonate, displayIncompleteSentences = false) {
|
function cleanUpMessage(getMessage, isImpersonate, displayIncompleteSentences = false) {
|
||||||
// Add the prompt bias before anything else
|
// Add the prompt bias before anything else
|
||||||
if (
|
if (
|
||||||
power_user.user_prompt_bias &&
|
power_user.user_prompt_bias &&
|
||||||
!isImpersonate &&
|
!isImpersonate &&
|
||||||
power_user.user_prompt_bias.length !== 0
|
power_user.user_prompt_bias.length !== 0
|
||||||
) {
|
) {
|
||||||
@@ -4908,8 +4929,8 @@ function updateMessage(div) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const regexResult = getRegexedString(
|
const regexResult = getRegexedString(
|
||||||
text,
|
text,
|
||||||
regexPlacement,
|
regexPlacement,
|
||||||
{
|
{
|
||||||
characterOverride: regexPlacement === regex_placement.SENDAS ? mes.name : undefined
|
characterOverride: regexPlacement === regex_placement.SENDAS ? mes.name : undefined
|
||||||
}
|
}
|
||||||
|
@@ -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();
|
||||||
@@ -1166,7 +1166,7 @@ function setAvgBG() {
|
|||||||
.attr('src')
|
.attr('src')
|
||||||
.replace(/^url\(['"]?/, '')
|
.replace(/^url\(['"]?/, '')
|
||||||
.replace(/['"]?\)$/, '');
|
.replace(/['"]?\)$/, '');
|
||||||
|
|
||||||
const userAvatar = new Image()
|
const userAvatar = new Image()
|
||||||
userAvatar.src = $("#user_avatar_block .avatar.selected img")
|
userAvatar.src = $("#user_avatar_block .avatar.selected img")
|
||||||
.attr('src')
|
.attr('src')
|
||||||
@@ -1185,7 +1185,7 @@ function setAvgBG() {
|
|||||||
.replace('rgb', '')
|
.replace('rgb', '')
|
||||||
.replace('(', '[')
|
.replace('(', '[')
|
||||||
.replace(')', ']'); //[50, 120, 200, 1]; // Example background color
|
.replace(')', ']'); //[50, 120, 200, 1]; // Example background color
|
||||||
const backgroundColorArray = JSON.parse(backgroundColorString) //[200, 200, 200, 1]
|
const backgroundColorArray = JSON.parse(backgroundColorString) //[200, 200, 200, 1]
|
||||||
console.log(backgroundColorArray)
|
console.log(backgroundColorArray)
|
||||||
$("#main-text-color-picker").attr('color', getReadableTextColor(backgroundColorArray));
|
$("#main-text-color-picker").attr('color', getReadableTextColor(backgroundColorArray));
|
||||||
console.log($("#main-text-color-picker").attr('color')); // Output: 'rgba(0, 47, 126, 1)'
|
console.log($("#main-text-color-picker").attr('color')); // Output: 'rgba(0, 47, 126, 1)'
|
||||||
@@ -1197,7 +1197,7 @@ function setAvgBG() {
|
|||||||
//console.log(rgb);
|
//console.log(rgb);
|
||||||
$("#bot-mes-blur-tint-color-picker").attr('color', 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')');
|
$("#bot-mes-blur-tint-color-picker").attr('color', 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
userAvatar.onload = function () {
|
userAvatar.onload = function () {
|
||||||
var rgb = getAverageRGB(userAvatar);
|
var rgb = getAverageRGB(userAvatar);
|
||||||
//console.log(`average color of the user avatar is:`);
|
//console.log(`average color of the user avatar is:`);
|
||||||
@@ -1300,16 +1300,16 @@ function setAvgBG() {
|
|||||||
//this version keeps BG and main text in same hue
|
//this version keeps BG and main text in same hue
|
||||||
/* function getReadableTextColor(rgb) {
|
/* function getReadableTextColor(rgb) {
|
||||||
const [r, g, b] = rgb;
|
const [r, g, b] = rgb;
|
||||||
|
|
||||||
// Convert RGB to HSL
|
// Convert RGB to HSL
|
||||||
const rgbToHsl = (r, g, b) => {
|
const rgbToHsl = (r, g, b) => {
|
||||||
const max = Math.max(r, g, b);
|
const max = Math.max(r, g, b);
|
||||||
const min = Math.min(r, g, b);
|
const min = Math.min(r, g, b);
|
||||||
const d = max - min;
|
const d = max - min;
|
||||||
const l = (max + min) / 2;
|
const l = (max + min) / 2;
|
||||||
|
|
||||||
if (d === 0) return [0, 0, l];
|
if (d === 0) return [0, 0, l];
|
||||||
|
|
||||||
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||||
const h = (() => {
|
const h = (() => {
|
||||||
switch (max) {
|
switch (max) {
|
||||||
@@ -1321,16 +1321,16 @@ function setAvgBG() {
|
|||||||
return (r - g) / d + 4;
|
return (r - g) / d + 4;
|
||||||
}
|
}
|
||||||
})() / 6;
|
})() / 6;
|
||||||
|
|
||||||
return [h, s, l];
|
return [h, s, l];
|
||||||
};
|
};
|
||||||
const [h, s, l] = rgbToHsl(r / 255, g / 255, b / 255);
|
const [h, s, l] = rgbToHsl(r / 255, g / 255, b / 255);
|
||||||
|
|
||||||
// Calculate appropriate text color based on background color
|
// Calculate appropriate text color based on background color
|
||||||
const targetLuminance = l > 0.5 ? 0.2 : 0.8;
|
const targetLuminance = l > 0.5 ? 0.2 : 0.8;
|
||||||
const targetSaturation = s > 0.5 ? s - 0.2 : s + 0.2;
|
const targetSaturation = s > 0.5 ? s - 0.2 : s + 0.2;
|
||||||
const [rNew, gNew, bNew] = hslToRgb(h, targetSaturation, targetLuminance);
|
const [rNew, gNew, bNew] = hslToRgb(h, targetSaturation, targetLuminance);
|
||||||
|
|
||||||
// Return the text color in RGBA format
|
// Return the text color in RGBA format
|
||||||
return `rgba(${rNew.toFixed(0)}, ${gNew.toFixed(0)}, ${bNew.toFixed(0)}, 1)`;
|
return `rgba(${rNew.toFixed(0)}, ${gNew.toFixed(0)}, ${bNew.toFixed(0)}, 1)`;
|
||||||
}*/
|
}*/
|
||||||
@@ -1824,7 +1824,7 @@ $(document).ready(() => {
|
|||||||
peekSpoilerMode();
|
peekSpoilerMode();
|
||||||
$(this).toggleClass('fa-eye fa-eye-slash');
|
$(this).toggleClass('fa-eye fa-eye-slash');
|
||||||
});
|
});
|
||||||
|
|
||||||
$(window).on('focus', function () {
|
$(window).on('focus', function () {
|
||||||
browser_has_focus = true;
|
browser_has_focus = true;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user