add roll command per request

This commit is contained in:
Cynthia Foxwell 2024-08-18 15:08:07 -06:00
parent 042f42e02e
commit 68a313e0ab

24
src/modules/misc/roll.js Normal file
View file

@ -0,0 +1,24 @@
const Command = require("#lib/command.js");
const roll = new Command("roll");
roll.category = "misc";
roll.helpText = "Roll a dice";
roll.usage = "<sides>";
roll.addAlias("img");
roll.callback = function (msg, line) {
line = Number(line);
if (!line || line == "" || Number.isNaN(line)) line = 6;
if (line < 0) line = Math.abs(line);
if (line == 0) return ":hole:";
if (line == 1) return ":one:";
const res = Math.floor(Math.random() * line);
if (line == 2) {
return `:coin:: ${res == 1 ? "Heads" : "Tails"}`;
}
return `:game_die: (d${line}): ${1 + res}`;
};
hf.registerCommand(roll);