fine. support up to d100

This commit is contained in:
jesopo 2019-09-26 14:15:54 +01:00
parent 3f71674369
commit e2ececa9fd

View file

@ -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_DICE = re.compile("([1-9]\d*)d([1-9]\d*)((?:[-+]\d+)*)", re.I)
RE_MODIFIERS = re.compile("([-+]\d+)") RE_MODIFIERS = re.compile("([-+]\d+)")
MAX_DICE = 6
MAX_SIDES = 100
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
@utils.hook("received.command.roll", min_args=1) @utils.hook("received.command.roll", min_args=1)
@utils.hook("received.command.dice", alias_of="roll") @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): 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]) match = RE_DICE.match(event["args_split"][0])
if match: if match:
roll = match.group(0) roll = match.group(0)
@ -23,9 +24,10 @@ class Module(ModuleManager.BaseModule):
modifiers = RE_MODIFIERS.findall(match.group(3)) modifiers = RE_MODIFIERS.findall(match.group(3))
if dice_count > 6: if dice_count > 6:
raise utils.EventError("Max number of dice is 6") raise utils.EventError("Max number of dice is %s" % MAX_DICE)
if side_count > 30: if side_count > MAX_SIDES:
raise utils.EventError("Max number of sides is 30") raise utils.EventError("Max number of sides is %s"
% MAX_SIDES)
results = random.choices(range(1, side_count+1), k=dice_count) results = random.choices(range(1, side_count+1), k=dice_count)