From 0594859fb9524e1d8ba5a31a9b7ab7f16ffeae79 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:11:05 +0300 Subject: [PATCH] #2046 Fix for undefined fields --- public/scripts/group-chats.js | 20 ++++++++++++++++++-- src/endpoints/groups.js | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 36f324b94..3ce9f0d29 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -353,14 +353,30 @@ export function getGroupCharacterCards(groupId, characterId) { return null; } - /** Runs the macro engine on a text, with custom replace @param {string} value @param {string} characterName @param {string} fieldName @returns {string} */ + /** + * Runs the macro engine on a text, with custom replace + * @param {string} value Value to replace + * @param {string} fieldName Name of the field + * @param {string} characterName Name of the character + * @returns {string} Replaced text + * */ function customBaseChatReplace(value, fieldName, characterName) { + if (!value) { + return ''; + } + // We should do the custom field name replacement first, and then run it through the normal macro engine with provided names value = value.replace(//gi, fieldName); return baseChatReplace(value.trim(), name1, characterName); } - /** Prepares text with prefix/suffix for a character field @param {string} value @param {string} characterName @param {string} fieldName @returns {string} */ + /** + * Prepares text with prefix/suffix for a character field + * @param {string} value Value to replace + * @param {string} characterName Name of the character + * @param {string} fieldName Name of the field + * @returns {string} Prepared text + * */ function replaceAndPrepareForJoin(value, characterName, fieldName) { value = value.trim(); if (!value) { diff --git a/src/endpoints/groups.js b/src/endpoints/groups.js index f8a117e84..ea2cc7377 100644 --- a/src/endpoints/groups.js +++ b/src/endpoints/groups.js @@ -74,6 +74,8 @@ router.post('/create', jsonParser, (request, response) => { chat_id: request.body.chat_id ?? id, chats: request.body.chats ?? [id], auto_mode_delay: request.body.auto_mode_delay ?? 5, + generation_mode_join_prefix: request.body.generation_mode_join_prefix ?? '', + generation_mode_join_suffix: request.body.generation_mode_join_suffix ?? '', }; const pathToFile = path.join(DIRECTORIES.groups, `${id}.json`); const fileData = JSON.stringify(groupMetadata);