Jelajahi Sumber

Update callback data for inline keyboard buttons in InfoCommands and TradingCommands - Changed callback data to include leading slashes for consistency across command handling. Enhanced error logging and command execution feedback to improve user interaction and clarity during bot operations.

Carles Sentis 4 hari lalu
induk
melakukan
4e2eb90b5b
2 mengubah file dengan 33 tambahan dan 24 penghapusan
  1. 15 15
      src/commands/info_commands.py
  2. 18 9
      src/commands/trading_commands.py

+ 15 - 15
src/commands/info_commands.py

@@ -954,35 +954,35 @@ Tap any button below for instant access to bot functions:
         
         keyboard = [
             [
-                InlineKeyboardButton("💰 Balance", callback_data="balance"),
-                InlineKeyboardButton("📈 Positions", callback_data="positions")
+                InlineKeyboardButton("💰 Balance", callback_data="/balance"),
+                InlineKeyboardButton("📈 Positions", callback_data="/positions")
             ],
             [
-                InlineKeyboardButton("📋 Orders", callback_data="orders"),
-                InlineKeyboardButton("📊 Stats", callback_data="stats")
+                InlineKeyboardButton("📋 Orders", callback_data="/orders"),
+                InlineKeyboardButton("📊 Stats", callback_data="/stats")
             ],
             [
-                InlineKeyboardButton("💵 Price", callback_data="price"),
-                InlineKeyboardButton("📊 Market", callback_data="market")
+                InlineKeyboardButton("💵 Price", callback_data="/price"),
+                InlineKeyboardButton("📊 Market", callback_data="/market")
             ],
             [
-                InlineKeyboardButton("🏆 Performance", callback_data="performance"),
-                InlineKeyboardButton("🔔 Alarms", callback_data="alarm")
+                InlineKeyboardButton("🏆 Performance", callback_data="/performance"),
+                InlineKeyboardButton("🔔 Alarms", callback_data="/alarm")
             ],
             [
-                InlineKeyboardButton("📅 Daily", callback_data="daily"),
-                InlineKeyboardButton("📊 Weekly", callback_data="weekly")
+                InlineKeyboardButton("📅 Daily", callback_data="/daily"),
+                InlineKeyboardButton("📊 Weekly", callback_data="/weekly")
             ],
             [
-                InlineKeyboardButton("📆 Monthly", callback_data="monthly"),
-                InlineKeyboardButton("🔄 Trades", callback_data="trades")
+                InlineKeyboardButton("📆 Monthly", callback_data="/monthly"),
+                InlineKeyboardButton("🔄 Trades", callback_data="/trades")
             ],
             [
-                InlineKeyboardButton("🔄 Monitoring", callback_data="monitoring"),
-                InlineKeyboardButton("📝 Logs", callback_data="logs")
+                InlineKeyboardButton("🔄 Monitoring", callback_data="/monitoring"),
+                InlineKeyboardButton("📝 Logs", callback_data="/logs")
             ],
             [
-                InlineKeyboardButton("⚙️ Help", callback_data="help")
+                InlineKeyboardButton("⚙️ Help", callback_data="/help")
             ]
         ]
         reply_markup = InlineKeyboardMarkup(keyboard)

+ 18 - 9
src/commands/trading_commands.py

@@ -619,29 +619,38 @@ This action cannot be undone.
                 # Add other management commands here if they have quick action buttons
             })
 
+        # Prepare key for map lookup, stripping leading '/' if present for general commands
+        mapped_command_key = callback_data
+        if callback_data.startswith('/') and not callback_data.startswith('/confirm_'): # Avoid stripping for confirm actions
+            mapped_command_key = callback_data[1:]
+
         # Check if the callback_data matches a mapped informational/management command
-        if callback_data in command_action_map:
-            command_method = command_action_map[callback_data]
+        if mapped_command_key in command_action_map:
+            command_method = command_action_map[mapped_command_key]
             try:
-                logger.info(f"Executing {callback_data} command via button callback.")
+                logger.info(f"Executing {mapped_command_key} command (from callback: {callback_data}) via button callback.")
                 # Edit the original message to indicate the action is being processed
-                # await query.edit_message_text(text=f"🔄 Processing {callback_data.capitalize()}...", parse_mode='HTML') # Optional
+                # await query.edit_message_text(text=f"🔄 Processing {mapped_command_key.capitalize()}...", parse_mode='HTML') # Optional
                 await command_method(update, context) # Call the actual command method
                 # After the command sends its own message(s), we might want to remove or clean up the original message with buttons.
                 # For now, let the command method handle all responses.
                 # Optionally, delete the message that had the buttons:
                 # await query.message.delete() 
             except Exception as e:
-                logger.error(f"Error executing command '{callback_data}' from button: {e}", exc_info=True)
+                logger.error(f"Error executing command '{mapped_command_key}' from button: {e}", exc_info=True)
                 try:
-                    await query.message.reply_text(f"❌ Error processing {callback_data.capitalize()}: {e}")
+                    await query.message.reply_text(f"❌ Error processing {mapped_command_key.capitalize()}: {e}")
                 except Exception as reply_e:
-                    logger.error(f"Failed to send error reply for {callback_data} button: {reply_e}")
+                    logger.error(f"Failed to send error reply for {mapped_command_key} button: {reply_e}")
             return # Handled
 
         # Special handling for 'help' callback from InfoCommands quick menu
-        if callback_data == "help":
-            logger.info("Handling 'help' button callback. Guiding user to /help command.")
+        # This check should use the modified key as well if we want /help to work via this mechanism
+        # However, the 'help' key in command_action_map is 'help', not '/help'.
+        # The current 'help' handling is separate and specific. Let's adjust it for consistency if needed or verify.
+        # The previous change to info_commands.py made help callback_data='/help'.
+        if callback_data == "/help": # Check for the actual callback_data value
+            logger.info("Handling '/help' button callback. Guiding user to /help command.")
             try:
                 # Remove the inline keyboard from the original message and provide guidance.
                 await query.edit_message_text(