Countdown: catch parsing error exception
This commit is contained in:
parent
988fe8729a
commit
dbcd367d66
|
@ -28,13 +28,14 @@ from Module import Module
|
||||||
|
|
||||||
class Countdown(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):
|
def do(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||||
"""Add/retrieve countdown items."""
|
"""Add/retrieve countdown items."""
|
||||||
|
|
||||||
match = re.search('^!countdown\s+add\s+(\S+)\s+(.*)$', what)
|
match = re.search('^!countdown\s+add\s+(\S+)\s+(.*)$', what)
|
||||||
if match:
|
if match:
|
||||||
|
try:
|
||||||
item = match.group(1)
|
item = match.group(1)
|
||||||
target = parse(match.group(2), default=datetime.now().replace(tzinfo=tzlocal()))
|
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())
|
self.config.set(self.__class__.__name__, item, target.astimezone(tzutc()).isoformat())
|
||||||
replystr = 'added countdown item ' + item
|
replystr = 'added countdown item ' + item
|
||||||
return self.reply(connection, event, replystr)
|
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)
|
match = re.search('^!countdown\s+remove\s+(\S+)$', what)
|
||||||
if match:
|
if match:
|
||||||
|
|
Loading…
Reference in New Issue