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:
pacnpal
2024-11-16 03:30:11 +00:00
parent 6aeb87fb40
commit 537a325807
8 changed files with 824 additions and 623 deletions

View File

@@ -0,0 +1,46 @@
"""Module for handling command errors"""
import logging
import traceback
from redbot.core.commands import Context, MissingPermissions, BotMissingPermissions, MissingRequiredArgument, BadArgument
from ..utils.exceptions import VideoArchiverError as ProcessingError, ConfigurationError as ConfigError
from .response_handler import handle_response
logger = logging.getLogger("VideoArchiver")
async def handle_command_error(ctx: Context, error: Exception) -> None:
"""Handle command errors"""
error_msg = None
try:
if isinstance(error, MissingPermissions):
error_msg = "❌ You don't have permission to use this command."
elif isinstance(error, BotMissingPermissions):
error_msg = "❌ I don't have the required permissions to do that."
elif isinstance(error, MissingRequiredArgument):
error_msg = f"❌ Missing required argument: {error.param.name}"
elif isinstance(error, BadArgument):
error_msg = f"❌ Invalid argument: {str(error)}"
elif isinstance(error, ConfigError):
error_msg = f"❌ Configuration error: {str(error)}"
elif isinstance(error, ProcessingError):
error_msg = f"❌ Processing error: {str(error)}"
else:
logger.error(
f"Command error in {ctx.command}: {traceback.format_exc()}"
)
error_msg = (
"❌ An unexpected error occurred. Check the logs for details."
)
if error_msg:
await handle_response(ctx, error_msg)
except Exception as e:
logger.error(f"Error handling command error: {str(e)}")
try:
await handle_response(
ctx,
"❌ An error occurred while handling another error. Please check the logs.",
)
except Exception:
pass