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() {
767767 }));
768768 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
769769 name: 'message-name',
770770 callback: changeMessageNamemessageNameCallback,
771771 returns: 'The updated name of the message sender',
772772 namedArgumentList: [
773773 SlashCommandNamedArgument.fromProps({
774774 name: 'at',
@@ -782,7 +782,7 @@ export function initDefaultSlashCommands() {
782782 SlashCommandArgument.fromProps({
783783 description: 'Persona name, character name, or unique character identifier (avatar key)',
784784 typeList: [ARGUMENT_TYPE.STRING],
785785 isRequired: truefalse,
786786 enumProvider: (executor) => {
787787 let modifyAt = Number(executor.namedArgumentList.find(arg => arg.name === 'at')?.value ?? (chat.length - 1));
788788 if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) {
@@ -797,11 +797,17 @@ export function initDefaultSlashCommands() {
797797 helpString: `
798798 <div>
799799 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.
800802 </div>
801803 <div>
802804 <strong>Example:</strong>
803805 <ul>
804806 <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>
805811 <pre><code>/message-name at=-2 "Chloe"</code></pre>
806812 Will change the third message from the bottom to be sent by "Chloe".
807813 </li>
@@ -4562,13 +4568,7 @@ export function getNameAndAvatarForMessage(character, name = null) {
45624568 *
45634569 * @returns {Promise<string>} The updated message name.
45644570 */
45654571export 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-
45724572 let modifyAt = Number(args?.at ?? (chat.length - 1));
45734573 // Convert possible depth parameter to index
45744574 if (!isNaN(modifyAt) && (modifyAt < 0 || Object.is(modifyAt, -0))) {
@@ -4582,6 +4582,11 @@ export async function changeMessageName(args, name) {
45824582 return '';
45834583 }
45844584
4585+ name = String(name ?? '').trim();
4586+ if (!name) {
4587+ return message.name;
4588+ }
4589+
45854590 let newName = '';
45864591
45874592 if (message.is_user) {