Erinaldordso commited on
Commit
6715f27
·
verified ·
1 Parent(s): 9cfc968

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +54 -54
main.py CHANGED
@@ -21,104 +21,104 @@ def log(acao, status="INFO"):
21
  class ServidorFalso(BaseHTTPRequestHandler):
22
  def do_GET(self):
23
  self.send_response(200); self.end_headers()
24
- self.wfile.write(b"Bot Tribal Wars v2.3 - Bypass de Popups Ativo")
25
  def log_message(self, format, *args): pass
26
 
27
  def manter_dock_viva():
28
  try: HTTPServer(('0.0.0.0', 7860), ServidorFalso).serve_forever()
29
  except: pass
30
 
31
- # --- FUNÇÃO DE CLIQUE INFALÍVEL ---
32
  def force_click(driver, element):
33
- """Clica no elemento via JavaScript, ignorando bloqueios visuais"""
34
  driver.execute_script("arguments[0].click();", element)
35
 
36
- # --- LOGIN RESILIENTE ---
37
  def realizar_login(driver):
38
- log("A abrir página principal do Tribos...", "LOGIN")
39
  driver.get("https://www.tribalwars.com.br/")
40
- time.sleep(5)
41
-
42
  try:
43
  driver.type('input#user', USER_TW)
44
  driver.type('input#password', PASS_TW)
45
- time.sleep(1)
46
-
47
- log("A enviar formulário de login...", "LOGIN")
48
- # Usa JS para clicar no botão de login
49
  login_btn = driver.find_element(By.CSS_SELECTOR, 'a.btn-login')
50
  force_click(driver, login_btn)
51
- time.sleep(10)
52
 
53
- log(f"A procurar acesso ao Mundo {MUNDO_ID}...", "LOGIN")
54
-
55
- # Procura todos os links e clica no que contém o ID do mundo via JS
56
  links = driver.find_elements(By.TAG_NAME, "a")
57
  for link in links:
58
- href = link.get_attribute("href") or ""
59
- if MUNDO_ID in href:
60
  force_click(driver, link)
61
- log(f"Sucesso! Entrámos no {MUNDO_ID} (via JS Bypass).", "SUCESSO")
62
  time.sleep(5)
63
  return True
64
-
65
  return False
66
-
67
  except Exception as e:
68
- log(f"Erro no login: {str(e)[:100]}", "ALERTA")
69
  return False
70
 
71
  def auditoria_e_obras(driver):
72
- # Força a ida para o Edifício Principal
73
  driver.get(f"https://{MUNDO_ID}.tribalwars.com.br/game.php?screen=main")
74
- time.sleep(5)
75
 
76
- # Tenta fechar qualquer modal (pop-up) que apareça dentro do jogo
77
- driver.execute_script("if(document.querySelector('.popup_box_close')) document.querySelector('.popup_box_close').click();")
 
 
 
 
78
 
79
  try:
80
- mad = driver.find_element(By.ID, "wood").text
81
- arg = driver.find_element(By.ID, "stone").text
82
- fer = driver.find_element(By.ID, "iron").text
83
- log(f"ESTADO ATUAL: Mad {mad} | Arg {arg} | Fer {fer}", "AUDITORIA")
 
 
 
 
 
 
 
84
 
85
- # Ordem de upgrade
86
- prioridade = ["wood", "stone", "iron", "storage", "main"]
87
 
88
  for ed in prioridade:
89
- btn_seletor = f"a.btn_build[data-building='{ed}']"
90
- if driver.is_element_visible(btn_seletor):
91
- fila = driver.find_elements(By.CLASS_NAME, "buildorder")
92
- if len(fila) < 2:
93
- # Clica via JS para garantir que a obra começa
94
- btn = driver.find_element(By.CSS_SELECTOR, btn_seletor)
95
  force_click(driver, btn)
96
- log(f"CONSTRUÇÃO REALIZADA: {ed.upper()}", "CONSTR")
97
- time.sleep(3)
98
  return
 
99
  except Exception as e:
100
- log("Erro na leitura de edifícios.", "INFO")
101
 
102
  def iniciar():
103
  display = Display(visible=0, size=(1920, 1080)); display.start()
104
  driver = Driver(uc=True, headless=False)
105
 
106
  try:
107
- while True:
108
- if realizar_login(driver):
109
- while True:
110
- auditoria_e_obras(driver)
111
-
112
- minutos = random.randint(10, 20)
113
- log(f"Aldeia segura. Próxima inspeção em {minutos} minutos...", "INFO")
114
-
115
- # Simula ver relatórios antes de dormir
116
- driver.get(f"https://{MUNDO_ID}.tribalwars.com.br/game.php?screen=report")
117
- time.sleep(minutos * 60)
118
- else:
119
- log("Tentativa de login falhou. Reiniciando ciclo...", "ALERTA")
120
- time.sleep(60)
121
 
 
 
 
 
 
 
 
 
122
  except Exception as e: log(f"Crash: {e}", "ALERTA")
123
  finally:
124
  driver.quit(); display.stop()
 
21
  class ServidorFalso(BaseHTTPRequestHandler):
