aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2018-11-17 12:18:26 +0000
committerGravatar jesopo2018-11-17 12:18:26 +0000
commit73ecb42ca9717dd0b4591c20f28c6d24c3c46ecb (patch)
tree5860229f004b41ae85fdc5054091cfcbb247fb85 /modules
parent'bol' -> 'bold' typo (diff)
signature
Simplify modules/dice.py
Diffstat (limited to 'modules')
-rw-r--r--modules/dice.py25
1 files changed, 8 insertions, 17 deletions
diff --git a/modules/dice.py b/modules/dice.py
index 42d048cf..0505bea6 100644
--- a/modules/dice.py
+++ b/modules/dice.py
@@ -10,29 +10,20 @@ class Module(ModuleManager.BaseModule):
:help: Roll some dice, DND style!
:usage: [1-5]d[1-20]
"""
- raw_input = event["args_split"][0]
- roll = raw_input.split("d")
- results = []
-
- if len(roll) is not 2:
- raise utils.EventError(ERROR_FORMAT)
-
- if roll[0].isdigit() is False or roll[1].isdigit() is False:
+ roll = event["args_split"][0].lower()
+ count, sides = roll.partition("d")
+ if not count.isdigit() or not sides.isdigit():
raise utils.EventError(ERROR_FORMAT)
- roll = [int(roll[0]), int(roll[1])]
+ count_n = min(int(roll[0]), 5)
+ sides_n = min(int(roll[1]), 20)
- num_of_die = 5 if roll[0] > 5 else roll[0]
- sides_of_die = 20 if roll[1] > 20 else roll[1]
-
- str_roll = str(num_of_die) + "d" + str(sides_of_die)
-
- for i in range(0, num_of_die):
- results.append(random.randint(1, sides_of_die))
+ reults = random.choices(range(1, die_sides), k=die_count)
total_n = sum(results)
total = ""
if len(results) > 1:
total = " (total: %d)" % total_n
+
event["stdout"].write("Rolled %s and got %s%s" % (
- str_roll, ", ".join(str(r) for r in results), total))
+ roll, total_n, ", ".join(results)))