Compare commits
No commits in common. "7413860601f044dc5cd87ee9eef71aa63375d1e1" and "53e75ad05c3c64db43afb5aa11d5275a0621fc4a" have entirely different histories.
7413860601
...
53e75ad05c
|
@ -57,9 +57,8 @@ 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(s,'%Y-%m-%d %H:%M:%S')
|
start = datetime.strptime(' '.join(args.start),'%Y-%m-%d %H:%M:%S')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return bot.msg("Datetime improperly formatted.")
|
return bot.msg("Datetime improperly formatted.")
|
||||||
else:
|
else:
|
||||||
|
@ -100,20 +99,69 @@ def remind_recur(bot, trigger):
|
||||||
bot.reply(msg)
|
bot.reply(msg)
|
||||||
|
|
||||||
|
|
||||||
def announce_reminder(bot, sched_time, channel, remindee, reminder, delta=None):
|
@module.commands('at')
|
||||||
|
@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 = sched_time + delta
|
sched_time = datetime.now() + 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, sched_time, remindee, reminder, delta=None):
|
def announce_lazy_reminder(bot, 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 = sched_time + delta
|
sched_time = datetime.now() + 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)
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ 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)
|
||||||
|
|
|
@ -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[1],) + task[2]
|
args = (self.bot,) + 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