~sircmpwn/reminderbot

aaec95ee5162cb5218442d630d583f8f566e0758 — Pedro Lucas Porcellis 1 year, 4 months ago 8435806 master
Snooze last reminder for that user
1 files changed, 13 insertions(+), 5 deletions(-)

M reminderbot/bot.py
M reminderbot/bot.py => reminderbot/bot.py +13 -5
@@ 23,7 23,7 @@ sh.setFormatter(fmt)
logger.addHandler(sh)

redis = Redis()
last_reminder = None
last_reminders = {}

UTC = timezone("UTC")



@@ 129,13 129,20 @@ async def on_want_reminder(msg, what=None, when=None, where=None):

@cmds.command("snooze")
async def snooze(*when, message=None):
    global last_reminder
    await on_want_reminder(message, when=" ".join(when), what=last_reminder)
    global last_reminders
    who = message.sender.name

    last_reminder_for_user = last_reminders[who]
    if last_reminder_for_user:
        await on_want_reminder(
                message, when=" ".join(when), what=last_reminder_for_user
        )

async def main():
    global last_reminder
    asyncio.ensure_future(bot.run())
    global reminders
    global last_reminders

    while True:
        await asyncio.sleep(1)
        if not connected:


@@ 145,6 152,7 @@ async def main():
        reminders = [r for r in reminders if r.when > now]
        for r in due:
            await bot.message(r.where, r.who + ": Reminder " + r.what)
            last_reminder = r.what
            last_reminders[r.who] = r.what

        if any(due):
            save_reminders(reminders)