fix reservation fansclub prejoin timing

This commit is contained in:
Your Name committed 2026-06-24 02:20:20 +08:00
1 parent ffebc8d0dc
commit 164f76658c
3 files changed
+69 -4

No files matched your search

@@ -32,10 +32,13 @@ def _scaled_point(analyser: Any, point: tuple[int, int]) -> tuple[int, int]:
def _fast_delay(analyser: Any, attr_name: str, default_seconds: float) -> None:
try:
seconds = float(getattr(analyser, attr_name, default_seconds) or default_seconds)
raw = getattr(analyser, attr_name, default_seconds)
if not isinstance(raw, (int, float, str)):
raw = default_seconds
seconds = float(raw or default_seconds)
except Exception:
seconds = default_seconds
seconds = max(0.0, min(seconds, 1.2))
seconds = max(0.0, min(seconds, 3.0))
try:
analyser.operation.delay(seconds)
except Exception:
@@ -74,7 +77,7 @@ def handle_reservation_prejoin_fansclub(
pass
return False
_fast_delay(analyser, "reservation_prejoin_fansclub_participate_wait_seconds", 0.6)
_fast_delay(analyser, "reservation_prejoin_fansclub_participate_wait_seconds", 1.2)
click_point = FANSCLUB_JOIN_CLICK
click_x, click_y = _scaled_point(analyser, click_point)
@@ -118,7 +121,7 @@ def handle_reservation_prejoin_fansclub(
pass
return False
_fast_delay(analyser, "reservation_prejoin_fansclub_confirm_wait_seconds", 0.8)
_fast_delay(analyser, "reservation_prejoin_fansclub_confirm_wait_seconds", 1.6)
try:
analyser.click(*DETAIL_OUTSIDE_CLICK)
@@ -33,6 +33,10 @@ _DIRECT_ATTEND_ACTIONABLE_BUTTON_TEXT_SNIPPETS = (
"发表",
"一键",
)
_DIRECT_ATTEND_FANSCLUB_TEXT_SNIPPETS = (
"粉丝团",
"关注主播",
)
# 错误处理工具占位(与原文件保持兼容降级)
try:
@@ -321,6 +325,33 @@ def _reservation_button_fallback_is_actionable(analyser: Any, item: Dict[str, An
return False, button_text, button_status
def _normalize_direct_button_text(text: str) -> str:
return "".join(ch for ch in str(text or "") if ch not in " \t\r\n·。.,,、::||-_")
def _looks_like_fansclub_button_text(button_text: str, button_status: str = "") -> bool:
joined = _normalize_direct_button_text(button_text) + _normalize_direct_button_text(
button_status
)
if not joined:
return False
if "粉丝团" in joined:
return True
if "关注主播" in joined and ("加入" in joined or "加人" in joined):
return True
if "需要加入粉丝" in joined:
return True
return False
def _reservation_may_need_fansclub_flow(item: Dict[str, Any]) -> bool:
button_text = str(item.get("button_text") or item.get("button_text_raw") or "")
button_status = str(item.get("button_status") or "")
if bool(item.get("prejoined_fansclub_before_reservation")):
return True
return _looks_like_fansclub_button_text(button_text, button_status)
def _ocr_current_attend_button_if_actionable(analyser: Any, item: Dict[str, Any]) -> tuple[bool, str, str]:
try:
from douyin.fudai.core.coords import get_fudai_detail_profile
@@ -817,6 +848,29 @@ def handle_reservation_direct_attend(analyser: Any) -> None:
except Exception:
pass
if has_button and _reservation_may_need_fansclub_flow(first_reservation):
current_ok, current_button_text, current_button_status = (
_ocr_current_attend_button_if_actionable(analyser, first_reservation)
)
if current_button_text and _looks_like_fansclub_button_text(
current_button_text,
current_button_status,
):
try:
analyser._log_kv(
"预约",
"[预约] 预约直参检测到当前仍是粉丝团任务按钮,交给详情页正常流程",
button_info=button_info,
button_text=current_button_text[:80],
button_status=current_button_status,
ocr_actionable=bool(current_ok),
reason="direct_attend_fansclub_button_semantic_guard",
)
except Exception:
pass
analyser._handle_in_fudai_detail() # type: ignore[attr-defined]
return
if not has_button:
fallback_ok, fallback_button_text, fallback_button_status = (
_reservation_button_fallback_is_actionable(analyser, first_reservation)
+8
View File
@@ -167,3 +167,11 @@ class TestReservationPrejoinFansclub:
delay_args = [c.args[0] for c in a.operation.delay.call_args_list]
assert delay_args == [0.2, 0.3]
def test_fast_prejoin_default_delays_wait_for_join_page_and_result(self):
a = _mk_analyser(auto_join_fansclub=True)
handle_reservation_prejoin_fansclub(a, "加入直播粉丝团并关注主播")
delay_args = [c.args[0] for c in a.operation.delay.call_args_list]
assert delay_args == [1.2, 1.6]