Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -26,23 +26,34 @@ def log(acao, status="INFO"):
|
|
| 26 |
icon = "✅" if status=="SUCESSO" else "🧠" if status=="GROQ" else "🚜"
|
| 27 |
print(f"[{agora}] [{icon}] {acao}", flush=True)
|
| 28 |
|
| 29 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def o_groq_decide(texto):
|
| 31 |
-
prompt = "És um bot de Farm RPG.
|
| 32 |
try:
|
| 33 |
res = cliente_ia.chat.completions.create(
|
| 34 |
messages=[{"role": "system", "content": prompt}, {"role": "user", "content": texto}],
|
| 35 |
model="llama-3.1-8b-instant", temperature=0.1, max_tokens=5
|
| 36 |
)
|
| 37 |
decisao = res.choices[0].message.content.strip().upper()
|
| 38 |
-
# Limpeza total: pega apenas a última palavra se a IA divagar
|
| 39 |
palavras = re.findall(r'VENDER|FAZENDA|EXPLORAR|REPOUSO', decisao)
|
| 40 |
return palavras[0] if palavras else "REPOUSO"
|
| 41 |
except: return "REPOUSO"
|
| 42 |
|
| 43 |
-
# ---
|
| 44 |
def click_real(driver, seletor_css):
|
| 45 |
-
"""Injeta um clique que o Framework7 do jogo consegue detetar"""
|
| 46 |
script = f"""
|
| 47 |
var el = document.querySelector("{seletor_css}");
|
| 48 |
if(el) {{
|
|
@@ -57,35 +68,32 @@ def click_real(driver, seletor_css):
|
|
| 57 |
|
| 58 |
def agir(driver, comando):
|
| 59 |
if comando == "VENDER":
|
| 60 |
-
log("
|
| 61 |
driver.get("https://farmrpg.com/index.php#!/sellall.php")
|
| 62 |
time.sleep(5)
|
| 63 |
-
#
|
| 64 |
click_real(driver, "a.button-fill.color-red")
|
| 65 |
time.sleep(2)
|
| 66 |
-
# Tenta confirmar no popup se houver
|
| 67 |
click_real(driver, ".modal-button-bold")
|
| 68 |
-
log("
|
| 69 |
|
| 70 |
elif comando == "FAZENDA":
|
| 71 |
-
log("
|
| 72 |
driver.get("https://farmrpg.com/index.php#!/farm.php")
|
| 73 |
time.sleep(5)
|
| 74 |
-
# Clica em Harvest All e depois Plant All
|
| 75 |
driver.execute_script("document.querySelectorAll('a.button').forEach(b => { if(b.innerText.includes('Harvest All')) b.click(); })")
|
| 76 |
time.sleep(3)
|
| 77 |
driver.execute_script("document.querySelectorAll('a.button').forEach(b => { if(b.innerText.includes('Plant All')) b.click(); })")
|
| 78 |
-
log("
|
| 79 |
|
| 80 |
elif comando == "EXPLORAR":
|
| 81 |
-
log("
|
| 82 |
driver.get("https://farmrpg.com/index.php#!/area.php?id=1")
|
| 83 |
time.sleep(4)
|
| 84 |
-
# Simula cliques rápidos que o servidor aceita
|
| 85 |
for _ in range(15):
|
| 86 |
if not click_real(driver, "#explorebtn"): break
|
| 87 |
time.sleep(0.4)
|
| 88 |
-
log("
|
| 89 |
|
| 90 |
def iniciar():
|
| 91 |
display = Display(visible=0, size=(1920, 1080)); display.start()
|
|
@@ -100,14 +108,15 @@ def iniciar():
|
|
| 100 |
driver.get("https://farmrpg.com/index.php#!/index.php")
|
| 101 |
time.sleep(7)
|
| 102 |
|
| 103 |
-
#
|
| 104 |
-
driver.execute_script("
|
| 105 |
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
if NOME_USUARIO.upper() not in corpo.upper():
|
| 108 |
-
log("Cookies
|
| 109 |
-
for c in MEUS_COOKIES: driver.add_cookie(c)
|
| 110 |
-
driver.refresh(); time.sleep(5)
|
| 111 |
|
| 112 |
comando = o_groq_decide(corpo[100:1500])
|
| 113 |
log(f"IA Decidiu: {comando}", "GROQ")
|
|
@@ -122,5 +131,6 @@ def iniciar():
|
|
| 122 |
driver.quit(); display.stop()
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|
|
|
|
| 125 |
threading.Thread(target=manter_dock_viva, daemon=True).start()
|
| 126 |
iniciar()
|
|
|
|
| 26 |
icon = "✅" if status=="SUCESSO" else "🧠" if status=="GROQ" else "🚜"
|
| 27 |
print(f"[{agora}] [{icon}] {acao}", flush=True)
|
| 28 |
|
| 29 |
+
# --- SERVIDOR PARA MANTER A DOCK VIVA ---
|
| 30 |
+
class ServidorFalso(BaseHTTPRequestHandler):
|
| 31 |
+
def do_GET(self):
|
| 32 |
+
self.send_response(200); self.end_headers()
|
| 33 |
+
self.wfile.write(b"Bot Farm RPG v10.1 - Estabilizado!")
|
| 34 |
+
def log_message(self, format, *args): pass
|
| 35 |
+
|
| 36 |
+
def manter_dock_viva():
|
| 37 |
+
try:
|
| 38 |
+
server = HTTPServer(('0.0.0.0', 7860), ServidorFalso)
|
| 39 |
+
server.serve_forever()
|
| 40 |
+
except: pass
|
| 41 |
+
|
| 42 |
+
# --- INTELIGÊNCIA ---
|
| 43 |
def o_groq_decide(texto):
|
| 44 |
+
prompt = "És um bot de Farm RPG. Responde APENAS UMA PALAVRA: VENDER, FAZENDA, EXPLORAR ou REPOUSO."
|
| 45 |
try:
|
| 46 |
res = cliente_ia.chat.completions.create(
|
| 47 |
messages=[{"role": "system", "content": prompt}, {"role": "user", "content": texto}],
|
| 48 |
model="llama-3.1-8b-instant", temperature=0.1, max_tokens=5
|
| 49 |
)
|
| 50 |
decisao = res.choices[0].message.content.strip().upper()
|
|
|
|
| 51 |
palavras = re.findall(r'VENDER|FAZENDA|EXPLORAR|REPOUSO', decisao)
|
| 52 |
return palavras[0] if palavras else "REPOUSO"
|
| 53 |
except: return "REPOUSO"
|
| 54 |
|
| 55 |
+
# --- AÇÕES REAIS (JS INJECTION) ---
|
| 56 |
def click_real(driver, seletor_css):
|
|
|
|
| 57 |
script = f"""
|
| 58 |
var el = document.querySelector("{seletor_css}");
|
| 59 |
if(el) {{
|
|
|
|
| 68 |
|
| 69 |
def agir(driver, comando):
|
| 70 |
if comando == "VENDER":
|
| 71 |
+
log("Navegando para Venda...", "ACAO")
|
| 72 |
driver.get("https://farmrpg.com/index.php#!/sellall.php")
|
| 73 |
time.sleep(5)
|
| 74 |
+
# Seletores de botões reais do jogo
|
| 75 |
click_real(driver, "a.button-fill.color-red")
|
| 76 |
time.sleep(2)
|
|
|
|
| 77 |
click_real(driver, ".modal-button-bold")
|
| 78 |
+
log("Venda executada.", "SUCESSO")
|
| 79 |
|
| 80 |
elif comando == "FAZENDA":
|
| 81 |
+
log("Navegando para Fazenda...", "ACAO")
|
| 82 |
driver.get("https://farmrpg.com/index.php#!/farm.php")
|
| 83 |
time.sleep(5)
|
|
|
|
| 84 |
driver.execute_script("document.querySelectorAll('a.button').forEach(b => { if(b.innerText.includes('Harvest All')) b.click(); })")
|
| 85 |
time.sleep(3)
|
| 86 |
driver.execute_script("document.querySelectorAll('a.button').forEach(b => { if(b.innerText.includes('Plant All')) b.click(); })")
|
| 87 |
+
log("Fazenda processada.", "SUCESSO")
|
| 88 |
|
| 89 |
elif comando == "EXPLORAR":
|
| 90 |
+
log("Navegando para Exploração...", "ACAO")
|
| 91 |
driver.get("https://farmrpg.com/index.php#!/area.php?id=1")
|
| 92 |
time.sleep(4)
|
|
|
|
| 93 |
for _ in range(15):
|
| 94 |
if not click_real(driver, "#explorebtn"): break
|
| 95 |
time.sleep(0.4)
|
| 96 |
+
log("Exploração terminada.", "SUCESSO")
|
| 97 |
|
| 98 |
def iniciar():
|
| 99 |
display = Display(visible=0, size=(1920, 1080)); display.start()
|
|
|
|
| 108 |
driver.get("https://farmrpg.com/index.php#!/index.php")
|
| 109 |
time.sleep(7)
|
| 110 |
|
| 111 |
+
# Limpa modais que bloqueiam a visão
|
| 112 |
+
driver.execute_script("var m = document.querySelector('.modal-button'); if(m) m.click();")
|
| 113 |
|
| 114 |
+
try:
|
| 115 |
+
corpo = driver.find_element(By.TAG_NAME, "body").text
|
| 116 |
+
except: corpo = "REPOUSO"
|
| 117 |
+
|
| 118 |
if NOME_USUARIO.upper() not in corpo.upper():
|
| 119 |
+
log("Cookies desatualizados ou Login falhou!", "ALERTA")
|
|
|
|
|
|
|
| 120 |
|
| 121 |
comando = o_groq_decide(corpo[100:1500])
|
| 122 |
log(f"IA Decidiu: {comando}", "GROQ")
|
|
|
|
| 131 |
driver.quit(); display.stop()
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
+
# Inicia o servidor HTTP em background para o Hugging Face não matar o bot
|
| 135 |
threading.Thread(target=manter_dock_viva, daemon=True).start()
|
| 136 |
iniciar()
|