feat: 黄豆登录后自动签到领积分

This commit is contained in:
Nixevol
2026-10-25 06:08:44 +08:00
parent 2286bc597d
commit fd9b155518
4 changed files with 84 additions and 2 deletions
+10
View File
@@ -73,6 +73,16 @@ def login_username(username: str, password: str, channel_code: str = "") -> dict
return data
def user_sign() -> dict:
data = client.request("/user/sign", {}, auth=True, identity="account")
return data if isinstance(data, dict) else {}
def user_do_sign() -> dict:
data = client.request("/user/doSign", {}, auth=True, identity="account")
return data if isinstance(data, dict) else {}
def user_info(*, identity: str = "guest") -> dict:
data = client.request("/user/info", {}, auth=True, identity=identity)
if not isinstance(data, dict):
+50 -2
View File
@@ -44,7 +44,8 @@ def login_account(username: str, password: str, rotate_fingerprint: bool = False
client.profile = profile
client.save()
api.remember_api_lines()
return {"token": client.token, "profile": profile}
sign = claim_daily_sign()
return {"token": client.token, "profile": client.profile, "sign": sign}
def resume() -> dict:
@@ -63,7 +64,54 @@ def current(token: str) -> dict:
profile = public_profile(account)
client.profile = profile
client.save()
return {"token": client.token, "profile": profile}
sign = claim_daily_sign()
return {"token": client.token, "profile": client.profile, "sign": sign}
def claim_daily_sign() -> dict | None:
if not client.account_token:
return None
try:
status = api.user_sign()
except (TokenExpired, RuntimeError):
return None
if _signed_today(status.get("today_signed") if isinstance(status, dict) else None):
return None
try:
result = api.user_do_sign()
except (TokenExpired, RuntimeError):
return None
if not isinstance(result, dict):
result = {}
balance = result.get("balance")
if balance not in (None, "") and isinstance(client.profile, dict):
client.profile["balance"] = balance
client.profile["score"] = _number(balance)
client.save()
return {"message": _sign_message(result)}
def _signed_today(value) -> bool:
if isinstance(value, bool):
return value
if isinstance(value, (int, float)) and not isinstance(value, bool):
return value != 0
text = str(value or "").strip().lower()
return text in {"y", "1", "true", "yes"}
def _sign_message(result: dict) -> str:
name = str(result.get("prize_name") or "").strip()
try:
amount = int(float(str(result.get("prize_num") or "0")))
except (TypeError, ValueError):
amount = 0
if amount > 0 and name:
return f"签到成功,获得 {name} × {amount}"
if amount > 0:
return f"签到成功,获得 {amount} 积分"
text = str(result.get("msg") or "").strip()
return text or "签到成功"
def account_balance() -> int: