优化斗鱼任务操作体验
This commit is contained in:
@@ -31,6 +31,8 @@ DOUYU_BIND_ROLE_POLL_SECONDS = 65
|
||||
DOUYU_BIND_ROLE_POLL_INTERVAL = 5
|
||||
DOUYU_PAYMENT_POLL_SECONDS = 600
|
||||
DOUYU_PAYMENT_POLL_INTERVAL = 5
|
||||
DOUYU_GIFT_POINTS_REFRESH_TIMES = 3
|
||||
DOUYU_GIFT_POINTS_REFRESH_INTERVAL = 2
|
||||
|
||||
|
||||
class DouyuBatchRunner:
|
||||
@@ -476,6 +478,51 @@ class DouyuBatchRunner:
|
||||
result["gold_balance"] = last_gold
|
||||
return False
|
||||
|
||||
def _refresh_points_after_elite_gift(
|
||||
self,
|
||||
db: Session,
|
||||
task: DouyuTask,
|
||||
account: Account,
|
||||
client: DouyuActivityClient,
|
||||
cookie: str,
|
||||
ctn: str | None,
|
||||
result: dict,
|
||||
baseline_points: int | None,
|
||||
gift_count: int,
|
||||
) -> dict:
|
||||
"""赠送精英令后短轮询积分;1 个精英令约等于 10 积分。"""
|
||||
expected_gain = max(0, gift_count) * 10
|
||||
target_points = baseline_points + expected_gain if baseline_points is not None else None
|
||||
result["gift_points_baseline"] = baseline_points
|
||||
result["gift_points_expected_gain"] = expected_gain
|
||||
result["gift_points_target"] = target_points
|
||||
|
||||
last_points = None
|
||||
refresh_result: dict = {}
|
||||
for index in range(1, DOUYU_GIFT_POINTS_REFRESH_TIMES + 1):
|
||||
refresh_result = self._refresh_account_points(client, account, cookie, ctn=ctn)
|
||||
db.commit()
|
||||
last_points = refresh_result["points"]
|
||||
result.update(refresh_result)
|
||||
result["gift_points_refresh_count"] = index
|
||||
if target_points is None or (last_points is not None and last_points >= target_points):
|
||||
result["gift_points_confirmed"] = target_points is None or last_points is not None
|
||||
return refresh_result
|
||||
if index < DOUYU_GIFT_POINTS_REFRESH_TIMES:
|
||||
self._update_task_progress(
|
||||
db,
|
||||
task,
|
||||
"running",
|
||||
f"赠送精英令成功,等待积分同步(当前 {last_points if last_points is not None else '-'},预期 {target_points})",
|
||||
result,
|
||||
)
|
||||
if self._stop.wait(DOUYU_GIFT_POINTS_REFRESH_INTERVAL):
|
||||
break
|
||||
|
||||
result["gift_points_confirmed"] = False
|
||||
result["points"] = last_points
|
||||
return refresh_result
|
||||
|
||||
def _task_payload(self, task: DouyuTask) -> dict:
|
||||
result = task.result if isinstance(task.result, dict) else {}
|
||||
payload = result.get("payload") if isinstance(result.get("payload"), dict) else {}
|
||||
@@ -1088,20 +1135,41 @@ class DouyuBatchRunner:
|
||||
payload = self._task_payload(task)
|
||||
gift_count = int(payload.get("gift_count") or payload.get("count") or 1)
|
||||
client = self._client(cookie)
|
||||
ctn = None
|
||||
baseline_points = account.points
|
||||
try:
|
||||
ctn = client.acf_ccn(refresh_subscribe=False)
|
||||
baseline_result = self._refresh_account_points(client, account, cookie, ctn=ctn)
|
||||
db.commit()
|
||||
baseline_points = baseline_result["points"]
|
||||
except Exception as exc:
|
||||
self._push_log("warning", f"赠送精英令前刷新积分失败: {exc}")
|
||||
result = client.donate_elite_gift(
|
||||
gift_count=gift_count,
|
||||
room_id=str(payload.get("room_id") or config["room_id"]),
|
||||
gift_id=str(payload.get("gift_id") or config["gift_id"]),
|
||||
skin_id=str(payload.get("skin_id") or config["skin_id"]),
|
||||
)
|
||||
result["gift_points_baseline"] = baseline_points
|
||||
refresh_errors = []
|
||||
try:
|
||||
result.update(self._refresh_account_gold_balance(client, account))
|
||||
except Exception as exc:
|
||||
refresh_errors.append(f"鱼翅余额: {exc}")
|
||||
try:
|
||||
ctn = client.acf_ccn(refresh_subscribe=False)
|
||||
result.update(self._refresh_account_points(client, account, cookie, ctn=ctn))
|
||||
result.update(
|
||||
self._refresh_points_after_elite_gift(
|
||||
db,
|
||||
task,
|
||||
account,
|
||||
client,
|
||||
cookie,
|
||||
ctn,
|
||||
result,
|
||||
baseline_points,
|
||||
gift_count,
|
||||
)
|
||||
)
|
||||
except Exception as exc:
|
||||
refresh_errors.append(f"积分: {exc}")
|
||||
if refresh_errors:
|
||||
@@ -1113,6 +1181,8 @@ class DouyuBatchRunner:
|
||||
message += f",鱼翅余额: {account.gold_balance}"
|
||||
if account.points is not None:
|
||||
message += f",积分: {account.points}"
|
||||
if result.get("gift_points_target") is not None and not result.get("gift_points_confirmed"):
|
||||
message += f"(未确认涨到 {result['gift_points_target']})"
|
||||
self._mark_task(db, task, "success", message, result)
|
||||
|
||||
def _execute_query_points(self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict):
|
||||
|
||||
Reference in New Issue
Block a user