ref: master
kaiowa/bot.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import asyncio import json import logging import re 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"]) 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"]) @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) |