(text)
| 94 | |
| 95 | |
| 96 | def rule_based_action(text): |
| 97 | cleaned = normalize_text(text) |
| 98 | if not cleaned: |
| 99 | return "" |
| 100 | if cleaned in CMD_OPEN_PHRASES: |
| 101 | return "open_cmd" |
| 102 | if is_dangerous_request(cleaned): |
| 103 | return "blocked" |
| 104 | |
| 105 | search_prefixes = ["search for ", "google search ", "look up ", "find ", "ara ", "google da ara "] |
| 106 | for prefix in search_prefixes: |
| 107 | if cleaned.startswith(prefix): |
| 108 | query = cleaned.removeprefix(prefix).strip() |
| 109 | return f"search_google:{query}" if query else "" |
| 110 | if cleaned.endswith(" ara"): |
| 111 | query = cleaned[: -len(" ara")].strip() |
| 112 | return f"search_google:{query}" if query else "" |
| 113 | |
| 114 | close_prefixes = ["close ", "kapat ", "close the ", "can you close "] |
| 115 | for prefix in close_prefixes: |
| 116 | if cleaned.startswith(prefix): |
| 117 | app = cleaned.removeprefix(prefix).strip() |
| 118 | return f"close_app:{app}" if app else "" |
| 119 | if cleaned.endswith(" kapat"): |
| 120 | app = cleaned[: -len(" kapat")].strip() |
| 121 | return f"close_app:{app}" if app else "" |
| 122 | |
| 123 | open_prefixes = ["open ", "launch ", "start ", "can you open ", "please open ", "ac ", "aç "] |
| 124 | suffix_open_words = [" ac", " aç", " i ac", " i aç", " u ac", " u aç"] |
| 125 | for site, url in KNOWN_SITES.items(): |
| 126 | if cleaned in {site, f"open {site}", f"{site} ac", f"{site} aç"}: |
| 127 | return f"open_web:{url}" |
| 128 | for prefix in open_prefixes: |
| 129 | if cleaned.startswith(prefix): |
| 130 | target = cleaned.removeprefix(prefix).strip() |
| 131 | if target in KNOWN_SITES: |
| 132 | return f"open_web:{target}" |
| 133 | return f"open_app:{target}" if target else "" |
| 134 | for suffix in suffix_open_words: |
| 135 | if cleaned.endswith(suffix): |
| 136 | target = cleaned[: -len(suffix)].strip() |
| 137 | if target in KNOWN_SITES: |
| 138 | return f"open_web:{target}" |
| 139 | return f"open_app:{target}" if target else "" |
| 140 | return "" |
| 141 | |
| 142 | |
| 143 | def handle_user_text(text): |
no test coverage detected