Add STscript returns, role changing, and aliases Adds the following STscript changes: -Returns to all commands and makes arguments optional -before_scenario option for chat insertion position (to match UI) -/note-role to change the chat insertion role -/note- Aliases to all commands so they're centralized
Signed| @@ -37,53 +37,82 @@ const chara_note_position = { | |||
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | function setNoteTextCommand(_, text) { | 39 | function 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]; | ||
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | function setNoteDepthCommand(_, text) { | 47 | function setNoteDepthCommand(_, text) { |
| 46 | const value = Number(text); | 48 | if (text) { |
| 49 | const value = Number(text); | ||
| 47 | 50 | ||
| 48 | if (Number.isNaN(value)) { | 51 | if (Number.isNaN(value)) { |
| 49 | toastr.error(t`Not a valid number`); | 52 | toastr.error(t`Not a valid number`); |
| 50 | return; | 53 | return; |
| 54 | } | ||
| 55 | |||
| 56 | $('#extension_floating_depth').val(Math.abs(value)).trigger('input'); | ||
| 57 | toastr.success(t`Author's Note depth updated`); | ||
| 51 | } | 58 | } |
| 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 ''; | ||
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | function setNoteIntervalCommand(_, text) { | 62 | function setNoteIntervalCommand(_, text) { |
| 59 | const value = Number(text); | 63 | if (text) { |
| 64 | const value = Number(text); | ||
| 60 | 65 | ||
| 61 | if (Number.isNaN(value)) { | 66 | if (Number.isNaN(value)) { |
| 62 | toastr.error(t`Not a valid number`); | 67 | toastr.error(t`Not a valid number`); |
| 63 | return; | 68 | return; |
| 64 | } | 69 | } |
| 65 | 70 | ||
| 66 | $('#extension_floating_interval').val(Math.abs(value)).trigger('input'); | 71 | $('#extension_floating_interval').val(Math.abs(value)).trigger('input'); |
| 67 | toastr.success(t`Author's Note frequency updated`); | 72 | toastr.success(t`Author's Note frequency updated`); |
| 68 | return ''; | 73 | } |
| 74 | return chat_metadata[metadata_keys.interval]; | ||
| 69 | } | 75 | } |
| 70 | 76 | ||
| 71 | function setNotePositionCommand(_, text) { | 77 | function setNotePositionCommand(_, text) { |
| 72 | const validPositions = { | 78 | const validPositions = { |
| 73 | 'scenario': 0, | 79 | 'scenario': 0, |
| 74 | 'chat': 1, | 80 | 'chat': 1, |
| 81 | 'before_scenario': 2 | ||
| 75 | }; | 82 | }; |
| 76 | 83 | ||
| 77 | const position = validPositions[text?.trim()]; | 84 | if (text) { |
| 85 | const position = validPositions[text?.trim()]; | ||
| 78 | 86 | ||
| 79 | if (Number.isNaN(position)) { | 87 | if (typeof position == 'undefined') { |
| 80 | toastr.error(t`Not a valid position`); | 88 | toastr.error(t`Not a valid position`); |
| 81 | return; | 89 | 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`); | ||
| 82 | } | 94 | } |
| 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()]; | ||
| 83 | 106 | ||
| 84 | $(`input[name="extension_floating_position"][value="${position}"]`).prop('checked', true).trigger('input'); | 107 | if (typeof role == 'undefined') { |
| 85 | toastr.info(t`Author's Note position updated`); | 108 | toastr.error(t`Not a valid role`); |
| 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]); | ||
| 87 | } | 116 | } |
| 88 | 117 | ||
| 89 | function updateSettings() { | 118 | function updateSettings() { |
| @@ -464,55 +493,77 @@ export function initAuthorsNote() { | |||
| 464 | 493 | ||
| 465 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'note', | 494 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'note', |
| 466 | callback: setNoteTextCommand, | 495 | callback: setNoteTextCommand, |
| 496 | returns: 'current author\'s note', | ||
| 467 | unnamedArgumentList: [ | 497 | unnamedArgumentList: [ |
| 468 | new SlashCommandArgument( | 498 | new SlashCommandArgument( |
| 469 | 'text', [ARGUMENT_TYPE.STRING], true, | 499 | 'text', [ARGUMENT_TYPE.STRING], false, |
| 470 | ), | 500 | ), |
| 471 | ], | 501 | ], |
| 472 | helpString: ` | 502 | helpString: ` |
| 473 | <div> | 503 | <div> |
| 474 | Sets an author's note for the currently selected chat. | 504 | Sets an author's note for the currently selected chat if specified and returns the current note. |
| 475 | </div> | 505 | </div> |
| 476 | `, | 506 | `, |
| 477 | })); | 507 | })); |
| 478 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'depth', | 508 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'depth', |
| 509 | aliases: ['note-depth'], | ||
| 479 | callback: setNoteDepthCommand, | 510 | callback: setNoteDepthCommand, |
| 511 | returns: 'current author\'s note depth', | ||
| 480 | unnamedArgumentList: [ | 512 | unnamedArgumentList: [ |
| 481 | new SlashCommandArgument( | 513 | new SlashCommandArgument( |
| 482 | 'number', [ARGUMENT_TYPE.NUMBER], true, | 514 | 'number', [ARGUMENT_TYPE.NUMBER], false, |
| 483 | ), | 515 | ), |
| 484 | ], | 516 | ], |
| 485 | helpString: ` | 517 | helpString: ` |
| 486 | <div> | 518 | <div> |
| 487 | Sets an author's note depth for in-chat positioning. | 519 | Sets an author's note depth for in-chat positioning if specified and returns the current depth. |
| 488 | </div> | 520 | </div> |
| 489 | `, | 521 | `, |
| 490 | })); | 522 | })); |
| 491 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'freq', | 523 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'freq', |
| 524 | aliases: ['note-freq'], | ||
| 492 | callback: setNoteIntervalCommand, | 525 | callback: setNoteIntervalCommand, |
| 526 | returns: 'current author\'s note insertion frequency', | ||
| 493 | namedArgumentList: [], | 527 | namedArgumentList: [], |
| 494 | unnamedArgumentList: [ | 528 | unnamedArgumentList: [ |
| 495 | new SlashCommandArgument( | 529 | new SlashCommandArgument( |
| 496 | 'number', [ARGUMENT_TYPE.NUMBER], true, | 530 | 'number', [ARGUMENT_TYPE.NUMBER], false, |
| 497 | ), | 531 | ), |
| 498 | ], | 532 | ], |
| 499 | helpString: ` | 533 | helpString: ` |
| 500 | <div> | 534 | <div> |
| 501 | Sets an author's note insertion frequency. | 535 | Sets an author's note insertion frequency if specified and returns the current frequency. |
| 502 | </div> | 536 | </div> |
| 503 | `, | 537 | `, |
| 504 | })); | 538 | })); |
| 505 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'pos', | 539 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'pos', |
| 506 | callback: setNotePositionCommand, | 540 | 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', | ||
| 507 | namedArgumentList: [], | 558 | namedArgumentList: [], |
| 508 | unnamedArgumentList: [ | 559 | unnamedArgumentList: [ |
| 509 | new SlashCommandArgument( | 560 | new SlashCommandArgument( |
| 510 | 'position', [ARGUMENT_TYPE.STRING], true, false, null, ['chat', 'scenario'], | 561 | 'position', [ARGUMENT_TYPE.STRING], false, false, null, ['system', 'user','assistant'], |
| 511 | ), | 562 | ), |
| 512 | ], | 563 | ], |
| 513 | helpString: ` | 564 | helpString: ` |
| 514 | <div> | 565 | <div> |
| 515 | Sets an author's note position. | 566 | Sets an author's note chat insertion role if specified and returns the current role. |
| 516 | </div> | 567 | </div> |
| 517 | `, | 568 | `, |
| 518 | })); | 569 | })); |