From 1de96ce11f0cc1982fb6acce66810842d2df736e Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Mon, 24 Jun 2024 08:42:33 -0400 Subject: [PATCH] add /break support in /times and /while --- public/scripts/variables.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/scripts/variables.js b/public/scripts/variables.js index c149ca504..90814da70 100644 --- a/public/scripts/variables.js +++ b/public/scripts/variables.js @@ -4,6 +4,7 @@ import { executeSlashCommandsWithOptions } from './slash-commands.js'; import { SlashCommand } from './slash-commands/SlashCommand.js'; import { SlashCommandAbortController } from './slash-commands/SlashCommandAbortController.js'; import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; +import { SlashCommandBreakController } from './slash-commands/SlashCommandBreakController.js'; import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js'; import { SlashCommandClosureResult } from './slash-commands/SlashCommandClosureResult.js'; import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js'; @@ -348,11 +349,13 @@ async function whileCallback(args, value) { if (result && command) { if (command instanceof SlashCommandClosure) { + command.breakController = new SlashCommandBreakController(); commandResult = await command.execute(); } else { commandResult = await executeSubCommands(command, args._scope, args._parserFlags, args._abortController); } if (commandResult.isAborted) break; + if (commandResult.isBreak) break; } else { break; } @@ -390,8 +393,8 @@ async function timesCallback(args, value) { const iterations = Math.min(Number(repeats), isGuardOff ? Number.MAX_SAFE_INTEGER : MAX_LOOPS); let result; for (let i = 0; i < iterations; i++) { - /**@type {SlashCommandClosureResult}*/ if (command instanceof SlashCommandClosure) { + command.breakController = new SlashCommandBreakController(); command.scope.setMacro('timesIndex', i); result = await command.execute(); } @@ -399,6 +402,7 @@ async function timesCallback(args, value) { result = await executeSubCommands(command.replace(/\{\{timesIndex\}\}/g, i.toString()), args._scope, args._parserFlags, args._abortController); } if (result.isAborted) break; + if (result.isBreak) break; } return result?.pipe ?? '';