Fixed up the current commands. Added a logger. Added a catch-all
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from .database import add_project, add_task
|
||||
from .database import add_project, get_project_id, add_task_to_project
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger('Dolly')
|
||||
|
||||
class ProjectCommands(app_commands.Group):
|
||||
def __init__(self):
|
||||
@@ -8,8 +12,12 @@ class ProjectCommands(app_commands.Group):
|
||||
|
||||
@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.")
|
||||
try:
|
||||
project_id = await add_project(name, description)
|
||||
await interaction.response.send_message(f"Project '{name}' created successfully with ID: {project_id}.")
|
||||
except Exception as e:
|
||||
await interaction.response.send_message("An error occurred while creating the project.", ephemeral=True)
|
||||
logger.error(f"Error in create_project: {e}")
|
||||
|
||||
class TaskCommands(app_commands.Group):
|
||||
def __init__(self):
|
||||
@@ -17,12 +25,25 @@ class TaskCommands(app_commands.Group):
|
||||
|
||||
@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}'.")
|
||||
try:
|
||||
datetime.strptime(deadline, "%m/%d/%Y") # Validate date format
|
||||
project_id = await get_project_id(project_name)
|
||||
if project_id:
|
||||
await add_task_to_project(project_id, description, assignee, deadline, status, priority)
|
||||
await interaction.response.send_message(f"Task '{description}' added to project '{project_name}'.")
|
||||
logger.info(f"Task added to project {project_name}: {description}")
|
||||
else:
|
||||
await interaction.response.send_message(f"Project '{project_name}' not found.", ephemeral=True)
|
||||
logger.warning(f"Attempted to add task to non-existent project: {project_name}")
|
||||
except ValueError:
|
||||
await interaction.response.send_message("Invalid date format. Please use MM/DD/YYYY format.", ephemeral=True)
|
||||
logger.error(f"Invalid date format provided by user: {deadline}")
|
||||
except Exception as e:
|
||||
await interaction.response.send_message("An error occurred while adding the task.", ephemeral=True)
|
||||
logger.error(f"Unexpected error in add_task: {e}")
|
||||
|
||||
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())
|
||||
|
||||
self.add_command(TaskCommands())
|
Reference in New Issue
Block a user