Fix: Added some code to fix the reconnect/disconnect error. Docs: Added setup.cfg to set everything to be 120.
78 lines
3.1 KiB
Python
78 lines
3.1 KiB
Python
import discord
|
|
from discord.ui import Button, View
|
|
|
|
from .database import remove_project, remove_task
|
|
from .logger import logger
|
|
|
|
|
|
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"Alright hun, I have completely forgotten about the "
|
|
f"Project {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 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="I see you changed your mind! I won't forget the project.",
|
|
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"Okay, I have completely forgotten about the Task by the "
|
|
f"ID {self.task_id}, and it 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="Wait! You changed your mind! I won't forget the task.", view=None
|
|
)
|
|
self.stop()
|