Spaces:
Running
Running
Create target_maia.py
Browse files- target_maia.py +74 -0
target_maia.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# --- CONFIGURATION ---
|
| 5 |
+
TOKEN = "lip_OFiAuROPc2oEicqT1YQg" # Your Lichess Token
|
| 6 |
+
TARGET_BOTS = ["maia1", "maia5", "maia9"]
|
| 7 |
+
|
| 8 |
+
# Challenge settings (3 mins blitz, casual)
|
| 9 |
+
CHALLENGE_DATA = {
|
| 10 |
+
"rated": "false",
|
| 11 |
+
"clock.limit": 180, # 180 seconds = 3 minutes
|
| 12 |
+
"clock.increment": 0, # 0 seconds increment
|
| 13 |
+
"variant": "standard"
|
| 14 |
+
}
|
| 15 |
+
# ---------------------
|
| 16 |
+
|
| 17 |
+
HEADERS = {"Authorization": f"Bearer {TOKEN}"}
|
| 18 |
+
|
| 19 |
+
def check_my_bot_status():
|
| 20 |
+
"""Checks if your bot is currently busy playing a game."""
|
| 21 |
+
try:
|
| 22 |
+
response = requests.get("https://lichess.org/api/account", headers=HEADERS)
|
| 23 |
+
if response.status_code == 200:
|
| 24 |
+
# If the account data returns an active game ID, your bot is busy
|
| 25 |
+
return response.json().get("playing", False)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Error checking status: {e}")
|
| 28 |
+
return True # Default to True on failure to avoid spamming challenges
|
| 29 |
+
|
| 30 |
+
def send_challenge(target):
|
| 31 |
+
"""Sends a direct challenge to a specific bot."""
|
| 32 |
+
url = f"https://lichess.org/api/challenge/{target}"
|
| 33 |
+
try:
|
| 34 |
+
response = requests.post(url, headers=HEADERS, data=CHALLENGE_DATA)
|
| 35 |
+
if response.status_code == 200:
|
| 36 |
+
print(f"[SUCCESS] Sent a challenge to {target}!")
|
| 37 |
+
return True
|
| 38 |
+
elif response.status_code == 400:
|
| 39 |
+
# Often means the target bot is already completely full/busy
|
| 40 |
+
print(f"[BUSY] Tried challenging {target}, but they declined or are full.")
|
| 41 |
+
else:
|
| 42 |
+
print(f"[INFO] Couldn't challenge {target}. Status Code: {response.status_code}")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"Network error: {e}")
|
| 45 |
+
return False
|
| 46 |
+
|
| 47 |
+
def main():
|
| 48 |
+
print("Targeted Maia Matchmaker Loop Started...")
|
| 49 |
+
print("This script will cycle through Maia 1, 5, and 9 whenever your bot is idle.")
|
| 50 |
+
|
| 51 |
+
while True:
|
| 52 |
+
# 1. Check if your bot is already playing someone else
|
| 53 |
+
if check_my_bot_status():
|
| 54 |
+
print("Your bot is currently in a match. Waiting 30 seconds...")
|
| 55 |
+
time.sleep(30)
|
| 56 |
+
continue
|
| 57 |
+
|
| 58 |
+
# 2. If free, try to challenge the Maias one by one
|
| 59 |
+
print("Your bot is idle! Attempting to challenge targets...")
|
| 60 |
+
for bot in TARGET_BOTS:
|
| 61 |
+
success = send_challenge(bot)
|
| 62 |
+
if success:
|
| 63 |
+
# Give Lichess a moment to process the match creation
|
| 64 |
+
print("Match created successfully. Pausing script for 2 minutes...")
|
| 65 |
+
time.sleep(120)
|
| 66 |
+
break
|
| 67 |
+
# Tiny cooldown between hitting different bots to avoid rate limits
|
| 68 |
+
time.sleep(2)
|
| 69 |
+
|
| 70 |
+
# Cooldown period before checking if your bot is idle again
|
| 71 |
+
time.sleep(45)
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
main()
|