From 651368112555881f0648191d4e30859bcce1dc46 Mon Sep 17 00:00:00 2001 From: machka pasla Date: Fri, 24 Oct 2025 10:33:10 +0300 Subject: [PATCH] fixed locales and traffic after adding days --- bot/services/subscription_service.py | 26 +++++++++++++++++++++++--- locales/en.json | 1 + locales/ru.json | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bot/services/subscription_service.py b/bot/services/subscription_service.py index 73fe993..e569b0b 100644 --- a/bot/services/subscription_service.py +++ b/bot/services/subscription_service.py @@ -568,6 +568,11 @@ class SubscriptionService: bonus_days: int, reason: str = "bonus", ) -> Optional[datetime]: + reason_lower = (reason or "").lower() + apply_main_traffic_limit = any( + keyword in reason_lower for keyword in ("admin", "promo code", "referral", "bonus") + ) + user = await user_dal.get_user_by_id(session, user_id) if not user: logging.warning( @@ -594,8 +599,12 @@ class SubscriptionService: start_date = datetime.now(timezone.utc) new_end_date_obj = start_date + timedelta(days=bonus_days) - # For promo code activations, use the configured user traffic limit - traffic_limit = self.settings.user_traffic_limit_bytes if "promo code" in reason.lower() else self.settings.trial_traffic_limit_bytes + # Apply main traffic limit for admin/referral/promo bonuses, fallback to trial limit otherwise + traffic_limit = ( + self.settings.user_traffic_limit_bytes + if apply_main_traffic_limit + else self.settings.trial_traffic_limit_bytes + ) bonus_sub_payload = { "user_id": user_id, @@ -626,12 +635,23 @@ class SubscriptionService: session, active_sub.subscription_id, new_end_date_obj ) + if ( + apply_main_traffic_limit + and updated_sub_model + and updated_sub_model.traffic_limit_bytes != self.settings.user_traffic_limit_bytes + ): + updated_sub_model = await subscription_dal.update_subscription( + session, + updated_sub_model.subscription_id, + {"traffic_limit_bytes": self.settings.user_traffic_limit_bytes}, + ) + if updated_sub_model: # Prepare panel update payload panel_update_payload = self._build_panel_update_payload( expire_at=new_end_date_obj, traffic_limit_bytes=( - self.settings.user_traffic_limit_bytes if "promo code" in reason.lower() else None + self.settings.user_traffic_limit_bytes if apply_main_traffic_limit else None ), include_uuid=False, ) diff --git a/locales/en.json b/locales/en.json index 46071a4..d74e821 100644 --- a/locales/en.json +++ b/locales/en.json @@ -257,6 +257,7 @@ "admin_user_invalid_days": "❌ Invalid number of days. Enter number from 1 to 3650.", "admin_user_subscription_added_success": "✅ Successfully added {days} days to user {user_id}", "admin_user_subscription_added_error": "❌ Error adding subscription days", + "admin_panel_user_creation_failed": "❌ Failed to create or link panel user for ID {user_id}. Manual intervention required.", "admin_user_ban_toggle_success": "✅ User {status}", "admin_user_ban_toggle_error": "❌ Error changing ban status", "admin_user_ban_success": "✅ User {input} has been banned", diff --git a/locales/ru.json b/locales/ru.json index 77c8475..c20d53c 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -257,6 +257,7 @@ "admin_user_invalid_days": "❌ Неверное количество дней. Введите число от 1 до 3650.", "admin_user_subscription_added_success": "✅ Успешно добавлено {days} дней подписки пользователю {user_id}", "admin_user_subscription_added_error": "❌ Ошибка добавления дней подписки", + "admin_panel_user_creation_failed": "❌ Не удалось создать или привязать пользователя в панели для ID {user_id}. Требуется ручная проверка.", "admin_user_ban_toggle_success": "✅ Пользователь {status}", "admin_user_ban_toggle_error": "❌ Ошибка изменения статуса блокировки", "admin_user_ban_success": "✅ Пользователь {input} заблокирован",