Extract assignCharacterAsAssistant func

ae0aa42e7a2497be1bfb5a8ff49d025eb1678ae2

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +20 -12Showing whitespace changes
public/scripts/welcome-screen.js+20 -12
@@ -335,21 +335,16 @@ export async function openPermanentAssistantCard() {
335335 await selectCharacterById(characterId);
336336}
337337
338-export function initWelcomeScreen() {
338+/**
339- const events = [event_types.CHAT_CHANGED, event_types.APP_READY];
339+ * Assigns a character as the assistant.
340- for (const event of events) {
340+ * @param {string?} characterId Character ID
341- eventSource.makeFirst(event, openWelcomeScreen);
341+ */
342- }
342+export function assignCharacterAsAssistant(characterId) {
343-
343+ if (characterId === undefined) {
344- eventSource.on(event_types.CHARACTER_MANAGEMENT_DROPDOWN, (target) =>{
345- if (target !== 'set_as_assistant') {
346- return;
347- }
348- if (this_chid === undefined) {
349344 return;
350345 }
351346 /** @type {import('./char-data.js').v1CharData} */
352347 const character = characters[this_chidcharacterId];
353348 if (!character) {
354349 return;
355350 }
@@ -369,6 +364,19 @@ export function initWelcomeScreen() {
369364 accountStorage.setItem(assistantAvatarKey, character.avatar);
370365 printCharactersDebounced();
371366 toastr.success(t`Set ${character.name} as your assistant.`);
367+}
368+
369+export function initWelcomeScreen() {
370+ const events = [event_types.CHAT_CHANGED, event_types.APP_READY];
371+ for (const event of events) {
372+ eventSource.makeFirst(event, openWelcomeScreen);
373+ }
374+
375+ eventSource.on(event_types.CHARACTER_MANAGEMENT_DROPDOWN, (target) =>{
376+ if (target !== 'set_as_assistant') {
377+ return;
378+ }
379+ assignCharacterAsAssistant(this_chid);
372380 });
373381
374382 eventSource.on(event_types.CHARACTER_RENAMED, (oldAvatar, newAvatar) => {