From ac678c0f14976a6a734e356c1f1bc0366eded692 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 2 Dec 2015 18:04:54 -0600 Subject: [PATCH] Improve !remind time detection (allow e.g. "!remind 7d-2h") --- CHANGELOG | 2 +- earwigbot/commands/remind.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8c1dac9..0e3787f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ v0.3 (unreleased): - Copyvio detector: improved sentence splitting algorithm. -- IRC: Added !remind all. +- IRC > !remind: Added !remind all. Improved time detection. - IRC: Improved detection of maximum IRC message length. - IRC: Improved some help commands. diff --git a/earwigbot/commands/remind.py b/earwigbot/commands/remind.py index 9422e86..a8c568f 100644 --- a/earwigbot/commands/remind.py +++ b/earwigbot/commands/remind.py @@ -78,13 +78,11 @@ class Remind(Command): else: raise ValueError(node) - if arg and arg[-1] in time_units: - factor, arg = time_units[arg[-1]], arg[:-1] - else: - factor = 1 + for unit, factor in time_units.iteritems(): + arg = arg.replace(unit, "*" + str(factor)) try: - parsed = int(_evaluate(ast.parse(arg, mode="eval").body) * factor) + parsed = int(_evaluate(ast.parse(arg, mode="eval").body)) except (SyntaxError, KeyError): raise ValueError(arg) if parsed <= 0: