#2832 /ask text non-required
| @@ -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 chats | 2469 | // 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 | } |
| 2481 | 2475 | ||
| 2482 | let name = ''; | 2476 | let name = ''; |
| 2483 | let mesText = ''; | ||
| 2484 | 2477 | ||
| 2485 | if (args?.name) { | 2478 | if (args?.name) { |
| 2486 | name = args.name.trim(); | 2479 | name = args.name.trim(); |
| 2487 | mesText = text.trim(); | ||
| 2488 | 2480 | ||
| 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 | } |
| 2494 | 2486 | ||
| 2495 | mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND); | ||
| 2496 | |||
| 2497 | const prevChId = this_chid; | 2487 | const prevChId = this_chid; |
| 2498 | 2488 | ||
| 2499 | // Find the character | 2489 | // Find the character |
| @@ -2503,9 +2493,12 @@ async function askCharacter(args, text) { | |||
| 2503 | return ''; | 2493 | return ''; |
| 2504 | } | 2494 | } |
| 2505 | 2495 | ||
| 2506 | // Sending a message implicitly saves the chat, so this needs to be done before changing the character | 2496 | if (text) { |
| 2507 | // Otherwise, a corruption will occur | 2497 | const mesText = getRegexedString(text.trim(), regex_placement.SLASH_COMMAND); |
| 2508 | await sendMessageAsUser(mesText, ''); | 2498 | // Sending a message implicitly saves the chat, so this needs to be done before changing the character |
| 2499 | // Otherwise, a corruption will occur | ||
| 2500 | await sendMessageAsUser(mesText, ''); | ||
| 2501 | } | ||
| 2509 | 2502 | ||
| 2510 | // Override character and send a user message | 2503 | // Override character and send a user message |
| 2511 | setCharacterId(String(chId)); | 2504 | setCharacterId(String(chId)); |