虎牙精英宝典
This commit is contained in:
@@ -60,6 +60,7 @@ class HuyaBatchRunner(
|
||||
self._push_log("info", f"[{current}/{total}] 开始虎牙任务: {name}")
|
||||
|
||||
if self.task_type not in {
|
||||
"query_act_tasks",
|
||||
"query_points",
|
||||
"get_bind_qr",
|
||||
"confirm_bind",
|
||||
@@ -77,7 +78,11 @@ class HuyaBatchRunner(
|
||||
return
|
||||
|
||||
try:
|
||||
if self.task_type == "query_points":
|
||||
if self.task_type == "query_act_tasks":
|
||||
self._execute_query_act_tasks(
|
||||
worker_db, task, account, account_info, config_info
|
||||
)
|
||||
elif self.task_type == "query_points":
|
||||
self._execute_query_points(
|
||||
worker_db, task, account, account_info, config_info
|
||||
)
|
||||
|
||||
@@ -31,6 +31,52 @@ class GoodsMixin:
|
||||
def _wait_until(self, when: datetime, uid: int) -> bool: ...
|
||||
def _parse_scheduled_time(self, value: Any) -> datetime | None: ...
|
||||
|
||||
def _execute_query_act_tasks(
|
||||
self,
|
||||
worker_db: Session,
|
||||
task: HuyaTask,
|
||||
account: HuyaAccount,
|
||||
account_info: dict,
|
||||
config_info: dict,
|
||||
):
|
||||
"""读取精英宝典任务详情,供专用工作台展示购买/观看任务。"""
|
||||
uid = self._resolve_uid(account_info)
|
||||
cookie = account_info.get("cookie") or ""
|
||||
if not uid or not cookie:
|
||||
self._mark_task(worker_db, task, "failed", "账号 UID 或 Cookie 为空")
|
||||
return
|
||||
act_id = self._to_int(self.payload.get("act_id") or 25135)
|
||||
if not act_id:
|
||||
self._mark_task(worker_db, task, "failed", "精英宝典活动 ID 无效")
|
||||
return
|
||||
client: Any = HuyaHttpClient(
|
||||
logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")
|
||||
)
|
||||
response = client.get_act_task_detail(uid=uid, cookie=cookie, act_id=act_id)
|
||||
if response is None:
|
||||
self._mark_task(worker_db, task, "error", "虎牙活动任务接口无响应")
|
||||
return
|
||||
result = response.to_dict()
|
||||
result["act_id"] = act_id
|
||||
if response.status != 200:
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
task,
|
||||
"failed",
|
||||
response.msg or f"虎牙活动任务查询失败: {response.status}",
|
||||
result,
|
||||
)
|
||||
return
|
||||
account.status = "tasks_queried"
|
||||
account.updated_at = datetime.now(UTC)
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
task,
|
||||
"success",
|
||||
f"已读取 {len(result.get('tasks', []))} 项精英宝典任务",
|
||||
result,
|
||||
)
|
||||
|
||||
def _execute_query_points(
|
||||
self,
|
||||
worker_db: Session,
|
||||
|
||||
@@ -14,6 +14,7 @@ from ..huya_defaults import HUYA_CONFIG_DEFAULTS, HUYA_CONFIG_FIELDS
|
||||
from ..models import HuyaAccount, HuyaConfig, HuyaTask
|
||||
|
||||
SUPPORTED_TASK_TYPES = {
|
||||
"query_act_tasks": "查询精英宝典任务",
|
||||
"get_bind_qr": "获取绑定二维码",
|
||||
"query_points": "一键查询积分",
|
||||
"query_game_name": "一键查询游戏名",
|
||||
@@ -25,6 +26,19 @@ SUPPORTED_TASK_TYPES = {
|
||||
"create_recharge_order": "生成支付二维码",
|
||||
}
|
||||
|
||||
HUYA_HANDBOOK_TASK_TYPES = {
|
||||
"query_act_tasks",
|
||||
"get_bind_qr",
|
||||
"confirm_bind",
|
||||
"query_points",
|
||||
"query_game_name",
|
||||
"refresh_goods",
|
||||
"exchange_goods",
|
||||
"query_exchange_records",
|
||||
"refresh_recharge_goods",
|
||||
"create_recharge_order",
|
||||
}
|
||||
|
||||
|
||||
def huya_config_value(field: str, value: str | None) -> str:
|
||||
"""读取配置值;空值自动回退到当前活动默认配置。"""
|
||||
@@ -371,10 +385,15 @@ def create_planned_tasks(
|
||||
task_type: str,
|
||||
created_by: int,
|
||||
payload: dict | None = None,
|
||||
handbook_scope: str = "legacy",
|
||||
) -> tuple[str, int]:
|
||||
"""创建虎牙任务记录,等待后台执行器消费。"""
|
||||
if task_type not in SUPPORTED_TASK_TYPES:
|
||||
raise ValueError("不支持的任务类型")
|
||||
if handbook_scope not in {"legacy", "elite"}:
|
||||
raise ValueError("无效的工作台")
|
||||
if handbook_scope == "elite" and task_type not in HUYA_HANDBOOK_TASK_TYPES:
|
||||
raise ValueError("该任务不属于精英宝典工作台")
|
||||
|
||||
batch_id = uuid.uuid4().hex[:12]
|
||||
payload = payload or {}
|
||||
@@ -392,6 +411,7 @@ def create_planned_tasks(
|
||||
batch_id=batch_id,
|
||||
account_id=account.id,
|
||||
task_type=task_type,
|
||||
handbook_scope=handbook_scope,
|
||||
status="planned",
|
||||
message="任务已创建,等待执行",
|
||||
result={"payload": payload} if payload else None,
|
||||
|
||||
Reference in New Issue
Block a user