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,22 +28,28 @@ 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:
item = match.group(1)
target = parse(match.group(2), default=datetime.now().replace(tzinfo=tzlocal()))
try:
item = match.group(1)
target = parse(match.group(2), default=datetime.now().replace(tzinfo=tzlocal()))
if not self.config.has_section(self.__class__.__name__):
self.config.add_section(self.__class__.__name__)
if not self.config.has_section(self.__class__.__name__):
self.config.add_section(self.__class__.__name__)
self.config.set(self.__class__.__name__, item, target.astimezone(tzutc()).isoformat())
replystr = 'added countdown item ' + item
return self.reply(connection, event, replystr)
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: