Countdown: catch parsing error exception

This commit is contained in:
Brian S. Stephan 2012-07-29 09:44:23 -05:00
parent 988fe8729a
commit dbcd367d66
1 changed files with 14 additions and 8 deletions

View File

@ -28,13 +28,14 @@ from Module import Module
class Countdown(Module):
"""Class that adds a countdown item to the bot."""
"""Track when events will happen."""
def do(self, connection, event, nick, userhost, what, admin_unlocked):
"""Add/retrieve countdown items."""
match = re.search('^!countdown\s+add\s+(\S+)\s+(.*)$', what)
if match:
try:
item = match.group(1)
target = parse(match.group(2), default=datetime.now().replace(tzinfo=tzlocal()))
@ -44,6 +45,11 @@ class Countdown(Module):
self.config.set(self.__class__.__name__, item, target.astimezone(tzutc()).isoformat())
replystr = 'added countdown item ' + item
return self.reply(connection, event, replystr)
except ValueError as e:
self.log.error("could not parse countdown item")
self.log.exception(e)
return self.reply(connection, event,
"could not parse countdown item: {0:s}".format(str(e)))
match = re.search('^!countdown\s+remove\s+(\S+)$', what)
if match: