diff --git a/.gitignore b/.gitignore index 68bc17f..7d6881d 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +/dolly.db \ No newline at end of file diff --git a/dolly/commands.py b/dolly/commands.py index dd9f6a7..20bcf2c 100644 --- a/dolly/commands.py +++ b/dolly/commands.py @@ -1,16 +1,28 @@ -# bot/commands.py import discord from discord import app_commands from .database import add_project, add_task -class DollyProjectTrackerCommands(app_commands.Group, name="Dolly", description="Commands for Dolly's project tracker."): - - @app_commands.command(name="create-project", description="Create a new project in the database.") +class ProjectCommands(app_commands.Group): + def __init__(self): + super().__init__(name="project", description="Manage projects.") + + @app_commands.command(name="create", description="Create a new project.") async def create_project(self, interaction: discord.Interaction, name: str, description: str): await add_project(name, description) - await interaction.response.send_message(f"Project `{name}` created successfully.") - - @app_commands.command(name="add-task", description="Add a new task to a project in the database.") + await interaction.response.send_message(f"Project '{name}' created successfully.") + +class TaskCommands(app_commands.Group): + def __init__(self): + super().__init__(name="task", description="Manage tasks.") + + @app_commands.command(name="add", description="Add a new task to a project.") async def add_task(self, interaction: discord.Interaction, project_name: str, description: str, assignee: str, deadline: str, status: str, priority: str): - await add_task(project_name, description, assignee, deadline, status, priority) - await interaction.response.send_message(f"Task `{description}` added to project `{project_name}` successfully.") + await add_task(project_name, description, assignee, deadline, status, priority) + await interaction.response.send_message(f"Task '{description}' added to project '{project_name}'.") + +class DollyTracker(app_commands.Group, name="dolly", description="Dolly the Project Tracker."): + def __init__(self): + super().__init__() + self.add_command(ProjectCommands()) + self.add_command(TaskCommands()) + diff --git a/dolly/database.py b/dolly/database.py index ec1e2f6..605f6e8 100644 --- a/dolly/database.py +++ b/dolly/database.py @@ -3,33 +3,34 @@ from datetime import datetime DATABASE = "dolly.db" -async def setup_db(): +async def init_db(): async with aiosqlite.connect(DATABASE) as db: - await db.execute('''CREATE TABLE IF NOT EXISTS projects ( - id INTEGER PRIMARY KEY, - name TEXT UNIQUE, - description TEXT)''' + await db.execute( + '''CREATE TABLE IF NOT EXISTS projects( + id INTEGER PRIMARY KEY, + name TEXT UNIQUE, + description TEXT)''' ) - await db.execute('''CREATE TABLE IF NOT EXISTS tasks ( - id INTEGER PRIMARY KEY, - project_id INTEGER, - description TEXT, - assignee text, - deadline DATE, - status TEXT, - priority TEXT, - FOREIGN KEY(project_id) REFERENCES projects(id))''' + await db.execute( + '''CREATE TABLE IF NOT EXISTS tasks( + id INTEGER PRIMARY KEY, + project_id INTEGER, + description TEXT, + assignee TEXT, + deadline TEXT, + status TEXT, + priority TEXT, + FOREIGN KEY(project_id) REFERENCES projects(id))''' ) await db.commit() async def add_project(name, description): async with aiosqlite.connect(DATABASE) as db: - await db.execute("INSERT INTO projects (name, description) VALUES (?, ?)", (name, description)) + await db.execute("INSERT INTO projects(name, description) VALUES(?, ?)", (name, description)) await db.commit() async def add_task(project_id, description, assignee, deadline, status, priority): - deadline_date = datetime.strptime(deadline, '%Y-%m-%d').date() async with aiosqlite.connect(DATABASE) as db: - await db.execute("INSERT INTO tasks (project_id, description, assignee, deadline, status, priority) VALUES (?, ?, ?, ?, ?, ?)", - (project_id, description, assignee, deadline_date, status, priority)) + deadline_date = datetime.strptime(deadline, "%Y-%m-%d").date() + await db.execute("INSERT INTO tasks(project_id, description, assignee, deadline, status, priority) VALUES(?, ?, ?, ?, ?, ?)", (project_id, description, assignee, deadline_date, status, priority)) await db.commit() \ No newline at end of file diff --git a/dolly/dolly.py b/dolly/dolly.py index 995cff6..cdc2c16 100644 --- a/dolly/dolly.py +++ b/dolly/dolly.py @@ -1,17 +1,22 @@ import discord from discord import app_commands -from .commands import DollyProjectTrackerCommands +from .commands import DollyTracker +from dotenv import load_dotenv +import os + +load_dotenv() +GUILD_ID = int(os.getenv("DISCORD_GUILD_ID")) class Dolly(discord.Client): - + def __init__(self): super().__init__(intents=discord.Intents.default()) self.tree = app_commands.CommandTree(self) async def setup_hook(self): - # Register the commands via a group to the command tree - self.tree.add_command(DollyProjectTrackerCommands()) - await self.tree.sync() - + self.tree.add_command(DollyTracker()) + self.tree.copy_global_to(guild = discord.Object(id=GUILD_ID)) + await self.tree.sync(guild = discord.Object(id=GUILD_ID)) + async def on_ready(self): - print(f"Logged in as {self.user} (ID: {self.user.id})\n------") \ No newline at end of file + print(f"Logged on as {self.user}!") \ No newline at end of file diff --git a/main.py b/main.py index a87eba0..c8e693c 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,15 @@ from dolly.dolly import Dolly -from dolly.database import setup_db +from dolly.database import init_db import asyncio from dotenv import load_dotenv import os load_dotenv() -TOKEN = os.getenv('DISCORD_BOT_TOKEN') +TOKEN = os.getenv("DISCORD_BOT_TOKEN") async def main(): - await setup_db() + await init_db() client = Dolly() await client.start(TOKEN)