From fd26e339078f93e215bf293786269cd0e9157ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 15 Mar 2019 13:26:49 +0100 Subject: [PATCH] Allow to repeat the last roll formula --- clients/discord.py | 2 +- commands.py | 4 ++++ services/roll20.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clients/discord.py b/clients/discord.py index 21d6d9e..ed455f4 100644 --- a/clients/discord.py +++ b/clients/discord.py @@ -63,7 +63,7 @@ class DiscordClient(discord.Client): (re.compile(r'^!yt\s+(?P")?(?P.+)(?(q)")$'), self._do_yt), (re.compile(r'^!(find)?clip\s+(?P")?(?P.+)(?(q)")$'), self._do_clip), (re.compile(r'^!cheese\s+(?P")?(?P.+)(?(q)")$'), self._do_cheese), - (re.compile(r'^!roll\s+(?P")?(?P.+)(?(q)")$'), self._do_roll), + (re.compile(r'^!roll(\s+(?P")?(?P.+)(?(q)"))?$'), self._do_roll), (re.compile(r'^!nextstream$'), self._do_nextstream), ] super(DiscordClient, self).__init__() diff --git a/commands.py b/commands.py index 3b37c5a..ee706b8 100644 --- a/commands.py +++ b/commands.py @@ -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): diff --git a/services/roll20.py b/services/roll20.py index 8dce39f..f395762 100644 --- a/services/roll20.py +++ b/services/roll20.py @@ -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))