From 04d7324769d32fdd764bba4d47cfd5254a80fd1d Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Wed, 18 May 2022 05:12:04 -0400 Subject: [PATCH] deduplicated some code in the getModifiers func --- src/commands/roll/getModifiers.ts | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/commands/roll/getModifiers.ts b/src/commands/roll/getModifiers.ts index 0095e09..a97bed0 100644 --- a/src/commands/roll/getModifiers.ts +++ b/src/commands/roll/getModifiers.ts @@ -28,36 +28,22 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri // Check if any of the args are command flags and pull those out into the modifiers object for (let i = 0; i < args.length; i++) { log(LT.LOG, `Checking ${command}${args.join(" ")} for command modifiers ${i}`); + let defaultCase = false; switch (args[i].toLowerCase()) { case "-nd": modifiers.noDetails = true; - - args.splice(i, 1); - i--; break; case "-snd": modifiers.superNoDetails = true; - - args.splice(i, 1); - i--; break; case "-s": modifiers.spoiler = "||"; - - args.splice(i, 1); - i--; break; case "-m": modifiers.maxRoll = true; - - args.splice(i, 1); - i--; break; case "-n": modifiers.nominalRoll = true; - - args.splice(i, 1); - i--; break; case "-gm": modifiers.gmRoll = true; @@ -81,9 +67,6 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri } return modifiers; } - - args.splice(i, 1); - i--; break; case "-o": args.splice(i, 1); @@ -102,13 +85,17 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri } modifiers.order = args[i].toLowerCase()[0]; - - args.splice(i, 1); - i--; break; default: + // Default case should not mess with the array + defaultCase = true; break; } + + if (!defaultCase) { + args.splice(i, 1); + i--; + } } // maxRoll and nominalRoll cannot both be on, throw an error