diff --git a/requirements.txt b/requirements.txt index df87bde..8ba4066 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +dateutil irc requests diff --git a/rerunbot.py b/rerunbot.py index ea379cb..315b4c9 100644 --- a/rerunbot.py +++ b/rerunbot.py @@ -6,6 +6,7 @@ import os import re import unicodedata +import dateutil.parser import irc.bot import requests @@ -22,7 +23,7 @@ class ReplayBot(irc.bot.SingleServerIRCBot): self.config.read('settings.cfg') self.supported_commands = [ (re.compile(r'^!load\s+(?P\d+)$'), self._do_load), - (re.compile(r'^!start$'), self._do_start), + (re.compile(r'^!start(\s+(?P.+))?$'), self._do_start), (re.compile(r'^!stop$'), self._do_stop), ] self.messages = [] @@ -102,15 +103,18 @@ class ReplayBot(irc.bot.SingleServerIRCBot): else: send_response('@{0}: failed to load messages'.format(tags['display-name'])) - def _do_start(self, tags, send_response, **kwargs): + def _do_start(self, tags, send_response, at=None, **kwargs): if int(tags['user-id']) != self.control_user: send_response('Sorry @{0}, you are not allowed to do this'.format(tags['display-name'])) return - now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) + if at is None: + t = datetime.datetime.now().astimezone(tz=None) + else: + t = dateutil.parser.parse(at).astimezone(tz=None) for offset, user, msg in self.messages: def cb(user=user, msg=msg): return self._post_message(user, msg) - self.reactor.scheduler.execute_at(now + offset, cb) + self.reactor.scheduler.execute_at(t + offset, cb) def _do_stop(self, tags, send_response, **kwargs): if int(tags['user-id']) != self.control_user: