import asyncio from datetime import datetime import aiosqlite from .database import DATABASE async def reminder_worker(client): while True: await asyncio.sleep(60) # check every minute now = datetime.now() async with aiosqlite.connect(DATABASE) as db: cursor = await db.execute( "SELECT id, description, reminder_time, notification_channel_id FROM tasks WHERE reminder_time <= ? AND reminder_sent = FALSE", (now,) ) tasks = await cursor.fetchall() for task_id, description, reminder_time, channel_id in tasks: if channel_id: channel = client.get_channel(int(channel_id)) if channel: await channel.send(f"Reminder for task: {description}") await db.execute("UPDATE tasks SET reminder_sent = TRUE WHERE id = ?", (task_id,)) else: print(f"Failed to find channel with ID {channel_id}") else: print(f"No channel ID provided for task ID {task_id}") await db.commit()