mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into send-commands-return-value
This commit is contained in:
@ -15,13 +15,13 @@ import { SlashCommandScope } from './SlashCommandScope.js';
|
||||
* _abortController:SlashCommandAbortController,
|
||||
* _debugController:SlashCommandDebugController,
|
||||
* _hasUnnamedArgument:boolean,
|
||||
* [id:string]:string|SlashCommandClosure|(string|SlashCommandClosure)[],
|
||||
* [id:string]:string|SlashCommandClosure|(string|SlashCommandClosure)[]|undefined,
|
||||
* }} NamedArguments
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alternative object for local JSDocs, where you don't need existing pipe, scope, etc. arguments
|
||||
* @typedef {{[id:string]:string|SlashCommandClosure|(string|SlashCommandClosure)[]}} NamedArgumentsCapture
|
||||
* @typedef {{[id:string]:string|SlashCommandClosure|(string|SlashCommandClosure)[]|undefined}} NamedArgumentsCapture
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -508,6 +508,14 @@ export class SlashCommandClosure {
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
value ??= '';
|
||||
|
||||
// Make sure that if unnamed args are split, it should always return an array
|
||||
if (executor.command.splitUnnamedArgument && !Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { chat_metadata, characters, substituteParams, chat, extension_prompt_rol
|
||||
import { extension_settings } from '../extensions.js';
|
||||
import { getGroupMembers, groups } from '../group-chats.js';
|
||||
import { power_user } from '../power-user.js';
|
||||
import { searchCharByName, getTagsList, tags } from '../tags.js';
|
||||
import { searchCharByName, getTagsList, tags, tag_map } from '../tags.js';
|
||||
import { world_names } from '../world-info.js';
|
||||
import { SlashCommandClosure } from './SlashCommandClosure.js';
|
||||
import { SlashCommandEnumValue, enumTypes } from './SlashCommandEnumValue.js';
|
||||
@ -153,6 +153,35 @@ export const commonEnumProviders = {
|
||||
].filter((item, idx, list)=>idx == list.findIndex(it=>it.value == item.value));
|
||||
},
|
||||
|
||||
/**
|
||||
* Enum values for numbers and variable names
|
||||
*
|
||||
* Includes all variable names and the ability to specify any number
|
||||
*
|
||||
* @param {SlashCommandExecutor} executor - The executor of the slash command
|
||||
* @param {SlashCommandScope} scope - The scope of the slash command
|
||||
* @returns {SlashCommandEnumValue[]} The enum values
|
||||
*/
|
||||
numbersAndVariables: (executor, scope) => [
|
||||
...commonEnumProviders.variables('all')(executor, scope),
|
||||
new SlashCommandEnumValue(
|
||||
'any variable name',
|
||||
null,
|
||||
enumTypes.variable,
|
||||
enumIcons.variable,
|
||||
(input) => /^\w*$/.test(input),
|
||||
(input) => input,
|
||||
),
|
||||
new SlashCommandEnumValue(
|
||||
'any number',
|
||||
null,
|
||||
enumTypes.number,
|
||||
enumIcons.number,
|
||||
(input) => input == '' || !Number.isNaN(Number(input)),
|
||||
(input) => input,
|
||||
),
|
||||
],
|
||||
|
||||
/**
|
||||
* All possible char entities, like characters and groups. Can be filtered down to just one type.
|
||||
*
|
||||
@ -182,6 +211,18 @@ export const commonEnumProviders = {
|
||||
*/
|
||||
personas: () => Object.values(power_user.personas).map(persona => new SlashCommandEnumValue(persona, null, enumTypes.name, enumIcons.persona)),
|
||||
|
||||
/**
|
||||
* All possible tags, or only those that have been assigned
|
||||
*
|
||||
* @param {('all' | 'assigned')} [mode='all'] - Which types of tags to show
|
||||
* @returns {() => SlashCommandEnumValue[]}
|
||||
*/
|
||||
tags: (mode = 'all') => () => {
|
||||
let assignedTags = mode === 'assigned' ? new Set(Object.values(tag_map).flat()) : new Set();
|
||||
return tags.filter(tag => mode === 'all' || (mode === 'assigned' && assignedTags.has(tag.id)))
|
||||
.map(tag => new SlashCommandEnumValue(tag.name, null, enumTypes.command, enumIcons.tag));
|
||||
},
|
||||
|
||||
/**
|
||||
* All possible tags for a given char/group entity
|
||||
*
|
||||
@ -194,7 +235,7 @@ export const commonEnumProviders = {
|
||||
if (charName instanceof SlashCommandClosure) throw new Error('Argument \'name\' does not support closures');
|
||||
const key = searchCharByName(substituteParams(charName), { suppressLogging: true });
|
||||
const assigned = key ? getTagsList(key) : [];
|
||||
return tags.filter(it => !key || mode === 'all' || mode === 'existing' && assigned.includes(it) || mode === 'not-existing' && !assigned.includes(it))
|
||||
return tags.filter(it => mode === 'all' || mode === 'existing' && assigned.includes(it) || mode === 'not-existing' && !assigned.includes(it))
|
||||
.map(tag => new SlashCommandEnumValue(tag.name, null, enumTypes.command, enumIcons.tag));
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user