Update more commands for new char find

- Update /member-add to utilize new char find functionality
- Update /tag-add, /tag-remove, /tag-exists and /tag-list to utilize new char find functionality
. Update /lastsprite to utilize new char find functionality
This commit is contained in:
Wolfsblvt 2024-09-29 02:54:12 +02:00
parent 145023ba8d
commit edcf52e3a8
4 changed files with 25 additions and 18 deletions

View File

@ -12,6 +12,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
import { isFunctionCallingSupported } from '../../openai.js';
import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
import { findChar } from '../../slash-commands.js';
export { MODULE_NAME };
const MODULE_NAME = 'expressions';
@ -2105,14 +2106,20 @@ function migrateSettings() {
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'lastsprite',
callback: (_, value) => lastExpression[String(value).trim()] ?? '',
callback: (_, name) => {
if (typeof name !== 'string') throw new Error('name must be a string');
const char = findChar({ name: name });
const sprite = lastExpression[char?.name ?? name] ?? '';
return sprite;
},
returns: 'the last set sprite / expression for the named character.',
unnamedArgumentList: [
SlashCommandArgument.fromProps({
description: 'character name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
isRequired: true,
enumProvider: commonEnumProviders.characters('character'),
forceEnum: true,
}),
],
helpString: 'Returns the last set sprite / expression for the named character.',

View File

@ -441,6 +441,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
description: 'character name',
typeList: [ARGUMENT_TYPE.STRING],
enumProvider: commonEnumProviders.characters('character'),
forceEnum: true,
}),
SlashCommandNamedArgument.fromProps({
name: 'group',

View File

@ -210,7 +210,7 @@ export function initDefaultSlashCommands() {
],
unnamedArgumentList: [
SlashCommandArgument.fromProps({
description: 'Character name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
enumProvider: commonEnumProviders.characters('character'),
forceEnum: false,
@ -700,7 +700,7 @@ export function initDefaultSlashCommands() {
aliases: ['addmember', 'memberadd'],
unnamedArgumentList: [
SlashCommandArgument.fromProps({
description: 'character name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
isRequired: true,
enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [],
@ -2810,26 +2810,23 @@ async function removeGroupMemberCallback(_, arg) {
return '';
}
async function addGroupMemberCallback(_, arg) {
async function addGroupMemberCallback(_, name) {
if (!selected_group) {
toastr.warning('Cannot run /memberadd command outside of a group chat.');
return '';
}
if (!arg) {
if (!name) {
console.warn('WARN: No argument provided for /memberadd command');
return '';
}
arg = arg.trim();
const chid = findCharacterIndex(arg);
if (chid === -1) {
console.warn(`WARN: No character found for argument ${arg}`);
const character = findChar({ name: name, preferCurrentChar: false });
if (!character) {
console.warn(`WARN: No character found for argument ${name}`);
return '';
}
const character = characters[chid];
const group = groups.find(x => x.id === selected_group);
if (!group || !Array.isArray(group.members)) {

View File

@ -26,6 +26,7 @@ import { debounce_timeout } from './constants.js';
import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js';
import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
import { renderTemplateAsync } from './templates.js';
import { findChar } from './slash-commands.js';
export {
TAG_FOLDER_TYPES,
@ -507,7 +508,7 @@ export function getTagKeyForEntityElement(element) {
*/
export function searchCharByName(charName, { suppressLogging = false } = {}) {
const entity = charName
? (characters.find(x => x.name === charName) || groups.find(x => x.name == charName))
? (findChar({ name: charName }) || groups.find(x => equalsIgnoreCaseAndAccents(x.name, charName)))
: (selected_group ? groups.find(x => x.id == selected_group) : characters[this_chid]);
const key = getTagKeyForEntity(entity);
if (!key) {
@ -1861,8 +1862,9 @@ function registerTagsSlashCommands() {
return String(result);
},
namedArgumentList: [
SlashCommandNamedArgument.fromProps({ name: 'name',
description: 'Character name',
SlashCommandNamedArgument.fromProps({
name: 'name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
enumProvider: commonEnumProviders.characters(),
@ -1907,7 +1909,7 @@ function registerTagsSlashCommands() {
},
namedArgumentList: [
SlashCommandNamedArgument.fromProps({ name: 'name',
description: 'Character name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
enumProvider: commonEnumProviders.characters(),
@ -1950,7 +1952,7 @@ function registerTagsSlashCommands() {
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'name',
description: 'Character name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
enumProvider: commonEnumProviders.characters(),
@ -1993,7 +1995,7 @@ function registerTagsSlashCommands() {
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'name',
description: 'Character name',
description: 'Character name - or unique character identifier (avatar key)',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
enumProvider: commonEnumProviders.characters(),