Files
Nessa/nessa/confirm.py

49 lines
2.6 KiB
Python

import discord
from discord.ui import View, Button
class ConfirmView(View):
def __init__(self, project_id, timeout=180): # 180 seconds until the view expires
super().__init__(timeout=timeout)
self.project_id = project_id
self.value = None
@discord.ui.button(label="Confirm", style=discord.ButtonStyle.danger)
async def confirm(self, interaction: discord.Interaction, button: Button):
# Attempt to remove the project
try:
await remove_project(self.project_id)
await interaction.response.edit_message(content=f"Project ID {self.project_id} and all associated tasks have been successfully removed.", view=None)
logger.info(f"Project ID {self.project_id} and all associated tasks removed successfully.")
except Exception as e:
error_message = f"Failed to remove the project. Error: {e}"
await interaction.response.edit_message(content=error_message, view=None)
logger.error(f"Error in remove_project_command: {e}")
self.stop() # Stopping the view after an error is usually a good practice to clean up the UI.
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.secondary)
async def cancel(self, interaction: discord.Interaction, button: Button):
await interaction.response.edit_message(content="Project removal cancelled.", view=None)
self.stop()
class ConfirmTaskDeletionView(View):
def __init__(self, task_id, timeout=180): # 180 seconds until the view expires
super().__init__(timeout=timeout)
self.task_id = task_id
self.value = None
@discord.ui.button(label="Confirm", style=discord.ButtonStyle.danger)
async def confirm(self, interaction: discord.Interaction, button: Button):
# Attempt to remove the task
try:
await remove_task(self.task_id)
await interaction.response.edit_message(content=f"Task ID {self.task_id} has been successfully removed.", view=None)
logger.info(f"Task ID {self.task_id} removed successfully.")
except Exception as e:
error_message = f"Failed to remove the task. Error: {e}"
await interaction.response.edit_message(content=error_message, view=None)
logger.error(f"Error in remove_task_command: {e}")
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.secondary)
async def cancel(self, interaction: discord.Interaction, button: Button):
await interaction.response.edit_message(content="Task removal cancelled.", view=None)
self.stop()