#2832 /ask text non-required

This commit is contained in:
Cohee 2024-09-12 20:13:05 +03:00
parent 6a3b226da2
commit 81cd38d4f7

View File

@ -440,7 +440,7 @@ export function initDefaultSlashCommands() {
], ],
unnamedArgumentList: [ unnamedArgumentList: [
new SlashCommandArgument( new SlashCommandArgument(
'prompt', [ARGUMENT_TYPE.STRING], true, false, 'prompt', [ARGUMENT_TYPE.STRING], false, false,
), ),
], ],
helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.', helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.',
@ -2469,31 +2469,21 @@ async function askCharacter(args, text) {
// Not supported in group chats // Not supported in group chats
// TODO: Maybe support group chats? // TODO: Maybe support group chats?
if (selected_group) { if (selected_group) {
toastr.error('Cannot run this command in a group chat!'); toastr.error('Cannot run /ask command in a group chat!');
return '';
}
if (!text) {
console.warn('WARN: No text provided for /ask command');
toastr.warning('No text provided for /ask command');
return ''; return '';
} }
let name = ''; let name = '';
let mesText = '';
if (args?.name) { if (args?.name) {
name = args.name.trim(); name = args.name.trim();
mesText = text.trim();
if (!name && !mesText) { if (!name) {
toastr.warning('You must specify a name and text to ask.'); toastr.warning('You must specify a name of the character to ask.');
return ''; return '';
} }
} }
mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND);
const prevChId = this_chid; const prevChId = this_chid;
// Find the character // Find the character
@ -2503,9 +2493,12 @@ async function askCharacter(args, text) {
return ''; return '';
} }
// Sending a message implicitly saves the chat, so this needs to be done before changing the character if (text) {
// Otherwise, a corruption will occur const mesText = getRegexedString(text.trim(), regex_placement.SLASH_COMMAND);
await sendMessageAsUser(mesText, ''); // Sending a message implicitly saves the chat, so this needs to be done before changing the character
// Otherwise, a corruption will occur
await sendMessageAsUser(mesText, '');
}
// Override character and send a user message // Override character and send a user message
setCharacterId(String(chId)); setCharacterId(String(chId));