acescripters

main.py

Nov 12th, 2025
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.94 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2. # main.py - API Scan & Auto Connect Dual Bot
  3. import time
  4. import requests
  5. from dual import DualBot
  6. from prompt import debug_prompt, status_prompt
  7.  
  8. def scan_apis():
  9.     """Scan semua API keys dan test functionality"""
  10.     print("๐Ÿ” Scanning API Keys...")
  11.  
  12.     apis_to_test = [
  13.         {
  14.             "name": "Groq",
  15.             "key": "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",
  16.             "url": "https://api.groq.com/openai/v1/chat/completions",
  17.             "method": "groq"
  18.         },
  19.         {
  20.             "name": "DeepSeek",
  21.             "key": "sk-018cc05d3a574de68947e669673fdf65",
  22.             "url": "https://api.deepseek.com/chat/completions",
  23.             "method": "deepseek"
  24.         },
  25.         {
  26.             "name": "Gemini",
  27.             "key": "AIzaSyDVoBSniv6CtvNZDPxvPNRPfRXWvj3304M",
  28.             "url": "https://generativelanguage.googleapis.com/v1/models/gemini-2.0-flash:generateContent",
  29.             "method": "gemini"
  30.         }
  31.     ]
  32.  
  33.     working_apis = []
  34.  
  35.     for api in apis_to_test:
  36.         print(f"๐Ÿงช Testing {api['name']}...")
  37.         try:
  38.             if test_api(api):
  39.                 print(f"โœ… {api['name']} - WORKING")
  40.                 working_apis.append(api['name'])
  41.             else:
  42.                 print(f"โŒ {api['name']} - FAILED")
  43.         except Exception as e:
  44.             print(f"โŒ {api['name']} - ERROR: {e}")
  45.  
  46.     return working_apis
  47.  
  48. def test_api(api):
  49.     """Test individual API"""
  50.     test_prompt = "Hai! Beri salam pendek dalam Bahasa Malaysia."
  51.  
  52.     try:
  53.         if api['method'] == 'groq':
  54.             headers = {"Authorization": f"Bearer {api['key']}"}
  55.             data = {
  56.                 "model": "llama-3.1-8b-instant",
  57.                 "messages": [{"role": "user", "content": test_prompt}],
  58.                 "max_tokens": 50
  59.             }
  60.             response = requests.post(api['url'], headers=headers, json=data, timeout=10)
  61.             return response.status_code == 200
  62.  
  63.         elif api['method'] == 'deepseek':
  64.             headers = {"Authorization": f"Bearer {api['key']}"}
  65.             data = {
  66.                 "model": "deepseek-chat",
  67.                 "messages": [{"role": "user", "content": test_prompt}],
  68.                 "max_tokens": 50
  69.             }
  70.             response = requests.post(api['url'], headers=headers, json=data, timeout=10)
  71.             return response.status_code == 200
  72.  
  73.         elif api['method'] == 'gemini':
  74.             url = f"{api['url']}?key={api['key']}"
  75.             data = {"contents": [{"parts": [{"text": test_prompt}]}]}
  76.             response = requests.post(url, json=data, timeout=10)
  77.             return response.status_code == 200
  78.  
  79.     except:
  80.         return False
  81.  
  82. def start_system():
  83.     """Start system dengan timing adjustment"""
  84.     print(status_prompt("SYSTEM", "Starting Dual Bot System..."))
  85.  
  86.     # FASA 1: API Testing dengan TIMEOUT AWARENESS
  87.     print(debug_prompt("Phase 1: Quick API Scan"))
  88.     start_scan_time = time.time()
  89.  
  90.     working_apis = scan_apis()
  91.     scan_duration = time.time() - start_scan_time
  92.  
  93.     print(debug_prompt(f"API scan took {scan_duration:.1f}s"))
  94.  
  95.     # Adjust connection timeout based on scan time
  96.     remaining_time = 25 - scan_duration  # 25s total allocation
  97.     if remaining_time < 10:
  98.         print(debug_prompt(f"โš ๏ธ Low time remaining: {remaining_time:.1f}s"))
  99.  
  100.     if not working_apis:
  101.         print("โš ๏ธ Some APIs failed, but continuing with available ones...")
  102.  
  103.     # FASA 2: Auto Connect dengan adjusted timing
  104.     print(debug_prompt("Phase 2: Auto Connecting Dual Bot"))
  105.     dual_bot = DualBot()
  106.  
  107.     # ๐Ÿ†• SET CONNECTION TIMEOUT based on remaining time
  108.     min_timeout = max(15, remaining_time - 5)  # Minimum 15s, keep 5s buffer
  109.     print(debug_prompt(f"Set connection timeout: {min_timeout}s"))
  110.  
  111.     return dual_bot.start()
  112.  
  113. def main():
  114.     print(status_prompt("SYSTEM", "Starting API Scan & Auto Connect..."))
  115.  
  116.     # FASA 1: Scan API Keys
  117.     print(debug_prompt("Phase 1: Scanning APIs"))
  118.     working_apis = scan_apis()
  119.  
  120.     if not working_apis:
  121.         print("โŒ CRITICAL: No working APIs found!")
  122.         return
  123.  
  124.     print(status_prompt("API", f"Working: {', '.join(working_apis)}"))
  125.  
  126.     # FASA 2: Auto Connect Dual Bot
  127.     print(debug_prompt("Phase 2: Auto Connecting Dual Bot"))
  128.     bot = DualBot()
  129.  
  130.     try:
  131.         if bot.start():
  132.             print(status_prompt("SYSTEM", "โœ… Dual Bot Connected & Running!"))
  133.             print(debug_prompt("Press Ctrl+C to stop"))
  134.  
  135.             # Monitor loop
  136.             while bot.is_running():
  137.                 time.sleep(10)
  138.         else:
  139.             print(status_prompt("SYSTEM", "โŒ Dual Bot failed to connect"))
  140.  
  141.     except KeyboardInterrupt:
  142.         print(status_prompt("SYSTEM", "Shutdown requested..."))
  143.         bot.stop()
  144.     except Exception as e:
  145.         print(debug_prompt(f"System error: {e}"))
  146.         bot.stop()
  147.  
  148. if __name__ == "__main__":
  149.     main()
Advertisement
Add Comment
Please, Sign In to add comment