diff --git a/public/scripts/popup.js b/public/scripts/popup.js index 7315fd536..1a9d9ce36 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -92,7 +92,7 @@ const showPopupHelper = { * @param {string?} header - The header text for the popup. * @param {string?} text - The main text for the popup. * @param {PopupOptions} [popupOptions={}] - Options for the popup. - * @return {Promise} A Promise that resolves with the result of the user's interaction. + * @return {Promise} A Promise that resolves with the result of the user's interaction. */ confirm: async (header, text, popupOptions = {}) => { const content = PopupUtils.BuildTextWithHeader(header, text); @@ -107,7 +107,7 @@ const showPopupHelper = { * @param {string?} header - The header text for the popup. * @param {string?} text - The main text for the popup. * @param {PopupOptions} [popupOptions={}] - Options for the popup. - * @return {Promise} A Promise that resolves with the result of the user's interaction. + * @return {Promise} A Promise that resolves with the result of the user's interaction. */ text: async (header, text, popupOptions = {}) => { const content = PopupUtils.BuildTextWithHeader(header, text); diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index ecc2b2259..444639760 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1267,20 +1267,59 @@ export function initDefaultSlashCommands() { callback: popupCallback, returns: 'popup text', namedArgumentList: [ - new SlashCommandNamedArgument( - 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false, - ), + SlashCommandNamedArgument.fromProps({ + name: 'large', + description: 'show large popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', + }), + SlashCommandNamedArgument.fromProps({ + name: 'wide', + description: 'show wide popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', + }), + SlashCommandNamedArgument.fromProps({ + name: 'wider', + description: 'show wider popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', + }), + SlashCommandNamedArgument.fromProps({ + name: 'transparent', + description: 'show transparent popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', + }), + SlashCommandNamedArgument.fromProps({ + name: 'okButton', + description: 'text for the OK button', + typeList: [ARGUMENT_TYPE.STRING], + defaultValue: 'OK', + }), + SlashCommandNamedArgument.fromProps({ + name: 'cancelButton', + description: 'text for the Cancel button', + 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 cancel button, empty string for exiting out.', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', + }), ], unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), + SlashCommandArgument.fromProps({ + description: 'popup text', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + }), ], helpString: `
@@ -1291,7 +1330,10 @@ export function initDefaultSlashCommands() { Example:
  • -
    /popup large=on wide=on okButton="Submit" Enter some text:
    +
    /popup large=on wide=on okButton="Confirm" Please confirm this action.
    +
  • +
  • +
    /popup okButton="Left" cancelButton="Right" result=true Do you want to go left or right? | /echo 0 means right, 1 means left. Choice: {{pipe}}
@@ -1882,16 +1924,21 @@ async function buttonsCallback(args, text) { } async function popupCallback(args, value) { - const safeValue = DOMPurify.sanitize(value || ''); + const safeBody = DOMPurify.sanitize(value || ''); + const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null; + const requestedResult = isTrueBoolean(args?.result); + + /** @type {import('./popup.js').PopupOptions} */ const popupOptions = { large: isTrueBoolean(args?.large), wide: isTrueBoolean(args?.wide), + wider: isTrueBoolean(args?.wider), + transparent: isTrueBoolean(args?.transparent), okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok', + cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null, }; - await delay(1); - await callGenericPopup(safeValue, POPUP_TYPE.TEXT, '', popupOptions); - await delay(1); - return String(value); + const result = await Popup.show.text(safeHeader, safeBody, popupOptions); + return String(requestedResult ? result ?? '' : value); } async function getMessagesCallback(args, value) {