From 4464e0107d35e05c119a8a3356ff7cfff46cbbca Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 5 May 2024 19:22:15 -0400 Subject: [PATCH] Removed the extra reminder.py, fixed the .bat, fixed up nessa.py --- nessa/nessa.py | 29 +++++++++++++++++++++++++++-- nessa/reminder_tracker.py | 26 -------------------------- start_nessa.bat | 2 +- 3 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 nessa/reminder_tracker.py diff --git a/nessa/nessa.py b/nessa/nessa.py index 90c4cc7..065e7e7 100644 --- a/nessa/nessa.py +++ b/nessa/nessa.py @@ -1,8 +1,11 @@ import discord from discord import app_commands +import aiosqlite +import asyncio +from datetime import datetime from .commands import NessaTracker from .consent import ConsentView, check_user_consent, store_user_consent -from .reminder_tracker import reminder_worker +from .database import DATABASE from dotenv import load_dotenv import os @@ -32,8 +35,30 @@ class Nessa(discord.Client): print(f"Logged on as {self.user}!") self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID)) await self.tree.sync(guild=discord.Object(id=GUILD_ID)) + self.loop.create_task(reminder_worker()) print("Starting reminder worker...") - await self.loop.create_task(reminder_worker()) + + async def reminder_worker(self): + 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() async def on_interaction(self, interaction: discord.Interaction): if interaction.type == discord.InteractionType.application_command: diff --git a/nessa/reminder_tracker.py b/nessa/reminder_tracker.py deleted file mode 100644 index 7be7b32..0000000 --- a/nessa/reminder_tracker.py +++ /dev/null @@ -1,26 +0,0 @@ -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() diff --git a/start_nessa.bat b/start_nessa.bat index e9d2964..c8a4836 100644 --- a/start_nessa.bat +++ b/start_nessa.bat @@ -10,5 +10,5 @@ call .venv\Scripts\activate REM Run the Python script python main.py -echo Dolly stopped. Press any key to exit. +echo Nessa stopped. Press any key to exit. pause >nul