recovered snapshot from suspended aaronjaworski710 (history unavailable)
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env python3
|
||||
"""ArcAI (askarc.chat) — account registrar + API client.
|
||||
|
||||
ArcAI is a Supabase-backed AI chat platform. This tool talks to its public
|
||||
Supabase endpoints directly:
|
||||
|
||||
* register / login / refresh (auth, no captcha, instant session)
|
||||
* chat (POST /functions/v1/chat, streaming JSON)
|
||||
* models / service status
|
||||
|
||||
The Supabase publishable key + URL live in config.json (public frontend
|
||||
constants). NO payment / card / captcha-bypass code here — this is a clean
|
||||
client for the free API surface only.
|
||||
|
||||
Usage:
|
||||
python arcai.py reg N [gmail|outlook|voidash] # register N accounts
|
||||
python arcai.py status # is chat live or restricted?
|
||||
python arcai.py models # list known model ids
|
||||
python arcai.py chat "your prompt" [model] # send one chat (needs live svc)
|
||||
python arcai.py accounts # count saved accounts
|
||||
"""
|
||||
import json, os, re, sys, time, random, string, urllib.request, urllib.error
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
CFG = json.load(open(os.path.join(HERE, "config.json")))
|
||||
SB = CFG["supabase_url"]
|
||||
KEY = CFG["publishable_key"]
|
||||
SITE = CFG.get("site", "https://askarc.chat")
|
||||
MODELS = CFG["models"]
|
||||
ACC = os.path.join(HERE, "accounts.jsonl")
|
||||
|
||||
|
||||
def req(url, payload=None, token=None):
|
||||
h = {"apikey": KEY, "Content-Type": "application/json"}
|
||||
if token:
|
||||
h["Authorization"] = "Bearer " + token
|
||||
body = json.dumps(payload).encode() if payload is not None else None
|
||||
r = urllib.request.Request(url, data=body, headers=h)
|
||||
try:
|
||||
with urllib.request.urlopen(r, timeout=60) as resp:
|
||||
return resp.status, resp.read().decode()
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, e.read().decode()
|
||||
except Exception as e:
|
||||
return 0, str(e)
|
||||
|
||||
|
||||
def rnd(n=10):
|
||||
return "".join(random.choices(string.ascii_lowercase + string.digits, k=n))
|
||||
|
||||
|
||||
def register(domain="gmail"):
|
||||
if domain == "gmail":
|
||||
em = f"youraddress+arc{rnd(6)}@gmail.com"
|
||||
elif domain == "outlook":
|
||||
em = f"arc{rnd(8)}@outlook.com"
|
||||
else:
|
||||
em = f"arc{rnd(10)}@voidash.bond"
|
||||
pw = rnd(10) + "aA1!"
|
||||
st, body = req(SB + "/auth/v1/signup", {"email": em, "password": pw})
|
||||
if st == 200:
|
||||
d = json.loads(body)
|
||||
rec = {"email": em, "pass": pw, "uid": d["user"]["id"],
|
||||
"access_token": d["access_token"], "refresh_token": d["refresh_token"],
|
||||
"ts": int(time.time())}
|
||||
with open(ACC, "a") as f:
|
||||
f.write(json.dumps(rec) + "\n")
|
||||
return rec
|
||||
return {"error": body[:160], "status": st, "email": em}
|
||||
|
||||
|
||||
def refresh(rec):
|
||||
st, body = req(SB + "/auth/v1/token?grant_type=refresh_token",
|
||||
{"refresh_token": rec["refresh_token"]})
|
||||
if st == 200:
|
||||
d = json.loads(body)
|
||||
rec["access_token"] = d["access_token"]
|
||||
rec["refresh_token"] = d["refresh_token"]
|
||||
return rec if st == 200 else None
|
||||
|
||||
|
||||
def login(email, pw):
|
||||
st, body = req(SB + "/auth/v1/token?grant_type=password",
|
||||
{"email": email, "password": pw})
|
||||
if st == 200:
|
||||
d = json.loads(body)
|
||||
return {"email": email, "pass": pw, "uid": d["user"]["id"],
|
||||
"access_token": d["access_token"], "refresh_token": d["refresh_token"]}
|
||||
return None
|
||||
|
||||
|
||||
def last_acc():
|
||||
if not os.path.exists(ACC):
|
||||
return None
|
||||
lines = [l for l in open(ACC) if l.strip()]
|
||||
return json.loads(lines[-1]) if lines else None
|
||||
|
||||
|
||||
def chat(prompt, model="gemini-3.8-flash", rec=None):
|
||||
rec = rec or last_acc()
|
||||
if not rec:
|
||||
return {"error": "no account; run: arcai.py reg 1"}
|
||||
st, body = req(SB + "/functions/v1/chat",
|
||||
{"messages": [{"role": "user", "content": prompt}], "model": model},
|
||||
token=rec["access_token"])
|
||||
return {"status": st, "body": body[:500]}
|
||||
|
||||
|
||||
def service_status():
|
||||
st, b = req(SITE + "/api/location")
|
||||
c = chat("ping", MODELS["text_free"][0])
|
||||
restricted = c.get("status") == 403 or "arc_incident_restricted" in str(c.get("body"))
|
||||
return {"site_status": st,
|
||||
"under_construction": "under construction" in b.lower(),
|
||||
"chat_status": c.get("status"),
|
||||
"chat_restricted": restricted,
|
||||
"chat_body": str(c.get("body"))[:160]}
|
||||
|
||||
|
||||
def main():
|
||||
cmd = sys.argv[1] if len(sys.argv) > 1 else "status"
|
||||
if cmd == "reg":
|
||||
n = int(sys.argv[2]) if len(sys.argv) > 2 else 1
|
||||
dom = sys.argv[3] if len(sys.argv) > 3 else "gmail"
|
||||
ok = 0
|
||||
for i in range(n):
|
||||
r = register(dom)
|
||||
if "uid" in r:
|
||||
ok += 1
|
||||
print(f"[{i+1}/{n}] OK {r['email']} uid={r['uid'][:8]}")
|
||||
else:
|
||||
print(f"[{i+1}/{n}] FAIL {r}")
|
||||
time.sleep(1.1)
|
||||
print(f"registered {ok}/{n} -> {ACC}")
|
||||
elif cmd == "status":
|
||||
print(json.dumps(service_status(), indent=2))
|
||||
elif cmd == "models":
|
||||
for k, v in MODELS.items():
|
||||
print(f"{k}: {', '.join(v)}")
|
||||
elif cmd == "chat":
|
||||
prompt = sys.argv[2] if len(sys.argv) > 2 else "hello"
|
||||
model = sys.argv[3] if len(sys.argv) > 3 else MODELS["text_free"][0]
|
||||
print(json.dumps(chat(prompt, model), indent=2))
|
||||
elif cmd == "accounts":
|
||||
n = sum(1 for _ in open(ACC)) if os.path.exists(ACC) else 0
|
||||
print(f"{n} accounts in {ACC}")
|
||||
else:
|
||||
print(__doc__)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user