roll: actually fix 0 and no args/nan

This commit is contained in:
Cynthia Foxwell 2024-08-18 15:15:32 -06:00
parent 16ea0aaef0
commit 33065b8aa6

View file

@ -6,14 +6,14 @@ roll.helpText = "Roll a dice";
roll.usage = "<sides>"; roll.usage = "<sides>";
roll.addAlias("img"); roll.addAlias("img");
roll.callback = function (msg, line) { roll.callback = function (msg, line) {
if (line == null || line == "") line = 6;
line = Number(line); line = Number(line);
if (Number.isNaN(line)) line = 6;
if (line < 0) line = Math.abs(line);
if (line == 0) return ":hole:"; if (line == 0) return ":hole:";
if (line == 1) return ":one:"; if (line == 1) return ":one:";
if (line == null || line == "" || Number.isNaN(line)) line = 6;
if (line < 0) line = Math.abs(line);
const res = Math.floor(Math.random() * line); const res = Math.floor(Math.random() * line);
if (line == 2) { if (line == 2) {