#!/usr/bin/env python3 """ Demo showing the fix for underscore command execution """ def demo_underscore_command_fix(): """Demonstrate the fix for underscore command execution""" print("šŸ”§ FIX FOR UNDERSCORE COMMAND EXECUTION") print("=" * 50) product_id = "68ce9e6a1621c4a87cc441b5" print("\nāŒ THE PROBLEM:") print("-" * 20) print(f"""User clicks: /product_{product_id} Bot behavior: Command executes but returns empty/nothing Root cause: filters.command("product") only matches "/product" but "/product_68ce..." is treated as a different command """) print("\nāœ… THE SOLUTION:") print("-" * 20) print(f"""Added separate regex handlers: • filters.regex(r"^/product_[a-zA-Z0-9]+") → Catches /product_xxx • filters.regex(r"^/stop_[a-zA-Z0-9]+") → Catches /stop_xxx Now when user clicks: /product_{product_id} āœ… Regex handler catches it āœ… Extracts ID: {product_id} āœ… Queries database āœ… Returns product details """) print("\nšŸ“± HOW IT WORKS NOW:") print("-" * 25) print(f"""1. User sees: šŸ” Get details: /product_{product_id} 2. Command appears as blue clickable link 3. User clicks → /product_{product_id} 4. Pyrogram regex filter matches the pattern 5. Handler extracts ID from command name 6. Database query executed with ID 7. Product details displayed successfully! """) print("\nšŸŽÆ TECHNICAL IMPLEMENTATION:") print("-" * 35) print("""Two handlers for each command type: PRODUCT COMMANDS: • @app.on_message(filters.command("product")) → Handles: /product 68ce9e6a1621c4a87cc441b5 • @app.on_message(filters.regex(r"^/product_[a-zA-Z0-9]+")) → Handles: /product_68ce9e6a1621c4a87cc441b5 STOP COMMANDS: • @app.on_message(filters.command("stop")) → Handles: /stop 68ce9e6a1621c4a87cc441b5 • @app.on_message(filters.regex(r"^/stop_[a-zA-Z0-9]+")) → Handles: /stop_68ce9e6a1621c4a87cc441b5 """) print("\n" + "=" * 50) print("✨ RESULT:") print(" āœ… Clickable commands work perfectly") print(" āœ… No more empty responses") print(" āœ… Full product details displayed") print(" āœ… Seamless user experience") print(" āœ… Both traditional and clickable formats supported") if __name__ == "__main__": demo_underscore_command_fix()