22
  def do_GET(self):
23
  self.send_response(200); self.end_headers()
24
+ self.wfile.write(b"Bot Tribal Wars v2.4 - Alta Frequencia")
25
  def log_message(self, format, *args): pass
26
 
27
  def manter_dock_viva():
28
  try: HTTPServer(('0.0.0.0', 7860), ServidorFalso).serve_forever()
29
  except: pass
30
 
 
31
  def force_click(driver, element):
 
32
  driver.execute_script("arguments[0].click();", element)
33
 
 
34
  def realizar_login(driver):
35
+ log("Acedendo ao servidor br...", "LOGIN")
36
  driver.get("https://www.tribalwars.com.br/")
37
+ time.sleep(4)
 
38
  try:
39
  driver.type('input#user', USER_TW)
40
  driver.type('input#password', PASS_TW)
 
 
 
 
41
  login_btn = driver.find_element(By.CSS_SELECTOR, 'a.btn-login')
42
  force_click(driver, login_btn)
43
+ time.sleep(8)
44
 
45
+ # Busca dinâmica pelo mundo
 
 
46
  links = driver.find_elements(By.TAG_NAME, "a")
47
  for link in links:
48
+ if MUNDO_ID in (link.get_attribute("href") or ""):
 
49
  force_click(driver, link)
50
+ log(f"Sessão iniciada no {MUNDO_ID}.", "SUCESSO")
51
  time.sleep(5)
52
  return True
 
53
  return False
 
54
  except Exception as e:
55
+ log(f"Erro no login: {str(e)[:50]}", "ALERTA")
56
  return False
57
 
58
  def auditoria_e_obras(driver):
59
+ # Vai para o Edifício Principal
60
  driver.get(f"https://{MUNDO_ID}.tribalwars.com.br/game.php?screen=main")
61
+ time.sleep(3)
62
 
63
+ # 🧹 VASSOURA JS: Fecha TUDO o que for pop-up ou bloqueio
64
+ driver.execute_script("""
65
+ document.querySelectorAll('.popup_box_close, .close-vn-dot, .modal-close').forEach(b => b.click());
66
+ document.querySelectorAll('.greymask, .modal-overlay').forEach(m => m.remove());
67
+ """)
68
+ time.sleep(1)
69
 
70
  try:
71
+ # Leitura de Recursos com Fallback
72
+ mad = driver.execute_script("return document.getElementById('wood').innerText")
73
+ arg = driver.execute_script("return document.getElementById('stone').innerText")
74
+ fer = driver.execute_script("return document.getElementById('iron').innerText")
75
+ log(f"RECURSOS: 🪵 {mad} | 🧱 {arg} | ⚙️ {fer}", "AUDITORIA")
76
+
77
+ # Verifica se a fila está livre (Máximo 2 construções no grátis)
78
+ fila = driver.find_elements(By.CLASS_NAME, "buildorder")
79
+ if len(fila) >= 2:
80
+ log("Fila ocupada (2/2). A aguardar conclusão...", "INFO")
81
+ return
82
 
83
+ # Prioridades de Upgrade (Ordem lógica de crescimento)
84
+ prioridade = ["wood", "stone", "iron", "storage", "main", "farm"]
85
 
86
  for ed in prioridade:
87
+ btn_css = f"a.btn_build[data-building='{ed}']"
88
+ # Verifica se o botão existe e se não está "desativado" (sem recursos)
89
+ if driver.is_element_visible(btn_css):
90
+ btn = driver.find_element(By.CSS_SELECTOR, btn_css)
91
+ if "btn-disabled" not in btn.get_attribute("class"):
 
92
  force_click(driver, btn)
93
+ log(f"ORDEM ENVIADA: Expandir {ed.upper()}", "CONSTR")
 
94
  return
95
+ log("Recursos insuficientes para novos upgrades.", "INFO")
96
  except Exception as e:
97
+ log("Erro ao analisar Edifício Principal. A tentar novamente...", "ALERTA")
98
 
99
  def iniciar():
100
  display = Display(visible=0, size=(1920, 1080)); display.start()
101
  driver = Driver(uc=True, headless=False)
102
 
103
  try:
104
+ if realizar_login(driver):
105
+ while True:
106
+ auditoria_e_obras(driver)
107
+
108
+ # Tempo de ciclo de 30 segundos (conforme solicitado)
109
+ # Adicionamos um pequeno random (28-35) para não ser um robô óbvio
110
+ pausa = random.randint(28, 35)
111
+ log(f"Ciclo concluído. Próxima verificação em {pausa}s...", "INFO")
112
+ time.sleep(pausa)
 
 
 
 
 
113
 
114
+ # Se deslogar por inatividade, volta ao início
115
+ if "login" in driver.current_url.lower():
116
+ log("Sessão expirada. A relogar...", "ALERTA")
117
+ realizar_login(driver)
118
+ else:
119
+ log("Falha crítica no login. A reiniciar em 60s...", "ALERTA")
120
+ time.sleep(60)
121
+
122
  except Exception as e: log(f"Crash: {e}", "ALERTA")
123
  finally:
124
  driver.quit(); display.stop()