Enhance ticketing and modal handling in cogs

- Improved exception handling in `create_ticket` for better user feedback.
- Added "Apply for PM Position" button in `WorkView` to facilitate PM applications.
- Updated `Hiring` class to manage guild settings and ensure persistent views.
- Restructured `OrderModal` and `ReviewModal` in `KofiShop` for improved user experience and error handling.
- Refactored `ModMail` class for better thread management and added ticket closure functionality with logging.
- Converted several commands in `KofiShop` from hybrid to app commands for better interaction.
- Enhanced overall code structure for readability and maintainability.
This commit is contained in:
2025-09-23 02:40:35 -04:00
parent 07b436ed8c
commit 500c7daaae
3 changed files with 153 additions and 288 deletions

View File

@@ -131,13 +131,9 @@ async def create_ticket(interaction: discord.Interaction, ticket_type: str, moda
if not interaction.response.is_done():
await interaction.response.send_message(f"An unexpected error occurred: {e}", ephemeral=True)
# --- Button Views for Commands ---
class HireView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.cog = cog
@discord.ui.button(label="Staff", style=discord.ButtonStyle.primary, custom_id="staff_apply_button_persistent")
async def staff_button(self, interaction: discord.Interaction, button: discord.ui.Button):
@@ -155,7 +151,10 @@ class HireView(discord.ui.View):
class WorkView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.cog = cog
@discord.ui.button(label="Apply for PM Position", style=discord.ButtonStyle.green, custom_id="work_apply_pm_persistent")
async def work_apply_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await create_ticket(interaction, "pm", PMApplicationModal)
@discord.ui.button(label="Apply for PM Position", style=discord.ButtonStyle.green, custom_id="work_apply_pm_persistent")
async def work_apply_button(self, interaction: discord.Interaction, button: discord.ui.Button):
@@ -170,6 +169,7 @@ class Hiring(commands.Cog):
"""
def __init__(self, bot: "Red"):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567891, force_registration=True)
default_guild = {
"staff_category": None,
"pm_category": None,
@@ -178,15 +178,11 @@ class Hiring(commands.Cog):
"closed_applications": {}
}
self.config.register_guild(**default_guild)
# We need to make sure the views are persistent so buttons work after a restart
self.bot.add_view(HireView(self))
self.bot.add_view(WorkView(self))
async def cog_load(self):
self.bot.add_view(HireView())
self.bot.add_view(WorkView())
# --- Commands ---
@commands.hybrid_command() # type: ignore
@app_commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
@@ -232,7 +228,6 @@ class Hiring(commands.Cog):
await ctx.send("I don't have permission to send messages in that channel.", ephemeral=True)
# --- Settings Commands ---
@commands.group(aliases=["hset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)