mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Several million refactoring of existing slash commands with enums (really)
This commit is contained in:
@ -198,7 +198,10 @@ jQuery(async () => {
|
|||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'db',
|
name: 'db',
|
||||||
callback: () => document.getElementById('manageAttachments')?.click(),
|
callback: () => {
|
||||||
|
document.getElementById('manageAttachments')?.click();
|
||||||
|
return '';
|
||||||
|
},
|
||||||
aliases: ['databank', 'data-bank'],
|
aliases: ['databank', 'data-bank'],
|
||||||
helpString: 'Open the data bank',
|
helpString: 'Open the data bank',
|
||||||
}));
|
}));
|
||||||
|
@ -8,6 +8,7 @@ import { textgen_types, textgenerationwebui_settings } from '../../textgen-setti
|
|||||||
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
||||||
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
|
import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'caption';
|
const MODULE_NAME = 'caption';
|
||||||
@ -445,11 +446,14 @@ jQuery(async function () {
|
|||||||
returns: 'caption',
|
returns: 'caption',
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'quiet', 'suppress sending a captioned message', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ['true', 'false'],
|
'quiet', 'suppress sending a captioned message', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
|
||||||
),
|
|
||||||
new SlashCommandNamedArgument(
|
|
||||||
'id', 'get image from a message with this ID', [ARGUMENT_TYPE.NUMBER], false, false,
|
|
||||||
),
|
),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'id',
|
||||||
|
description: 'get image from a message with this ID',
|
||||||
|
typeList: [ARGUMENT_TYPE.NUMBER],
|
||||||
|
enumProvider: () => getContext().chat.map((_, i) => new SlashCommandEnumValue(String(i), null, 'number', '1️⃣')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
|
@ -11,6 +11,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
|||||||
import { ARGUMENT_TYPE, SlashCommandArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
import { isFunctionCallingSupported } from '../../openai.js';
|
import { isFunctionCallingSupported } from '../../openai.js';
|
||||||
import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
||||||
|
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'expressions';
|
const MODULE_NAME = 'expressions';
|
||||||
@ -2080,9 +2081,12 @@ function migrateSettings() {
|
|||||||
callback: (_, value) => lastExpression[String(value).trim()] ?? '',
|
callback: (_, value) => lastExpression[String(value).trim()] ?? '',
|
||||||
returns: 'sprite',
|
returns: 'sprite',
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'charName', [ARGUMENT_TYPE.STRING], true,
|
description: 'character name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: commonEnumProviders.charName(),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Returns the last set sprite / expression for the named character.',
|
helpString: 'Returns the last set sprite / expression for the named character.',
|
||||||
}));
|
}));
|
||||||
|
@ -11,6 +11,7 @@ import { dragElement } from '../../RossAscends-mods.js';
|
|||||||
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
||||||
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
||||||
import { ARGUMENT_TYPE, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
|
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
|
|
||||||
const extensionName = 'gallery';
|
const extensionName = 'gallery';
|
||||||
const extensionFolderPath = `scripts/extensions/${extensionName}/`;
|
const extensionFolderPath = `scripts/extensions/${extensionName}/`;
|
||||||
@ -419,7 +420,10 @@ function viewWithDragbox(items) {
|
|||||||
// Registers a simple command for opening the char gallery.
|
// Registers a simple command for opening the char gallery.
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'show-gallery',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'show-gallery',
|
||||||
aliases: ['sg'],
|
aliases: ['sg'],
|
||||||
callback: showGalleryCommand,
|
callback: () => {
|
||||||
|
showCharGallery();
|
||||||
|
return '';
|
||||||
|
},
|
||||||
helpString: 'Shows the gallery.',
|
helpString: 'Shows the gallery.',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'list-gallery',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'list-gallery',
|
||||||
@ -427,21 +431,22 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'list-gallery
|
|||||||
callback: listGalleryCommand,
|
callback: listGalleryCommand,
|
||||||
returns: 'list of images',
|
returns: 'list of images',
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
SlashCommandNamedArgument.fromProps({
|
||||||
'char', 'character name', [ARGUMENT_TYPE.STRING], false,
|
name: 'char',
|
||||||
),
|
description: 'character name',
|
||||||
new SlashCommandNamedArgument(
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
'group', 'group name', [ARGUMENT_TYPE.STRING], false,
|
enumProvider: commonEnumProviders.charName('character'),
|
||||||
),
|
}),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'group',
|
||||||
|
description: 'group name',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
enumProvider: commonEnumProviders.charName('group'),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'List images in the gallery of the current char / group or a specified char / group.',
|
helpString: 'List images in the gallery of the current char / group or a specified char / group.',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
function showGalleryCommand(args) {
|
|
||||||
showCharGallery();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listGalleryCommand(args) {
|
async function listGalleryCommand(args) {
|
||||||
try {
|
try {
|
||||||
let url = args.char ?? (args.group ? groups.find(it=>it.name == args.group)?.id : null) ?? (selected_group || this_chid);
|
let url = args.char ?? (args.group ? groups.find(it=>it.name == args.group)?.id : null) ?? (selected_group || this_chid);
|
||||||
|
@ -24,6 +24,7 @@ import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
|||||||
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
import { resolveVariable } from '../../variables.js';
|
import { resolveVariable } from '../../variables.js';
|
||||||
|
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = '1_memory';
|
const MODULE_NAME = '1_memory';
|
||||||
@ -919,7 +920,14 @@ jQuery(async function () {
|
|||||||
callback: summarizeCallback,
|
callback: summarizeCallback,
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument('source', 'API to use for summarization', [ARGUMENT_TYPE.STRING], false, false, '', ['main', 'extras']),
|
new SlashCommandNamedArgument('source', 'API to use for summarization', [ARGUMENT_TYPE.STRING], false, false, '', ['main', 'extras']),
|
||||||
new SlashCommandNamedArgument('prompt', 'prompt to use for summarization', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.VARIABLE_NAME], false, false, ''),
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'prompt',
|
||||||
|
description: 'prompt to use for summarization',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.VARIABLE_NAME],
|
||||||
|
defaultValue: '',
|
||||||
|
enumProvider: commonEnumProviders.variables('all'),
|
||||||
|
forceEnum: false,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''),
|
new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''),
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import { SlashCommand } from '../../../slash-commands/SlashCommand.js';
|
import { SlashCommand } from '../../../slash-commands/SlashCommand.js';
|
||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../../slash-commands/SlashCommandArgument.js';
|
||||||
|
import { SlashCommandEnumValue } from '../../../slash-commands/SlashCommandEnumValue.js';
|
||||||
import { SlashCommandParser } from '../../../slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from '../../../slash-commands/SlashCommandParser.js';
|
||||||
import { isTrueBoolean } from '../../../utils.js';
|
import { isTrueBoolean } from '../../../utils.js';
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
import { QuickReplyApi } from '../api/QuickReplyApi.js';
|
import { QuickReplyApi } from '../api/QuickReplyApi.js';
|
||||||
|
import { QuickReply } from './QuickReply.js';
|
||||||
|
import { QuickReplySet } from './QuickReplySet.js';
|
||||||
|
|
||||||
export class SlashCommandHandler {
|
export class SlashCommandHandler {
|
||||||
/**@type {QuickReplyApi}*/ api;
|
/**@type {QuickReplyApi}*/ api;
|
||||||
@ -29,86 +32,125 @@ export class SlashCommandHandler {
|
|||||||
helpString: 'Activates the specified Quick Reply',
|
helpString: 'Activates the specified Quick Reply',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qrset',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qrset',
|
||||||
callback: () => toastr.warning('The command /qrset has been deprecated. Use /qr-set, /qr-set-on, and /qr-set-off instead.'),
|
callback: () => {
|
||||||
|
toastr.warning('The command /qrset has been deprecated. Use /qr-set, /qr-set-on, and /qr-set-off instead.');
|
||||||
|
return '';
|
||||||
|
},
|
||||||
helpString: '<strong>DEPRECATED</strong> – The command /qrset has been deprecated. Use /qr-set, /qr-set-on, and /qr-set-off instead.',
|
helpString: '<strong>DEPRECATED</strong> – The command /qrset has been deprecated. Use /qr-set, /qr-set-on, and /qr-set-off instead.',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set',
|
||||||
callback: (args, value) => this.toggleGlobalSet(value, args),
|
callback: (args, value) => {
|
||||||
|
this.toggleGlobalSet(value, args);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'visible', 'set visibility', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
|
'visible', 'set visibility', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'QR set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Toggle global QR set',
|
helpString: 'Toggle global QR set',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-on',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-on',
|
||||||
callback: (args, value) => this.addGlobalSet(value, args),
|
callback: (args, value) => {
|
||||||
|
this.addGlobalSet(value, args);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'visible', 'set visibility', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
|
'visible', 'set visibility', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'QR set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Activate global QR set',
|
helpString: 'Activate global QR set',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-off',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-off',
|
||||||
callback: (_, value) => this.removeGlobalSet(value),
|
callback: (_, value) => {
|
||||||
|
this.removeGlobalSet(value);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'QR set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Deactivate global QR set',
|
helpString: 'Deactivate global QR set',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-chat-set',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-chat-set',
|
||||||
callback: (args, value) => this.toggleChatSet(value, args),
|
callback: (args, value) => {
|
||||||
|
this.toggleChatSet(value, args);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'visible', 'set visibility', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
|
'visible', 'set visibility', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'QR set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Toggle chat QR set',
|
helpString: 'Toggle chat QR set',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-chat-set-on',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-chat-set-on',
|
||||||
callback: (args, value) => this.addChatSet(value, args),
|
callback: (args, value) => {
|
||||||
|
this.addChatSet(value, args);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'visible', 'whether the QR set should be visible', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true', ['true', 'false'],
|
'visible', 'whether the QR set should be visible', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true', ['true', 'false'],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'QR set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Activate chat QR set',
|
helpString: 'Activate chat QR set',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-chat-set-off',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-chat-set-off',
|
||||||
callback: (_, value) => this.removeChatSet(value),
|
callback: (_, value) => {
|
||||||
|
this.removeChatSet(value);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'QR set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Deactivate chat QR set',
|
helpString: 'Deactivate chat QR set',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-list',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-list',
|
||||||
callback: (_, value) => this.listSets(value ?? 'all'),
|
callback: (_, value) => JSON.stringify(this.listSets(value ?? 'all')),
|
||||||
returns: 'list of QR sets',
|
returns: 'list of QR sets',
|
||||||
namedArgumentList: [],
|
namedArgumentList: [],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
@ -119,13 +161,18 @@ export class SlashCommandHandler {
|
|||||||
helpString: 'Gets a list of the names of all quick reply sets.',
|
helpString: 'Gets a list of the names of all quick reply sets.',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-list',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-list',
|
||||||
callback: (_, value) => this.listQuickReplies(value),
|
callback: (_, value) => {
|
||||||
|
return JSON.stringify(this.listQuickReplies(value));
|
||||||
|
},
|
||||||
returns: 'list of QRs',
|
returns: 'list of QRs',
|
||||||
namedArgumentList: [],
|
namedArgumentList: [],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'set name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Gets a list of the names of all quick replies in this quick reply set.',
|
helpString: 'Gets a list of the names of all quick replies in this quick reply set.',
|
||||||
}));
|
}));
|
||||||
@ -144,8 +191,12 @@ export class SlashCommandHandler {
|
|||||||
const qrUpdateArgs = [
|
const qrUpdateArgs = [
|
||||||
new SlashCommandNamedArgument('newlabel', 'new text for the button', [ARGUMENT_TYPE.STRING], false),
|
new SlashCommandNamedArgument('newlabel', 'new text for the button', [ARGUMENT_TYPE.STRING], false),
|
||||||
];
|
];
|
||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-create',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-create',
|
||||||
callback: (args, message) => this.createQuickReply(args, message),
|
callback: (args, message) => {
|
||||||
|
this.createQuickReply(args, message);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: qrArgs,
|
namedArgumentList: qrArgs,
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
@ -165,9 +216,15 @@ export class SlashCommandHandler {
|
|||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-update',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-update',
|
||||||
callback: (args, message) => this.updateQuickReply(args, message),
|
callback: (args, message) => {
|
||||||
|
this.updateQuickReply(args, message);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
returns: 'updated quick reply',
|
returns: 'updated quick reply',
|
||||||
namedArgumentList: [...qrUpdateArgs, ...qrArgs],
|
namedArgumentList: [...qrUpdateArgs, ...qrArgs],
|
||||||
|
unnamedArgumentList: [
|
||||||
|
new SlashCommandArgument('message', [ARGUMENT_TYPE.STRING]),
|
||||||
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
Updates Quick Reply.
|
Updates Quick Reply.
|
||||||
@ -183,34 +240,57 @@ export class SlashCommandHandler {
|
|||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-delete',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-delete',
|
||||||
callback: (args, name) => this.deleteQuickReply(args, name),
|
callback: (args, name) => {
|
||||||
|
this.deleteQuickReply(args, name);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
SlashCommandNamedArgument.fromProps({
|
||||||
'set', 'Quick Reply set', [ARGUMENT_TYPE.STRING], true,
|
name: 'set',
|
||||||
),
|
description: 'QR set name',
|
||||||
new SlashCommandNamedArgument(
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
'label', 'Quick Reply label', [ARGUMENT_TYPE.STRING], false,
|
isRequired: true,
|
||||||
),
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'label',
|
||||||
|
description: 'Quick Reply label',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
enumProvider: (executor) => QuickReplySet.get(String(executor.namedArgumentList.find(x => x.name == 'set')?.value))?.qrList.map(x => new SlashCommandEnumValue(x.label, null, 'qr-entry')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'Deletes a Quick Reply from the specified set. If no label is provided, the entire set is deleted.',
|
helpString: 'Deletes a Quick Reply from the specified set. If no label is provided, the entire set is deleted.',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-contextadd',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-contextadd',
|
||||||
callback: (args, name) => this.createContextItem(args, name),
|
callback: (args, name) => {
|
||||||
|
this.createContextItem(args, name);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
SlashCommandNamedArgument.fromProps({
|
||||||
'set', 'string', [ARGUMENT_TYPE.STRING], true,
|
name: 'set',
|
||||||
),
|
description: 'QR set name',
|
||||||
new SlashCommandNamedArgument(
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
'label', 'string', [ARGUMENT_TYPE.STRING], true,
|
isRequired: true,
|
||||||
),
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'label',
|
||||||
|
description: 'Quick Reply label',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
enumProvider: (executor) => QuickReplySet.get(String(executor.namedArgumentList.find(x => x.name == 'set')?.value))?.qrList.map(x => new SlashCommandEnumValue(x.label, null, 'qr-entry')),
|
||||||
|
}),
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'chain', 'boolean', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
|
'chain', 'boolean', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'preset name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
@ -227,19 +307,32 @@ export class SlashCommandHandler {
|
|||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-contextdel',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-contextdel',
|
||||||
callback: (args, name) => this.deleteContextItem(args, name),
|
callback: (args, name) => {
|
||||||
|
this.deleteContextItem(args, name);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
SlashCommandNamedArgument.fromProps({
|
||||||
'set', 'string', [ARGUMENT_TYPE.STRING], true,
|
name: 'set',
|
||||||
),
|
description: 'QR set name',
|
||||||
new SlashCommandNamedArgument(
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
'label', 'string', [ARGUMENT_TYPE.STRING], true,
|
isRequired: true,
|
||||||
),
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'label',
|
||||||
|
description: 'Quick Reply label',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
enumProvider: (executor) => QuickReplySet.get(String(executor.namedArgumentList.find(x => x.name == 'set')?.value))?.qrList.map(x => new SlashCommandEnumValue(x.label, null, 'qr-entry')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'preset name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
@ -256,16 +349,25 @@ export class SlashCommandHandler {
|
|||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-contextclear',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-contextclear',
|
||||||
callback: (args, label) => this.clearContextMenu(args, label),
|
callback: (args, label) => {
|
||||||
|
this.clearContextMenu(args, label);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
SlashCommandNamedArgument.fromProps({
|
||||||
'set', 'context menu preset name', [ARGUMENT_TYPE.STRING], true,
|
name: 'set',
|
||||||
),
|
description: 'QR set name',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'label', [ARGUMENT_TYPE.STRING], true,
|
description: 'Quick Reply label',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
enumProvider: (executor) => QuickReplySet.get(String(executor.namedArgumentList.find(x => x.name == 'set')?.value))?.qrList.map(x => new SlashCommandEnumValue(x.label, null, 'qr-entry')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
@ -288,13 +390,19 @@ export class SlashCommandHandler {
|
|||||||
new SlashCommandNamedArgument('inject', 'inject user input automatically (if disabled use {{input}})', [ARGUMENT_TYPE.BOOLEAN], false),
|
new SlashCommandNamedArgument('inject', 'inject user input automatically (if disabled use {{input}})', [ARGUMENT_TYPE.BOOLEAN], false),
|
||||||
];
|
];
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-create',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-create',
|
||||||
callback: (args, name) => this.createSet(name, args),
|
callback: (args, name) => {
|
||||||
|
this.createSet(name, args);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
aliases: ['qr-presetadd'],
|
aliases: ['qr-presetadd'],
|
||||||
namedArgumentList: presetArgs,
|
namedArgumentList: presetArgs,
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'name', [ARGUMENT_TYPE.STRING], true,
|
description: 'QR set name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
@ -312,11 +420,19 @@ export class SlashCommandHandler {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-update',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-update',
|
||||||
callback: (args, name) => this.updateSet(name, args),
|
callback: (args, name) => {
|
||||||
|
this.updateSet(name, args);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
aliases: ['qr-presetupdate'],
|
aliases: ['qr-presetupdate'],
|
||||||
namedArgumentList: presetArgs,
|
namedArgumentList: presetArgs,
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument('name', [ARGUMENT_TYPE.STRING], true),
|
SlashCommandArgument.fromProps({
|
||||||
|
description: 'QR set name',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
@ -329,10 +445,18 @@ export class SlashCommandHandler {
|
|||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-delete',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'qr-set-delete',
|
||||||
callback: (args, name) => this.deleteSet(name),
|
callback: (_, name) => {
|
||||||
|
this.deleteSet(name);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
aliases: ['qr-presetdelete'],
|
aliases: ['qr-presetdelete'],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument('name', [ARGUMENT_TYPE.STRING], true),
|
SlashCommandArgument.fromProps({
|
||||||
|
description: 'QR set name',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => QuickReplySet.list.map(qrSet => new SlashCommandEnumValue(qrSet.name, null, 'qr-set', 'QR')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
@ -468,7 +592,7 @@ export class SlashCommandHandler {
|
|||||||
}
|
}
|
||||||
deleteQuickReply(args, label) {
|
deleteQuickReply(args, label) {
|
||||||
try {
|
try {
|
||||||
this.api.deleteQuickReply(args.set, label);
|
this.api.deleteQuickReply(args.set, args.label ?? label);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
toastr.error(ex.message);
|
toastr.error(ex.message);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ function getRegexedString(rawString, placement, { characterOverride, isMarkdown,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the provided regex script on the given string
|
* Runs the provided regex script on the given string
|
||||||
* @param {object} regexScript The regex script to run
|
* @param {import('./index.js').RegexScript} regexScript The regex script to run
|
||||||
* @param {string} rawString The string to run the regex script on
|
* @param {string} rawString The string to run the regex script on
|
||||||
* @param {RegexScriptParams} params The parameters to use for the regex script
|
* @param {RegexScriptParams} params The parameters to use for the regex script
|
||||||
* @returns {string} The new string
|
* @returns {string} The new string
|
||||||
|
@ -3,11 +3,31 @@ import { extension_settings, renderExtensionTemplateAsync, writeExtensionField }
|
|||||||
import { selected_group } from '../../group-chats.js';
|
import { selected_group } from '../../group-chats.js';
|
||||||
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
|
import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
||||||
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
||||||
import { download, getFileText, getSortableDelay, uuidv4 } from '../../utils.js';
|
import { download, getFileText, getSortableDelay, uuidv4 } from '../../utils.js';
|
||||||
import { resolveVariable } from '../../variables.js';
|
import { resolveVariable } from '../../variables.js';
|
||||||
import { regex_placement, runRegexScript } from './engine.js';
|
import { regex_placement, runRegexScript } from './engine.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RegexScript
|
||||||
|
* @property {string} scriptName - The name of the script
|
||||||
|
* @property {boolean} disabled - Whether the script is disabled
|
||||||
|
* @property {string} replaceString - The replace string
|
||||||
|
* @property {string[]} trimStrings - The trim strings
|
||||||
|
* @property {string?} findRegex - The find regex
|
||||||
|
* @property {string?} substituteRegex - The substitute regex
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the list of regex scripts by combining the scripts from the extension settings and the character data
|
||||||
|
*
|
||||||
|
* @return {RegexScript[]} An array of regex scripts, where each script is an object containing the necessary information.
|
||||||
|
*/
|
||||||
|
export function getRegexScripts() {
|
||||||
|
return [...(extension_settings.regex ?? []), ...(characters[this_chid]?.data?.extensions?.regex_scripts ?? [])];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a regex script to the extension settings or character data.
|
* Saves a regex script to the extension settings or character data.
|
||||||
* @param {import('../../char-data.js').RegexScriptData} regexScript
|
* @param {import('../../char-data.js').RegexScriptData} regexScript
|
||||||
@ -339,7 +359,7 @@ function runRegexCallback(args, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scriptName = String(resolveVariable(args.name));
|
const scriptName = String(resolveVariable(args.name));
|
||||||
const scripts = [...(extension_settings.regex ?? []), ...(characters[this_chid]?.data?.extensions?.regex_scripts ?? [])];
|
const scripts = getRegexScripts();
|
||||||
|
|
||||||
for (const script of scripts) {
|
for (const script of scripts) {
|
||||||
if (String(script.scriptName).toLowerCase() === String(scriptName).toLowerCase()) {
|
if (String(script.scriptName).toLowerCase() === String(scriptName).toLowerCase()) {
|
||||||
@ -556,9 +576,13 @@ jQuery(async () => {
|
|||||||
callback: runRegexCallback,
|
callback: runRegexCallback,
|
||||||
returns: 'replaced text',
|
returns: 'replaced text',
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
SlashCommandNamedArgument.fromProps({
|
||||||
'name', 'script name', [ARGUMENT_TYPE.STRING], true,
|
name: 'name',
|
||||||
),
|
description: 'script name',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.VARIABLE_NAME],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => getRegexScripts().map(script => new SlashCommandEnumValue(script.scriptName, null, 'regex', '🔍')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
|
@ -31,6 +31,8 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
|||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
import { resolveVariable } from '../../variables.js';
|
import { resolveVariable } from '../../variables.js';
|
||||||
import { debounce_timeout } from '../../constants.js';
|
import { debounce_timeout } from '../../constants.js';
|
||||||
|
import { commonEnumProviders, getEnumBooleanValues } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
|
import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'sd';
|
const MODULE_NAME = 'sd';
|
||||||
@ -3335,11 +3337,14 @@ jQuery(async () => {
|
|||||||
aliases: ['sd', 'img', 'image'],
|
aliases: ['sd', 'img', 'image'],
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'quiet', 'whether to post the generated image to chat', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ['false', 'true'],
|
'quiet', 'whether to post the generated image to chat', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
|
||||||
),
|
|
||||||
new SlashCommandNamedArgument(
|
|
||||||
'negative', 'negative prompt prefix', [ARGUMENT_TYPE.STRING], false, false, '',
|
|
||||||
),
|
),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'negative',
|
||||||
|
description: 'negative prompt prefix',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.VARIABLE_NAME],
|
||||||
|
enumProvider: () => [...getEnumBooleanValues(), ...commonEnumProviders.variables('all')()],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
@ -3361,9 +3366,12 @@ jQuery(async () => {
|
|||||||
callback: changeComfyWorkflow,
|
callback: changeComfyWorkflow,
|
||||||
aliases: ['icw'],
|
aliases: ['icw'],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
SlashCommandArgument.fromProps({
|
||||||
'workflowName', [ARGUMENT_TYPE.STRING], true,
|
description: 'workflow name',
|
||||||
),
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
isRequired: true,
|
||||||
|
enumProvider: () => Array.from(document.querySelectorAll('#sd_comfy_workflow > [value]')).map(x => x.getAttribute('value')).map(x => new SlashCommandEnumValue(x, null, 'workflow', 'W')),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
helpString: '(workflowName) - change the workflow to be used for image generation with ComfyUI, e.g. <pre><code>/imagine-comfy-workflow MyWorkflow</code></pre>',
|
helpString: '(workflowName) - change the workflow to be used for image generation with ComfyUI, e.g. <pre><code>/imagine-comfy-workflow MyWorkflow</code></pre>',
|
||||||
}));
|
}));
|
||||||
|
@ -123,6 +123,7 @@ async function doCount() {
|
|||||||
//toastr success with the token count of the chat
|
//toastr success with the token count of the chat
|
||||||
const count = await getTokenCountAsync(allMessages);
|
const count = await getTokenCountAsync(allMessages);
|
||||||
toastr.success(`Token count: ${count}`);
|
toastr.success(`Token count: ${count}`);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery(() => {
|
jQuery(() => {
|
||||||
@ -134,7 +135,7 @@ jQuery(() => {
|
|||||||
$('#extensionsMenu').prepend(buttonHtml);
|
$('#extensionsMenu').prepend(buttonHtml);
|
||||||
$('#token_counter').on('click', doTokenCounter);
|
$('#token_counter').on('click', doTokenCounter);
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'count',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'count',
|
||||||
callback: doCount,
|
callback: async () => String(await doCount()),
|
||||||
returns: 'number of tokens',
|
returns: 'number of tokens',
|
||||||
helpString: 'Counts the number of tokens in the current chat.',
|
helpString: 'Counts the number of tokens in the current chat.',
|
||||||
}));
|
}));
|
||||||
|
@ -1102,7 +1102,10 @@ $(document).ready(function () {
|
|||||||
eventSource.makeLast(event_types.CHARACTER_MESSAGE_RENDERED, onMessageEvent);
|
eventSource.makeLast(event_types.CHARACTER_MESSAGE_RENDERED, onMessageEvent);
|
||||||
eventSource.makeLast(event_types.USER_MESSAGE_RENDERED, onMessageEvent);
|
eventSource.makeLast(event_types.USER_MESSAGE_RENDERED, onMessageEvent);
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'speak',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'speak',
|
||||||
callback: onNarrateText,
|
callback: () => {
|
||||||
|
onNarrateText();
|
||||||
|
return '';
|
||||||
|
},
|
||||||
aliases: ['narrate', 'tts'],
|
aliases: ['narrate', 'tts'],
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
|
@ -199,16 +199,18 @@ const custom_prompt_post_processing_types = {
|
|||||||
CLAUDE: 'claude',
|
CLAUDE: 'claude',
|
||||||
};
|
};
|
||||||
|
|
||||||
const prefixMap = selected_group ? {
|
function getPrefixMap() {
|
||||||
|
return selected_group ? {
|
||||||
assistant: '',
|
assistant: '',
|
||||||
user: '',
|
user: '',
|
||||||
system: 'OOC: ',
|
system: 'OOC: ',
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
assistant: '{{char}}:',
|
assistant: '{{char}}:',
|
||||||
user: '{{user}}:',
|
user: '{{user}}:',
|
||||||
system: '',
|
system: '',
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const default_settings = {
|
const default_settings = {
|
||||||
preset_settings_openai: 'Default',
|
preset_settings_openai: 'Default',
|
||||||
@ -1709,7 +1711,7 @@ async function sendOpenAIRequest(type, messages, signal) {
|
|||||||
|
|
||||||
if (isAI21) {
|
if (isAI21) {
|
||||||
const joinedMsgs = messages.reduce((acc, obj) => {
|
const joinedMsgs = messages.reduce((acc, obj) => {
|
||||||
const prefix = prefixMap[obj.role];
|
const prefix = getPrefixMap()[obj.role];
|
||||||
return acc + (prefix ? (selected_group ? '\n' : prefix + ' ') : '') + obj.content + '\n';
|
return acc + (prefix ? (selected_group ? '\n' : prefix + ' ') : '') + obj.content + '\n';
|
||||||
}, '');
|
}, '');
|
||||||
messages = substituteParams(joinedMsgs) + (isImpersonate ? `${name1}:` : `${name2}:`);
|
messages = substituteParams(joinedMsgs) + (isImpersonate ? `${name1}:` : `${name2}:`);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { SlashCommandClosure } from './SlashCommandClosure.js';
|
import { SlashCommandClosure } from './SlashCommandClosure.js';
|
||||||
|
import { getEnumBooleanValues, getEnumIconByValueType } from './SlashCommandCommonEnumsProvider.js';
|
||||||
import { SlashCommandEnumValue } from './SlashCommandEnumValue.js';
|
import { SlashCommandEnumValue } from './SlashCommandEnumValue.js';
|
||||||
import { SlashCommandExecutor } from './SlashCommandExecutor.js';
|
import { SlashCommandExecutor } from './SlashCommandExecutor.js';
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ export class SlashCommandArgument {
|
|||||||
this.forceEnum = forceEnum;
|
this.forceEnum = forceEnum;
|
||||||
|
|
||||||
// If no enums were set explictly and the type is one where we know possible enum values, we set them here
|
// If no enums were set explictly and the type is one where we know possible enum values, we set them here
|
||||||
if (!this.enumList.length && types == ARGUMENT_TYPE.BOOLEAN) this.enumList = [new SlashCommandEnumValue('true'), new SlashCommandEnumValue('false')];
|
if (!this.enumList.length && types == ARGUMENT_TYPE.BOOLEAN) this.enumList = getEnumBooleanValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,22 +30,27 @@ export const commonEnumProviders = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All possible character and group names
|
* All possible char entities, like characters and groups. Can be filtered down to just one type.
|
||||||
*
|
*
|
||||||
* @returns {SlashCommandEnumValue[]}
|
* @param {('all' | 'character' | 'group')?} [mode='all'] - Which type to return
|
||||||
|
* @returns {() => SlashCommandEnumValue[]}
|
||||||
*/
|
*/
|
||||||
charName: () => [
|
charName: (mode) => () => {
|
||||||
...characters.map(it => new SlashCommandEnumValue(it.name, null, 'qr', 'C')),
|
mode = mode ?? 'all';
|
||||||
...groups.map(it => new SlashCommandEnumValue(it.name, null, 'variable', 'G')),
|
return [
|
||||||
],
|
...['all', 'character'].includes(mode) ? characters.map(it => new SlashCommandEnumValue(it.name, null, 'qr', 'C')) : [],
|
||||||
|
...['all', 'group'].includes(mode) ? groups.map(it => new SlashCommandEnumValue(it.name, null, 'variable', 'G')) : [],
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All possible tags for a given char/group entity
|
* All possible tags for a given char/group entity
|
||||||
*
|
*
|
||||||
* @param {'all' | 'existing' | 'not-existing'} mode - Which types of tags to show
|
* @param {('all' | 'existing' | 'not-existing')?} [mode='all'] - Which types of tags to show
|
||||||
* @returns {() => SlashCommandEnumValue[]}
|
* @returns {() => SlashCommandEnumValue[]}
|
||||||
*/
|
*/
|
||||||
tagsForChar: (mode) => (/** @type {SlashCommandExecutor} */ executor) => {
|
tagsForChar: (mode) => (/** @type {SlashCommandExecutor} */ executor) => {
|
||||||
|
mode = mode ?? 'all';
|
||||||
// Try to see if we can find the char during execution to filter down the tags list some more. Otherwise take all tags.
|
// Try to see if we can find the char during execution to filter down the tags list some more. Otherwise take all tags.
|
||||||
const key = searchCharByName(substituteParams(/**@type {string?}*/(executor.namedArgumentList.find(it => it.name == 'name')?.value)), { suppressLogging: true });
|
const key = searchCharByName(substituteParams(/**@type {string?}*/(executor.namedArgumentList.find(it => it.name == 'name')?.value)), { suppressLogging: true });
|
||||||
const assigned = key ? getTagsList(key) : [];
|
const assigned = key ? getTagsList(key) : [];
|
||||||
@ -61,6 +66,14 @@ export const commonEnumProviders = {
|
|||||||
worlds: () => $('#world_info').children().toArray().map(x => new SlashCommandEnumValue(x.textContent)),
|
worlds: () => $('#world_info').children().toArray().map(x => new SlashCommandEnumValue(x.textContent)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the enum values for boolean type, with class and icon
|
||||||
|
*
|
||||||
|
* @return {Array<SlashCommandEnumValue>} An array of SlashCommandEnumValue objects representing the boolean values 'true' and 'false'.
|
||||||
|
*/
|
||||||
|
export function getEnumBooleanValues() {
|
||||||
|
return [new SlashCommandEnumValue('true', null, 'boolean', getEnumIconByValueType('boolean')), new SlashCommandEnumValue('false', null, 'boolean', getEnumIconByValueType('boolean'))];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the unicode icon for the given enum value type
|
* Get the unicode icon for the given enum value type
|
||||||
|
@ -1607,7 +1607,7 @@ function registerTagsSlashCommands() {
|
|||||||
description: 'Character name',
|
description: 'Character name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.charName,
|
enumProvider: commonEnumProviders.charName(),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
@ -1652,7 +1652,7 @@ function registerTagsSlashCommands() {
|
|||||||
description: 'Character name',
|
description: 'Character name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.charName,
|
enumProvider: commonEnumProviders.charName(),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
@ -1695,7 +1695,7 @@ function registerTagsSlashCommands() {
|
|||||||
description: 'Character name',
|
description: 'Character name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.charName,
|
enumProvider: commonEnumProviders.charName(),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
@ -1738,7 +1738,7 @@ function registerTagsSlashCommands() {
|
|||||||
description: 'Character name',
|
description: 'Character name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '{{char}}',
|
defaultValue: '{{char}}',
|
||||||
enumProvider: commonEnumProviders.charName,
|
enumProvider: commonEnumProviders.charName(),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
|
Reference in New Issue
Block a user