mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-02 19:07:40 +01:00
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:
parent
145023ba8d
commit
edcf52e3a8
@ -12,6 +12,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
|
|||||||
import { isFunctionCallingSupported } from '../../openai.js';
|
import { isFunctionCallingSupported } from '../../openai.js';
|
||||||
import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
|
import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
|
||||||
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
|
import { findChar } from '../../slash-commands.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'expressions';
|
const MODULE_NAME = 'expressions';
|
||||||
@ -2105,14 +2106,20 @@ function migrateSettings() {
|
|||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'lastsprite',
|
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.',
|
returns: 'the last set sprite / expression for the named character.',
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'character name',
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
enumProvider: commonEnumProviders.characters('character'),
|
enumProvider: commonEnumProviders.characters('character'),
|
||||||
|
forceEnum: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Returns the last set sprite / expression for the named character.',
|
helpString: 'Returns the last set sprite / expression for the named character.',
|
||||||
|
@ -441,6 +441,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|||||||
description: 'character name',
|
description: 'character name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
enumProvider: commonEnumProviders.characters('character'),
|
enumProvider: commonEnumProviders.characters('character'),
|
||||||
|
forceEnum: true,
|
||||||
}),
|
}),
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'group',
|
name: 'group',
|
||||||
|
@ -210,7 +210,7 @@ export function initDefaultSlashCommands() {
|
|||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'Character name',
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
enumProvider: commonEnumProviders.characters('character'),
|
enumProvider: commonEnumProviders.characters('character'),
|
||||||
forceEnum: false,
|
forceEnum: false,
|
||||||
@ -700,7 +700,7 @@ export function initDefaultSlashCommands() {
|
|||||||
aliases: ['addmember', 'memberadd'],
|
aliases: ['addmember', 'memberadd'],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'character name',
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [],
|
enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [],
|
||||||
@ -2810,26 +2810,23 @@ async function removeGroupMemberCallback(_, arg) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addGroupMemberCallback(_, arg) {
|
async function addGroupMemberCallback(_, name) {
|
||||||
if (!selected_group) {
|
if (!selected_group) {
|
||||||
toastr.warning('Cannot run /memberadd command outside of a group chat.');
|
toastr.warning('Cannot run /memberadd command outside of a group chat.');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arg) {
|
if (!name) {
|
||||||
console.warn('WARN: No argument provided for /memberadd command');
|
console.warn('WARN: No argument provided for /memberadd command');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
arg = arg.trim();
|
const character = findChar({ name: name, preferCurrentChar: false });
|
||||||
const chid = findCharacterIndex(arg);
|
if (!character) {
|
||||||
|
console.warn(`WARN: No character found for argument ${name}`);
|
||||||
if (chid === -1) {
|
|
||||||
console.warn(`WARN: No character found for argument ${arg}`);
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const character = characters[chid];
|
|
||||||
const group = groups.find(x => x.id === selected_group);
|
const group = groups.find(x => x.id === selected_group);
|
||||||
|
|
||||||
if (!group || !Array.isArray(group.members)) {
|
if (!group || !Array.isArray(group.members)) {
|
||||||
|
@ -26,6 +26,7 @@ import { debounce_timeout } from './constants.js';
|
|||||||
import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js';
|
import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js';
|
||||||
import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
import { renderTemplateAsync } from './templates.js';
|
import { renderTemplateAsync } from './templates.js';
|
||||||
|
import { findChar } from './slash-commands.js';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
TAG_FOLDER_TYPES,
|
TAG_FOLDER_TYPES,
|
||||||
@ -507,7 +508,7 @@ export function getTagKeyForEntityElement(element) {
|
|||||||
*/
|
*/
|
||||||
export function searchCharByName(charName, { suppressLogging = false } = {}) {
|
export function searchCharByName(charName, { suppressLogging = false } = {}) {
|
||||||
const entity = charName
|
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]);
|
: (selected_group ? groups.find(x => x.id == selected_group) : characters[this_chid]);
|
||||||
const key = getTagKeyForEntity(entity);
|
const key = getTagKeyForEntity(entity);
|
||||||
if (!key) {
|
if (!key) {
|
||||||
@ -1861,8 +1862,9 @@ function registerTagsSlashCommands() {
|
|||||||
return String(result);
|
return String(result);
|
||||||
},
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
SlashCommandNamedArgument.fromProps({ name: 'name',
|
SlashCommandNamedArgument.fromProps({
|
||||||
description: 'Character name',
|
name: 'name',
|
||||||
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.characters(),
|
enumProvider: commonEnumProviders.characters(),
|
||||||
@ -1907,7 +1909,7 @@ function registerTagsSlashCommands() {
|
|||||||
},
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
SlashCommandNamedArgument.fromProps({ name: 'name',
|
SlashCommandNamedArgument.fromProps({ name: 'name',
|
||||||
description: 'Character name',
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.characters(),
|
enumProvider: commonEnumProviders.characters(),
|
||||||
@ -1950,7 +1952,7 @@ function registerTagsSlashCommands() {
|
|||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'name',
|
name: 'name',
|
||||||
description: 'Character name',
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.characters(),
|
enumProvider: commonEnumProviders.characters(),
|
||||||
@ -1993,7 +1995,7 @@ function registerTagsSlashCommands() {
|
|||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'name',
|
name: 'name',
|
||||||
description: 'Character name',
|
description: 'Character name - or unique character identifier (avatar key)',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.characters(),
|
enumProvider: commonEnumProviders.characters(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user