- Updated `config.json` to modify `yanghao_recommend_interval_seconds` for better timing control. - Refactored logging in `douyin_detection.py` to enhance readability and error handling. - Improved pixel loading and error management in image processing functions across multiple modules. - Enhanced GUI elements in `gui_app.py` to support new configuration options and improve user experience.
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
"""
|
|
Lottery helpers shim (WebGUI version)
|
|
=====================================
|
|
|
|
Exports:
|
|
- wait_for_lottery_result
|
|
- process_lottery_result
|
|
"""
|
|
|
|
from typing import Any, Dict, Tuple
|
|
import time
|
|
|
|
|
|
def wait_for_lottery_result(
|
|
analyser: Any,
|
|
lastsecond: int,
|
|
future_timestamp: float,
|
|
reservation_after_action_pending: bool,
|
|
reservation_should_preempt_callback,
|
|
) -> Tuple[bool, int, float | None, int | None]:
|
|
"""兼容实现:按原始签名等待开奖,当前版本只做时间等待与简单抢占判断。"""
|
|
start = time.time()
|
|
# 简单轮询等待一小段时间,保留结构但不做重型逻辑
|
|
detect_attempts = 0
|
|
first_detect_ts: float | None = None
|
|
initial_check_result: int | None = None
|
|
|
|
# 最多等待 min(倒计时+5, 15) 秒,避免阻塞过久
|
|
total_wait_s = max(0.0, float(lastsecond or 0) + 5.0)
|
|
total_wait_s = min(total_wait_s, 15.0)
|
|
step_s = 1.5
|
|
|
|
while (time.time() - start) < total_wait_s:
|
|
detect_attempts += 1
|
|
if first_detect_ts is None:
|
|
first_detect_ts = time.time()
|
|
# 若有"预约应抢占"回调,则在等待期间尊重其判断
|
|
try:
|
|
if (
|
|
reservation_should_preempt_callback is not None
|
|
and reservation_should_preempt_callback()
|
|
):
|
|
return True, detect_attempts, first_detect_ts, initial_check_result or 0
|
|
except Exception:
|
|
pass
|
|
try:
|
|
analyser.operation.delay(step_s)
|
|
except Exception:
|
|
time.sleep(step_s)
|
|
|
|
# 占位返回:未被预约抢占,未检测到明确结果
|
|
return False, detect_attempts, first_detect_ts, initial_check_result
|
|
|
|
|
|
def process_lottery_result(
|
|
analyser: Any,
|
|
x: int,
|
|
t_participate: float,
|
|
detect_attempts: int,
|
|
first_detect_ts: float | None,
|
|
initial_check_result: int | None,
|
|
reservation_focus_until_ts: float,
|
|
reservation_focus_until_ts_ref: list,
|
|
reservation_after_action_pending_ref: list,
|
|
needswitch: bool,
|
|
post_switch_delay_s: float,
|
|
swipe_up_switch_callback,
|
|
clear_reservations_callback,
|
|
get_recommend_seconds_callback,
|
|
yanghao_wait_callback,
|
|
) -> bool:
|
|
"""兼容实现:记录开奖阶段的调试信息,当前版本不修改预约/房间状态。"""
|
|
try:
|
|
analyser._log_kv(
|
|
"开奖",
|
|
"process_lottery_result",
|
|
x=x,
|
|
detect_attempts=detect_attempts,
|
|
first_detect_ts=first_detect_ts,
|
|
initial_check_result=initial_check_result,
|
|
)
|
|
except Exception:
|
|
pass
|
|
return False
|