/char-find command to get a specific unique char

- findChar utility function that does the heavy lifting of finding a specific char based on conditions
- Log/warn if multiple characters match
- Validation function for named args that should be arrays
This commit is contained in:
Wolfsblvt
2024-09-29 00:36:13 +02:00
parent 20a82fb242
commit 0be48c567a
3 changed files with 138 additions and 14 deletions

View File

@ -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
*/
/**

View File

@ -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';
@ -181,6 +181,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
*