Allow getting current name in message-name
| @@ -767,8 +767,8 @@ export function initDefaultSlashCommands() { | ||
| 767 | 767 | })); |
| 768 | 768 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 769 | 769 | name: 'message-name', |
| 770 | 770 | callback: changeMessageNamemessageNameCallback, |
| 771 | 771 | returns: 'The updated name of the message sender', |
| 772 | 772 | namedArgumentList: [ |
| 773 | 773 | SlashCommandNamedArgument.fromProps({ |
| 774 | 774 | name: 'at', |
| @@ -782,7 +782,7 @@ export function initDefaultSlashCommands() { | ||
| 782 | 782 | SlashCommandArgument.fromProps({ |
| 783 | 783 | description: 'Persona name, character name, or unique character identifier (avatar key)', |
| 784 | 784 | typeList: [ARGUMENT_TYPE.STRING], |
| 785 | 785 | isRequired: truefalse, |
| 786 | 786 | enumProvider: (executor) => { |
| 787 | 787 | let modifyAt = Number(executor.namedArgumentList.find(arg => arg.name === 'at')?.value ?? (chat.length - 1)); |
| 788 | 788 | if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) { |
| @@ -797,11 +797,17 @@ export function initDefaultSlashCommands() { | ||
| 797 | 797 | helpString: ` |
| 798 | 798 | <div> |
| 799 | 799 | Changes the name of a message sender to one of your choice. |
| 800 | + If no name is provided, just gets the current name of the message sender. | |
| 801 | + If no index is provided, the last message is chosen. | |
| 800 | 802 | </div> |
| 801 | 803 | <div> |
| 802 | 804 | <strong>Example:</strong> |
| 803 | 805 | <ul> |
| 804 | 806 | <li> |
| 807 | + <pre><code>/message-name | /echo</code></pre> | |
| 808 | + Will output the name of the sender of the last message. | |
| 809 | + </li> | |
| 810 | + <li> | |
| 805 | 811 | <pre><code>/message-name at=-2 "Chloe"</code></pre> |
| 806 | 812 | Will change the third message from the bottom to be sent by "Chloe". |
| 807 | 813 | </li> |
| @@ -4562,13 +4568,7 @@ export function getNameAndAvatarForMessage(character, name = null) { | ||
| 4562 | 4568 | * |
| 4563 | 4569 | * @returns {Promise<string>} The updated message name. |
| 4564 | 4570 | */ |
| 4565 | 4571 | export async function changeMessageNamemessageNameCallback(args, name) { |
| 4566 | - name = String(name ?? '').trim(); | |
| 4567 | - if (!name) { | |
| 4568 | - toastr.warning(t`You must provide a name to change the message to.`); | |
| 4569 | - return ''; | |
| 4570 | - } | |
| 4571 | - | |
| 4572 | 4572 | let modifyAt = Number(args?.at ?? (chat.length - 1)); |
| 4573 | 4573 | // Convert possible depth parameter to index |
| 4574 | 4574 | if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) { |
| @@ -4582,6 +4582,11 @@ export async function changeMessageName(args, name) { | ||
| 4582 | 4582 | return ''; |
| 4583 | 4583 | } |
| 4584 | 4584 | |
| 4585 | + name = String(name ?? '').trim(); | |
| 4586 | + if (!name) { | |
| 4587 | + return message.name; | |
| 4588 | + } | |
| 4589 | + | |
| 4585 | 4590 | let newName = ''; |
| 4586 | 4591 | |
| 4587 | 4592 | if (message.is_user) { |