Merged redundant args for /setpromptentry

This commit is contained in:
splitclover 2024-06-16 12:16:56 +02:00 committed by GitHub
parent e5d9f2937e
commit 7f284a3752
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 27 deletions

View File

@ -1211,20 +1211,14 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
callback: setPromptEntryCallback, callback: setPromptEntryCallback,
namedArgumentList: [ namedArgumentList: [
new SlashCommandNamedArgument( new SlashCommandNamedArgument(
'identifier', 'Prompt entry identifier to set (UUID)', [ARGUMENT_TYPE.STRING], false, 'identifier', 'Prompt entry identifier(s) to target', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], false, true,
), ),
new SlashCommandNamedArgument( new SlashCommandNamedArgument(
'identifiers', 'List of prompt entry identifiers to set (UUID)', [ARGUMENT_TYPE.LIST], false, 'name', 'Prompt entry name(s) to target', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], false, true,
),
new SlashCommandNamedArgument(
'name', 'Prompt entry name to set', [ARGUMENT_TYPE.STRING], false,
),
new SlashCommandNamedArgument(
'names', 'Prompt entry names to set', [ARGUMENT_TYPE.LIST], false,
), ),
], ],
unnamedArgumentList: [ unnamedArgumentList: [
SlashCommandArgument.fromProps({ description: 'Set entry/entries on, off or toggle current state', SlashCommandArgument.fromProps({ description: 'Set entry/entries on or off',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
isRequired: true, isRequired: true,
acceptsMultiple: false, acceptsMultiple: false,
@ -1232,7 +1226,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
enumList: ['on', 'off', 'toggle'], enumList: ['on', 'off', 'toggle'],
}), }),
], ],
helpString: 'Sets or toggles individual chat completion prompt entries.', helpString: 'Sets the model for the current API. Gets the current model name if no argument is provided.',
})); }));
registerVariableCommands(); registerVariableCommands();
@ -2860,9 +2854,7 @@ function modelCallback(_, model) {
* Sets state of prompt entries (toggles) either via identifier/uuid or name. * Sets state of prompt entries (toggles) either via identifier/uuid or name.
* @param {object} args Object containing arguments * @param {object} args Object containing arguments
* @param {string} args.identifier Select prompt entry using an identifier (uuid) * @param {string} args.identifier Select prompt entry using an identifier (uuid)
* @param {string} args.identifiers List of identifiers to set
* @param {string} args.name Select prompt entry using name * @param {string} args.name Select prompt entry using name
* @param {string} args.names List of names to set
* @param {string} targetState The targeted state of the entry/entries * @param {string} targetState The targeted state of the entry/entries
* @returns {String} empty string * @returns {String} empty string
*/ */
@ -2872,15 +2864,14 @@ function setPromptEntryCallback(args, targetState) {
const prompts = promptManager.serviceSettings.prompts; const prompts = promptManager.serviceSettings.prompts;
let identifiersList = []; let identifiersList = [];
// Check identifier(s) args // Check identifiers args
if (args.identifier) identifiersList.push(args.identifier);
if (args.identifiers) {
try { try {
identifiersList = identifiersList.concat(JSON.parse(args.identifiers)); const parsedIdentifiers = JSON.parse(args.identifier);
identifiersList = identifiersList.concat(Array.isArray(parsedIdentifiers) ? parsedIdentifiers : [args.identifier]);
} catch { } catch {
// Do nothing identifiersList.push(args.identifier);
}
} }
// Check if identifiers exists in prompt, else remove from list // Check if identifiers exists in prompt, else remove from list
if (identifiersList.length !== 0) { if (identifiersList.length !== 0) {
identifiersList = identifiersList.filter(identifier => { identifiersList = identifiersList.filter(identifier => {
@ -2890,13 +2881,11 @@ function setPromptEntryCallback(args, targetState) {
let nameList = []; let nameList = [];
// Get list of names // Get list of names
if (args.name) nameList.push(args.name);
if (args.names) {
try { try {
nameList = nameList.concat(JSON.parse(args.names)); const parsedNames = JSON.parse(args.name);
nameList = nameList.concat(Array.isArray(parsedNames) ? parsedNames : [args.name]);
} catch { } catch {
// Do nothing nameList.push(args.name);
}
} }
if (nameList.length !== 0) { if (nameList.length !== 0) {