fix(douyu): 恢复限兑商品查询展示口径
This commit is contained in:
@@ -124,13 +124,38 @@ def _group_by_scope(
|
||||
return grouped
|
||||
|
||||
|
||||
def _overview_owned_text(snapshot: dict[str, Any]) -> str:
|
||||
def _overview_success_message(
|
||||
snapshot: dict[str, Any],
|
||||
errors: dict[str, Any],
|
||||
*,
|
||||
view: str = "",
|
||||
) -> str:
|
||||
if view == "limited_goods":
|
||||
goods = [
|
||||
str(item.get("commodityName") or item.get("name") or "")
|
||||
for item in (snapshot.get("limited_goods") or [])
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
names = [name for name in goods if name]
|
||||
message = (
|
||||
"无受限商品(均可兑换)"
|
||||
if not names
|
||||
else f"已达上限 {len(names)} 个: {', '.join(names[:5])}"
|
||||
)
|
||||
if errors.get("limited_goods"):
|
||||
message += f"({errors['limited_goods']})"
|
||||
return message
|
||||
owned = [
|
||||
str(item.get("name") or "")
|
||||
for item in (snapshot.get("high_value_goods") or [])
|
||||
if isinstance(item, dict) and not item.get("missing") and item.get("owned")
|
||||
g["name"]
|
||||
for g in (snapshot.get("high_value_goods") or [])
|
||||
if isinstance(g, dict) and not g.get("missing") and g.get("owned")
|
||||
]
|
||||
return f": {', '.join(owned)}" if owned else ""
|
||||
message = f"一键查询完成;高价值套装已拥有 {len(owned)} 个"
|
||||
if owned:
|
||||
message += f": {', '.join(owned)}"
|
||||
if errors:
|
||||
message += f"({len(errors)} 项未取到)"
|
||||
return message
|
||||
|
||||
|
||||
def _goods_config(config: dict) -> list[str]:
|
||||
@@ -177,7 +202,15 @@ class OverviewMixin:
|
||||
def _client(self, cookie: str) -> DouyuActivityClient: ...
|
||||
def _mark_task(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def _push_log(self, level: str, message: str) -> None: ...
|
||||
def _task_payload(self, task: DouyuTask) -> dict: ...
|
||||
|
||||
def _overview_view(self, task: DouyuTask) -> str:
|
||||
result = task.result if isinstance(task.result, dict) else {}
|
||||
payload_raw = result.get("payload")
|
||||
payload = payload_raw if isinstance(payload_raw, dict) else {}
|
||||
runtime_payload = getattr(self, "payload", None)
|
||||
if isinstance(runtime_payload, dict):
|
||||
payload = {**payload, **runtime_payload}
|
||||
return str(payload.get("view") or "").strip()
|
||||
def _refresh_account_gold_balance(
|
||||
self, client: DouyuActivityClient, account: Account
|
||||
) -> dict: ...
|
||||
@@ -447,19 +480,16 @@ class OverviewMixin:
|
||||
绝不因此让整次查询失败(账号没绑电竞手册就是最常见的例子)。
|
||||
"""
|
||||
started_at = datetime.now(UTC)
|
||||
view = self._overview_view(task)
|
||||
cached = self._cached_overview(account, task, now=started_at)
|
||||
if cached is not None:
|
||||
owned_count = sum(
|
||||
1
|
||||
for item in (cached.get("high_value_goods") or [])
|
||||
if isinstance(item, dict)
|
||||
and not item.get("missing")
|
||||
and item.get("owned")
|
||||
)
|
||||
message = (
|
||||
"一键查询命中本地新鲜快照;"
|
||||
f"高价值套装已拥有 {owned_count} 个"
|
||||
f"{_overview_owned_text(cached)}"
|
||||
cached["view"] = view or str(cached.get("view") or "")
|
||||
message = _overview_success_message(
|
||||
cached,
|
||||
cached.get("errors")
|
||||
if isinstance(cached.get("errors"), dict)
|
||||
else {},
|
||||
view=view,
|
||||
)
|
||||
self._push_log(
|
||||
"info",
|
||||
@@ -475,6 +505,7 @@ class OverviewMixin:
|
||||
queried_at = datetime.now(UTC)
|
||||
overview: dict[str, Any] = {
|
||||
"queried_at": queried_at.isoformat(),
|
||||
"view": view,
|
||||
"assets": {},
|
||||
"elite": {},
|
||||
"esports": {},
|
||||
@@ -1043,16 +1074,7 @@ class OverviewMixin:
|
||||
# 但**不改生命周期状态,也不制造业务事实事件**;任务活动由执行器统一记录。
|
||||
account.updated_at = datetime.now(UTC)
|
||||
|
||||
owned = [
|
||||
g["name"]
|
||||
for g in overview["high_value_goods"]
|
||||
if not g.get("missing") and g.get("owned")
|
||||
]
|
||||
message = f"一键查询完成;高价值套装已拥有 {len(owned)} 个"
|
||||
if owned:
|
||||
message += f": {', '.join(owned)}"
|
||||
if errors:
|
||||
message += f"({len(errors)} 项未取到)"
|
||||
message = _overview_success_message(overview, errors, view=view)
|
||||
|
||||
# 落到账号上:任务会被保留策略清掉,而「这个账号现在什么情况」是账号的信息,
|
||||
# 应该在账号管理里看,不该依赖一条日志的寿命。
|
||||
|
||||
Reference in New Issue
Block a user