feat(promo): Добавлена локализация при изменении процента скидки и логи при активации промокода на скидку

This commit is contained in:
VAQYBIN
2026-01-20 01:26:14 +05:00
parent e7df5e539c
commit fed1c1c960
5 changed files with 50 additions and 8 deletions
+1 -4
View File
@@ -445,10 +445,7 @@ async def promo_edit_field_handler(callback: types.CallbackQuery, state: FSMCont
}
prompt_key = prompts.get(field, "error_occurred_try_again")
if field == "discount_percentage":
prompt_text = "Enter the new discount percentage (1-100):"
else:
prompt_text = _(prompt_key)
prompt_text = _(prompt_key)
await state.set_state(AdminStates.waiting_for_promo_edit_details)
await callback.message.edit_text(prompt_text)
+15
View File
@@ -165,6 +165,21 @@ async def process_promo_code_input(message: types.Message, state: FSMContext,
f"Discount promo code '{code_input}' successfully applied for user {user.id}."
)
discount_pct = result_discount # Returns percentage
# Send notification about discount promo activation
if settings.LOG_PROMO_ACTIVATIONS:
try:
from bot.services.notification_service import NotificationService
notification_service = NotificationService(bot, settings, i18n)
await notification_service.notify_discount_promo_activation(
user_id=user.id,
promo_code=code_input.upper(),
discount_percentage=discount_pct,
username=user.username
)
except Exception as e:
logging.error(f"Failed to send discount promo activation notification: {e}")
response_to_user_text = _(
"discount_promo_code_applied_success",
code=hcode(code_input.upper()),
+30 -4
View File
@@ -271,15 +271,15 @@ class NotificationService:
"""Send notification about promo code activation"""
if not self.settings.LOG_PROMO_ACTIVATIONS:
return
admin_lang = self.settings.DEFAULT_LANGUAGE
_ = lambda k, **kw: self.i18n.gettext(admin_lang, k, **kw) if self.i18n else k
user_display = self._format_user_display(
user_id=user_id,
username=username,
)
message = _(
"log_promo_activation",
user_display=user_display,
@@ -287,7 +287,33 @@ class NotificationService:
bonus_days=bonus_days,
timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
)
# Send to log channel
profile_keyboard = self._build_profile_keyboard(_, user_id)
await self._send_to_log_channel(message, reply_markup=profile_keyboard)
async def notify_discount_promo_activation(self, user_id: int, promo_code: str, discount_percentage: int,
username: Optional[str] = None):
"""Send notification about discount promo code activation"""
if not self.settings.LOG_PROMO_ACTIVATIONS:
return
admin_lang = self.settings.DEFAULT_LANGUAGE
_ = lambda k, **kw: self.i18n.gettext(admin_lang, k, **kw) if self.i18n else k
user_display = self._format_user_display(
user_id=user_id,
username=username,
)
message = _(
"log_promo_discount_activation",
user_display=user_display,
promo_code=promo_code,
discount_percentage=discount_percentage,
timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
)
# Send to log channel
profile_keyboard = self._build_profile_keyboard(_, user_id)
await self._send_to_log_channel(message, reply_markup=profile_keyboard)