#!/usr/bin/env python3 """ Test the regex patterns for underscore commands """ import re def test_regex_patterns(): """Test the regex patterns for product and stop commands""" print("๐Ÿงช TESTING REGEX PATTERNS FOR UNDERSCORE COMMANDS") print("=" * 55) # Test product command regex product_pattern = r"^/product_[a-zA-Z0-9]+" stop_pattern = r"^/stop_[a-zA-Z0-9]+" # Test cases test_commands = [ "/product_68ce9e6a1621c4a87cc441b5", "/stop_68ce9e6a1621c4a87cc441b5", "/product_abc123def456", "/stop_xyz789", "/product 68ce9e6a1621c4a87cc441b5", # Should NOT match "/stop 68ce9e6a1621c4a87cc441b5", # Should NOT match "/my_trackings", # Should NOT match "/product_", # Should NOT match (no ID) ] print("\n๐Ÿ“‹ PRODUCT COMMAND TESTS:") print("-" * 30) for cmd in test_commands: match = re.match(product_pattern, cmd) status = "โœ… MATCH" if match else "โŒ NO MATCH" print(f"{status}: {cmd}") if match and cmd.startswith("/product_"): product_id = cmd.replace("/product_", "") print(f" Extracted ID: {product_id}") print("\n๐Ÿ“‹ STOP COMMAND TESTS:") print("-" * 30) for cmd in test_commands: match = re.match(stop_pattern, cmd) status = "โœ… MATCH" if match else "โŒ NO MATCH" print(f"{status}: {cmd}") if match and cmd.startswith("/stop_"): product_id = cmd.replace("/stop_", "") print(f" Extracted ID: {product_id}") print("\n" + "=" * 55) print("๐ŸŽฏ EXPECTED BEHAVIOR:") print(" โœ… /product_68ce9e6a1621c4a87cc441b5 โ†’ Should match and extract ID") print(" โœ… /stop_68ce9e6a1621c4a87cc441b5 โ†’ Should match and extract ID") print(" โŒ /product 68ce9e6a1621c4a87cc441b5 โ†’ Should NOT match (has space)") print(" โŒ /my_trackings โ†’ Should NOT match (different command)") print("\n๐Ÿ”ง HANDLER LOGIC:") print(" 1. Pyrogram filters.regex() catches the pattern") print(" 2. Handler extracts ID from command name") print(" 3. Queries database with extracted ID") print(" 4. Returns product information") if __name__ == "__main__": test_regex_patterns()