Răsfoiți Sursa

Refactor Telegram bot application setup and message formatting - Removed the drop_pending_updates option during application initialization for improved functionality. Updated startup message formatting to ensure proper escape sequences for better readability. Enhanced the bot's polling mechanism to align with the latest version, contributing to a more reliable and user-friendly experience.

Carles Sentis 4 zile în urmă
părinte
comite
986e3d42ed
1 a modificat fișierele cu 8 adăugiri și 6 ștergeri
  1. 8 6
      src/bot/core.py

+ 8 - 6
src/bot/core.py

@@ -288,7 +288,7 @@ For support or issues, check the logs or contact the administrator.
         logger.info(f"🔧 Using python-telegram-bot version: {telegram.__version__} (Running in v20.x style)")
 
         # Create application
-        self.application = Application.builder().token(Config.TELEGRAM_BOT_TOKEN).drop_pending_updates(True).build()
+        self.application = Application.builder().token(Config.TELEGRAM_BOT_TOKEN).build()
         
         # Connect notification manager to the bot application
         self.notification_manager.set_bot_application(self.application)
@@ -305,10 +305,10 @@ For support or issues, check the logs or contact the administrator.
             logger.info(f"🚀 Starting Telegram trading bot v{self.version} (v20.x style)...")
             
             await self.send_message(
-                f"🤖 <b>Manual Trading Bot v{self.version} Started (v20.x style)</b>\n\n"
-                f"✅ Connected to Hyperliquid {'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}\n"
-                f"📊 Default Symbol: {Config.DEFAULT_TRADING_TOKEN}\n"
-                f"🔄 All systems ready!\n\n"
+                f"🤖 <b>Manual Trading Bot v{self.version} Started (v20.x style)</b>\\n\\n"
+                f"✅ Connected to Hyperliquid {{'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}}\\n"
+                f"📊 Default Symbol: {Config.DEFAULT_TRADING_TOKEN}\\n"
+                f"🔄 All systems ready!\\n\\n"
                 "Use /start for quick actions or /help for all commands."
             )
             
@@ -318,7 +318,9 @@ For support or issues, check the logs or contact the administrator.
             await self.application.start()
             
             logger.info("Bot is now running. Awaiting external stop signal (e.g., Ctrl+C) (v20.x style)...")
-            await keep_running_future
+            await self.application.run_polling(drop_pending_updates=Config.TELEGRAM_DROP_PENDING_UPDATES) 
+            
+            await keep_running_future 
                     
         except (KeyboardInterrupt, SystemExit):
             logger.info("🛑 Bot run interrupted by user/system. Initiating shutdown (v20.x style)...")