Allow to repeat the last roll formula

master
Nikola Forró 6 years ago
parent aaf9db6133
commit fd26e33907

@ -63,7 +63,7 @@ class DiscordClient(discord.Client):
(re.compile(r'^!yt\s+(?P<q>")?(?P<query>.+)(?(q)")$'), self._do_yt),
(re.compile(r'^!(find)?clip\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_clip),
(re.compile(r'^!cheese\s+(?P<q>")?(?P<query>.+)(?(q)")$'), self._do_cheese),
(re.compile(r'^!roll\s+(?P<q>")?(?P<formula>.+)(?(q)")$'), self._do_roll),
(re.compile(r'^!roll(\s+(?P<q>")?(?P<formula>.+)(?(q)"))?$'), self._do_roll),
(re.compile(r'^!nextstream$'), self._do_nextstream),
]
super(DiscordClient, self).__init__()

@ -20,6 +20,7 @@ class Commands(object):
def __init__(self, config, logger):
self.config = config
self.logger = logger
self.last_roll_formula = None
def add_quote(self, id, text, game, date):
try:
@ -192,11 +193,14 @@ class Commands(object):
return event
def roll(self, formula):
if not formula:
formula = self.last_roll_formula
try:
result = Roll20.execute(formula)
except Roll20Error:
raise CommandError('failed to interpret or execute the formula')
else:
self.last_roll_formula = formula
return result
def _get_instagram_media(self, params):

@ -676,5 +676,5 @@ class Roll20(object):
except AttributeError:
calculated = num(result)
return '{0} = __**{1}**__'.format(str(result), calculated)
except (parsy.ParseError, RuntimeError) as e:
except (parsy.ParseError, TypeError, RuntimeError) as e:
raise Roll20Error(str(e))

Loading…
Cancel
Save