Doing a lot of overhaul to add reminders
This commit is contained in:
@@ -54,37 +54,55 @@ class TaskCommands(app_commands.Group):
|
||||
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, reminder_time: str = None):
|
||||
try:
|
||||
datetime.strptime(deadline, "%m/%d/%Y") # Validate date format
|
||||
datetime.strptime(deadline, "%m/%d/%Y") # Validate deadline date format
|
||||
reminder_dt = None
|
||||
if reminder_time:
|
||||
reminder_dt = datetime.strptime(reminder_time, "%m/%d/%Y %H:%M") # Validate and convert reminder time if provided
|
||||
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"Okay so we are adding the task called '{description}' to project '{project_name}'. got it!. Make sure you filled out your project and task details correctly. \nIf you need to update the task, use the `/task update` command.")
|
||||
logger.info(f"Task added to project {project_name}: {description}")
|
||||
await add_task_to_project(project_id, description, assignee, deadline, status, priority, reminder_dt)
|
||||
response_msg = f"Okay, I've added Task '{description}' to your project,'{project_name}'."
|
||||
if reminder_time:
|
||||
response_msg += f" And you wanted a reminder about this taks at {reminder_time}. Got it!"
|
||||
await interaction.response.send_message(response_msg)
|
||||
logger.info(f"Task added to project {project_name}: {description} with reminder set for {reminder_time if reminder_time else 'No reminder set'}.")
|
||||
else:
|
||||
await interaction.response.send_message(f"Whoops! I don't have that project named '{project_name}'. Did you mean to use the `/project create` command? or did you enter the name wrong?", ephemeral=True)
|
||||
await interaction.response.send_message(f"Silly, you can't add a task to a project that doesn't exist. I don't have a Project '{project_name}' in my memory. Use `/project create` to add it first.", ephemeral=True)
|
||||
logger.warning(f"Attempted to add task to non-existent project: {project_name}")
|
||||
except ValueError:
|
||||
await interaction.response.send_message("Silly! I know that's not a date! Please use the right format, i.e. MM/DD/YYYY format!", ephemeral=True)
|
||||
logger.error(f"Invalid date format provided by user: {deadline}")
|
||||
except ValueError as ve:
|
||||
if 'does not match format' in str(ve):
|
||||
await interaction.response.send_message("Wait a sec! That's not right! Please use the right format, i.e. MM/DD/YYYY for dates, and HH:MM for times. I can't do anything otherwise!", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message("Invalid date or time format!", ephemeral=True)
|
||||
logger.error(f"Invalid date or time format provided by user: {ve}")
|
||||
except Exception as e:
|
||||
await interaction.response.send_message("Huh, that's never happened before... Try again!", ephemeral=True)
|
||||
logger.error(f"Unexpected error in add_task: {e}")
|
||||
|
||||
await interaction.response.send_message("An unexpected error occurred. Please try again!", ephemeral=True)
|
||||
logger.error(f"Unexpected error in add_task: {e}")
|
||||
|
||||
@app_commands.command(name="update", description="Update an existing task.")
|
||||
async def update_task_command(self, interaction: discord.Interaction, task_id: int, description: str, assignee: str, deadline: str, status: str, priority: str):
|
||||
async def update_task_command(self, interaction: discord.Interaction, task_id: int, description: str, assignee: str, deadline: str, status: str, priority: str, reminder_time: str = None):
|
||||
try:
|
||||
datetime.strptime(deadline, "%m/%d/%Y") # Validate date format
|
||||
await update_task(task_id, description, assignee, deadline, status, priority)
|
||||
await interaction.response.send_message(f"Okay hun, so I updated the task with ID {task_id} with the changes you wanted made!")
|
||||
logger.info(f"Task ID {task_id} updated: {description}")
|
||||
except ValueError:
|
||||
await interaction.response.send_message("Silly! I know that's not a date! Please use the right format, i.e. MM/DD/YYYY format!", ephemeral=True)
|
||||
logger.error(f"Invalid date format provided by user for task update: {deadline}")
|
||||
datetime.strptime(deadline, "%m/%d/%Y") # Validate deadline date format
|
||||
reminder_dt = None
|
||||
if reminder_time:
|
||||
reminder_dt = datetime.strptime(reminder_time, "%m/%d/%Y %H:%M") # Validate and convert reminder time if provided
|
||||
await update_task(task_id, description, assignee, deadline, status, priority, reminder_dt)
|
||||
response_msg = f"Okay hun, so I updated the task with ID {task_id} with the changes you wanted made!"
|
||||
if reminder_time:
|
||||
response_msg += f" And you wanted a reminder about this taks at {reminder_time}. Got it!"
|
||||
await interaction.response.send_message(response_msg)
|
||||
logger.info(f"Task ID {task_id} updated: {description} with reminder set for {reminder_time if reminder_time else 'No reminder set'}.")
|
||||
except ValueError as ve:
|
||||
if 'does not match format' in str(ve):
|
||||
await interaction.response.send_message("Wait a sec! That's not right! Please use the right format, i.e. MM/DD/YYYY for dates, and HH:MM for times. I can't do anything otherwise!", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message("Invalid date or time format!", ephemeral=True)
|
||||
logger.error(f"Invalid date or time format provided by user: {ve}")
|
||||
except Exception as e:
|
||||
await interaction.response.send_message("Huh, that's never happened before... Try again!", ephemeral=True)
|
||||
logger.error(f"Unexpected error in update_task_command: {e}")
|
||||
await interaction.response.send_message("An unexpected error occurred. Please try again!", ephemeral=True)
|
||||
logger.error(f"Unexpected error in update_task_command: {e}")
|
||||
|
||||
@app_commands.command(name="list", description="List tasks for a project.")
|
||||
async def list_tasks(self, interaction: discord.Interaction, project_id: int):
|
||||
@@ -111,7 +129,6 @@ class TaskCommands(app_commands.Group):
|
||||
view = ConfirmTaskDeletionView(task_id)
|
||||
await interaction.response.send_message(f"So, are you sure you want to remove Task ID {task_id}? Once I forget, that's it! You'll have 180 seconds to confirm.", view=view, ephemeral=True)
|
||||
|
||||
|
||||
class ConsentCommands(app_commands.Group):
|
||||
def __init__(self):
|
||||
super().__init__(name="consent", description="Manage data consent settings.")
|
||||
|
Reference in New Issue
Block a user