From 3f79a066f6de45fbdbd8e858d397de4c3b4c359c Mon Sep 17 00:00:00 2001 From: Cohee Date: Fri, 9 Jun 2023 02:50:35 +0300 Subject: [PATCH] Don't replace well-know substitution marcos with bias. Support macros in sys and sendas messages. --- public/script.js | 13 ++++++++++--- public/scripts/slash-commands.js | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/public/script.js b/public/script.js index 51ccd69b3..50a3e6abc 100644 --- a/public/script.js +++ b/public/script.js @@ -1467,13 +1467,20 @@ export function extractMessageBias(message) { return null; } + const forbiddenMatches = ['user', 'char', 'time', 'date']; const found = []; - const rxp = /{{(\*?.+\*?)}}/g; + const rxp = /\{\{(.+?)\}\}/g; //const rxp = /{([^}]+)}/g; let curMatch; while ((curMatch = rxp.exec(message))) { - found.push(curMatch[1].trim()); + const match = curMatch[1].trim(); + + if (forbiddenMatches.includes(match)) { + continue; + } + + found.push(match); } let biasString = ''; @@ -2610,7 +2617,7 @@ export async function sendMessageAsUser(textareaText, messageBias) { chat[chat.length - 1]['is_user'] = true; chat[chat.length - 1]['is_name'] = true; chat[chat.length - 1]['send_date'] = humanizedDateTime(); - chat[chat.length - 1]['mes'] = textareaText; + chat[chat.length - 1]['mes'] = substituteParams(textareaText); chat[chat.length - 1]['extra'] = {}; if (messageBias) { diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 34f349e53..b68768cc1 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -11,6 +11,7 @@ import { replaceBiasMarkup, saveChatConditional, sendSystemMessage, + substituteParams, system_avatar, system_message_types } from "../script.js"; @@ -143,7 +144,7 @@ async function sendMessageAs(_, text) { is_name: true, is_system: isSystem, send_date: humanizedDateTime(), - mes: mesText, + mes: substituteParams(mesText), force_avatar: force_avatar, original_avatar: original_avatar, extra: { @@ -174,7 +175,7 @@ async function sendNarratorMessage(_, text) { is_name: false, is_system: isSystem, send_date: humanizedDateTime(), - mes: text.trim(), + mes: substituteParams(text.trim()), force_avatar: system_avatar, extra: { type: system_message_types.NARRATOR,