Add !resync command

master
Nikola Forró 6 years ago
parent 17788581fc
commit 56b62c50d5

@ -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<id>\d+)$'), self._do_load),
(re.compile(r'^!start(\s+(?P<at>.+))?$'), self._do_start),
(re.compile(r'^!resync\s+(?P<offset>.+)$'), 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']))

Loading…
Cancel
Save