Doing a lot of overhaul to add reminders

This commit is contained in:
Dan
2024-05-05 19:09:19 -04:00
parent ff15da0061
commit 9ce8c910c8
6 changed files with 94 additions and 48 deletions

26
nessa/reminder_tracker.py Normal file
View File

@ -0,0 +1,26 @@
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()