mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Allow sending empty messages with /sendas, /sys, etc.
This commit is contained in:
@ -2004,14 +2004,14 @@ export function initDefaultSlashCommands() {
|
|||||||
aliases: ['re'],
|
aliases: ['re'],
|
||||||
callback: (async ({ mode = 'literal', pattern, replacer = '' }, text) => {
|
callback: (async ({ mode = 'literal', pattern, replacer = '' }, text) => {
|
||||||
if (pattern === '')
|
if (pattern === '')
|
||||||
throw new Error("Argument of 'pattern=' cannot be empty");
|
throw new Error('Argument of \'pattern=\' cannot be empty');
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'literal':
|
case 'literal':
|
||||||
return text.replaceAll(pattern, replacer);
|
return text.replaceAll(pattern, replacer);
|
||||||
case 'regex':
|
case 'regex':
|
||||||
return text.replace(regexFromString(pattern), replacer);
|
return text.replace(regexFromString(pattern), replacer);
|
||||||
default:
|
default:
|
||||||
throw new Error("Invalid '/replace mode=' argument specified!");
|
throw new Error('Invalid \'/replace mode=\' argument specified!');
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
returns: 'replaced text',
|
returns: 'replaced text',
|
||||||
@ -3250,12 +3250,7 @@ function findPersonaByName(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendUserMessageCallback(args, text) {
|
async function sendUserMessageCallback(args, text) {
|
||||||
if (!text) {
|
text = String(text ?? '').trim();
|
||||||
toastr.warning('You must specify text to send');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
text = text.trim();
|
|
||||||
const compact = isTrueBoolean(args?.compact);
|
const compact = isTrueBoolean(args?.compact);
|
||||||
const bias = extractMessageBias(text);
|
const bias = extractMessageBias(text);
|
||||||
|
|
||||||
@ -3564,13 +3559,7 @@ export function getNameAndAvatarForMessage(character, name = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function sendMessageAs(args, text) {
|
export async function sendMessageAs(args, text) {
|
||||||
if (!text) {
|
|
||||||
toastr.warning('You must specify text to send as');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
let name = args.name?.trim();
|
let name = args.name?.trim();
|
||||||
let mesText;
|
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
const namelessWarningKey = 'sendAsNamelessWarningShown';
|
const namelessWarningKey = 'sendAsNamelessWarningShown';
|
||||||
@ -3581,7 +3570,7 @@ export async function sendMessageAs(args, text) {
|
|||||||
name = name2;
|
name = name2;
|
||||||
}
|
}
|
||||||
|
|
||||||
mesText = text.trim();
|
let mesText = String(text ?? '').trim();
|
||||||
|
|
||||||
// Requires a regex check after the slash command is pushed to output
|
// Requires a regex check after the slash command is pushed to output
|
||||||
mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND, { characterOverride: name });
|
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) {
|
export async function sendNarratorMessage(args, text) {
|
||||||
if (!text) {
|
text = String(text ?? '');
|
||||||
toastr.warning('You must specify text to send');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT;
|
const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT;
|
||||||
// Messages that do nothing but set bias will be hidden from the context
|
// Messages that do nothing but set bias will be hidden from the context
|
||||||
const bias = extractMessageBias(text);
|
const bias = extractMessageBias(text);
|
||||||
@ -3754,18 +3739,13 @@ export async function promptQuietForLoudResponse(who, text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendCommentMessage(args, text) {
|
async function sendCommentMessage(args, text) {
|
||||||
if (!text) {
|
|
||||||
toastr.warning('You must specify text to send');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const compact = isTrueBoolean(args?.compact);
|
const compact = isTrueBoolean(args?.compact);
|
||||||
const message = {
|
const message = {
|
||||||
name: COMMENT_NAME_DEFAULT,
|
name: COMMENT_NAME_DEFAULT,
|
||||||
is_user: false,
|
is_user: false,
|
||||||
is_system: true,
|
is_system: true,
|
||||||
send_date: getMessageTimeStamp(),
|
send_date: getMessageTimeStamp(),
|
||||||
mes: substituteParams(text.trim()),
|
mes: substituteParams(String(text ?? '').trim()),
|
||||||
force_avatar: comment_avatar,
|
force_avatar: comment_avatar,
|
||||||
extra: {
|
extra: {
|
||||||
type: system_message_types.COMMENT,
|
type: system_message_types.COMMENT,
|
||||||
|
Reference in New Issue
Block a user