mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add tri-state argument for /lock command
This commit is contained in:
@ -590,7 +590,37 @@ function selectCurrentPersona() {
|
||||
}
|
||||
}
|
||||
|
||||
async function lockUserNameToChat() {
|
||||
/**
|
||||
* Checks if the persona is locked for the current chat.
|
||||
* @returns {boolean} Whether the persona is locked
|
||||
*/
|
||||
function isPersonaLocked() {
|
||||
return !!chat_metadata['persona'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks or unlocks the persona for the current chat.
|
||||
* @param {boolean} state Desired lock state
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function setPersonaLockState(state) {
|
||||
return state ? await lockPersona() : await unlockPersona();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the persona lock state for the current chat.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function togglePersonaLock() {
|
||||
return isPersonaLocked()
|
||||
? await unlockPersona()
|
||||
: await lockPersona();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock the persona for the current chat.
|
||||
*/
|
||||
async function unlockPersona() {
|
||||
if (chat_metadata['persona']) {
|
||||
console.log(`Unlocking persona for this chat ${chat_metadata['persona']}`);
|
||||
delete chat_metadata['persona'];
|
||||
@ -599,9 +629,13 @@ async function lockUserNameToChat() {
|
||||
toastr.info('User persona is now unlocked for this chat. Click the "Lock" again to revert.', 'Persona unlocked');
|
||||
}
|
||||
updateUserLockIcon();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the persona for the current chat.
|
||||
*/
|
||||
async function lockPersona() {
|
||||
if (!(user_avatar in power_user.personas)) {
|
||||
console.log(`Creating a new persona ${user_avatar}`);
|
||||
if (power_user.persona_show_notifications) {
|
||||
@ -625,6 +659,7 @@ async function lockUserNameToChat() {
|
||||
updateUserLockIcon();
|
||||
}
|
||||
|
||||
|
||||
async function deleteUserAvatar(e) {
|
||||
e?.stopPropagation();
|
||||
const avatarId = $(this).closest('.avatar-container').find('.avatar').attr('imgfile');
|
||||
@ -973,7 +1008,7 @@ export function initPersonas() {
|
||||
$(document).on('click', '.bind_user_name', bindUserNameToPersona);
|
||||
$(document).on('click', '.set_default_persona', setDefaultPersona);
|
||||
$(document).on('click', '.delete_avatar', deleteUserAvatar);
|
||||
$('#lock_user_name').on('click', lockUserNameToChat);
|
||||
$('#lock_user_name').on('click', togglePersonaLock);
|
||||
$('#create_dummy_persona').on('click', createDummyPersona);
|
||||
$('#persona_description').on('input', onPersonaDescriptionInput);
|
||||
$('#persona_description_position').on('input', onPersonaDescriptionPositionInput);
|
||||
|
Reference in New Issue
Block a user