roll: forgot to fix parsing
This commit is contained in:
parent
05e3ac30f1
commit
0a38640879
1 changed files with 14 additions and 14 deletions
|
@ -6,33 +6,33 @@ const roll = new Command("roll");
|
||||||
roll.category = "misc";
|
roll.category = "misc";
|
||||||
roll.helpText = "Roll a dice";
|
roll.helpText = "Roll a dice";
|
||||||
roll.usage = "<sides>";
|
roll.usage = "<sides>";
|
||||||
roll.callback = function (msg, line, args, {advantage, disadvantage}) {
|
roll.callback = function (msg, line, [sides], {advantage, disadvantage}) {
|
||||||
if (line == null || line == "") line = 6;
|
if (sides == null || sides == "") sides = 6;
|
||||||
line = Number(line);
|
sides = Number(sides);
|
||||||
if (Number.isNaN(line)) line = 6;
|
if (Number.isNaN(sides)) sides = 6;
|
||||||
if (line < 0) line = Math.abs(line);
|
if (sides < 0) sides = Math.abs(sides);
|
||||||
|
|
||||||
if (line == 0) return ":hole:";
|
if (sides == 0) return ":hole:";
|
||||||
if (line == 1) return ":one:";
|
if (sides == 1) return ":one:";
|
||||||
|
|
||||||
const res = Math.floor(Math.random() * line);
|
const res = Math.floor(Math.random() * sides);
|
||||||
|
|
||||||
if (line == 2) {
|
if (sides == 2) {
|
||||||
return `:coin:: ${res == 1 ? "Heads" : "Tails"}`;
|
return `:coin:: ${res == 1 ? "Heads" : "Tails"}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (advantage) {
|
if (advantage) {
|
||||||
const res2 = Math.floor(Math.random() * line);
|
const res2 = Math.floor(Math.random() * sides);
|
||||||
const adv = Math.max(res + 1, res2 + 1);
|
const adv = Math.max(res + 1, res2 + 1);
|
||||||
|
|
||||||
return `:game_die: (d${line} with advantage): ${adv}`;
|
return `:game_die: (d${sides} with advantage): ${adv}`;
|
||||||
} else if (disadvantage) {
|
} else if (disadvantage) {
|
||||||
const res2 = Math.floor(Math.random() * line);
|
const res2 = Math.floor(Math.random() * sides);
|
||||||
const adv = Math.min(res + 1, res2 + 1);
|
const adv = Math.min(res + 1, res2 + 1);
|
||||||
|
|
||||||
return `:game_die: (d${line} with disadvantage): ${adv}`;
|
return `:game_die: (d${sides} with disadvantage): ${adv}`;
|
||||||
} else {
|
} else {
|
||||||
return `:game_die: (d${line}): ${1 + res}`;
|
return `:game_die: (d${sides}): ${1 + res}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
hf.registerCommand(roll);
|
hf.registerCommand(roll);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue