Allow sending empty messages with /sendas, /sys, etc.

This commit is contained in:
Cohee
2025-01-31 22:03:09 +02:00
parent f155cc7e92
commit 9a03aac224

View File

@ -2002,16 +2002,16 @@ export function initDefaultSlashCommands() {
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'replace',
aliases: ['re'],
callback: (async ({mode = 'literal', pattern, replacer = ''}, text) => {
callback: (async ({ mode = 'literal', pattern, replacer = '' }, text) => {
if (pattern === '')
throw new Error("Argument of 'pattern=' cannot be empty");
throw new Error('Argument of \'pattern=\' cannot be empty');
switch (mode) {
case 'literal':
return text.replaceAll(pattern, replacer);
case 'regex':
return text.replace(regexFromString(pattern), replacer);
default:
throw new Error("Invalid '/replace mode=' argument specified!");
throw new Error('Invalid \'/replace mode=\' argument specified!');
}
}),
returns: 'replaced text',
@ -3250,12 +3250,7 @@ function findPersonaByName(name) {
}
async function sendUserMessageCallback(args, text) {
if (!text) {
toastr.warning('You must specify text to send');
return;
}
text = text.trim();
text = String(text ?? '').trim();
const compact = isTrueBoolean(args?.compact);
const bias = extractMessageBias(text);
@ -3564,13 +3559,7 @@ export function getNameAndAvatarForMessage(character, name = null) {
}
export async function sendMessageAs(args, text) {
if (!text) {
toastr.warning('You must specify text to send as');
return '';
}
let name = args.name?.trim();
let mesText;
if (!name) {
const namelessWarningKey = 'sendAsNamelessWarningShown';
@ -3581,7 +3570,7 @@ export async function sendMessageAs(args, text) {
name = name2;
}
mesText = text.trim();
let mesText = String(text ?? '').trim();
// Requires a regex check after the slash command is pushed to output
mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND, { characterOverride: name });
@ -3659,11 +3648,7 @@ export async function sendMessageAs(args, text) {
}
export async function sendNarratorMessage(args, text) {
if (!text) {
toastr.warning('You must specify text to send');
return '';
}
text = String(text ?? '');
const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT;
// Messages that do nothing but set bias will be hidden from the context
const bias = extractMessageBias(text);
@ -3754,18 +3739,13 @@ export async function promptQuietForLoudResponse(who, text) {
}
async function sendCommentMessage(args, text) {
if (!text) {
toastr.warning('You must specify text to send');
return '';
}
const compact = isTrueBoolean(args?.compact);
const message = {
name: COMMENT_NAME_DEFAULT,
is_user: false,
is_system: true,
send_date: getMessageTimeStamp(),
mes: substituteParams(text.trim()),
mes: substituteParams(String(text ?? '').trim()),
force_avatar: comment_avatar,
extra: {
type: system_message_types.COMMENT,