Allow /popup to optionally return popup result

a3468db94e4a06e9776b73c476d62bcd4ca00a1c

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +14 -2Showing whitespace changes
public/scripts/slash-commands.js+14 -2
@@ -1272,24 +1272,28 @@ export function initDefaultSlashCommands() {
1272 description: 'show large popup',1272 description: 'show large popup',
1273 typeList: [ARGUMENT_TYPE.BOOLEAN],1273 typeList: [ARGUMENT_TYPE.BOOLEAN],
1274 enumList: commonEnumProviders.boolean('onOff')(),1274 enumList: commonEnumProviders.boolean('onOff')(),
1275 defaultValue: 'off',
1275 }),1276 }),
1276 SlashCommandNamedArgument.fromProps({1277 SlashCommandNamedArgument.fromProps({
1277 name: 'wide',1278 name: 'wide',
1278 description: 'show wide popup',1279 description: 'show wide popup',
1279 typeList: [ARGUMENT_TYPE.BOOLEAN],1280 typeList: [ARGUMENT_TYPE.BOOLEAN],
1280 enumList: commonEnumProviders.boolean('onOff')(),1281 enumList: commonEnumProviders.boolean('onOff')(),
1282 defaultValue: 'off',
1281 }),1283 }),
1282 SlashCommandNamedArgument.fromProps({1284 SlashCommandNamedArgument.fromProps({
1283 name: 'wider',1285 name: 'wider',
1284 description: 'show wider popup',1286 description: 'show wider popup',
1285 typeList: [ARGUMENT_TYPE.BOOLEAN],1287 typeList: [ARGUMENT_TYPE.BOOLEAN],
1286 enumList: commonEnumProviders.boolean('onOff')(),1288 enumList: commonEnumProviders.boolean('onOff')(),
1289 defaultValue: 'off',
1287 }),1290 }),
1288 SlashCommandNamedArgument.fromProps({1291 SlashCommandNamedArgument.fromProps({
1289 name: 'transparent',1292 name: 'transparent',
1290 description: 'show transparent popup',1293 description: 'show transparent popup',
1291 typeList: [ARGUMENT_TYPE.BOOLEAN],1294 typeList: [ARGUMENT_TYPE.BOOLEAN],
1292 enumList: commonEnumProviders.boolean('onOff')(),1295 enumList: commonEnumProviders.boolean('onOff')(),
1296 defaultValue: 'off',
1293 }),1297 }),
1294 SlashCommandNamedArgument.fromProps({1298 SlashCommandNamedArgument.fromProps({
1295 name: 'okButton',1299 name: 'okButton',
@@ -1302,6 +1306,13 @@ export function initDefaultSlashCommands() {
1302 description: 'text for the Cancel button',1306 description: 'text for the Cancel button',
1303 typeList: [ARGUMENT_TYPE.STRING],1307 typeList: [ARGUMENT_TYPE.STRING],
1304 }),1308 }),
1309 SlashCommandNamedArgument.fromProps({
1310 name: 'result',
1311 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.',
1312 typeList: [ARGUMENT_TYPE.BOOLEAN],
1313 enumList: commonEnumProviders.boolean('onOff')(),
1314 defaultValue: 'off',
1315 }),
1305 ],1316 ],
1306 unnamedArgumentList: [1317 unnamedArgumentList: [
1307 new SlashCommandArgument(1318 new SlashCommandArgument(
@@ -1910,6 +1921,7 @@ async function buttonsCallback(args, text) {
1910async function popupCallback(args, value) {1921async function popupCallback(args, value) {
1911 const safeBody = DOMPurify.sanitize(value || '');1922 const safeBody = DOMPurify.sanitize(value || '');
1912 const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null;1923 const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null;
1924 const requestedResult = isTrueBoolean(args?.result);
19131925
1914 /** @type {import('./popup.js').PopupOptions} */1926 /** @type {import('./popup.js').PopupOptions} */
1915 const popupOptions = {1927 const popupOptions = {
@@ -1920,8 +1932,8 @@ async function popupCallback(args, value) {
1920 okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok',1932 okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok',
1921 cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null,1933 cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null,
1922 };1934 };
1923 await Popup.show.text(safeHeader, safeBody, popupOptions);1935 const result = await Popup.show.text(safeHeader, safeBody, popupOptions);
1924 return String(value);1936 return String(requestedResult ? result : value);
1925}1937}
19261938
1927async function getMessagesCallback(args, value) {1939async function getMessagesCallback(args, value) {