Enhance private handlers structure and add database support

- Introduced a new `PrivateHandlers` class to encapsulate private message handling logic, improving organization and maintainability.
- Added new dependencies in `requirements.txt` for database support with `aiosqlite`.
- Updated the private handlers to utilize modular components for better separation of concerns and easier testing.
- Implemented error handling and logging for improved robustness in message processing.
This commit is contained in:
2025-08-28 01:41:19 +03:00
parent e17a9f9c29
commit f75e7f82c9
9 changed files with 1830 additions and 451 deletions

View File

@@ -0,0 +1,29 @@
"""Decorators and utility functions for private handlers"""
import traceback
from aiogram import types
from logs.custom_logger import logger
def error_handler(func):
"""Decorator for centralized error handling"""
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as e:
logger.error(f"Error in {func.__name__}: {str(e)}")
# Try to send error to logs if possible
try:
message = next((arg for arg in args if isinstance(arg, types.Message)), None)
if message and hasattr(message, 'bot'):
from helper_bot.utils.base_dependency_factory import get_global_instance
bdf = get_global_instance()
important_logs = bdf.settings['Telegram']['important_logs']
await message.bot.send_message(
chat_id=important_logs,
text=f"Произошла ошибка в {func.__name__}: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
)
except:
pass # If we can't log the error, at least it was logged to logger
raise
return wrapper