Countdown: catch parsing error exception
This commit is contained in:
parent
988fe8729a
commit
dbcd367d66
|
@ -28,22 +28,28 @@ 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:
|
||||||
item = match.group(1)
|
try:
|
||||||
target = parse(match.group(2), default=datetime.now().replace(tzinfo=tzlocal()))
|
item = match.group(1)
|
||||||
|
target = parse(match.group(2), default=datetime.now().replace(tzinfo=tzlocal()))
|
||||||
|
|
||||||
if not self.config.has_section(self.__class__.__name__):
|
if not self.config.has_section(self.__class__.__name__):
|
||||||
self.config.add_section(self.__class__.__name__)
|
self.config.add_section(self.__class__.__name__)
|
||||||
|
|
||||||
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