use isFalseBoolean in while and times

This commit is contained in:
LenAnderson 2023-12-15 19:48:25 +00:00
parent 74d0ef5572
commit 279b731f64
1 changed files with 3 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { chat_metadata, getCurrentChatId, saveSettingsDebounced, sendSystemMessage, system_message_types } from '../script.js'; import { chat_metadata, getCurrentChatId, saveSettingsDebounced, sendSystemMessage, system_message_types } from '../script.js';
import { extension_settings, saveMetadataDebounced } from './extensions.js'; import { extension_settings, saveMetadataDebounced } from './extensions.js';
import { executeSlashCommands, registerSlashCommand } from './slash-commands.js'; import { executeSlashCommands, registerSlashCommand } from './slash-commands.js';
import { isFalseBoolean } from './utils.js';
@ -307,7 +308,7 @@ function listVariablesCallback() {
} }
async function whileCallback(args, command) { async function whileCallback(args, command) {
const isGuardOff = ['off', 'false', '0'].includes(args.guard?.toLowerCase()); const isGuardOff = isFalseBoolean(args.guard);
const iterations = isGuardOff ? Number.MAX_SAFE_INTEGER : MAX_LOOPS; const iterations = isGuardOff ? Number.MAX_SAFE_INTEGER : MAX_LOOPS;
for (let i = 0; i < iterations; i++) { for (let i = 0; i < iterations; i++) {
@ -327,7 +328,7 @@ async function whileCallback(args, command) {
async function timesCallback(args, value) { async function timesCallback(args, value) {
const [repeats, ...commandParts] = value.split(' '); const [repeats, ...commandParts] = value.split(' ');
const command = commandParts.join(' '); const command = commandParts.join(' ');
const isGuardOff = ['off', 'false', '0'].includes(args.guard?.toLowerCase()); const isGuardOff = isFalseBoolean(args.guard);
const iterations = Math.min(Number(repeats), isGuardOff ? Number.MAX_SAFE_INTEGER : MAX_LOOPS); const iterations = Math.min(Number(repeats), isGuardOff ? Number.MAX_SAFE_INTEGER : MAX_LOOPS);
for (let i = 0; i < iterations; i++) { for (let i = 0; i < iterations; i++) {