refactor(douyu): 统一腾讯角色绑定协议与状态判断
This commit is contained in:
@@ -9,7 +9,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -19,8 +19,9 @@ from core.douyu import DouyuActivityClient
|
||||
from ..models import Account
|
||||
from .account_binding import (
|
||||
SCOPE_ELITE,
|
||||
derive_from_bind_info,
|
||||
binding_snapshot,
|
||||
is_role_change_cooling,
|
||||
role_change_available_at,
|
||||
set_bind_status,
|
||||
)
|
||||
from .account_lifecycle import on_ck_verdict
|
||||
@@ -235,30 +236,20 @@ def _apply_bind_state(
|
||||
*,
|
||||
checked_at: datetime,
|
||||
) -> datetime | None:
|
||||
derived = derive_from_bind_info(bind_info)
|
||||
snapshot = binding_snapshot(bind_info)
|
||||
derived = snapshot["bind_status"]
|
||||
if derived is not None:
|
||||
set_bind_status(account, SCOPE_ELITE, derived)
|
||||
|
||||
role_name = str(bind_info.get("role_name") or bind_info.get("role") or "").strip()
|
||||
role_name = snapshot["role_name"]
|
||||
if role_name:
|
||||
account.game_name = role_name[:128]
|
||||
area_name = str(bind_info.get("area_name") or "").strip()
|
||||
plat_name = str(bind_info.get("plat_name") or "").strip()
|
||||
channel = " · ".join(item for item in (area_name, plat_name) if item)
|
||||
channel = snapshot["game_channel"]
|
||||
if channel:
|
||||
account.game_channel = channel[:128]
|
||||
account.game_channel = channel.replace(" / ", " · ")[:128]
|
||||
|
||||
wait_seconds = _to_int(bind_info.get("change_role_wait_time"))
|
||||
can_change_time = _to_int(bind_info.get("can_change_time"))
|
||||
account.change_role_wait_time = wait_seconds
|
||||
if not is_role_change_cooling(bind_info):
|
||||
available_at = None
|
||||
elif can_change_time is not None and can_change_time > 0:
|
||||
available_at = datetime.fromtimestamp(can_change_time, tz=UTC)
|
||||
elif wait_seconds is not None and wait_seconds > 0:
|
||||
available_at = checked_at + timedelta(seconds=wait_seconds)
|
||||
else:
|
||||
available_at = account.role_change_available_at
|
||||
account.change_role_wait_time = snapshot["change_role_wait_time"]
|
||||
available_at = role_change_available_at(bind_info, checked_at=checked_at)
|
||||
account.role_change_available_at = available_at
|
||||
return available_at
|
||||
|
||||
|
||||
Reference in New Issue
Block a user