mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
On char rename, update auxiliary connections
- Move WI char lore (additional lorebooks) based on rename - Move character-bound Author's Note based on rename - Extend core `getCharFilename` to be able to take an avatarKey, instead of just uid
This commit is contained in:
@ -493,6 +493,7 @@ export const event_types = {
|
|||||||
// TODO: Naming convention is inconsistent with other events
|
// TODO: Naming convention is inconsistent with other events
|
||||||
CHARACTER_DELETED: 'characterDeleted',
|
CHARACTER_DELETED: 'characterDeleted',
|
||||||
CHARACTER_DUPLICATED: 'character_duplicated',
|
CHARACTER_DUPLICATED: 'character_duplicated',
|
||||||
|
CHARACTER_RENAMED: 'character_renamed',
|
||||||
/** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */
|
/** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */
|
||||||
SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',
|
SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',
|
||||||
STREAM_TOKEN_RECEIVED: 'stream_token_received',
|
STREAM_TOKEN_RECEIVED: 'stream_token_received',
|
||||||
@ -6241,9 +6242,29 @@ export async function renameCharacter(name = null, { silent = false, renameChats
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const newAvatar = data.avatar;
|
const newAvatar = data.avatar;
|
||||||
|
|
||||||
// Replace tags list
|
const oldName = getCharaFilename(null, { manualAvatarKey: oldAvatar });
|
||||||
|
const newName = getCharaFilename(null, { manualAvatarKey: newAvatar });
|
||||||
|
|
||||||
|
// Replace other auxillery fields where was referenced by avatar key
|
||||||
|
// Tag List
|
||||||
renameTagKey(oldAvatar, newAvatar);
|
renameTagKey(oldAvatar, newAvatar);
|
||||||
|
|
||||||
|
// Addtional lore books
|
||||||
|
const charLore = world_info.charLore?.find(x => x.name == oldName);
|
||||||
|
if (charLore) {
|
||||||
|
charLore.name = newName;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Char-bound Author's Notes
|
||||||
|
const charNote = extension_settings.note.chara?.find(x => x.name == oldName);
|
||||||
|
if (charNote) {
|
||||||
|
charNote.name = newName;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
|
eventSource.emit(event_types.CHARACTER_RENAMED, oldAvatar, newAvatar);
|
||||||
|
|
||||||
// Reload characters list
|
// Reload characters list
|
||||||
await getCharacters();
|
await getCharacters();
|
||||||
|
|
||||||
|
@ -994,13 +994,18 @@ export function getImageSizeFromDataURL(dataUrl) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCharaFilename(chid) {
|
/**
|
||||||
|
* Gets the filename of the character avatar without extension
|
||||||
|
* @param {number?} [chid=null] - Character ID. If not provided, uses the current character ID
|
||||||
|
* @param {object} [options={}] - Options arguments
|
||||||
|
* @param {string?} [options.manualAvatarKey=null] - Manually take the following avatar key, instead of using the chid to determine the name
|
||||||
|
* @returns {string?} The filename of the character avatar without extension, or null if the character ID is invalid
|
||||||
|
*/
|
||||||
|
export function getCharaFilename(chid = null, { manualAvatarKey = null } = {}) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
const fileName = context.characters[chid ?? context.characterId]?.avatar;
|
const fileName = manualAvatarKey ?? context.characters[chid ?? context.characterId]?.avatar;
|
||||||
|
|
||||||
if (fileName) {
|
return fileName?.replace(/\.[^/.]+$/, '') ?? null;
|
||||||
return fileName.replace(/\.[^/.]+$/, '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user