Refactor notification handling and streamline router registration
- Replaced legacy notification functions with a unified NotificationService for better maintainability and clarity. - Updated the main bot router registration to utilize a root router, simplifying the inclusion of user and admin routes. - Removed unused middleware and helper functions to enhance code cleanliness and focus on essential components. - Improved localization by adding new error messages for user interactions.
This commit is contained in:
@@ -295,51 +295,4 @@ class NotificationService:
|
||||
if to_admins:
|
||||
await self._send_to_admins(message)
|
||||
|
||||
|
||||
# Legacy functions for backward compatibility
|
||||
async def notify_admins(bot: Bot, settings: Settings, i18n: JsonI18n,
|
||||
message_key: str, parse_mode: str | None = None,
|
||||
**kwargs) -> None:
|
||||
if not settings.ADMIN_IDS:
|
||||
return
|
||||
admin_lang = settings.DEFAULT_LANGUAGE
|
||||
msg = i18n.gettext(admin_lang, message_key, **kwargs)
|
||||
for admin_id in settings.ADMIN_IDS:
|
||||
try:
|
||||
await bot.send_message(admin_id, msg, parse_mode=parse_mode)
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to send admin notification to {admin_id}: {e}")
|
||||
|
||||
|
||||
async def notify_admin_new_trial(bot: Bot, settings: Settings, i18n: JsonI18n,
|
||||
user_id: int, end_date: datetime) -> None:
|
||||
"""Send notification to admins about new trial activation (legacy)"""
|
||||
notification_service = NotificationService(bot, settings, i18n)
|
||||
await notification_service.notify_trial_activation(user_id, end_date)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async def notify_admin_promo_activation(bot: Bot, settings: Settings,
|
||||
i18n: JsonI18n, user_id: int,
|
||||
code: str,
|
||||
bonus_days: int) -> None:
|
||||
await notify_admins(
|
||||
bot,
|
||||
settings,
|
||||
i18n,
|
||||
"admin_promo_activation_notification",
|
||||
user_id=user_id,
|
||||
code=code,
|
||||
bonus_days=bonus_days,
|
||||
)
|
||||
|
||||
|
||||
async def notify_admin_panel_sync(bot: Bot, settings: Settings,
|
||||
i18n: JsonI18n, status: str,
|
||||
details: str, users_processed: int,
|
||||
subs_synced: int) -> None:
|
||||
"""Send notification to admins about panel sync (legacy)"""
|
||||
notification_service = NotificationService(bot, settings, i18n)
|
||||
await notification_service.notify_panel_sync(status, details, users_processed, subs_synced)
|
||||
# Removed legacy helper functions that duplicated NotificationService API
|
||||
Reference in New Issue
Block a user