Fixed up the code. Now just need to fix the add_task command
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -158,3 +158,4 @@ cython_debug/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# 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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
/dolly.db
|
@ -1,16 +1,28 @@
|
|||||||
# bot/commands.py
|
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from .database import add_project, add_task
|
from .database import add_project, add_task
|
||||||
|
|
||||||
class DollyProjectTrackerCommands(app_commands.Group, name="Dolly", description="Commands for Dolly's project tracker."):
|
class ProjectCommands(app_commands.Group):
|
||||||
|
def __init__(self):
|
||||||
@app_commands.command(name="create-project", description="Create a new project in the database.")
|
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):
|
async def create_project(self, interaction: discord.Interaction, name: str, description: str):
|
||||||
await add_project(name, description)
|
await add_project(name, description)
|
||||||
await interaction.response.send_message(f"Project `{name}` created successfully.")
|
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.")
|
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):
|
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 add_task(project_name, description, assignee, deadline, status, priority)
|
||||||
await interaction.response.send_message(f"Task `{description}` added to project `{project_name}` successfully.")
|
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())
|
||||||
|
|
||||||
|
@ -3,33 +3,34 @@ from datetime import datetime
|
|||||||
|
|
||||||
DATABASE = "dolly.db"
|
DATABASE = "dolly.db"
|
||||||
|
|
||||||
async def setup_db():
|
async def init_db():
|
||||||
async with aiosqlite.connect(DATABASE) as db:
|
async with aiosqlite.connect(DATABASE) as db:
|
||||||
await db.execute('''CREATE TABLE IF NOT EXISTS projects (
|
await db.execute(
|
||||||
id INTEGER PRIMARY KEY,
|
'''CREATE TABLE IF NOT EXISTS projects(
|
||||||
name TEXT UNIQUE,
|
id INTEGER PRIMARY KEY,
|
||||||
description TEXT)'''
|
name TEXT UNIQUE,
|
||||||
|
description TEXT)'''
|
||||||
)
|
)
|
||||||
await db.execute('''CREATE TABLE IF NOT EXISTS tasks (
|
await db.execute(
|
||||||
id INTEGER PRIMARY KEY,
|
'''CREATE TABLE IF NOT EXISTS tasks(
|
||||||
project_id INTEGER,
|
id INTEGER PRIMARY KEY,
|
||||||
description TEXT,
|
project_id INTEGER,
|
||||||
assignee text,
|
description TEXT,
|
||||||
deadline DATE,
|
assignee TEXT,
|
||||||
status TEXT,
|
deadline TEXT,
|
||||||
priority TEXT,
|
status TEXT,
|
||||||
FOREIGN KEY(project_id) REFERENCES projects(id))'''
|
priority TEXT,
|
||||||
|
FOREIGN KEY(project_id) REFERENCES projects(id))'''
|
||||||
)
|
)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
async def add_project(name, description):
|
async def add_project(name, description):
|
||||||
async with aiosqlite.connect(DATABASE) as db:
|
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()
|
await db.commit()
|
||||||
|
|
||||||
async def add_task(project_id, description, assignee, deadline, status, priority):
|
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:
|
async with aiosqlite.connect(DATABASE) as db:
|
||||||
await db.execute("INSERT INTO tasks (project_id, description, assignee, deadline, status, priority) VALUES (?, ?, ?, ?, ?, ?)",
|
deadline_date = datetime.strptime(deadline, "%Y-%m-%d").date()
|
||||||
(project_id, description, assignee, deadline_date, status, priority))
|
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()
|
await db.commit()
|
@ -1,17 +1,22 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
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):
|
class Dolly(discord.Client):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(intents=discord.Intents.default())
|
super().__init__(intents=discord.Intents.default())
|
||||||
self.tree = app_commands.CommandTree(self)
|
self.tree = app_commands.CommandTree(self)
|
||||||
|
|
||||||
async def setup_hook(self):
|
async def setup_hook(self):
|
||||||
# Register the commands via a group to the command tree
|
self.tree.add_command(DollyTracker())
|
||||||
self.tree.add_command(DollyProjectTrackerCommands())
|
self.tree.copy_global_to(guild = discord.Object(id=GUILD_ID))
|
||||||
await self.tree.sync()
|
await self.tree.sync(guild = discord.Object(id=GUILD_ID))
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print(f"Logged in as {self.user} (ID: {self.user.id})\n------")
|
print(f"Logged on as {self.user}!")
|
6
main.py
6
main.py
@ -1,15 +1,15 @@
|
|||||||
from dolly.dolly import Dolly
|
from dolly.dolly import Dolly
|
||||||
from dolly.database import setup_db
|
from dolly.database import init_db
|
||||||
import asyncio
|
import asyncio
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
TOKEN = os.getenv('DISCORD_BOT_TOKEN')
|
TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
await setup_db()
|
await init_db()
|
||||||
client = Dolly()
|
client = Dolly()
|
||||||
await client.start(TOKEN)
|
await client.start(TOKEN)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user