本文整理汇总了Python中Core.Util.UtilBot.get_all_reminders方法的典型用法代码示例。如果您正苦于以下问题:Python UtilBot.get_all_reminders方法的具体用法?Python UtilBot.get_all_reminders怎么用?Python UtilBot.get_all_reminders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core.Util.UtilBot
的用法示例。
在下文中一共展示了UtilBot.get_all_reminders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _reminder_on_connect_listener
# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import get_all_reminders [as 别名]
def _reminder_on_connect_listener(bot):
reminders = UtilBot.get_all_reminders()
for reminder in reminders:
reminder_time = dateutil.parser.parse(reminder[2])
reminder_interval = (reminder_time - datetime.now()).seconds
conv = bot._conv_list.get(reminder[0])
reminder_timer = threading.Timer(reminder_interval, send_reminder,
[bot, conv, reminder_interval, reminder[1], asyncio.get_event_loop()])
reminder_timer.start()
示例2: remind
# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import get_all_reminders [as 别名]
def remind(bot, event, *args):
# TODO Implement a private chat feature. Have reminders save across reboots?
"""
**Remind:**
Usage: /remind <optional: date [defaults to today]> <optional: time [defaults to an hour from now]> <message> {/remind 1/1/15 2:00PM Call mom}
Usage: /remind
Usage /remind delete <index to delete> {/remind delete 1}
Purpose: Will post a message on the date and time specified to the current chat. With no arguments, it'll list all the reminders."""
# Show all reminders
if len(args) == 0:
segments = [hangups.ChatMessageSegment('Reminders:', is_bold=True),
hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)]
reminders = UtilBot.get_all_reminders(event.conv_id)
if len(reminders) > 0:
for x in range(0, len(reminders)):
reminder = reminders[x]
reminder_text = reminder[1]
date_to_post = dateutil.parser.parse(reminder[2])
segments.append(
hangups.ChatMessageSegment(
str(x + 1) + ' - ' + date_to_post.strftime('%m/%d/%y %I:%M%p') + ' : ' + reminder_text))
segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK))
segments.pop()
bot.send_message_segments(event.conv, segments)
if len(segments) <= 2:
bot.send_message(event.conv, "No reminders set for this chat.")
return
# Delete a reminder
if args[0] == 'delete':
try:
x = int(args[1])
x -= 1
except ValueError:
bot.send_message(event.conv, 'Invalid integer: ' + args[1])
return
reminders = UtilBot.get_all_reminders(event.conv_id)
reminder_to_delete_text = None
if x in range(0, len(reminders)):
to_delete_reminder = reminders[x]
for running_reminder in currently_running_reminders:
if running_reminder[1] == to_delete_reminder:
running_reminder[0].cancel()
if reminder_to_delete_text:
bot.send_message(event.conv, 'Removed reminder: ' + str(reminder_to_delete_text))
else:
bot.send_message(event.conv, 'The reminder chosen is not currently running.')
return
# Set a new reminder
args = list(args)
reminder_text = ' '.join(args)
c = parsedatetime.Calendar()
result = c.nlp(reminder_text)
if result is None:
bot.send_message(event.conv, "Couldn't parse a valid date from {}'s message.".format(event.user.full_name))
return
reminder_time = result[0][0]
reminder_text = reminder_text.replace(result[0][-1], '')
if reminder_text.strip() == '':
bot.send_message(event.conv, 'No reminder text set.')
return
current_time = datetime.now()
if reminder_time < current_time:
bot.send_message("Invalid Date: {}".format(reminder_time.strftime('%B %d, %Y %I:%M%p')))
reminder_interval = (reminder_time - current_time).total_seconds()
reminder_timer = threading.Timer(reminder_interval, send_reminder,
[bot, event.conv, reminder_interval, reminder_text, asyncio.get_event_loop()])
UtilBot.add_reminder(event.conv_id, reminder_text, reminder_time)
reminder_timer.start()
currently_running_reminders.append((reminder_timer, (event.conv_id, reminder_text, reminder_time)))
bot.send_message(event.conv, "Reminder set for " + reminder_time.strftime('%B %d, %Y %I:%M%p'))