feat(fulfillment): 实时刷新斗鱼账号并支持租约时长设置
This commit is contained in:
@@ -32,6 +32,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from ..models import Account
|
||||
|
||||
# ── 作用域 ──────────────────────────────────────────────
|
||||
@@ -239,3 +242,37 @@ def derive_from_bind_info(info: dict | None) -> str | None:
|
||||
return BIND_UNBOUND
|
||||
# 接口没给结论:保持 unknown,别把"没查到"写成"没绑定"
|
||||
return None
|
||||
|
||||
|
||||
def is_role_change_cooling(info: dict | None) -> bool:
|
||||
"""是否处于真实换绑冷却:已有绑定角色且当前不可换绑。"""
|
||||
if not isinstance(info, dict):
|
||||
return False
|
||||
role_name = str(info.get("role_name") or info.get("role") or "").strip()
|
||||
if not role_name or not _truthy_flag(info.get("is_bound_act")):
|
||||
return False
|
||||
if str(info.get("api_version") or "") == "esports":
|
||||
can_change_time = _to_int(info.get("can_change_time"))
|
||||
if can_change_time is not None:
|
||||
return can_change_time > int(datetime.now(UTC).timestamp())
|
||||
wait_time = _to_int(info.get("change_role_wait_time"))
|
||||
if wait_time is not None and wait_time > 0:
|
||||
return True
|
||||
if info.get("can_change_role") is not None:
|
||||
return not _truthy_flag(info.get("can_change_role"))
|
||||
return False
|
||||
|
||||
|
||||
def _truthy_flag(value: Any) -> bool:
|
||||
if value is True:
|
||||
return True
|
||||
if value is False or value is None:
|
||||
return False
|
||||
return str(value).strip().lower() in {"1", "true", "yes", "y"}
|
||||
|
||||
|
||||
def _to_int(value: Any) -> int | None:
|
||||
try:
|
||||
return int(float(value))
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user