chore(security): replace silent exception swallowing across handlers

This commit is contained in:
kavore
2026-02-08 21:30:39 +03:00
parent 199c7797f5
commit da03510a92
16 changed files with 322 additions and 316 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
import logging
from aiogram import Bot from aiogram import Bot
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
@@ -87,8 +88,8 @@ def build_core_services(
setattr(subscription_service, "yookassa_service", yookassa_service) setattr(subscription_service, "yookassa_service", yookassa_service)
# Allow panel webhook to trigger renewals through subscription service # Allow panel webhook to trigger renewals through subscription service
setattr(panel_webhook_service, "subscription_service", subscription_service) setattr(panel_webhook_service, "subscription_service", subscription_service)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/app/factories/build_services.py: %s", exc)
return { return {
"panel_service": panel_service, "panel_service": panel_service,
+4 -4
View File
@@ -46,8 +46,8 @@ async def show_ads_menu(callback: types.CallbackQuery, settings: Settings, i18n_
await callback.message.edit_text(text, reply_markup=reply_markup) await callback.message.edit_text(text, reply_markup=reply_markup)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/admin/ads.py: %s", exc)
@router.callback_query(F.data.startswith("admin_ads:page:")) @router.callback_query(F.data.startswith("admin_ads:page:"))
@@ -262,8 +262,8 @@ async def ads_create_start(callback: types.CallbackQuery, state: FSMContext, set
await callback.message.edit_text(_("admin_ads_create_source_prompt")) await callback.message.edit_text(_("admin_ads_create_source_prompt"))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/admin/ads.py: %s", exc)
@router.message( @router.message(
+2 -2
View File
@@ -171,8 +171,8 @@ async def change_broadcast_target_handler(
current_lang, i18n, target=new_target current_lang, i18n, target=new_target
), ),
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/admin/broadcast.py: %s", exc)
await callback.answer() await callback.answer()
+2 -2
View File
@@ -1,5 +1,5 @@
import logging import logging
import random import secrets
import string import string
import csv import csv
import io import io
@@ -56,7 +56,7 @@ async def create_bulk_promo_prompt_handler(callback: types.CallbackQuery,
def generate_unique_promo_code(length: int = 8) -> str: def generate_unique_promo_code(length: int = 8) -> str:
"""Generate a unique random promo code""" """Generate a unique random promo code"""
characters = string.ascii_uppercase + string.digits characters = string.ascii_uppercase + string.digits
return ''.join(random.choice(characters) for _ in range(length)) return ''.join(secrets.choice(characters) for _ in range(length))
# Step 1: Process quantity # Step 1: Process quantity
+24 -24
View File
@@ -48,13 +48,13 @@ async def send_main_menu(target_event: Union[types.Message,
if isinstance(target_event, types.CallbackQuery): if isinstance(target_event, types.CallbackQuery):
try: try:
await target_event.answer(err_msg_fallback, show_alert=True) await target_event.answer(err_msg_fallback, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
elif isinstance(target_event, types.Message): elif isinstance(target_event, types.Message):
try: try:
await target_event.answer(err_msg_fallback) await target_event.answer(err_msg_fallback)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
return return
@@ -102,8 +102,8 @@ async def send_main_menu(target_event: Union[types.Message,
if isinstance(target_event, types.CallbackQuery): if isinstance(target_event, types.CallbackQuery):
try: try:
await target_event.answer() await target_event.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
except Exception as e_send_edit: except Exception as e_send_edit:
logging.warning( logging.warning(
f"Failed to send/edit main menu (user: {user_id}, is_edit: {is_edit}): {type(e_send_edit).__name__} - {e_send_edit}." f"Failed to send/edit main menu (user: {user_id}, is_edit: {is_edit}): {type(e_send_edit).__name__} - {e_send_edit}."
@@ -119,8 +119,8 @@ async def send_main_menu(target_event: Union[types.Message,
try: try:
await target_event.answer( await target_event.answer(
_("error_occurred_try_again") if is_edit else None) _("error_occurred_try_again") if is_edit else None)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
async def ensure_required_channel_subscription( async def ensure_required_channel_subscription(
@@ -220,13 +220,13 @@ async def ensure_required_channel_subscription(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(error_text, show_alert=True) await event.answer(error_text, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
if message_obj: if message_obj:
try: try:
await message_obj.answer(error_text) await message_obj.answer(error_text)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
else: else:
await event.answer(error_text) await event.answer(error_text)
return False return False
@@ -241,13 +241,13 @@ async def ensure_required_channel_subscription(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(error_text, show_alert=True) await event.answer(error_text, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
if message_obj: if message_obj:
try: try:
await message_obj.answer(error_text) await message_obj.answer(error_text)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
else: else:
await event.answer(error_text) await event.answer(error_text)
return False return False
@@ -296,12 +296,12 @@ async def ensure_required_channel_subscription(
if keyboard is None and message_obj: if keyboard is None and message_obj:
try: try:
await message_obj.answer(prompt_text) await message_obj.answer(prompt_text)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
try: try:
await event.answer(prompt_text, show_alert=True) await event.answer(prompt_text, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
else: else:
await event.answer(prompt_text, reply_markup=keyboard) await event.answer(prompt_text, reply_markup=keyboard)
@@ -462,8 +462,8 @@ async def start_command_handler(message: types.Message,
logging.error(f"Failed to attribute user {user_id} to ad '{ad_start_param}': {e_attr}") logging.error(f"Failed to attribute user {user_id} to ad '{ad_start_param}': {e_attr}")
try: try:
await session.rollback() await session.rollback()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
if not await ensure_required_channel_subscription(message, settings, i18n, if not await ensure_required_channel_subscription(message, settings, i18n,
current_lang, session, current_lang, session,
@@ -574,8 +574,8 @@ async def verify_channel_subscription_callback(
try: try:
await callback.answer(_(key="channel_subscription_verified_success"), await callback.answer(_(key="channel_subscription_verified_success"),
show_alert=True) show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/start.py: %s", exc)
await send_main_menu(callback, await send_main_menu(callback,
settings, settings,
+52 -52
View File
@@ -57,8 +57,8 @@ async def display_subscription_options(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(err_msg, show_alert=True) await event.answer(err_msg, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
elif isinstance(event, types.Message): elif isinstance(event, types.Message):
await event.answer(err_msg) await event.answer(err_msg)
return return
@@ -118,8 +118,8 @@ async def display_subscription_options(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(get_text("error_occurred_try_again"), show_alert=True) await event.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
@@ -129,8 +129,8 @@ async def display_subscription_options(
await target_message_obj.answer(text_content, reply_markup=reply_markup) await target_message_obj.answer(text_content, reply_markup=reply_markup)
try: try:
await event.answer() await event.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
else: else:
await target_message_obj.answer(text_content, reply_markup=reply_markup) await target_message_obj.answer(text_content, reply_markup=reply_markup)
@@ -186,8 +186,8 @@ async def my_subscription_command_handler(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer() await event.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
try: try:
await event.message.edit_text(text, reply_markup=kb) await event.message.edit_text(text, reply_markup=kb)
except Exception: except Exception:
@@ -209,8 +209,8 @@ async def my_subscription_command_handler(
if isinstance(val, (int, float)): if isinstance(val, (int, float)):
val_gb = float(val) / (2**30) val_gb = float(val) / (2**30)
return f"{val_gb:.2f} GB" return f"{val_gb:.2f} GB"
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return str(val) return str(val)
if traffic_mode: if traffic_mode:
@@ -222,8 +222,8 @@ async def my_subscription_command_handler(
used_val = active.get("traffic_used_bytes") or 0 used_val = active.get("traffic_used_bytes") or 0
remaining_val = max(0, float(limit_val) - float(used_val)) remaining_val = max(0, float(limit_val) - float(used_val))
remaining_display = _fmt_gb(remaining_val) remaining_display = _fmt_gb(remaining_val)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
text = get_text( text = get_text(
"my_traffic_details", "my_traffic_details",
status=active.get("status_from_panel", get_text("status_active")).capitalize(), status=active.get("status_from_panel", get_text("status_active")).capitalize(),
@@ -342,15 +342,15 @@ async def my_subscription_command_handler(
if prepend_rows: if prepend_rows:
kb = prepend_rows + kb kb = prepend_rows + kb
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
markup = InlineKeyboardMarkup(inline_keyboard=kb) markup = InlineKeyboardMarkup(inline_keyboard=kb)
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer() await event.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
try: try:
await event.message.edit_text(text, reply_markup=markup, parse_mode="HTML", disable_web_page_preview=True) await event.message.edit_text(text, reply_markup=markup, parse_mode="HTML", disable_web_page_preview=True)
except Exception: except Exception:
@@ -389,8 +389,8 @@ async def my_devices_command_handler(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(get_text("my_devices_feature_disabled"), show_alert=True) await event.answer(get_text("my_devices_feature_disabled"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
else: else:
await target.answer(get_text("my_devices_feature_disabled")) await target.answer(get_text("my_devices_feature_disabled"))
return return
@@ -402,8 +402,8 @@ async def my_devices_command_handler(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(message, show_alert=True) await event.answer(message, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
else: else:
await target.answer(message) await target.answer(message)
return return
@@ -413,8 +413,8 @@ async def my_devices_command_handler(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer(get_text("no_devices_found"), show_alert=True) await event.answer(get_text("no_devices_found"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
else: else:
await target.answer(get_text("no_devices_found")) await target.answer(get_text("no_devices_found"))
return return
@@ -475,8 +475,8 @@ async def my_devices_command_handler(
if isinstance(event, types.CallbackQuery): if isinstance(event, types.CallbackQuery):
try: try:
await event.answer() await event.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
try: try:
await event.message.edit_text(text, reply_markup=markup) await event.message.edit_text(text, reply_markup=markup)
except Exception: except Exception:
@@ -502,8 +502,8 @@ async def disconnect_device_handler(
if not settings.MY_DEVICES_SECTION_ENABLED: if not settings.MY_DEVICES_SECTION_ENABLED:
try: try:
await callback.answer(get_text("my_devices_feature_disabled"), show_alert=True) await callback.answer(get_text("my_devices_feature_disabled"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
try: try:
@@ -511,8 +511,8 @@ async def disconnect_device_handler(
except Exception: except Exception:
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
active = await subscription_service.get_active_subscription_details(session, callback.from_user.id) active = await subscription_service.get_active_subscription_details(session, callback.from_user.id)
@@ -549,8 +549,8 @@ async def disconnect_device_handler(
await session.commit() await session.commit()
try: try:
await callback.answer(get_text("device_disconnected")) await callback.answer(get_text("device_disconnected"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
await my_devices_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) await my_devices_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot)
@@ -576,8 +576,8 @@ async def toggle_autorenew_handler(
except Exception: except Exception:
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
sub = await session.get(Subscription, sub_id) sub = await session.get(Subscription, sub_id)
@@ -592,8 +592,8 @@ async def toggle_autorenew_handler(
if not has_saved_card: if not has_saved_card:
try: try:
await callback.answer(get_text("autorenew_enable_requires_card"), show_alert=True) await callback.answer(get_text("autorenew_enable_requires_card"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
# Show confirmation popup and inline buttons # Show confirmation popup and inline buttons
@@ -604,12 +604,12 @@ async def toggle_autorenew_handler(
except Exception: except Exception:
try: try:
await callback.message.answer(confirm_text, reply_markup=kb) await callback.message.answer(confirm_text, reply_markup=kb)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
@@ -634,8 +634,8 @@ async def confirm_autorenew_handler(
except Exception: except Exception:
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
sub = await session.get(Subscription, sub_id) sub = await session.get(Subscription, sub_id)
@@ -650,20 +650,20 @@ async def confirm_autorenew_handler(
if not has_saved_card: if not has_saved_card:
try: try:
await callback.answer(get_text("autorenew_enable_requires_card"), show_alert=True) await callback.answer(get_text("autorenew_enable_requires_card"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
try: try:
await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
await subscription_dal.update_subscription(session, sub.subscription_id, {"auto_renew_enabled": enable}) await subscription_dal.update_subscription(session, sub.subscription_id, {"auto_renew_enabled": enable})
await session.commit() await session.commit()
try: try:
await callback.answer(get_text("subscription_autorenew_updated")) await callback.answer(get_text("subscription_autorenew_updated"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot)
@@ -687,21 +687,21 @@ async def autorenew_cancel_from_webhook_button(
if not sub: if not sub:
try: try:
await callback.answer(get_text("subscription_not_active"), show_alert=True) await callback.answer(get_text("subscription_not_active"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
if sub.provider != "yookassa": if sub.provider != "yookassa":
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
return return
await subscription_dal.update_subscription(session, sub.subscription_id, {"auto_renew_enabled": False}) await subscription_dal.update_subscription(session, sub.subscription_id, {"auto_renew_enabled": False})
await session.commit() await session.commit()
try: try:
await callback.answer(get_text("subscription_autorenew_updated")) await callback.answer(get_text("subscription_autorenew_updated"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/core.py: %s", exc)
await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot) await my_subscription_command_handler(callback, i18n_data, settings, panel_service, subscription_service, session, bot)
@@ -1,3 +1,4 @@
import logging
from aiogram import Router, F, types from aiogram import Router, F, types
from typing import Optional, List from typing import Optional, List
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
@@ -26,8 +27,8 @@ async def payment_methods_manage(callback: types.CallbackQuery, settings: Settin
try: try:
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
await callback.answer(_("error_service_unavailable"), show_alert=True) await callback.answer(_("error_service_unavailable"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
@@ -67,8 +68,8 @@ async def payment_methods_manage(callback: types.CallbackQuery, settings: Settin
await callback.message.edit_text(text, reply_markup=get_payment_methods_list_keyboard(cards, 0, current_lang, i18n)) await callback.message.edit_text(text, reply_markup=get_payment_methods_list_keyboard(cards, 0, current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
@router.callback_query(F.data == "pm:bind") @router.callback_query(F.data == "pm:bind")
@@ -79,8 +80,8 @@ async def payment_method_bind(callback: types.CallbackQuery, settings: Settings,
try: try:
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
await callback.answer(_("error_service_unavailable"), show_alert=True) await callback.answer(_("error_service_unavailable"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
@@ -101,8 +102,8 @@ async def payment_method_bind(callback: types.CallbackQuery, settings: Settings,
await callback.message.edit_text(_("payment_methods_title"), reply_markup=get_bind_url_keyboard(resp["confirmation_url"], current_lang, i18n)) await callback.message.edit_text(_("payment_methods_title"), reply_markup=get_bind_url_keyboard(resp["confirmation_url"], current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
@router.callback_query(F.data.startswith("pm:delete_confirm")) @router.callback_query(F.data.startswith("pm:delete_confirm"))
@@ -113,8 +114,8 @@ async def payment_method_delete_confirm(callback: types.CallbackQuery, settings:
try: try:
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
await callback.answer(_("error_service_unavailable"), show_alert=True) await callback.answer(_("error_service_unavailable"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
parts = callback.data.split(":", 2) parts = callback.data.split(":", 2)
@@ -122,8 +123,8 @@ async def payment_method_delete_confirm(callback: types.CallbackQuery, settings:
await callback.message.edit_text(_("payment_method_delete_confirm"), reply_markup=get_payment_method_delete_confirm_keyboard(pm_id, current_lang, i18n)) await callback.message.edit_text(_("payment_method_delete_confirm"), reply_markup=get_payment_method_delete_confirm_keyboard(pm_id, current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
@router.callback_query(F.data.startswith("pm:delete")) @router.callback_query(F.data.startswith("pm:delete"))
@@ -134,8 +135,8 @@ async def payment_method_delete(callback: types.CallbackQuery, settings: Setting
try: try:
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
await callback.answer(_("error_service_unavailable"), show_alert=True) await callback.answer(_("error_service_unavailable"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
parts = callback.data.split(":", 2) parts = callback.data.split(":", 2)
@@ -156,8 +157,8 @@ async def payment_method_delete(callback: types.CallbackQuery, settings: Setting
try: try:
legacy_deleted = await user_billing_dal.delete_yk_payment_method(session, callback.from_user.id) legacy_deleted = await user_billing_dal.delete_yk_payment_method(session, callback.from_user.id)
deleted = deleted or legacy_deleted deleted = deleted or legacy_deleted
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
await session.commit() await session.commit()
methods = await list_user_payment_methods(session, callback.from_user.id) methods = await list_user_payment_methods(session, callback.from_user.id)
@@ -189,15 +190,15 @@ async def payment_method_delete(callback: types.CallbackQuery, settings: Setting
await callback.message.edit_text(f"{msg}\n\n{text}", reply_markup=get_payment_methods_list_keyboard(cards, 0, current_lang, i18n)) await callback.message.edit_text(f"{msg}\n\n{text}", reply_markup=get_payment_methods_list_keyboard(cards, 0, current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
except Exception: except Exception:
await session.rollback() await session.rollback()
try: try:
await callback.answer(_("error_try_again"), show_alert=True) await callback.answer(_("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
@router.callback_query(F.data.startswith("pm:view")) @router.callback_query(F.data.startswith("pm:view"))
@@ -208,8 +209,8 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings,
try: try:
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
await callback.answer(_("error_service_unavailable"), show_alert=True) await callback.answer(_("error_service_unavailable"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
@@ -262,14 +263,14 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings,
lp = result.scalar_one_or_none() lp = result.scalar_one_or_none()
if lp and lp.created_at: if lp and lp.created_at:
last_tx = lp.created_at.strftime('%Y-%m-%d') last_tx = lp.created_at.strftime('%Y-%m-%d')
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
details = f"{title}\n{_('payment_method_added_at', date=added_at)}\n{_('payment_method_last_tx', date=last_tx)}" details = f"{title}\n{_('payment_method_added_at', date=added_at)}\n{_('payment_method_last_tx', date=last_tx)}"
await callback.message.edit_text(details, reply_markup=get_payment_method_details_keyboard(str(sel.method_id), current_lang, i18n)) await callback.message.edit_text(details, reply_markup=get_payment_method_details_keyboard(str(sel.method_id), current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
added_at = billing.created_at.strftime('%Y-%m-%d') if getattr(billing, 'created_at', None) else "" added_at = billing.created_at.strftime('%Y-%m-%d') if getattr(billing, 'created_at', None) else ""
@@ -289,8 +290,8 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings,
last_payment = result.scalar_one_or_none() last_payment = result.scalar_one_or_none()
if last_payment and last_payment.created_at: if last_payment and last_payment.created_at:
last_tx = last_payment.created_at.strftime('%Y-%m-%d') last_tx = last_payment.created_at.strftime('%Y-%m-%d')
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
def _is_yoomoney_network(network: Optional[str]) -> bool: def _is_yoomoney_network(network: Optional[str]) -> bool:
s = (network or "").lower() s = (network or "").lower()
@@ -317,8 +318,8 @@ async def payment_method_view(callback: types.CallbackQuery, settings: Settings,
await callback.message.edit_text(details, reply_markup=get_payment_method_details_keyboard(billing.yookassa_payment_method_id, current_lang, i18n)) await callback.message.edit_text(details, reply_markup=get_payment_method_details_keyboard(billing.yookassa_payment_method_id, current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
@router.callback_query(F.data.startswith("pm:history")) @router.callback_query(F.data.startswith("pm:history"))
@@ -329,8 +330,8 @@ async def payment_method_history(callback: types.CallbackQuery, settings: Settin
try: try:
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
await callback.answer(_("error_service_unavailable"), show_alert=True) await callback.answer(_("error_service_unavailable"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
return return
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) if i18n else key
@@ -371,8 +372,8 @@ async def payment_method_history(callback: types.CallbackQuery, settings: Settin
if pm.get("id") == selected_pm_provider_id: if pm.get("id") == selected_pm_provider_id:
filtered.append(p) filtered.append(p)
continue continue
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
user_payments = filtered user_payments = filtered
if not user_payments: if not user_payments:
@@ -459,6 +460,6 @@ async def payment_methods_list(callback: types.CallbackQuery, settings: Settings
await callback.message.edit_text(text, reply_markup=get_payment_methods_list_keyboard(cards, page, current_lang, i18n)) await callback.message.edit_text(text, reply_markup=get_payment_methods_list_keyboard(cards, page, current_lang, i18n))
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payment_methods.py: %s", exc)
@@ -1,3 +1,4 @@
import logging
from typing import Optional from typing import Optional
from aiogram import F, Router, types from aiogram import F, Router, types
@@ -27,15 +28,15 @@ async def pay_crypto_callback_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc)
return return
if not cryptopay_service or not getattr(cryptopay_service, "configured", False): if not cryptopay_service or not getattr(cryptopay_service, "configured", False):
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc)
return return
try: try:
@@ -47,8 +48,8 @@ async def pay_crypto_callback_handler(
except (ValueError, IndexError): except (ValueError, IndexError):
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc)
return return
user_id = callback.from_user.id user_id = callback.from_user.id
@@ -103,15 +104,15 @@ async def pay_crypto_callback_handler(
), ),
disable_web_page_preview=False, disable_web_page_preview=False,
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc)
return return
try: try:
await callback.answer(get_text("error_payment_gateway"), show_alert=True) await callback.answer(get_text("error_payment_gateway"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_crypto.py: %s", exc)
@@ -30,20 +30,20 @@ async def pay_fk_callback_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
return return
if not freekassa_service or not freekassa_service.configured: if not freekassa_service or not freekassa_service.configured:
logging.error("FreeKassa service is not configured or unavailable.") logging.error("FreeKassa service is not configured or unavailable.")
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
try: try:
await callback.message.edit_text(get_text("payment_service_unavailable")) await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
return return
try: try:
@@ -56,8 +56,8 @@ async def pay_fk_callback_handler(
logging.error(f"Invalid pay_fk data in callback: {callback.data}") logging.error(f"Invalid pay_fk data in callback: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
return return
user_id = callback.from_user.id user_id = callback.from_user.id
@@ -95,12 +95,12 @@ async def pay_fk_callback_handler(
) )
try: try:
await callback.message.edit_text(get_text("error_creating_payment_record")) await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
return return
success, response_data = await freekassa_service.create_order( success, response_data = await freekassa_service.create_order(
@@ -181,12 +181,12 @@ async def pay_fk_callback_handler(
), ),
disable_web_page_preview=False, disable_web_page_preview=False,
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
return return
logging.error( logging.error(
@@ -214,9 +214,9 @@ async def pay_fk_callback_handler(
try: try:
await callback.message.edit_text(get_text("error_payment_gateway")) await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
try: try:
await callback.answer(get_text("error_payment_gateway"), show_alert=True) await callback.answer(get_text("error_payment_gateway"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_freekassa.py: %s", exc)
@@ -30,20 +30,20 @@ async def pay_platega_callback_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
return return
if not platega_service or not platega_service.configured: if not platega_service or not platega_service.configured:
logging.error("Platega service is not configured or unavailable.") logging.error("Platega service is not configured or unavailable.")
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
try: try:
await callback.message.edit_text(get_text("payment_service_unavailable")) await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
return return
try: try:
@@ -56,8 +56,8 @@ async def pay_platega_callback_handler(
logging.error(f"Invalid pay_platega data in callback: {callback.data}") logging.error(f"Invalid pay_platega data in callback: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
return return
user_id = callback.from_user.id user_id = callback.from_user.id
@@ -95,12 +95,12 @@ async def pay_platega_callback_handler(
) )
try: try:
await callback.message.edit_text(get_text("error_creating_payment_record")) await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
return return
payload_meta = json.dumps( payload_meta = json.dumps(
@@ -183,12 +183,12 @@ async def pay_platega_callback_handler(
), ),
disable_web_page_preview=False, disable_web_page_preview=False,
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
return return
logging.error( logging.error(
@@ -210,9 +210,9 @@ async def pay_platega_callback_handler(
try: try:
await callback.message.edit_text(get_text("error_payment_gateway")) await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
try: try:
await callback.answer(get_text("error_payment_gateway"), show_alert=True) await callback.answer(get_text("error_payment_gateway"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_platega.py: %s", exc)
@@ -29,20 +29,20 @@ async def pay_severpay_callback_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
return return
if not severpay_service or not severpay_service.configured: if not severpay_service or not severpay_service.configured:
logging.error("SeverPay service is not configured or unavailable.") logging.error("SeverPay service is not configured or unavailable.")
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
try: try:
await callback.message.edit_text(get_text("payment_service_unavailable")) await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
return return
try: try:
@@ -55,8 +55,8 @@ async def pay_severpay_callback_handler(
logging.error(f"Invalid pay_severpay data in callback: {callback.data}") logging.error(f"Invalid pay_severpay data in callback: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
return return
user_id = callback.from_user.id user_id = callback.from_user.id
@@ -94,12 +94,12 @@ async def pay_severpay_callback_handler(
) )
try: try:
await callback.message.edit_text(get_text("error_creating_payment_record")) await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
return return
success, response_data = await severpay_service.create_payment( success, response_data = await severpay_service.create_payment(
@@ -172,12 +172,12 @@ async def pay_severpay_callback_handler(
), ),
disable_web_page_preview=False, disable_web_page_preview=False,
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
return return
logging.error( logging.error(
@@ -199,9 +199,9 @@ async def pay_severpay_callback_handler(
try: try:
await callback.message.edit_text(get_text("error_payment_gateway")) await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
try: try:
await callback.answer(get_text("error_payment_gateway"), show_alert=True) await callback.answer(get_text("error_payment_gateway"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_severpay.py: %s", exc)
@@ -28,15 +28,15 @@ async def pay_stars_callback_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc)
return return
if not settings.STARS_ENABLED: if not settings.STARS_ENABLED:
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc)
return return
try: try:
@@ -48,8 +48,8 @@ async def pay_stars_callback_handler(
except (ValueError, IndexError): except (ValueError, IndexError):
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc)
return return
user_id = callback.from_user.id user_id = callback.from_user.id
@@ -89,23 +89,23 @@ async def pay_stars_callback_handler(
logging.warning(f"Stars payment: failed to show invoice info message ({e_edit})") logging.warning(f"Stars payment: failed to show invoice info message ({e_edit})")
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc)
return return
try: try:
await callback.answer(get_text("error_payment_gateway"), show_alert=True) await callback.answer(get_text("error_payment_gateway"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_stars.py: %s", exc)
@router.pre_checkout_query() @router.pre_checkout_query()
async def handle_pre_checkout_query(query: types.PreCheckoutQuery): async def handle_pre_checkout_query(query: types.PreCheckoutQuery):
try: try:
await query.answer(ok=True) await query.answer(ok=True)
except Exception: except Exception as exc:
# Nothing else to do here; Telegram will show an error if not answered # Nothing else to do here; Telegram will show an error if not answered
pass logging.debug("Failed to answer pre_checkout_query in payments_stars: %s", exc)
@router.message(F.successful_payment) @router.message(F.successful_payment)
@@ -27,8 +27,8 @@ async def select_subscription_period_callback_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_subscription.py: %s", exc)
return return
traffic_packages = getattr(settings, "traffic_packages", {}) or {} traffic_packages = getattr(settings, "traffic_packages", {}) or {}
@@ -40,8 +40,8 @@ async def select_subscription_period_callback_handler(
logging.error(f"Invalid subscription period in callback_data: {callback.data}") logging.error(f"Invalid subscription period in callback_data: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_subscription.py: %s", exc)
return return
price_source = traffic_packages if traffic_mode else settings.subscription_options price_source = traffic_packages if traffic_mode else settings.subscription_options
@@ -111,8 +111,8 @@ async def select_subscription_period_callback_handler(
) )
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_subscription.py: %s", exc)
return return
price_rub = 0.0 price_rub = 0.0
currency_symbol_val = "" currency_symbol_val = ""
@@ -122,8 +122,8 @@ async def select_subscription_period_callback_handler(
) )
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_subscription.py: %s", exc)
return return
text_content = get_text("choose_payment_method_traffic") if traffic_mode else get_text("choose_payment_method") text_content = get_text("choose_payment_method_traffic") if traffic_mode else get_text("choose_payment_method")
@@ -150,5 +150,5 @@ async def select_subscription_period_callback_handler(
await callback.message.answer(text_content, reply_markup=reply_markup) await callback.message.answer(text_content, reply_markup=reply_markup)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_subscription.py: %s", exc)
@@ -150,15 +150,15 @@ async def _initiate_yk_payment(
) )
try: try:
await callback.message.edit_text(get_text("error_creating_payment_record")) await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False return False
if not db_payment_record: if not db_payment_record:
try: try:
await callback.message.edit_text(get_text("error_creating_payment_record")) await callback.message.edit_text(get_text("error_creating_payment_record"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False return False
yookassa_metadata = { yookassa_metadata = {
@@ -222,8 +222,8 @@ async def _initiate_yk_payment(
card_network=display_network, card_network=display_network,
set_default=save_payment_method, set_default=save_payment_method,
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
await session.commit() await session.commit()
except Exception: except Exception:
await session.rollback() await session.rollback()
@@ -251,8 +251,8 @@ async def _initiate_yk_payment(
) )
try: try:
await callback.message.edit_text(get_text("error_payment_gateway_link_failed")) await callback.message.edit_text(get_text("error_payment_gateway_link_failed"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False return False
try: try:
@@ -291,8 +291,8 @@ async def _initiate_yk_payment(
), ),
disable_web_page_preview=False, disable_web_page_preview=False,
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return True return True
if payment_response_yk and payment_method_id: if payment_response_yk and payment_method_id:
@@ -320,8 +320,8 @@ async def _initiate_yk_payment(
) )
try: try:
await callback.message.edit_text(get_text("error_payment_gateway")) await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False return False
message_text = get_text("yookassa_autopay_charge_initiated") message_text = get_text("yookassa_autopay_charge_initiated")
@@ -337,8 +337,8 @@ async def _initiate_yk_payment(
message_text, message_text,
reply_markup=get_back_to_main_menu_markup(current_lang, i18n), reply_markup=get_back_to_main_menu_markup(current_lang, i18n),
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return True return True
try: try:
@@ -357,8 +357,8 @@ async def _initiate_yk_payment(
) )
try: try:
await callback.message.edit_text(get_text("error_payment_gateway")) await callback.message.edit_text(get_text("error_payment_gateway"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return False return False
@@ -371,8 +371,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
if not yookassa_service or not yookassa_service.configured: if not yookassa_service or not yookassa_service.configured:
@@ -381,8 +381,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
await target_msg_edit.edit_text(get_text("payment_service_unavailable")) await target_msg_edit.edit_text(get_text("payment_service_unavailable"))
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
try: try:
@@ -391,8 +391,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk data in callback: {callback.data}") logging.error(f"Invalid pay_yk data in callback: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
parsed = _parse_offer_payload(data_payload) parsed = _parse_offer_payload(data_payload)
@@ -400,8 +400,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk payload structure: {callback.data}") logging.error(f"Invalid pay_yk payload structure: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
months, price_rub, sale_mode = parsed months, price_rub, sale_mode = parsed
@@ -448,12 +448,12 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
sale_mode=sale_mode, sale_mode=sale_mode,
), ),
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
await _initiate_yk_payment( await _initiate_yk_payment(
@@ -475,8 +475,8 @@ async def pay_yk_callback_handler(callback: types.CallbackQuery, settings: Setti
) )
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
@router.callback_query(F.data.startswith("pay_yk_new:")) @router.callback_query(F.data.startswith("pay_yk_new:"))
@@ -488,20 +488,20 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
if not yookassa_service or not yookassa_service.configured: if not yookassa_service or not yookassa_service.configured:
logging.error("YooKassa service unavailable for pay_yk_new.") logging.error("YooKassa service unavailable for pay_yk_new.")
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try: try:
await callback.message.edit_text(get_text("payment_service_unavailable")) await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
try: try:
@@ -510,8 +510,8 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk_new data in callback: {callback.data}") logging.error(f"Invalid pay_yk_new data in callback: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
parsed = _parse_offer_payload(data_payload) parsed = _parse_offer_payload(data_payload)
@@ -519,8 +519,8 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
logging.error(f"Invalid pay_yk_new payload structure: {callback.data}") logging.error(f"Invalid pay_yk_new payload structure: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
months, price_rub, sale_mode = parsed months, price_rub, sale_mode = parsed
@@ -550,8 +550,8 @@ async def pay_yk_new_card_handler(callback: types.CallbackQuery, settings: Setti
) )
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
@router.callback_query(F.data.startswith("pay_yk_saved_list:")) @router.callback_query(F.data.startswith("pay_yk_saved_list:"))
@@ -563,8 +563,8 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
try: try:
@@ -573,8 +573,8 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
logging.error(f"Invalid pay_yk_saved_list data: {callback.data}") logging.error(f"Invalid pay_yk_saved_list data: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
parts = data_payload.split(":") parts = data_payload.split(":")
@@ -582,8 +582,8 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
logging.error(f"pay_yk_saved_list payload missing components: {callback.data}") logging.error(f"pay_yk_saved_list payload missing components: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
try: try:
@@ -595,16 +595,16 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
logging.error(f"pay_yk_saved_list payload parsing error: {callback.data}") logging.error(f"pay_yk_saved_list payload parsing error: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
autopay_enabled = bool(settings.yookassa_autopayments_active and sale_mode != "traffic" and not settings.traffic_sale_mode) autopay_enabled = bool(settings.yookassa_autopayments_active and sale_mode != "traffic" and not settings.traffic_sale_mode)
if not autopay_enabled: if not autopay_enabled:
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
user_id = callback.from_user.id user_id = callback.from_user.id
@@ -643,12 +643,12 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
sale_mode=sale_mode, sale_mode=sale_mode,
), ),
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
cards: List[Tuple[str, str]] = [] cards: List[Tuple[str, str]] = []
@@ -690,12 +690,12 @@ async def pay_yk_saved_list_handler(callback: types.CallbackQuery, settings: Set
sale_mode=sale_mode, sale_mode=sale_mode,
), ),
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
@router.callback_query(F.data.startswith("pay_yk_use_saved:")) @router.callback_query(F.data.startswith("pay_yk_use_saved:"))
@@ -707,20 +707,20 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(get_text("error_occurred_try_again"), show_alert=True) await callback.answer(get_text("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
if not yookassa_service or not yookassa_service.configured: if not yookassa_service or not yookassa_service.configured:
logging.error("YooKassa service unavailable for pay_yk_use_saved.") logging.error("YooKassa service unavailable for pay_yk_use_saved.")
try: try:
await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True) await callback.answer(get_text("payment_service_unavailable_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
try: try:
await callback.message.edit_text(get_text("payment_service_unavailable")) await callback.message.edit_text(get_text("payment_service_unavailable"))
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
try: try:
@@ -729,8 +729,8 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.error(f"Invalid pay_yk_use_saved data: {callback.data}") logging.error(f"Invalid pay_yk_use_saved data: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
parts = data_payload.split(":") parts = data_payload.split(":")
@@ -738,8 +738,8 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.error(f"pay_yk_use_saved payload missing components: {callback.data}") logging.error(f"pay_yk_use_saved payload missing components: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
try: try:
@@ -750,16 +750,16 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.error(f"pay_yk_use_saved months/price parsing error: {callback.data}") logging.error(f"pay_yk_use_saved months/price parsing error: {callback.data}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
autopay_enabled = bool(settings.yookassa_autopayments_active and sale_mode != "traffic" and not settings.traffic_sale_mode) autopay_enabled = bool(settings.yookassa_autopayments_active and sale_mode != "traffic" and not settings.traffic_sale_mode)
if not autopay_enabled: if not autopay_enabled:
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
method_identifier = parts[2] method_identifier = parts[2]
@@ -787,8 +787,8 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
logging.warning(f"Selected payment method not found for user {user_id}: {method_identifier}") logging.warning(f"Selected payment method not found for user {user_id}: {method_identifier}")
try: try:
await callback.answer(get_text("error_try_again"), show_alert=True) await callback.answer(get_text("error_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
return return
currency_code_for_yk = "RUB" currency_code_for_yk = "RUB"
@@ -814,5 +814,5 @@ async def pay_yk_use_saved_handler(callback: types.CallbackQuery, settings: Sett
) )
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/subscription/payments_yookassa.py: %s", exc)
+20 -20
View File
@@ -35,8 +35,8 @@ async def request_trial_confirmation_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(_("error_occurred_try_again"), show_alert=True) await callback.answer(_("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
return return
show_trial_btn_in_menu_if_fail = False show_trial_btn_in_menu_if_fail = False
@@ -53,8 +53,8 @@ async def request_trial_confirmation_handler(
) )
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
return return
if await subscription_service.has_had_any_subscription(session, user_id): if await subscription_service.has_had_any_subscription(session, user_id):
@@ -66,8 +66,8 @@ async def request_trial_confirmation_handler(
) )
try: try:
await callback.answer() await callback.answer()
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
return return
# Directly activate trial without confirmation # Directly activate trial without confirmation
@@ -84,8 +84,8 @@ async def request_trial_confirmation_handler(
if activation_result and activation_result.get("activated"): if activation_result and activation_result.get("activated"):
try: try:
await callback.answer(_("trial_activated_alert"), show_alert=True) await callback.answer(_("trial_activated_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
end_date_obj = activation_result.get("end_date") end_date_obj = activation_result.get("end_date")
config_link_display_for_trial, connect_button_url_for_trial = await prepare_config_links( config_link_display_for_trial, connect_button_url_for_trial = await prepare_config_links(
@@ -134,8 +134,8 @@ async def request_trial_confirmation_handler(
final_message_text_in_chat = _(message_key_from_service) final_message_text_in_chat = _(message_key_from_service)
try: try:
await callback.answer(final_message_text_in_chat, show_alert=True) await callback.answer(final_message_text_in_chat, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
if ( if (
settings.TRIAL_ENABLED settings.TRIAL_ENABLED
and not await subscription_service.has_had_any_subscription( and not await subscription_service.has_had_any_subscription(
@@ -197,15 +197,15 @@ async def confirm_activate_trial_handler(
if not i18n or not callback.message: if not i18n or not callback.message:
try: try:
await callback.answer(_("error_occurred_try_again"), show_alert=True) await callback.answer(_("error_occurred_try_again"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
return return
if not settings.TRIAL_ENABLED: if not settings.TRIAL_ENABLED:
try: try:
await callback.answer(_("trial_feature_disabled"), show_alert=True) await callback.answer(_("trial_feature_disabled"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
await send_main_menu( await send_main_menu(
callback, settings, i18n_data, subscription_service, session, is_edit=True callback, settings, i18n_data, subscription_service, session, is_edit=True
@@ -216,8 +216,8 @@ async def confirm_activate_trial_handler(
await callback.answer( await callback.answer(
_("trial_already_had_subscription_or_trial"), show_alert=True _("trial_already_had_subscription_or_trial"), show_alert=True
) )
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
await send_main_menu( await send_main_menu(
callback, settings, i18n_data, subscription_service, session, is_edit=True callback, settings, i18n_data, subscription_service, session, is_edit=True
) )
@@ -236,8 +236,8 @@ async def confirm_activate_trial_handler(
if activation_result and activation_result.get("activated"): if activation_result and activation_result.get("activated"):
try: try:
await callback.answer(_("trial_activated_alert"), show_alert=True) await callback.answer(_("trial_activated_alert"), show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
end_date_obj = activation_result.get("end_date") end_date_obj = activation_result.get("end_date")
config_link_display_for_trial, connect_button_url_for_trial = await prepare_config_links( config_link_display_for_trial, connect_button_url_for_trial = await prepare_config_links(
@@ -274,8 +274,8 @@ async def confirm_activate_trial_handler(
final_message_text_in_chat = _(message_key_from_service) final_message_text_in_chat = _(message_key_from_service)
try: try:
await callback.answer(final_message_text_in_chat, show_alert=True) await callback.answer(final_message_text_in_chat, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Suppressed exception in bot/handlers/user/trial_handler.py: %s", exc)
if ( if (
settings.TRIAL_ENABLED settings.TRIAL_ENABLED
and not await subscription_service.has_had_any_subscription( and not await subscription_service.has_had_any_subscription(
+5 -2
View File
@@ -32,6 +32,9 @@ class ChannelSubscriptionMiddleware(BaseMiddleware):
event: Update, event: Update,
data: Dict[str, Any], data: Dict[str, Any],
) -> Any: ) -> Any:
if not self.settings.REQUIRED_CHANNEL_SUBSCRIBE_TO_USE:
return await handler(event, data)
required_channel_id = self.settings.REQUIRED_CHANNEL_ID required_channel_id = self.settings.REQUIRED_CHANNEL_ID
if not required_channel_id: if not required_channel_id:
return await handler(event, data) return await handler(event, data)
@@ -124,8 +127,8 @@ class ChannelSubscriptionMiddleware(BaseMiddleware):
) -> None: ) -> None:
try: try:
await callback.answer(prompt_text, show_alert=True) await callback.answer(prompt_text, show_alert=True)
except Exception: except Exception as exc:
pass logging.debug("Failed to answer callback for channel gate prompt: %s", exc)
if callback.message: if callback.message:
try: try: