功能: 按用户同步斗鱼工作台
This commit is contained in:
@@ -48,6 +48,27 @@ SUPPORTED_DOUYU_TASK_TYPES = { "get_bind_qr": "获取绑定二维码",
|
||||
"exchange_xpd_goods": "兑换小店商品",
|
||||
}
|
||||
|
||||
DOUYU_HANDBOOK_SCOPES = {"elite", "esports", "peace"}
|
||||
DOUYU_HANDBOOK_TASK_TYPES = {
|
||||
"elite": {
|
||||
"get_bind_qr", "confirm_bind", "create_elite_qr", "create_gold_qr", "donate_elite_gift",
|
||||
"query_points", "exchange_goods", "query_game_name", "query_change_bind_time",
|
||||
"query_limited_goods", "query_gold_balance", "refresh_goods", "query_exchange_records",
|
||||
"prefetch_csrf_token",
|
||||
},
|
||||
"esports": {
|
||||
"prepare_esports_bind", "get_esports_bind_qr", "query_esports_game_name", "confirm_esports_bind",
|
||||
"create_esports_qr", "query_esports_points", "query_gold_balance", "query_change_bind_time",
|
||||
"query_limited_goods", "refresh_esports_goods", "exchange_esports_goods", "create_gold_qr",
|
||||
"donate_esports_chicken_gift", "donate_esports_firework_gift",
|
||||
},
|
||||
"peace": {
|
||||
"get_xpd_bind_qr", "query_xpd_bind_info", "confirm_xpd_bind", "query_xpd_role",
|
||||
"refresh_xpd_goods", "query_xpd_balance", "query_xpd_fragments",
|
||||
"query_xpd_purchase_records", "exchange_xpd_goods",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
DOUYU_CONFIG_DEFAULTS = { "manual_id": "G4KA4Qnz4LDp7",
|
||||
"rid": "9263298",
|
||||
@@ -171,12 +192,17 @@ def create_douyu_planned_tasks(
|
||||
db: Session,
|
||||
account_ids: list[int],
|
||||
task_type: str,
|
||||
handbook_scope: str,
|
||||
created_by: int,
|
||||
payload: dict | None = None,
|
||||
) -> tuple[str, int]:
|
||||
"""创建斗鱼任务记录,等待后台执行器消费。"""
|
||||
if task_type not in SUPPORTED_DOUYU_TASK_TYPES:
|
||||
raise ValueError("不支持的任务类型")
|
||||
if handbook_scope not in DOUYU_HANDBOOK_SCOPES:
|
||||
raise ValueError("无效的工作台")
|
||||
if task_type not in DOUYU_HANDBOOK_TASK_TYPES[handbook_scope]:
|
||||
raise ValueError("该任务不属于当前工作台")
|
||||
|
||||
accounts = visible_douyu_task_accounts(db, account_ids)
|
||||
if task_type in {"refresh_goods", "refresh_esports_goods", "refresh_xpd_goods"} and accounts:
|
||||
@@ -190,6 +216,7 @@ def create_douyu_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,
|
||||
@@ -333,6 +360,7 @@ def douyu_task_payload(task: DouyuTask, *, include_detail: bool = False) -> dict
|
||||
"account_uid": (account.uid if account else "") or "",
|
||||
"account_nickname": (account.nickname if account else "") or "",
|
||||
"task_type": task.task_type or "",
|
||||
"handbook_scope": task.handbook_scope or "legacy",
|
||||
"status": task.status or "",
|
||||
"message": task.message or "",
|
||||
"result": sanitize_douyu_task_result(
|
||||
|
||||
Reference in New Issue
Block a user