fix remind time drift
This commit is contained in:
parent
53e75ad05c
commit
288b8dad29
|
@ -57,8 +57,9 @@ def remind_recur(bot, trigger):
|
||||||
return bot.reply(type(e).__name__ + ": " + str(e))
|
return bot.reply(type(e).__name__ + ": " + str(e))
|
||||||
|
|
||||||
if args.start:
|
if args.start:
|
||||||
|
s = ' '.join(args.start)
|
||||||
try:
|
try:
|
||||||
start = datetime.strptime(' '.join(args.start),'%Y-%m-%d %H:%M:%S')
|
start = datetime.strptime(s,'%Y-%m-%d %H:%M:%S')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return bot.msg("Datetime improperly formatted.")
|
return bot.msg("Datetime improperly formatted.")
|
||||||
else:
|
else:
|
||||||
|
@ -99,69 +100,20 @@ def remind_recur(bot, trigger):
|
||||||
bot.reply(msg)
|
bot.reply(msg)
|
||||||
|
|
||||||
|
|
||||||
@module.commands('at')
|
def announce_reminder(bot, sched_time, channel, remindee, reminder, delta=None):
|
||||||
@module.example('.at 2012-12-21 18:00:00 End the world.')
|
|
||||||
def at(bot, trigger):
|
|
||||||
"""
|
|
||||||
Gives you a reminder at the given time and date. Datetime must be in
|
|
||||||
YYYY-MM-DD HH:MM:SS format. Only the bot's timezone is used. If
|
|
||||||
YYYY-MM-DD is excluded, it is assumed to be today's date.
|
|
||||||
|
|
||||||
-l, --lazy - Only activates the reminder when you speak.
|
|
||||||
"""
|
|
||||||
if len(trigger.args) < 2:
|
|
||||||
return bot.msg("Missing arguments for reminder command.")
|
|
||||||
if trigger.args[1] in ['-l', '--lazy']:
|
|
||||||
if len(trigger.args) < 3:
|
|
||||||
return bot.msg("Missing arguments for reminder command.")
|
|
||||||
lazy = True
|
|
||||||
trigger.args.pop(1)
|
|
||||||
else:
|
|
||||||
lazy = False
|
|
||||||
if ':' in trigger.args[1]:
|
|
||||||
at_time = datetime.now().strftime('%Y-%m-%d') + ' ' + trigger.args[1]
|
|
||||||
reminder = ' '.join(trigger.args[2:])
|
|
||||||
else:
|
|
||||||
at_time = ' '.join(trigger.args[1:3])
|
|
||||||
reminder = ' '.join(trigger.args[3:])
|
|
||||||
|
|
||||||
if reminder:
|
|
||||||
reminder = trigger.nick + ': ' + reminder
|
|
||||||
else:
|
|
||||||
reminder = trigger.nick + '!'
|
|
||||||
|
|
||||||
try:
|
|
||||||
sched_time = datetime.strptime(at_time, '%Y-%m-%d %H:%M:%S')
|
|
||||||
except ValueError:
|
|
||||||
return bot.msg("Datetime improperly formatted.")
|
|
||||||
|
|
||||||
if lazy:
|
|
||||||
sched_args = (trigger.nick, reminder)
|
|
||||||
bot.scheduler.add_task(announce_lazy_reminder, sched_time, sched_args)
|
|
||||||
else:
|
|
||||||
sched_args = (trigger.channel, trigger.nick, reminder)
|
|
||||||
bot.scheduler.add_task(announce_reminder, sched_time, sched_args)
|
|
||||||
msg = "Okay, will "
|
|
||||||
msg += "\x0310lazy\x03 " if lazy else ""
|
|
||||||
msg += "remind at "
|
|
||||||
msg+= sched_time.strftime('[%Y-%m-%d %H:%M:%S]')
|
|
||||||
bot.reply(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def announce_reminder(bot, channel, remindee, reminder, delta=None):
|
|
||||||
"""Announce the reminder."""
|
"""Announce the reminder."""
|
||||||
bot.msg(channel, reminder)
|
bot.msg(channel, reminder)
|
||||||
if delta:
|
if delta:
|
||||||
sched_time = datetime.now() + delta
|
sched_time = sched_time + delta
|
||||||
args = (channel, remindee, reminder, delta)
|
args = (channel, remindee, reminder, delta)
|
||||||
bot.scheduler.add_task(announce_reminder, sched_time, args)
|
bot.scheduler.add_task(announce_reminder, sched_time, args)
|
||||||
|
|
||||||
|
|
||||||
def announce_lazy_reminder(bot, remindee, reminder, delta=None):
|
def announce_lazy_reminder(bot, sched_time, remindee, reminder, delta=None):
|
||||||
"""Announce the reminder."""
|
"""Announce the reminder."""
|
||||||
bot.memory['lazy_remind'][remindee].append(reminder)
|
bot.memory['lazy_remind'][remindee].append(reminder)
|
||||||
if delta:
|
if delta:
|
||||||
sched_time = datetime.now() + delta
|
sched_time = sched_time + delta
|
||||||
args = (remindee, reminder, delta)
|
args = (remindee, reminder, delta)
|
||||||
bot.scheduler.add_task(announce_lazy_reminder, sched_time, args)
|
bot.scheduler.add_task(announce_lazy_reminder, sched_time, args)
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Scheduler:
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
tasks_due = [t for t in self.tasks if t[1] <= datetime.now()]
|
tasks_due = [t for t in self.tasks if t[1] <= datetime.now()]
|
||||||
for task in tasks_due:
|
for task in tasks_due:
|
||||||
args = (self.bot,) + task[2]
|
args = (self.bot,) + (task[1],) + task[2]
|
||||||
t = threading.Thread(target=task[0], args=args)
|
t = threading.Thread(target=task[0], args=args)
|
||||||
t.start()
|
t.start()
|
||||||
self.tasks.remove(task)
|
self.tasks.remove(task)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user