aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2019-09-26 14:15:54 +0100
committerGravatar jesopo2019-09-26 14:15:54 +0100
commite2ececa9fdf958d0638249d5fe12d7ff416d65e2 (patch)
tree4e05b72f6ece84bfa849f0db2eb827af0761f81d
parentallow up to d30, not just d20 (diff)
signature
fine. support up to d100
-rw-r--r--modules/dice.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/modules/dice.py b/modules/dice.py
index a287ea35..e6764142 100644
--- a/modules/dice.py
+++ b/modules/dice.py
@@ -7,14 +7,15 @@ ERROR_FORMAT = "Incorrect format! Format must be [number]d[number], e.g. 1d20"
RE_DICE = re.compile("([1-9]\d*)d([1-9]\d*)((?:[-+]\d+)*)", re.I)
RE_MODIFIERS = re.compile("([-+]\d+)")
+MAX_DICE = 6
+MAX_SIDES = 100
+
class Module(ModuleManager.BaseModule):
@utils.hook("received.command.roll", min_args=1)
@utils.hook("received.command.dice", alias_of="roll")
+ @utils.kwarg("help", "Roll dice DND-style")
+ @utils.kwarg("usage", "[1-%s]d[1-%d]" % (MAX_DICE, MAX_SIDES))
def roll_dice(self, event):
- """
- :help: Roll some dice, DND style
- :usage: [1-6]d[1-30]
- """
match = RE_DICE.match(event["args_split"][0])
if match:
roll = match.group(0)
@@ -23,9 +24,10 @@ class Module(ModuleManager.BaseModule):
modifiers = RE_MODIFIERS.findall(match.group(3))
if dice_count > 6:
- raise utils.EventError("Max number of dice is 6")
- if side_count > 30:
- raise utils.EventError("Max number of sides is 30")
+ raise utils.EventError("Max number of dice is %s" % MAX_DICE)
+ if side_count > MAX_SIDES:
+ raise utils.EventError("Max number of sides is %s"
+ % MAX_SIDES)
results = random.choices(range(1, side_count+1), k=dice_count)