Merge pull request #3103 from Finadil/staging Add author's note STscript returns, role changing, and aliases

3af5302714c8d13e8b4770099e1d39bd6c6d7085

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

Signed
1 files changed, +85 -34Ignore whitespace
public/scripts/authors-note.js+85 -34
@@ -37,53 +37,82 @@ const chara_note_position = {
3737};
3838
3939function setNoteTextCommand(_, text) {
40- $('#extension_floating_prompt').val(text).trigger('input');
40+ if (text) {
41- toastr.success(t`Author's Note text updated`);
41+ $('#extension_floating_prompt').val(text).trigger('input');
42- return '';
42+ toastr.success(t`Author's Note text updated`);
43+ }
44+ return chat_metadata[metadata_keys.prompt];
4345}
4446
4547function setNoteDepthCommand(_, text) {
4648 const value =if Number(text); {
49+ const value = Number(text);
4750
4851 if (Number.isNaN(value)) {
4952 toastr.error(t`Not a valid number`);
5053 return;
54+ }
55+
56+ $('#extension_floating_depth').val(Math.abs(value)).trigger('input');
57+ toastr.success(t`Author's Note depth updated`);
5158 }
52-
59+ return chat_metadata[metadata_keys.depth];
53- $('#extension_floating_depth').val(Math.abs(value)).trigger('input');
54- toastr.success(t`Author's Note depth updated`);
55- return '';
5660}
5761
5862function setNoteIntervalCommand(_, text) {
5963 const value =if Number(text); {
64+ const value = Number(text);
6065
6166 if (Number.isNaN(value)) {
6267 toastr.error(t`Not a valid number`);
6368 return;
6469 }
6570
6671 $('#extension_floating_interval').val(Math.abs(value)).trigger('input');
6772 toastr.success(t`Author's Note frequency updated`);
68- return '';
73+ }
74+ return chat_metadata[metadata_keys.interval];
6975}
7076
7177function setNotePositionCommand(_, text) {
7278 const validPositions = {
7379 'scenario': 0,
7480 'chat': 1,
81+ 'before_scenario': 2
7582 };
7683
77- const position = validPositions[text?.trim()];
84+ if (text) {
85+ const position = validPositions[text?.trim()];
7886
79- if (Number.isNaN(position)) {
87+ if (typeof position == 'undefined') {
8088 toastr.error(t`Not a valid position`);
8189 return;
90+ }
91+
92+ $(`input[name="extension_floating_position"][value="${position}"]`).prop('checked', true).trigger('input');
93+ toastr.info(t`Author's Note position updated`);
8294 }
95+ return Object.keys(validPositions).find(key => validPositions[key] == chat_metadata[metadata_keys.position]);
96+}
97+function setNoteRoleCommand(_, text) {
98+ const validRoles = {
99+ 'system': 0,
100+ 'user': 1,
101+ 'assistant': 2
102+ };
103+
104+ if (text) {
105+ const role = validRoles[text?.trim()];
83106
84- $(`input[name="extension_floating_position"][value="${position}"]`).prop('checked', true).trigger('input');
107+ if (typeof role == 'undefined') {
85108 toastr.infoerror(t`Author'sNot Notea positionvalid updatedrole`);
86- return '';
109+ return;
110+ }
111+
112+ $(`#extension_floating_role`).val(Math.abs(role)).trigger('input');
113+ toastr.info(t`Author's Note role updated`);
114+ }
115+ return Object.keys(validRoles).find(key => validRoles[key] == chat_metadata[metadata_keys.role]);
87116}
88117
89118function updateSettings() {
@@ -464,55 +493,77 @@ export function initAuthorsNote() {
464493
465494 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'note',
466495 callback: setNoteTextCommand,
496+ returns: 'current author\'s note',
467497 unnamedArgumentList: [
468498 new SlashCommandArgument(
469499 'text', [ARGUMENT_TYPE.STRING], truefalse,
470500 ),
471501 ],
472502 helpString: `
473503 <div>
474504 Sets an author's note for the currently selected chat if specified and returns the current note.
475505 </div>
476506 `,
477507 }));
478508 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'depth',
509+ aliases: ['note-depth'],
479510 callback: setNoteDepthCommand,
511+ returns: 'current author\'s note depth',
480512 unnamedArgumentList: [
481513 new SlashCommandArgument(
482514 'number', [ARGUMENT_TYPE.NUMBER], truefalse,
483515 ),
484516 ],
485517 helpString: `
486518 <div>
487519 Sets an author's note depth for in-chat positioning if specified and returns the current depth.
488520 </div>
489521 `,
490522 }));
491523 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'freq',
524+ aliases: ['note-freq'],
492525 callback: setNoteIntervalCommand,
526+ returns: 'current author\'s note insertion frequency',
493527 namedArgumentList: [],
494528 unnamedArgumentList: [
495529 new SlashCommandArgument(
496530 'number', [ARGUMENT_TYPE.NUMBER], truefalse,
497531 ),
498532 ],
499533 helpString: `
500534 <div>
501535 Sets an author's note insertion frequency if specified and returns the current frequency.
502536 </div>
503537 `,
504538 }));
505539 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'pos',
506540 callback: setNotePositionCommand,
541+ aliases: ['note-pos'],
542+ returns: 'current author\'s note insertion position',
543+ namedArgumentList: [],
544+ unnamedArgumentList: [
545+ new SlashCommandArgument(
546+ 'position', [ARGUMENT_TYPE.STRING], false, false, null, ['chat', 'scenario','before_scenario'],
547+ ),
548+ ],
549+ helpString: `
550+ <div>
551+ Sets an author's note position if specified and returns the current position.
552+ </div>
553+ `,
554+ }));
555+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'note-role',
556+ callback: setNoteRoleCommand,
557+ returns: 'current author\'s note chat insertion role',
507558 namedArgumentList: [],
508559 unnamedArgumentList: [
509560 new SlashCommandArgument(
510561 'position', [ARGUMENT_TYPE.STRING], truefalse, false, null, ['chatsystem', 'scenariouser','assistant'],
511562 ),
512563 ],
513564 helpString: `
514565 <div>
515566 Sets an author's note positionchat insertion role if specified and returns the current role.
516567 </div>
517568 `,
518569 }));