aboutsummaryrefslogtreecommitdiff
path: root/modules/dice.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-26 18:27:17 +0100
committerGravatar jesopo2018-09-26 18:27:17 +0100
commit51a52e2b0e54031cce5876f54d1d48c268b5441c (patch)
treea4c0e8e86c55aa701b06297d5b5a2ceebeaab60d /modules/dice.py
parentAlso use docstrings to check if a command has help available, allow one-string (diff)
signature
Switch to using @Utils.hook and docstrings for event hooks
Diffstat (limited to 'modules/dice.py')
-rw-r--r--modules/dice.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/modules/dice.py b/modules/dice.py
index 30e4f319..cb48efae 100644
--- a/modules/dice.py
+++ b/modules/dice.py
@@ -1,28 +1,24 @@
import random
-from src import Utils
+from src import ModuleManager, Utils
-class Module(object):
- def __init__(self, bot, events, exports):
- events.on("received.command.roll").hook(
- self.roll_dice,
- min_args=1,
- help="Roll some dice, DND style!",
- usage="[1-5]d[1-20]"
- )
-
- self.err_msg = "Incorrectly formatted dice! Format must be [number]d[number], for example, 1d20"
+ERROR_FORMAT = "Incorrect format! Format must be [number]d[number], e.g. 1d20"
+class Module(ModuleManager.BaseModule):
+ @Utils.hook("received.command.roll", min_args=1, usage="[1-5]d[1-20]")
def roll_dice(self, event):
+ """
+ Roll some dice, DND style!
+ """
raw_input = event["args_split"][0]
roll = raw_input.split("d")
results = []
if len(roll) is not 2:
- event["stderr"].write(self.err_msg)
+ event["stderr"].write(ERROR_FORMAT)
return
if roll[0].isdigit() is False or roll[1].isdigit() is False:
- event["stderr"].write(self.err_msg)
+ event["stderr"].write(ERROR_FORMAT)
return
roll = [int(roll[0]), int(roll[1])]