mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #2036 from Wolfsblvt/group-chat-desc-join-template
Group chat-specific join prefix/suffix for char fields
This commit is contained in:
@@ -9,9 +9,11 @@ import {
|
||||
saveBase64AsFile,
|
||||
PAGINATION_TEMPLATE,
|
||||
getBase64Async,
|
||||
resetScrollHeight,
|
||||
initScrollHeight,
|
||||
} from './utils.js';
|
||||
import { RA_CountCharTokens, humanizedDateTime, dragElement, favsToHotswap, getMessageTimeStamp } from './RossAscends-mods.js';
|
||||
import { loadMovingUIState, sortEntitiesList } from './power-user.js';
|
||||
import { power_user, loadMovingUIState, sortEntitiesList } from './power-user.js';
|
||||
|
||||
import {
|
||||
chat,
|
||||
@@ -351,6 +353,30 @@ export function getGroupCharacterCards(groupId, characterId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Runs the macro engine on a text, with custom <FIELDNAME> replace @param {string} value @param {string} characterName @param {string} fieldName @returns {string} */
|
||||
function customBaseChatReplace(value, fieldName, characterName) {
|
||||
// We should do the custom field name replacement first, and then run it through the normal macro engine with provided names
|
||||
value = value.replace(/<FIELDNAME>/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} */
|
||||
function replaceAndPrepareForJoin(value, characterName, fieldName) {
|
||||
value = value.trim();
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Prepare and replace prefixes
|
||||
const prefix = customBaseChatReplace(group.generation_mode_join_prefix, fieldName, characterName);
|
||||
const suffix = customBaseChatReplace(group.generation_mode_join_suffix, fieldName, characterName);
|
||||
const separator = power_user.instruct.wrap ? '\n' : '';
|
||||
// Also run the macro replacement on the actual content
|
||||
value = customBaseChatReplace(value, fieldName, characterName);
|
||||
|
||||
return `${prefix ? prefix + separator : ''}${value}${suffix ? separator + suffix : ''}`;
|
||||
}
|
||||
|
||||
const scenarioOverride = chat_metadata['scenario'];
|
||||
|
||||
let descriptions = [];
|
||||
@@ -372,10 +398,10 @@ export function getGroupCharacterCards(groupId, characterId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
descriptions.push(baseChatReplace(character.description.trim(), name1, character.name));
|
||||
personalities.push(baseChatReplace(character.personality.trim(), name1, character.name));
|
||||
scenarios.push(baseChatReplace(character.scenario.trim(), name1, character.name));
|
||||
mesExamplesArray.push(baseChatReplace(character.mes_example.trim(), name1, character.name));
|
||||
descriptions.push(replaceAndPrepareForJoin(character.description, character.name, 'Description'));
|
||||
personalities.push(replaceAndPrepareForJoin(character.personality, character.name, 'Personality'));
|
||||
scenarios.push(replaceAndPrepareForJoin(character.scenario, character.name, 'Scenario'));
|
||||
mesExamplesArray.push(replaceAndPrepareForJoin(character.mes_example, character.name, 'Example Messages'));
|
||||
}
|
||||
|
||||
const description = descriptions.filter(x => x.length).join('\n');
|
||||
@@ -1093,6 +1119,8 @@ async function onGroupGenerationModeInput(e) {
|
||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||
_thisGroup.generation_mode = Number(e.target.value);
|
||||
await editGroup(openGroupId, false, false);
|
||||
|
||||
toggleHiddenControls(_thisGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,6 +1133,15 @@ async function onGroupAutoModeDelayInput(e) {
|
||||
}
|
||||
}
|
||||
|
||||
async function onGroupGenerationModeTemplateInput(e) {
|
||||
if (openGroupId) {
|
||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||
const prop = $(e.target).attr('setting');
|
||||
_thisGroup[prop] = String(e.target.value);
|
||||
await editGroup(openGroupId, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function onGroupNameInput() {
|
||||
if (openGroupId) {
|
||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||
@@ -1270,6 +1307,14 @@ async function onHideMutedSpritesClick(value) {
|
||||
}
|
||||
}
|
||||
|
||||
function toggleHiddenControls(group, generationMode = null) {
|
||||
const isJoin = [group_generation_mode.APPEND, group_generation_mode.APPEND_DISABLED].includes(generationMode ?? group?.generation_mode);
|
||||
$('#rm_group_generation_mode_join_prefix').parent().toggle(isJoin);
|
||||
$('#rm_group_generation_mode_join_suffix').parent().toggle(isJoin);
|
||||
initScrollHeight($('#rm_group_generation_mode_join_prefix'));
|
||||
initScrollHeight($('#rm_group_generation_mode_join_suffix'));
|
||||
}
|
||||
|
||||
function select_group_chats(groupId, skipAnimation) {
|
||||
openGroupId = groupId;
|
||||
newGroupMembers = [];
|
||||
@@ -1305,6 +1350,10 @@ function select_group_chats(groupId, skipAnimation) {
|
||||
$('#rm_group_hidemutedsprites').prop('checked', group && group.hideMutedSprites);
|
||||
$('#rm_group_automode_delay').val(group?.auto_mode_delay ?? DEFAULT_AUTO_MODE_DELAY);
|
||||
|
||||
$('#rm_group_generation_mode_join_prefix').val(group?.generation_mode_join_prefix ?? '').attr('setting', 'generation_mode_join_prefix');
|
||||
$('#rm_group_generation_mode_join_suffix').val(group?.generation_mode_join_suffix ?? '').attr('setting', 'generation_mode_join_suffix');
|
||||
toggleHiddenControls(group, generationMode);
|
||||
|
||||
// bottom buttons
|
||||
if (openGroupId) {
|
||||
$('#rm_group_submit').hide();
|
||||
@@ -1338,6 +1387,11 @@ function select_group_chats(groupId, skipAnimation) {
|
||||
$('#rm_group_automode_label').hide();
|
||||
}
|
||||
|
||||
// Toggle textbox sizes, as input events have not fired here
|
||||
$('#rm_group_chats_block .autoSetHeight').each(element => {
|
||||
resetScrollHeight(element);
|
||||
});
|
||||
|
||||
eventSource.emit('groupSelected', { detail: { id: openGroupId, group: group } });
|
||||
}
|
||||
|
||||
@@ -1796,6 +1850,10 @@ function doCurMemberListPopout() {
|
||||
}
|
||||
|
||||
jQuery(() => {
|
||||
$(document).on('input', '#rm_group_chats_block .autoSetHeight', function () {
|
||||
resetScrollHeight($(this));
|
||||
});
|
||||
|
||||
$(document).on('click', '.group_select', function () {
|
||||
const groupId = $(this).attr('chid') || $(this).attr('grid') || $(this).data('id');
|
||||
openGroupById(groupId);
|
||||
@@ -1823,6 +1881,8 @@ jQuery(() => {
|
||||
$('#rm_group_activation_strategy').on('change', onGroupActivationStrategyInput);
|
||||
$('#rm_group_generation_mode').on('change', onGroupGenerationModeInput);
|
||||
$('#rm_group_automode_delay').on('input', onGroupAutoModeDelayInput);
|
||||
$('#rm_group_generation_mode_join_prefix').on('input', onGroupGenerationModeTemplateInput);
|
||||
$('#rm_group_generation_mode_join_suffix').on('input', onGroupGenerationModeTemplateInput);
|
||||
$('#group_avatar_button').on('input', uploadGroupAvatar);
|
||||
$('#rm_group_restore_avatar').on('click', restoreGroupAvatar);
|
||||
$(document).on('click', '.group_member .right_menu_button', onGroupActionClick);
|
||||
|
Reference in New Issue
Block a user