Add at argument to !start command

master
Nikola Forró 6 years ago
parent 0344fe59c9
commit 17788581fc

@ -1,2 +1,3 @@
dateutil
irc
requests

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

Loading…
Cancel
Save