fix: continue daemon refill after registration failures
This commit is contained in:
45
main.py
45
main.py
@@ -226,6 +226,34 @@ def _perform_registration_once(cfg: dict[str, Any], proxy: Optional[str]) -> dic
|
||||
|
||||
token_data = json.loads(token_json)
|
||||
email = str(token_data.get("email") or "unknown")
|
||||
oauth_status = str(token_data.get("oauth_status") or "oauth=ok").strip() or "oauth=ok"
|
||||
|
||||
if oauth_status != "oauth=ok":
|
||||
run_result: dict[str, Any] = {"ok": False, "email": email, "oauth_status": oauth_status}
|
||||
if cfg.get("db_enabled"):
|
||||
try:
|
||||
db_result = save_registered_account(
|
||||
cfg,
|
||||
{
|
||||
"email": token_data.get("email", ""),
|
||||
"chatgpt_password": token_data.get("account_password", ""),
|
||||
"mail_password": token_data.get("mail_password", ""),
|
||||
"oauth_status": oauth_status,
|
||||
"mail_token": token_data.get("mail_token", ""),
|
||||
"name": token_data.get("name", ""),
|
||||
"birthdate": token_data.get("birthdate", ""),
|
||||
"source": cfg.get("db_source", "standalone_cli"),
|
||||
},
|
||||
)
|
||||
run_result["db_saved"] = bool(db_result.get("ok", False))
|
||||
print(f"[{'+' if db_result.get('ok') else '-'}] 失败记录{'写入成功' if db_result.get('ok') else '写入失败'}: {email}")
|
||||
except Exception as exc:
|
||||
run_result["db_saved"] = False
|
||||
run_result["db_error"] = str(exc)
|
||||
print(f"[-] 失败记录写入异常: {exc}")
|
||||
print("[-] 本次注册失败。")
|
||||
return run_result
|
||||
|
||||
file_name = f"token_{email.replace('@', '_')}_{time.time_ns()}.json"
|
||||
file_path = Path(TOKENS_DIR) / file_name
|
||||
_write_text_atomic(str(file_path), token_json)
|
||||
@@ -366,11 +394,20 @@ def handle_daemon(args: argparse.Namespace) -> dict[str, Any]:
|
||||
try:
|
||||
result = _perform_registration_once(cfg, proxy)
|
||||
if not result.get("ok"):
|
||||
print("[!] 本次自动补号失败,停止本轮剩余补号")
|
||||
break
|
||||
email = str(result.get("email") or "").strip()
|
||||
status = str(result.get("oauth_status") or result.get("error") or "failed").strip()
|
||||
if email:
|
||||
print(f"[!] 本次自动补号失败,继续下一个: {email} ({status})")
|
||||
else:
|
||||
print(f"[!] 本次自动补号失败,继续下一个: {status}")
|
||||
continue
|
||||
if index < planned - 1:
|
||||
wait_seconds = random.randint(30, 60)
|
||||
print(f"[*] 本次注册成功,等待 {wait_seconds} 秒后继续下一个账号...")
|
||||
time.sleep(wait_seconds)
|
||||
except Exception as exc:
|
||||
print(f"[Error] 自动补号失败: {exc}")
|
||||
break
|
||||
print(f"[Error] 自动补号异常,继续下一个: {exc}")
|
||||
continue
|
||||
else:
|
||||
print("[+] 当前号池满足阈值,本轮不执行注册")
|
||||
elif bool(cfg.get("auto_register", False)):
|
||||
|
||||
Reference in New Issue
Block a user