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