New syntax for /ask command

This commit is contained in:
Cohee 2024-06-05 21:37:33 +03:00
parent c911265dbd
commit 0a3e91287d
1 changed files with 27 additions and 17 deletions

View File

@ -336,15 +336,17 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'ask', name: 'ask',
callback: askCharacter, callback: askCharacter,
unnamedArgumentList: [ namedArgumentList: [
new SlashCommandArgument( new SlashCommandNamedArgument(
'character name', [ARGUMENT_TYPE.STRING], true, 'name', 'character name', [ARGUMENT_TYPE.STRING], true, false, '',
),
new SlashCommandArgument(
'prompt', [ARGUMENT_TYPE.STRING], true,
), ),
], ],
helpString: 'Asks a specified character card a prompt. Character name and prompt have to be separated by a new line.', unnamedArgumentList: [
new SlashCommandArgument(
'prompt', [ARGUMENT_TYPE.STRING], true, false,
),
],
helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.',
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'delname', name: 'delname',
@ -1815,7 +1817,7 @@ async function deleteSwipeCallback(_, arg) {
await reloadCurrentChat(); await reloadCurrentChat();
} }
async function askCharacter(_, text) { async function askCharacter(args, text) {
// Prevent generate recursion // Prevent generate recursion
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true })); $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
@ -1828,17 +1830,25 @@ async function askCharacter(_, text) {
if (!text) { if (!text) {
console.warn('WARN: No text provided for /ask command'); console.warn('WARN: No text provided for /ask command');
} toastr.warning('No text provided for /ask command');
const parts = text.split('\n');
if (parts.length <= 1) {
toastr.warning('Both character name and message are required. Separate them with a new line.');
return; return;
} }
// Grabbing the message let name = '';
const name = parts.shift().trim(); let mesText = '';
let mesText = parts.join('\n').trim();
if (args?.name) {
name = args.name.trim();
mesText = text.trim();
if (!name && !mesText) {
toastr.warning('You must specify a name and text to ask.');
return;
}
}
mesText = getRegexedString(mesText, regex_placement.SLASH_COMMAND);
const prevChId = this_chid; const prevChId = this_chid;
// Find the character // Find the character
@ -1849,7 +1859,7 @@ async function askCharacter(_, text) {
} }
// Override character and send a user message // Override character and send a user message
setCharacterId(chId); setCharacterId(String(chId));
// TODO: Maybe look up by filename instead of name // TODO: Maybe look up by filename instead of name
const character = characters[chId]; const character = characters[chId];