refactor: 删除 fudai_core 中重复的 4 个开奖检查函数
check_lucky_draw_result / check_have_reward_notice_confirm / check_in_order_confirm_page / get_reward 在 fudai_result_checker.py 中已有更新版本(使用 preprocess_for_ocr 等改进)。 douyin_fudai_core.py 中保留薄包装函数作为兼容 re-export, 确保任何旧调用点继续工作。 文件行数:6347 -> 6250(减 97 行) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0031f17ebc
commit
e38640eb63
1 file changed
+30
-127
@@ -16,6 +16,12 @@ from douyin.fudai.core.fudai_filter import (
|
||||
is_watch_task_fudai,
|
||||
_is_short_countdown_text,
|
||||
)
|
||||
from douyin.fudai.core.fudai_result_checker import (
|
||||
check_lucky_draw_result,
|
||||
check_have_reward_notice_confirm,
|
||||
check_in_order_confirm_page,
|
||||
get_reward,
|
||||
)
|
||||
|
||||
# 从新模块导入调试工具函数
|
||||
from douyin.fudai.core.fudai_debug_utils import (
|
||||
@@ -3771,141 +3777,38 @@ def attend_choujiang(analyser) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def check_lucky_draw_result(analyser):
|
||||
"""判定福袋抽奖的结果(简化)。
|
||||
def check_lucky_draw_result(analyser): # noqa: F811 — 兼容性 re-export
|
||||
"""[兼容] 已迁移到 douyin.fudai.core.fudai_result_checker。"""
|
||||
from douyin.fudai.core.fudai_result_checker import (
|
||||
check_lucky_draw_result as _impl,
|
||||
)
|
||||
|
||||
统一只检测开奖结果按钮区域(使用 HelperFunctions.check_lottery_result_by_ocr),
|
||||
不再对弹窗文字或其它区域进行OCR识别。
|
||||
返回:1='我知道了', 2='立即领取奖品', False=未识别
|
||||
"""
|
||||
try:
|
||||
from douyin.utils.douyin_helpers import HelperFunctions
|
||||
|
||||
detected = HelperFunctions.check_lottery_result_by_ocr(analyser)
|
||||
if detected == "我知道了":
|
||||
return 1
|
||||
if detected == "立即领取奖品":
|
||||
return 2
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
return _impl(analyser)
|
||||
|
||||
|
||||
def check_have_reward_notice_confirm(analyser) -> bool:
|
||||
"""判断是否有领奖的二次确认提醒。"""
|
||||
analyser._shot_and_diagnose("领奖确认", "识别是否有我知道了", analyser.device_id)
|
||||
analyser.cut_pic(370, 1350, 680, 1440, "", "奖励通知确认")
|
||||
reward_notice_confirm = analyser.operation.analyse_pic_word("奖励通知确认", 1)
|
||||
if "我知道了" in (reward_notice_confirm or ""):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"开奖诊断",
|
||||
"存在奖品领取提醒",
|
||||
text=(reward_notice_confirm or "")[:80],
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
return False
|
||||
def check_have_reward_notice_confirm(analyser) -> bool: # noqa: F811
|
||||
"""[兼容] 已迁移到 douyin.fudai.core.fudai_result_checker。"""
|
||||
from douyin.fudai.core.fudai_result_checker import (
|
||||
check_have_reward_notice_confirm as _impl,
|
||||
)
|
||||
|
||||
return _impl(analyser)
|
||||
|
||||
|
||||
def check_in_order_confirm_page(analyser) -> bool:
|
||||
"""判断是否在中奖下单后的购买成功的页面。"""
|
||||
analyser._shot_and_diagnose("下单结果", "识别是否购买成功页", analyser.device_id)
|
||||
analyser.cut_pic(370, 120, 700, 220, "", "订单确认")
|
||||
order_confirm = analyser.operation.analyse_pic_word("订单确认")
|
||||
if "购买成功" in (order_confirm or ""):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"开奖诊断",
|
||||
"订单确认页面:购买成功",
|
||||
text=(order_confirm or "")[:80],
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
return False
|
||||
def check_in_order_confirm_page(analyser) -> bool: # noqa: F811
|
||||
"""[兼容] 已迁移到 douyin.fudai.core.fudai_result_checker。"""
|
||||
from douyin.fudai.core.fudai_result_checker import (
|
||||
check_in_order_confirm_page as _impl,
|
||||
)
|
||||
|
||||
return _impl(analyser)
|
||||
|
||||
|
||||
def get_reward(analyser, reward_y: int = 0) -> None:
|
||||
"""中奖后领奖然后返回。"""
|
||||
analyser.operation.save_reward_pic(analyser.device_id)
|
||||
try:
|
||||
analyser._log_kv("领奖", "保存中奖截图", step="save_reward_pic")
|
||||
except Exception:
|
||||
pass
|
||||
def get_reward(analyser, reward_y: int = 0) -> None: # noqa: F811
|
||||
"""[兼容] 已迁移到 douyin.fudai.core.fudai_result_checker。"""
|
||||
from douyin.fudai.core.fudai_result_checker import get_reward as _impl
|
||||
|
||||
analyser.click(243, reward_y) # 勾选协议
|
||||
analyser.operation.delay(1)
|
||||
analyser.click(540, reward_y - 140) # 点击领取
|
||||
try:
|
||||
analyser._log_kv("领奖", "勾选协议并点击领取", reward_y=reward_y)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
analyser.operation.delay(5)
|
||||
analyser.click(886, 2170) # 点击下单
|
||||
try:
|
||||
analyser._log_kv("领奖", "点击下单")
|
||||
except Exception:
|
||||
pass
|
||||
analyser.operation.delay(10)
|
||||
|
||||
# 循环检查下单结果,增加保护避免极端死循环
|
||||
max_checks = 5
|
||||
checks = 0
|
||||
while checks < max_checks and check_in_order_confirm_page(analyser):
|
||||
checks += 1
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
try:
|
||||
analyser._log_kv("领奖", "点击回退按钮", check_round=checks)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.operation.delay(4)
|
||||
|
||||
try:
|
||||
analyser._log_kv("领奖", "下完单返回到直播间", checks=checks)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.operation.delay(4)
|
||||
|
||||
if check_lucky_draw_result(analyser):
|
||||
try:
|
||||
analyser._log_kv("领奖", "领奖弹窗未关闭,准备关闭")
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(540, reward_y + 180)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"领奖",
|
||||
"点击关闭领奖弹窗",
|
||||
x=540,
|
||||
y=(reward_y + 180) * analyser.resolution_ratio_y // 2400,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.operation.delay(2)
|
||||
analyser.operation.save_reward_pic(analyser.device_id)
|
||||
try:
|
||||
analyser._log_kv("领奖", "保存关闭领奖弹窗后的截图")
|
||||
except Exception:
|
||||
pass
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
analyser.operation.delay(2)
|
||||
|
||||
if check_have_reward_notice_confirm(analyser):
|
||||
try:
|
||||
analyser._log_kv("领奖", "提醒领奖弹窗未关闭,点击我知道了")
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(540, 1400)
|
||||
analyser.operation.delay(2)
|
||||
|
||||
try:
|
||||
analyser._log_kv("领奖", "关闭中奖提醒后等待", wait_seconds=30)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.operation.delay(30)
|
||||
return _impl(analyser, reward_y=reward_y)
|
||||
|
||||
|
||||
def is_watch_task_fudai(content: str) -> bool: # noqa: F811 — 兼容性 re-export
|
||||
|
||||
Reference in new issue
Block a user