Compare commits

...

2 Commits

Author SHA1 Message Date
7413860601 fix wikipedia useskin 2023-06-29 19:55:28 -04:00
288b8dad29 fix remind time drift 2023-06-29 19:50:57 -04:00
3 changed files with 8 additions and 55 deletions

View File

@ -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)

View File

@ -65,6 +65,7 @@ def wiki_info(bot, url):
server. server.
""" """
_, _, query = url.partition("wiki/") _, _, query = url.partition("wiki/")
query = query.partition('?')[0]
if not query: if not query:
return return
say_snippet(bot, query, False) say_snippet(bot, query, False)

View File

@ -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)