mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
Core Functionality:
base.py: Streamlined to core cog functionality and lifecycle management initialization.py: Centralized initialization logic error_handler.py: Unified error handling response_handler.py: Consistent response handling Command Organization: commands/archiver_commands.py: Core archiver functionality commands/database_commands.py: Database operations commands/settings_commands.py: Settings management All commands properly integrated with the cog using setup functions Improved Architecture: Consistent command registration pattern Better separation of concerns Maintained all original functionality Enhanced error handling and response management Proper command integration with the cog structure
This commit is contained in:
78
videoarchiver/core/response_handler.py
Normal file
78
videoarchiver/core/response_handler.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Module for handling command responses"""
|
||||
|
||||
import logging
|
||||
import discord
|
||||
from redbot.core.commands import Context
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
async def handle_response(ctx: Context, content: str = None, embed: discord.Embed = None) -> None:
|
||||
"""Helper method to handle responses for both regular commands and interactions"""
|
||||
try:
|
||||
# Check if this is a slash command interaction
|
||||
is_interaction = hasattr(ctx, "interaction") and ctx.interaction is not None
|
||||
|
||||
if is_interaction:
|
||||
try:
|
||||
# For slash commands
|
||||
if not ctx.interaction.response.is_done():
|
||||
# If not responded yet, send initial response
|
||||
if embed:
|
||||
await ctx.interaction.response.send_message(
|
||||
content=content, embed=embed
|
||||
)
|
||||
else:
|
||||
await ctx.interaction.response.send_message(content=content)
|
||||
else:
|
||||
# If already responded (deferred), use followup
|
||||
try:
|
||||
if embed:
|
||||
await ctx.interaction.followup.send(
|
||||
content=content, embed=embed
|
||||
)
|
||||
else:
|
||||
await ctx.interaction.followup.send(content=content)
|
||||
except AttributeError:
|
||||
# Fallback if followup is not available
|
||||
if embed:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
else:
|
||||
await ctx.send(content=content)
|
||||
except discord.errors.InteractionResponded:
|
||||
# If interaction was already responded to, try followup
|
||||
try:
|
||||
if embed:
|
||||
await ctx.interaction.followup.send(
|
||||
content=content, embed=embed
|
||||
)
|
||||
else:
|
||||
await ctx.interaction.followup.send(content=content)
|
||||
except (AttributeError, discord.errors.HTTPException):
|
||||
# Final fallback to regular message
|
||||
if embed:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
else:
|
||||
await ctx.send(content=content)
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling interaction response: {e}")
|
||||
# Fallback to regular message
|
||||
if embed:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
else:
|
||||
await ctx.send(content=content)
|
||||
else:
|
||||
# Regular command response
|
||||
if embed:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
else:
|
||||
await ctx.send(content=content)
|
||||
except Exception as e:
|
||||
logger.error(f"Error sending response: {e}")
|
||||
# Final fallback attempt
|
||||
try:
|
||||
if embed:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
else:
|
||||
await ctx.send(content=content)
|
||||
except Exception as e2:
|
||||
logger.error(f"Failed to send fallback message: {e2}")
|
||||
Reference in New Issue
Block a user