From 68459a707527cd9231fbbe2f8ea6a87844534245 Mon Sep 17 00:00:00 2001 From: Machka Pasla <161734431+machka-pasla@users.noreply.github.com> Date: Fri, 11 Jul 2025 19:28:45 +0700 Subject: [PATCH] Add admin notifications for promos and non-YK payments --- bot/services/notification_service.py | 15 +++++++++++++++ bot/services/promo_code_service.py | 10 +++++++++- bot/services/stars_service.py | 11 +++++++++++ bot/services/tribute_service.py | 11 +++++++++++ locales/en.json | 1 + locales/ru.json | 1 + 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/bot/services/notification_service.py b/bot/services/notification_service.py index 5f9212b..d2162ca 100644 --- a/bot/services/notification_service.py +++ b/bot/services/notification_service.py @@ -177,3 +177,18 @@ async def notify_admin_new_payment(bot: Bot, settings: Settings, i18n: JsonI18n, amount=f"{amount:.2f}", currency=currency_symbol, ) + + +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, + ) diff --git a/bot/services/promo_code_service.py b/bot/services/promo_code_service.py index e0398fc..55ed22c 100644 --- a/bot/services/promo_code_service.py +++ b/bot/services/promo_code_service.py @@ -10,6 +10,7 @@ from db.models import PromoCode, User from .subscription_service import SubscriptionService from bot.middlewares.i18n import JsonI18n +from .notification_service import notify_admin_promo_activation class PromoCodeService: @@ -56,7 +57,14 @@ class PromoCodeService: session, promo_data.promo_code_id) if activation_recorded and promo_incremented: - + await notify_admin_promo_activation( + self.bot, + self.settings, + self.i18n, + user_id, + code_input_upper, + bonus_days, + ) return True, _("promo_code_applied_success", code=code_input_upper, bonus_days=bonus_days, diff --git a/bot/services/stars_service.py b/bot/services/stars_service.py index bc5d536..840ec0f 100644 --- a/bot/services/stars_service.py +++ b/bot/services/stars_service.py @@ -10,6 +10,7 @@ from db.dal import payment_dal, user_dal from .subscription_service import SubscriptionService from .referral_service import ReferralService from bot.middlewares.i18n import JsonI18n +from .notification_service import notify_admin_new_payment class StarsService: @@ -133,3 +134,13 @@ class StarsService: logging.error( f"Failed to send stars payment success message: {e_send}") + await notify_admin_new_payment( + self.bot, + self.settings, + self.i18n, + message.from_user.id, + months, + float(stars_amount), + currency="XTR", + ) + diff --git a/bot/services/tribute_service.py b/bot/services/tribute_service.py index 4b4bf54..b4d8225 100644 --- a/bot/services/tribute_service.py +++ b/bot/services/tribute_service.py @@ -13,6 +13,7 @@ from bot.middlewares.i18n import JsonI18n from bot.services.subscription_service import SubscriptionService from bot.services.panel_api_service import PanelApiService from bot.services.referral_service import ReferralService +from .notification_service import notify_admin_new_payment from db.dal import payment_dal, user_dal, subscription_dal @@ -157,6 +158,16 @@ class TributeService: except Exception as e: logging.error( f"Failed to send Tribute payment success message to user {user_id}: {e}") + + await notify_admin_new_payment( + bot, + settings, + i18n, + user_id, + months, + float(price_rub), + currency="RUB", + ) elif event_name == 'cancelled_subscription': db_user = await user_dal.get_user_by_id(session, user_id) lang = db_user.language_code if db_user and db_user.language_code else settings.DEFAULT_LANGUAGE diff --git a/locales/en.json b/locales/en.json index 8ed8beb..c363d6c 100644 --- a/locales/en.json +++ b/locales/en.json @@ -216,6 +216,7 @@ "admin_new_trial_notification": "\ud83c\udf21 User {user_id} activated a free trial until {end_date}.", "admin_new_payment_notification": "\ud83d\udcb3 Payment received from user {user_id}: {months} mo. for {amount} {currency}.", + "admin_promo_activation_notification": "\ud83c\udf81 Promo code {code} activated by user {user_id} (+{bonus_days}d).", "error_unknown": "An unknown error occurred." } diff --git a/locales/ru.json b/locales/ru.json index 25fd0bc..5182788 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -216,6 +216,7 @@ "admin_new_trial_notification": "\ud83c\udf21 Пользователь {user_id} активировал пробный период до {end_date}.", "admin_new_payment_notification": "\ud83d\udcb3 Получен платеж от пользователя {user_id}: {months} мес. за {amount} {currency}.", + "admin_promo_activation_notification": "\ud83c\udf81 Пользователь {user_id} активировал промокод {code} (+{bonus_days} дн.)", "error_unknown": "Произошла неизвестная ошибка." }