Removed the extra reminder.py, fixed the .bat, fixed up nessa.py
This commit is contained in:
@ -1,8 +1,11 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
|
import aiosqlite
|
||||||
|
import asyncio
|
||||||
|
from datetime import datetime
|
||||||
from .commands import NessaTracker
|
from .commands import NessaTracker
|
||||||
from .consent import ConsentView, check_user_consent, store_user_consent
|
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
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -32,8 +35,30 @@ class Nessa(discord.Client):
|
|||||||
print(f"Logged on as {self.user}!")
|
print(f"Logged on as {self.user}!")
|
||||||
self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID))
|
self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID))
|
||||||
await self.tree.sync(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...")
|
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):
|
async def on_interaction(self, interaction: discord.Interaction):
|
||||||
if interaction.type == discord.InteractionType.application_command:
|
if interaction.type == discord.InteractionType.application_command:
|
||||||
|
@ -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()
|
|
@ -10,5 +10,5 @@ call .venv\Scripts\activate
|
|||||||
REM Run the Python script
|
REM Run the Python script
|
||||||
python main.py
|
python main.py
|
||||||
|
|
||||||
echo Dolly stopped. Press any key to exit.
|
echo Nessa stopped. Press any key to exit.
|
||||||
pause >nul
|
pause >nul
|
||||||
|
Reference in New Issue
Block a user