deduplicated some code in the getModifiers func

This commit is contained in:
Ean Milligan (Bastion) 2022-05-18 05:12:04 -04:00
parent 394ae211df
commit 04d7324769
1 changed files with 8 additions and 21 deletions

View File

@ -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 // 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++) { for (let i = 0; i < args.length; i++) {
log(LT.LOG, `Checking ${command}${args.join(" ")} for command modifiers ${i}`); log(LT.LOG, `Checking ${command}${args.join(" ")} for command modifiers ${i}`);
let defaultCase = false;
switch (args[i].toLowerCase()) { switch (args[i].toLowerCase()) {
case "-nd": case "-nd":
modifiers.noDetails = true; modifiers.noDetails = true;
args.splice(i, 1);
i--;
break; break;
case "-snd": case "-snd":
modifiers.superNoDetails = true; modifiers.superNoDetails = true;
args.splice(i, 1);
i--;
break; break;
case "-s": case "-s":
modifiers.spoiler = "||"; modifiers.spoiler = "||";
args.splice(i, 1);
i--;
break; break;
case "-m": case "-m":
modifiers.maxRoll = true; modifiers.maxRoll = true;
args.splice(i, 1);
i--;
break; break;
case "-n": case "-n":
modifiers.nominalRoll = true; modifiers.nominalRoll = true;
args.splice(i, 1);
i--;
break; break;
case "-gm": case "-gm":
modifiers.gmRoll = true; modifiers.gmRoll = true;
@ -81,9 +67,6 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
} }
return modifiers; return modifiers;
} }
args.splice(i, 1);
i--;
break; break;
case "-o": case "-o":
args.splice(i, 1); args.splice(i, 1);
@ -102,13 +85,17 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
} }
modifiers.order = args[i].toLowerCase()[0]; modifiers.order = args[i].toLowerCase()[0];
args.splice(i, 1);
i--;
break; break;
default: default:
// Default case should not mess with the array
defaultCase = true;
break; break;
} }
if (!defaultCase) {
args.splice(i, 1);
i--;
}
} }
// maxRoll and nominalRoll cannot both be on, throw an error // maxRoll and nominalRoll cannot both be on, throw an error