Dice: break out the !roll handler

This commit is contained in:
Brian S. Stephan 2012-03-30 17:26:51 -05:00
parent 1aa7a542f2
commit f5b367406b
1 changed files with 18 additions and 5 deletions

View File

@ -264,15 +264,28 @@ class Dice(Module):
global output
return output
def do_roll(self, dicestr):
"""
Roll some dice and get the result (with broken out rolls).
Keyword arguments:
dicestr - format:
N#X/YdS+M label
N#: do the following roll N times (optional)
X/: take the top X rolls of the Y times rolled (optional)
Y : roll the die specified Y times (optional, defaults to 1)
dS: roll a S-sided die
+M: add M to the result (-M for subtraction) (optional)
"""
self.build()
yacc.parse(dicestr)
return self.get_result()
def do(self, connection, event, nick, userhost, what, admin_unlocked):
match = re.search('!roll\s+(.*)$', what)
if match:
dicestr = match.group(1)
self.build()
yacc.parse(dicestr)
reply = self.get_result()
if reply is not "":
return self.reply(connection, event, nick + ': ' + reply)
return self.reply(connection, event, nick + ": " + self.do_roll(dicestr))
match = re.search('!ctech\s+(.*)$', what)
if match: