diff --git a/dolly/commands.py b/dolly/commands.py new file mode 100644 index 0000000..1500340 --- /dev/null +++ b/dolly/commands.py @@ -0,0 +1,15 @@ +import discord +from discord import app_commands +from .database import add_project, add_task + +class DollyProjectTrackerCommands(app_commands.Group): + + @tree.command(name="create-project", description="Create a new project in the database.") + 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.") + + @tree.command(name="add-task", description="Add a new task to a project in the database.") + 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.") diff --git a/dolly/database.py b/dolly/database.py new file mode 100644 index 0000000..ec1e2f6 --- /dev/null +++ b/dolly/database.py @@ -0,0 +1,35 @@ +import aiosqlite +from datetime import datetime + +DATABASE = "dolly.db" + +async def setup_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 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.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.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)) + await db.commit() \ No newline at end of file diff --git a/dolly/dolly.py b/dolly/dolly.py new file mode 100644 index 0000000..92cb4e5 --- /dev/null +++ b/dolly/dolly.py @@ -0,0 +1,16 @@ +import discord +from discord import app_commands +from .commands import DollyProjectTrackerCommands + +class Dolly(discord.Client): + + def __init__(self): + super().__init__(intents=discord.Intents.default()) + self.tree = app_commands.CommandTree(self) + self.tree.add_command(DollyProjectTrackerCommands()) + + async def setup_hook(self): + await self.tree.sync() + + async def on_ready(self): + print(f"Logged in as {self.user} (ID: {self.user.id})\n------") \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..634b76e --- /dev/null +++ b/main.py @@ -0,0 +1,14 @@ +from dolly.dolly import Dolly +from dolly.database import setup_db +import asyncio +from dotenv import load_dotenv + +load_dotenv() +TOKEN = os.getenv('DISCORD_BOT_TOKEN') + +async def main(): + await setup_db() + client = Dolly() + await client.start(TOKEN) + +asyncio.run(main()) \ No newline at end of file