#2832 /ask text non-required

81cd38d4f70bfbb31641618382afd6d0d8df99aa

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +7 -14Showing whitespace changes
public/scripts/slash-commands.js+7 -14
@@ -440,7 +440,7 @@ export function initDefaultSlashCommands() {
440 ],440 ],
441 unnamedArgumentList: [441 unnamedArgumentList: [
442 new SlashCommandArgument(442 new SlashCommandArgument(
443 'prompt', [ARGUMENT_TYPE.STRING], true, false,443 'prompt', [ARGUMENT_TYPE.STRING], false, false,
444 ),444 ),
445 ],445 ],
446 helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.',446 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) {
2469 // Not supported in group chats2469 // Not supported in group chats
2470 // TODO: Maybe support group chats?2470 // TODO: Maybe support group chats?
2471 if (selected_group) {2471 if (selected_group) {
2472 toastr.error('Cannot run this command in a group chat!');2472 toastr.error('Cannot run /ask command in a group chat!');
2473 return '';
2474 }
2475
2476 if (!text) {
2477 console.warn('WARN: No text provided for /ask command');
2478 toastr.warning('No text provided for /ask command');
2479 return '';2473 return '';
2480 }2474 }
24812475
2482 let name = '';2476 let name = '';
2483 let mesText = '';
24842477
2485 if (args?.name) {2478 if (args?.name) {
2486 name = args.name.trim();2479 name = args.name.trim();
2487 mesText = text.trim();
24882480
2489 if (!name && !mesText) {2481 if (!name) {
2490 toastr.warning('You must specify a name and text to ask.');2482 toastr.warning('You must specify a name of the character to ask.');
2491 return '';2483 return '';
2492 }2484 }
2493 }2485 }
24942486
2495 mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND);
2496
2497 const prevChId = this_chid;2487 const prevChId = this_chid;
24982488
2499 // Find the character2489 // Find the character
@@ -2503,9 +2493,12 @@ async function askCharacter(args, text) {
2503 return '';2493 return '';
2504 }2494 }
25052495
2496 if (text) {
2497 const mesText = getRegexedString(text.trim(), regex_placement.SLASH_COMMAND);
2506 // Sending a message implicitly saves the chat, so this needs to be done before changing the character2498 // Sending a message implicitly saves the chat, so this needs to be done before changing the character
2507 // Otherwise, a corruption will occur2499 // Otherwise, a corruption will occur
2508 await sendMessageAsUser(mesText, '');2500 await sendMessageAsUser(mesText, '');
2501 }
25092502
2510 // Override character and send a user message2503 // Override character and send a user message
2511 setCharacterId(String(chId));2504 setCharacterId(String(chId));