Allow getting current name in message-name

a14b0855eee46af1895b349d154e8575d79a7221

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

1 files changed, +15 -10Showing whitespace changes
public/scripts/slash-commands.js+15 -10
@@ -767,8 +767,8 @@ export function initDefaultSlashCommands() {
767 }));767 }));
768 SlashCommandParser.addCommandObject(SlashCommand.fromProps({768 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
769 name: 'message-name',769 name: 'message-name',
770 callback: changeMessageName,770 callback: messageNameCallback,
771 returns: 'The updated name of the message sender',771 returns: 'The name of the message sender',
772 namedArgumentList: [772 namedArgumentList: [
773 SlashCommandNamedArgument.fromProps({773 SlashCommandNamedArgument.fromProps({
774 name: 'at',774 name: 'at',
@@ -782,7 +782,7 @@ export function initDefaultSlashCommands() {
782 SlashCommandArgument.fromProps({782 SlashCommandArgument.fromProps({
783 description: 'Persona name, character name, or unique character identifier (avatar key)',783 description: 'Persona name, character name, or unique character identifier (avatar key)',
784 typeList: [ARGUMENT_TYPE.STRING],784 typeList: [ARGUMENT_TYPE.STRING],
785 isRequired: true,785 isRequired: false,
786 enumProvider: (executor) => {786 enumProvider: (executor) => {
787 let modifyAt = Number(executor.namedArgumentList.find(arg => arg.name === 'at')?.value ?? (chat.length - 1));787 let modifyAt = Number(executor.namedArgumentList.find(arg => arg.name === 'at')?.value ?? (chat.length - 1));
788 if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) {788 if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) {
@@ -797,11 +797,17 @@ export function initDefaultSlashCommands() {
797 helpString: `797 helpString: `
798 <div>798 <div>
799 Changes the name of a message sender to one of your choice.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 </div>802 </div>
801 <div>803 <div>
802 <strong>Example:</strong>804 <strong>Example:</strong>
803 <ul>805 <ul>
804 <li>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 <pre><code>/message-name at=-2 "Chloe"</code></pre>811 <pre><code>/message-name at=-2 "Chloe"</code></pre>
806 Will change the third message from the bottom to be sent by "Chloe".812 Will change the third message from the bottom to be sent by "Chloe".
807 </li>813 </li>
@@ -4562,13 +4568,7 @@ export function getNameAndAvatarForMessage(character, name = null) {
4562 *4568 *
4563 * @returns {Promise<string>} The updated message name.4569 * @returns {Promise<string>} The updated message name.
4564 */4570 */
4565export async function changeMessageName(args, name) {4571export async function messageNameCallback(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 let modifyAt = Number(args?.at ?? (chat.length - 1));4572 let modifyAt = Number(args?.at ?? (chat.length - 1));
4573 // Convert possible depth parameter to index4573 // Convert possible depth parameter to index
4574 if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) {4574 if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) {
@@ -4582,6 +4582,11 @@ export async function changeMessageName(args, name) {
4582 return '';4582 return '';
4583 }4583 }
45844584
4585 name = String(name ?? '').trim();
4586 if (!name) {
4587 return message.name;
4588 }
4589
4585 let newName = '';4590 let newName = '';
45864591
4587 if (message.is_user) {4592 if (message.is_user) {