diff --git a/bot.py b/bot.py index 894eef61..84190d9f 100644 --- a/bot.py +++ b/bot.py @@ -43,7 +43,24 @@ async def errors_handler(event: ErrorEvent, bot: Bot) -> bool: or "message can't be deleted for everyone" in error_message or "message to delete not found" in error_message ): - logger.warning("Отправляем стартовое меню.") + try: + tb = "".join(traceback.format_exception(type(event.exception), event.exception, event.exception.__traceback__)) + logger.warning(f"Показываем стартовое меню из-за TelegramBadRequest: {error_message}") + logger.error(f"Traceback:\n{tb}") + + if ADMIN_ID: + for admin_id in ADMIN_ID: + await bot.send_document( + chat_id=admin_id, + document=BufferedInputFile( + tb.encode(), + filename=f"error_{event.update.update_id}.txt", + ), + caption=f"{hbold(type(event.exception).__name__)}: {error_message[:1021]}...", + ) + except Exception as e: + logger.error(f"Сбой при логировании/отправке ошибки админу: {e}", exc_info=True) + try: from handlers.start import start_entry @@ -129,3 +146,5 @@ async def errors_handler(event: ErrorEvent, bot: Bot) -> bool: logger.warning(f"Не удалось отправить детали ошибки: {exception}") except Exception as exception: logger.error(f"Неожиданная ошибка в error handler: {exception}") + + return True \ No newline at end of file diff --git a/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so b/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so index 80b53cee..fcd1cfa4 100644 Binary files a/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so and b/handlers/payments/gift.cpython-312-x86_64-linux-gnu.so differ diff --git a/handlers/start.py b/handlers/start.py index b09a1f80..a4d8c027 100644 --- a/handlers/start.py +++ b/handlers/start.py @@ -239,8 +239,8 @@ async def show_start_menu(message: Message, admin: bool, session: AsyncSession): trial_status = await get_trial(session, message.chat.id) if session else None - show_trial = (trial_status == 0) and (not TRIAL_TIME_DISABLE) - show_profile = ((not SHOW_START_MENU_ONCE) or (trial_status != 0) or TRIAL_TIME_DISABLE) and (trial_status != -1) and (not show_trial) + show_trial = (trial_status in (-1, 0)) and (not TRIAL_TIME_DISABLE) + show_profile = ((not SHOW_START_MENU_ONCE) or (trial_status not in (-1, 0)) or TRIAL_TIME_DISABLE) and (not show_trial) if show_trial: kb.row(InlineKeyboardButton(text=TRIAL_SUB, callback_data="create_key")) diff --git a/middlewares/direct_start_blocker.py b/middlewares/direct_start_blocker.py index 50af22c2..566e9e46 100644 --- a/middlewares/direct_start_blocker.py +++ b/middlewares/direct_start_blocker.py @@ -59,7 +59,9 @@ class DirectStartBlockerMiddleware(BaseMiddleware): return exists if not text.startswith("/"): - return await handler(event, data) + if await user_exists_cached(): + return await handler(event, data) + return parts = text.split(maxsplit=1) if parts[0] != "/start":