mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Update return types as optional via named arg
- Update the modified slash commands for chat sending to use the named arg - Add `slashCommandReturnHelper` for shared funcitonality on return type usage
This commit is contained in:
@ -71,6 +71,7 @@ import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCom
|
||||
import { SlashCommandDebugController } from './slash-commands/SlashCommandDebugController.js';
|
||||
import { SlashCommandBreakController } from './slash-commands/SlashCommandBreakController.js';
|
||||
import { SlashCommandExecutionError } from './slash-commands/SlashCommandExecutionError.js';
|
||||
import { slashCommandReturnHelper } from './slash-commands/SlashCommandReturnHelper.js';
|
||||
export {
|
||||
executeSlashCommands, executeSlashCommandsWithOptions, getSlashCommandsHelp, registerSlashCommand,
|
||||
};
|
||||
@ -176,7 +177,7 @@ export function initDefaultSlashCommands() {
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'sendas',
|
||||
callback: sendMessageAs,
|
||||
returns: 'The text of the sent message',
|
||||
returns: 'Optionally the text of the sent message, if specified in the "return" argument',
|
||||
namedArgumentList: [
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'name',
|
||||
@ -195,6 +196,14 @@ export function initDefaultSlashCommands() {
|
||||
typeList: [ARGUMENT_TYPE.NUMBER],
|
||||
enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
|
||||
}),
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'return',
|
||||
description: 'The way how you want the return value to be provided',
|
||||
typeList: [ARGUMENT_TYPE.STRING],
|
||||
defaultValue: 'none',
|
||||
enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
|
||||
forceEnum: true,
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
new SlashCommandArgument(
|
||||
@ -223,7 +232,7 @@ export function initDefaultSlashCommands() {
|
||||
name: 'sys',
|
||||
callback: sendNarratorMessage,
|
||||
aliases: ['nar'],
|
||||
returns: 'The text of the sent message',
|
||||
returns: 'Optionally the text of the sent message, if specified in the "return" argument',
|
||||
namedArgumentList: [
|
||||
new SlashCommandNamedArgument(
|
||||
'compact',
|
||||
@ -239,6 +248,14 @@ export function initDefaultSlashCommands() {
|
||||
typeList: [ARGUMENT_TYPE.NUMBER],
|
||||
enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
|
||||
}),
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'return',
|
||||
description: 'The way how you want the return value to be provided',
|
||||
typeList: [ARGUMENT_TYPE.STRING],
|
||||
defaultValue: 'none',
|
||||
enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
|
||||
forceEnum: true,
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
new SlashCommandArgument(
|
||||
@ -278,7 +295,7 @@ export function initDefaultSlashCommands() {
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'comment',
|
||||
callback: sendCommentMessage,
|
||||
returns: 'The text of the sent message',
|
||||
returns: 'Optionally the text of the sent message, if specified in the "return" argument',
|
||||
namedArgumentList: [
|
||||
new SlashCommandNamedArgument(
|
||||
'compact',
|
||||
@ -294,6 +311,14 @@ export function initDefaultSlashCommands() {
|
||||
typeList: [ARGUMENT_TYPE.NUMBER],
|
||||
enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
|
||||
}),
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'return',
|
||||
description: 'The way how you want the return value to be provided',
|
||||
typeList: [ARGUMENT_TYPE.STRING],
|
||||
defaultValue: 'none',
|
||||
enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
|
||||
forceEnum: true,
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
new SlashCommandArgument(
|
||||
@ -3210,7 +3235,7 @@ export async function sendMessageAs(args, text) {
|
||||
await saveChatConditional();
|
||||
}
|
||||
|
||||
return message.mes;
|
||||
return await slashCommandReturnHelper.doReturn(args.return ?? 'none', message, { objectToStringFunc: x => x.mes });
|
||||
}
|
||||
|
||||
export async function sendNarratorMessage(args, text) {
|
||||
@ -3264,7 +3289,7 @@ export async function sendNarratorMessage(args, text) {
|
||||
await saveChatConditional();
|
||||
}
|
||||
|
||||
return message.mes;
|
||||
return await slashCommandReturnHelper.doReturn(args.return ?? 'none', message, { objectToStringFunc: x => x.mes });
|
||||
}
|
||||
|
||||
export async function promptQuietForLoudResponse(who, text) {
|
||||
@ -3353,7 +3378,7 @@ async function sendCommentMessage(args, text) {
|
||||
await saveChatConditional();
|
||||
}
|
||||
|
||||
return message.mes;
|
||||
return await slashCommandReturnHelper.doReturn(args.return ?? 'none', message, { objectToStringFunc: x => x.mes });
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user