From 278c5b9c40f3585eadb5be02b26a718ccc34a187 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Wed, 19 Nov 2025 12:02:54 +0300 Subject: [PATCH] add token bug fix --- LichessClientTG_bot/bot.py | 8 ++++++-- LichessClientTG_bot/lichess_api.py | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/LichessClientTG_bot/bot.py b/LichessClientTG_bot/bot.py index 8e39dcf..27f3d46 100644 --- a/LichessClientTG_bot/bot.py +++ b/LichessClientTG_bot/bot.py @@ -294,8 +294,11 @@ class LichessBot: token = update.message.text.strip() user_id = update.effective_user.id + logger.info(f"Processing token for user {user_id}, token prefix: {token[:10]}...") + # Get username from token profile = await self.lichess_api.get_user_profile(token) + logger.info(f"Profile response: {profile is not None}") if profile: username = profile.get('username') if username: @@ -1317,6 +1320,7 @@ class LichessBot: self.application = application # Store application reference # Conversation handler for addtoken (token required) + # Must be added BEFORE general MessageHandler to avoid conflicts addtoken_conv = ConversationHandler( entry_points=[CommandHandler("addtoken", self.addtoken_start)], states={ @@ -1325,11 +1329,11 @@ class LichessBot: fallbacks=[CommandHandler("cancel", lambda u, c: ConversationHandler.END)] ) - # Add handlers + # Add handlers - ConversationHandler must be before general MessageHandler application.add_handler(CommandHandler("start", self.start_and_addgamer)) application.add_handler(CommandHandler("addgamer", self.addgamer_start)) + application.add_handler(addtoken_conv) # Add before general MessageHandler application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_username)) - application.add_handler(addtoken_conv) application.add_handler(CommandHandler("getgamers", self.getgamers)) application.add_handler(CommandHandler("delgamer", self.delgamer)) application.add_handler(CommandHandler("today", self.today)) diff --git a/LichessClientTG_bot/lichess_api.py b/LichessClientTG_bot/lichess_api.py index 6f61ca4..2a36a56 100644 --- a/LichessClientTG_bot/lichess_api.py +++ b/LichessClientTG_bot/lichess_api.py @@ -26,10 +26,13 @@ class LichessAPI: if response.status == 200: return await response.json() else: - logger.error(f"Failed to get user profile: {response.status}") + error_text = await response.text() + logger.error(f"Failed to get user profile: {response.status} - {error_text}") return None except Exception as e: logger.error(f"Error getting user profile: {e}") + import traceback + logger.error(traceback.format_exc()) return None async def get_today_stats(self, username: str) -> Optional[Dict[str, Any]]: