kaiowa

commit 23f44eb988020447f8993d6753f3207e3900e8c6

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

bot: add new command '.lembrar'

 kaiowa/bot.py | 31 ++++++++++++++++++++++++++++---


diff --git a/kaiowa/bot.py b/kaiowa/bot.py
index f026bccc7c8e8c9cdd478c483d2fe0c99acd23d3..ec9d52c38d46196f2b49cb93fd9adb9d1e8ea9a5 100644
--- a/kaiowa/bot.py
+++ b/kaiowa/bot.py
@@ -3,18 +3,36 @@ import json
 import logging
 import re
 
-from datetime import datetime
-
+from redis import Redis
 from asif import Client, CommandSet, Message
 from asif.util import bold
+from datetime import datetime
+from pytz import timezone
 
 from kaiowa.config import config
+from kaiowa.reminder import load_reminders, want_reminder, check_due_reminders
 
 bot = Client(**config["kwargs"])
-cs = CommandSet(bot)
+cmds = CommandSet(bot)
+redis = Redis()
 
 primary = bot.get_channel(config["channel"])
 
+reminders = load_reminders(redis)
+
+async def due_reminders():
+    """
+    Check for due reminders and remove them from the queue
+    """
+
+    global reminders
+    while True:
+        await asyncio.sleep(1)
+
+        await check_due_reminders(redis, reminders, bot)
+
+bot._bg(due_reminders())
+
 @bot.on_connected()
 async def on_connect():
     await bot.join(config["channel"])
@@ -22,3 +40,10 @@
 @primary.on_message(re.compile("^.ping"))
 async def pong(m: Message):
     await m.reply("pong", m.text[5:])
+
+@cmds.command("remindme")
+@cmds.command("lembrar")
+async def reminder(when, what, message=None):
+    ".remindme [when] [what]: Reminds you to [what] at [when]"
+    ".lembrar [quando] [o que]: Lembrar de [o que] em [quando]"
+    await want_reminder(redis, reminders, message, what, when)