diff --git a/rerunbot.py b/rerunbot.py index 315b4c9..6fe10bb 100644 --- a/rerunbot.py +++ b/rerunbot.py @@ -9,6 +9,7 @@ import unicodedata import dateutil.parser import irc.bot import requests +import tempora.schedule class ReplayBot(irc.bot.SingleServerIRCBot): @@ -24,6 +25,7 @@ class ReplayBot(irc.bot.SingleServerIRCBot): self.supported_commands = [ (re.compile(r'^!load\s+(?P\d+)$'), self._do_load), (re.compile(r'^!start(\s+(?P.+))?$'), self._do_start), + (re.compile(r'^!resync\s+(?P.+)$'), self._do_resync), (re.compile(r'^!stop$'), self._do_stop), ] self.messages = [] @@ -116,6 +118,18 @@ class ReplayBot(irc.bot.SingleServerIRCBot): return self._post_message(user, msg) self.reactor.scheduler.execute_at(t + offset, cb) + def _do_resync(self, tags, send_response, offset, **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 + offset = datetime.timedelta(seconds=float(offset)) + with self.reactor.mutex: + for i, dc in enumerate(self.reactor.scheduler.queue): + ndc = tempora.schedule.DelayedCommand.from_datetime(dc + offset) + ndc.delay = dc.delay + offset + ndc.target = dc.target + self.reactor.scheduler.queue[i] = ndc + def _do_stop(self, tags, send_response, **kwargs): if int(tags['user-id']) != self.control_user: send_response('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))