diff --git a/dolly/commands.py b/dolly/commands.py index 8d7d7fd..8c94604 100644 --- a/dolly/commands.py +++ b/dolly/commands.py @@ -72,13 +72,18 @@ class TaskCommands(app_commands.Group): @app_commands.command(name="list", description="List tasks for a project.") async def list_tasks(self, interaction: discord.Interaction, project_id: int): try: + project_name = await get_project_name(project_id) + if not project_name: + await interaction.response.send_message(f"No project found with ID {project_id}.", ephemeral=True) + return + tasks = await list_tasks_for_project(project_id) if tasks: message = "\n".join([f"ID: {id}, Description: {description}, Assignee: {assignee}, Deadline: {deadline}, Status: {status}, Priority: {priority}" for id, description, assignee, deadline, status, priority in tasks]) - await interaction.response.send_message(f"Tasks for Project ID {project_id}:\n{message}") + await interaction.response.send_message(f"Tasks for Project '{project_name}':\n{message}") else: - await interaction.response.send_message(f"No tasks found for project ID {project_id}.") + await interaction.response.send_message(f"No tasks found for project '{project_name}'.") except Exception as e: await interaction.response.send_message(f"Failed to retrieve tasks for project ID {project_id}.", ephemeral=True) logger.error(f"Error in list_tasks: {e}") diff --git a/dolly/database.py b/dolly/database.py index ff4609c..8b647b3 100644 --- a/dolly/database.py +++ b/dolly/database.py @@ -36,6 +36,12 @@ async def get_project_id(name): result = await cursor.fetchone() return result[0] if result else None +async def get_project_name(project_id): + async with aiosqlite.connect(DATABASE) as db: + cursor = await db.execute("SELECT name FROM projects WHERE id = ?", (project_id,)) + result = await cursor.fetchone() + return result[0] if result else None + async def add_task_to_project(project_id, description, assignee, deadline, status, priority): async with aiosqlite.connect(DATABASE) as db: # Change the date format to MM/DD/YYYY