Allow sending empty messages with /sendas, /sys, etc.
| @@ -2004,14 +2004,14 @@ export function initDefaultSlashCommands() { | |||
| 2004 | aliases: ['re'], | 2004 | aliases: ['re'], |
| 2005 | callback: (async ({ mode = 'literal', pattern, replacer = '' }, text) => { | 2005 | callback: (async ({ mode = 'literal', pattern, replacer = '' }, text) => { |
| 2006 | if (pattern === '') | 2006 | if (pattern === '') |
| 2007 | throw new Error("Argument of 'pattern=' cannot be empty"); | 2007 | throw new Error('Argument of \'pattern=\' cannot be empty'); |
| 2008 | switch (mode) { | 2008 | switch (mode) { |
| 2009 | case 'literal': | 2009 | case 'literal': |
| 2010 | return text.replaceAll(pattern, replacer); | 2010 | return text.replaceAll(pattern, replacer); |
| 2011 | case 'regex': | 2011 | case 'regex': |
| 2012 | return text.replace(regexFromString(pattern), replacer); | 2012 | return text.replace(regexFromString(pattern), replacer); |
| 2013 | default: | 2013 | default: |
| 2014 | throw new Error("Invalid '/replace mode=' argument specified!"); | 2014 | throw new Error('Invalid \'/replace mode=\' argument specified!'); |
| 2015 | } | 2015 | } |
| 2016 | }), | 2016 | }), |
| 2017 | returns: 'replaced text', | 2017 | returns: 'replaced text', |
| @@ -3250,12 +3250,7 @@ function findPersonaByName(name) { | |||
| 3250 | } | 3250 | } |
| 3251 | 3251 | ||
| 3252 | async function sendUserMessageCallback(args, text) { | 3252 | async function sendUserMessageCallback(args, text) { |
| 3253 | if (!text) { | 3253 | text = String(text ?? '').trim(); |
| 3254 | toastr.warning('You must specify text to send'); | ||
| 3255 | return; | ||
| 3256 | } | ||
| 3257 | |||
| 3258 | text = text.trim(); | ||
| 3259 | const compact = isTrueBoolean(args?.compact); | 3254 | const compact = isTrueBoolean(args?.compact); |
| 3260 | const bias = extractMessageBias(text); | 3255 | const bias = extractMessageBias(text); |
| 3261 | 3256 | ||
| @@ -3564,13 +3559,7 @@ export function getNameAndAvatarForMessage(character, name = null) { | |||
| 3564 | } | 3559 | } |
| 3565 | 3560 | ||
| 3566 | export async function sendMessageAs(args, text) { | 3561 | export async function sendMessageAs(args, text) { |
| 3567 | if (!text) { | ||
| 3568 | toastr.warning('You must specify text to send as'); | ||
| 3569 | return ''; | ||
| 3570 | } | ||
| 3571 | |||
| 3572 | let name = args.name?.trim(); | 3562 | let name = args.name?.trim(); |
| 3573 | let mesText; | ||
| 3574 | 3563 | ||
| 3575 | if (!name) { | 3564 | if (!name) { |
| 3576 | const namelessWarningKey = 'sendAsNamelessWarningShown'; | 3565 | const namelessWarningKey = 'sendAsNamelessWarningShown'; |
| @@ -3581,7 +3570,7 @@ export async function sendMessageAs(args, text) { | |||
| 3581 | name = name2; | 3570 | name = name2; |
| 3582 | } | 3571 | } |
| 3583 | 3572 | ||
| 3584 | mesText = text.trim(); | 3573 | let mesText = String(text ?? '').trim(); |
| 3585 | 3574 | ||
| 3586 | // Requires a regex check after the slash command is pushed to output | 3575 | // Requires a regex check after the slash command is pushed to output |
| 3587 | mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND, { characterOverride: name }); | 3576 | mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND, { characterOverride: name }); |
| @@ -3659,11 +3648,7 @@ export async function sendMessageAs(args, text) { | |||
| 3659 | } | 3648 | } |
| 3660 | 3649 | ||
| 3661 | export async function sendNarratorMessage(args, text) { | 3650 | export async function sendNarratorMessage(args, text) { |
| 3662 | if (!text) { | 3651 | text = String(text ?? ''); |
| 3663 | toastr.warning('You must specify text to send'); | ||
| 3664 | return ''; | ||
| 3665 | } | ||
| 3666 | |||
| 3667 | const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT; | 3652 | const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT; |
| 3668 | // Messages that do nothing but set bias will be hidden from the context | 3653 | // Messages that do nothing but set bias will be hidden from the context |
| 3669 | const bias = extractMessageBias(text); | 3654 | const bias = extractMessageBias(text); |
| @@ -3754,18 +3739,13 @@ export async function promptQuietForLoudResponse(who, text) { | |||
| 3754 | } | 3739 | } |
| 3755 | 3740 | ||
| 3756 | async function sendCommentMessage(args, text) { | 3741 | async function sendCommentMessage(args, text) { |
| 3757 | if (!text) { | ||
| 3758 | toastr.warning('You must specify text to send'); | ||
| 3759 | return ''; | ||
| 3760 | } | ||
| 3761 | |||
| 3762 | const compact = isTrueBoolean(args?.compact); | 3742 | const compact = isTrueBoolean(args?.compact); |
| 3763 | const message = { | 3743 | const message = { |
| 3764 | name: COMMENT_NAME_DEFAULT, | 3744 | name: COMMENT_NAME_DEFAULT, |
| 3765 | is_user: false, | 3745 | is_user: false, |
| 3766 | is_system: true, | 3746 | is_system: true, |
| 3767 | send_date: getMessageTimeStamp(), | 3747 | send_date: getMessageTimeStamp(), |
| 3768 | mes: substituteParams(text.trim()), | 3748 | mes: substituteParams(String(text ?? '').trim()), |
| 3769 | force_avatar: comment_avatar, | 3749 | force_avatar: comment_avatar, |
| 3770 | extra: { | 3750 | extra: { |
| 3771 | type: system_message_types.COMMENT, | 3751 | type: system_message_types.COMMENT, |