mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-15 19:27:20 +02:00
Allow /popup to optionally return popup result
This commit is contained in:
parent
e4e10c3d6b
commit
a3468db94e
@ -1272,24 +1272,28 @@ export function initDefaultSlashCommands() {
|
|||||||
description: 'show large popup',
|
description: 'show large popup',
|
||||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
enumList: commonEnumProviders.boolean('onOff')(),
|
enumList: commonEnumProviders.boolean('onOff')(),
|
||||||
|
defaultValue: 'off',
|
||||||
}),
|
}),
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'wide',
|
name: 'wide',
|
||||||
description: 'show wide popup',
|
description: 'show wide popup',
|
||||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
enumList: commonEnumProviders.boolean('onOff')(),
|
enumList: commonEnumProviders.boolean('onOff')(),
|
||||||
|
defaultValue: 'off',
|
||||||
}),
|
}),
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'wider',
|
name: 'wider',
|
||||||
description: 'show wider popup',
|
description: 'show wider popup',
|
||||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
enumList: commonEnumProviders.boolean('onOff')(),
|
enumList: commonEnumProviders.boolean('onOff')(),
|
||||||
|
defaultValue: 'off',
|
||||||
}),
|
}),
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'transparent',
|
name: 'transparent',
|
||||||
description: 'show transparent popup',
|
description: 'show transparent popup',
|
||||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
enumList: commonEnumProviders.boolean('onOff')(),
|
enumList: commonEnumProviders.boolean('onOff')(),
|
||||||
|
defaultValue: 'off',
|
||||||
}),
|
}),
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
name: 'okButton',
|
name: 'okButton',
|
||||||
@ -1302,6 +1306,13 @@ export function initDefaultSlashCommands() {
|
|||||||
description: 'text for the Cancel button',
|
description: 'text for the Cancel button',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
}),
|
}),
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'result',
|
||||||
|
description: 'if enabled, returns the popup result (as an integer) instead of the popup text. Resolves to 1 for OK and 0/null for cancel or exiting out.',
|
||||||
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
|
enumList: commonEnumProviders.boolean('onOff')(),
|
||||||
|
defaultValue: 'off',
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
@ -1910,6 +1921,7 @@ async function buttonsCallback(args, text) {
|
|||||||
async function popupCallback(args, value) {
|
async function popupCallback(args, value) {
|
||||||
const safeBody = DOMPurify.sanitize(value || '');
|
const safeBody = DOMPurify.sanitize(value || '');
|
||||||
const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null;
|
const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null;
|
||||||
|
const requestedResult = isTrueBoolean(args?.result);
|
||||||
|
|
||||||
/** @type {import('./popup.js').PopupOptions} */
|
/** @type {import('./popup.js').PopupOptions} */
|
||||||
const popupOptions = {
|
const popupOptions = {
|
||||||
@ -1920,8 +1932,8 @@ async function popupCallback(args, value) {
|
|||||||
okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok',
|
okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok',
|
||||||
cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null,
|
cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null,
|
||||||
};
|
};
|
||||||
await Popup.show.text(safeHeader, safeBody, popupOptions);
|
const result = await Popup.show.text(safeHeader, safeBody, popupOptions);
|
||||||
return String(value);
|
return String(requestedResult ? result : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMessagesCallback(args, value) {
|
async function getMessagesCallback(args, value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user