Refactor /classify-expressions, deprecating...
- Update /classify-expressions, deprecating the old "format" - Fix some oversights
This commit is contained in:
parent
697b3b2034
commit
7a1b43eb89
|
@ -12,6 +12,8 @@ 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 { slashCommandReturnHelper } from '../../slash-commands/SlashCommandReturnHelper.js';
|
||||||
|
import { SlashCommandClosure } from '../../slash-commands/SlashCommandClosure.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'expressions';
|
const MODULE_NAME = 'expressions';
|
||||||
|
@ -2128,18 +2130,42 @@ function migrateSettings() {
|
||||||
name: 'classify-expressions',
|
name: 'classify-expressions',
|
||||||
aliases: ['expressions'],
|
aliases: ['expressions'],
|
||||||
callback: async (args) => {
|
callback: async (args) => {
|
||||||
const list = await getExpressionsList();
|
/** @type {import('../../slash-commands/SlashCommandReturnHelper.js').SlashCommandReturnType} */
|
||||||
switch (String(args.format).toLowerCase()) {
|
// @ts-ignore
|
||||||
case 'json':
|
let returnType = args.return;
|
||||||
return JSON.stringify(list);
|
|
||||||
default:
|
// Old legacy return type handling
|
||||||
return list.join(', ');
|
if (args.format) {
|
||||||
|
toastr.warning(`Legacy argument 'format' with value '${args.format}' is deprecated. Please use 'return' instead. Routing to the correct return type...`, 'Deprecation warning');
|
||||||
|
const type = String(args?.format).toLowerCase().trim();
|
||||||
|
switch (type) {
|
||||||
|
case 'json':
|
||||||
|
returnType = 'object';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
returnType = 'pipe';
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now the actual new return type handling
|
||||||
|
const list = await getExpressionsList();
|
||||||
|
|
||||||
|
return await slashCommandReturnHelper.doReturn(returnType ?? 'pipe', list, { objectToStringFunc: list => list.join(', ') });
|
||||||
},
|
},
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'return',
|
||||||
|
description: 'The way how you want the return value to be provided',
|
||||||
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
|
defaultValue: 'pipe',
|
||||||
|
enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
|
||||||
|
forceEnum: true,
|
||||||
|
}),
|
||||||
|
// TODO remove some day
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'format',
|
name: 'format',
|
||||||
description: 'The format to return the list in: comma-separated plain text or JSON array. Default is plain text.',
|
description: '!!! DEPRECATED - use "return" instead !!! The format to return the list in: comma-separated plain text or JSON array. Default is plain text.',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
enumList: [
|
enumList: [
|
||||||
new SlashCommandEnumValue('plain', null, enumTypes.enum, ', '),
|
new SlashCommandEnumValue('plain', null, enumTypes.enum, ', '),
|
||||||
|
|
|
@ -1538,7 +1538,7 @@ export function initDefaultSlashCommands() {
|
||||||
// TODO remove some day
|
// TODO remove some day
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'format',
|
name: 'format',
|
||||||
description: '!!! DEPRECATED - use "return" instead !!! output format)',
|
description: '!!! DEPRECATED - use "return" instead !!! output format',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
forceEnum: true,
|
forceEnum: true,
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const slashCommandReturnHelper = {
|
||||||
*/
|
*/
|
||||||
enumList: ({ allowPipe = true, allowObject = false, allowChat = false, allowPopup = false, allowTextVersion = true } = {}) => [
|
enumList: ({ allowPipe = true, allowObject = false, allowChat = false, allowPopup = false, allowTextVersion = true } = {}) => [
|
||||||
allowPipe && new SlashCommandEnumValue('pipe', 'Return to the pipe for the next command', enumTypes.name, '|'),
|
allowPipe && new SlashCommandEnumValue('pipe', 'Return to the pipe for the next command', enumTypes.name, '|'),
|
||||||
allowObject && new SlashCommandEnumValue('object', 'Return as an object to the pipe for the next command', enumTypes.variable, enumIcons.dictionary),
|
allowObject && new SlashCommandEnumValue('object', 'Return as an object (or array) to the pipe for the next command', enumTypes.variable, enumIcons.dictionary),
|
||||||
allowChat && new SlashCommandEnumValue('chat-html', 'Sending a chat message with the return value - Can display HTML', enumTypes.command, enumIcons.message),
|
allowChat && new SlashCommandEnumValue('chat-html', 'Sending a chat message with the return value - Can display HTML', enumTypes.command, enumIcons.message),
|
||||||
allowChat && allowTextVersion && new SlashCommandEnumValue('chat-text', 'Sending a chat message with the return value - Will only display as text', enumTypes.qr, enumIcons.message),
|
allowChat && allowTextVersion && new SlashCommandEnumValue('chat-text', 'Sending a chat message with the return value - Will only display as text', enumTypes.qr, enumIcons.message),
|
||||||
allowPopup && new SlashCommandEnumValue('popup-html', 'Showing as a popup with the return value - Can display HTML', enumTypes.command, enumIcons.popup),
|
allowPopup && new SlashCommandEnumValue('popup-html', 'Showing as a popup with the return value - Can display HTML', enumTypes.command, enumIcons.popup),
|
||||||
|
|
|
@ -951,7 +951,7 @@ export function registerVariableCommands() {
|
||||||
// TODO remove some day
|
// TODO remove some day
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'format',
|
name: 'format',
|
||||||
description: '!!! DEPRECATED - use "return" instead !!! output format)',
|
description: '!!! DEPRECATED - use "return" instead !!! output format',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
forceEnum: true,
|
forceEnum: true,
|
||||||
|
|
Loading…
Reference in New Issue