refactor: 抽取 is_watch_task_fudai / _is_short_countdown_text 到 fudai_filter
douyin_fudai_core.py 中存在与 fudai_filter.py 完全重复的 is_watch_task_fudai 实现,_is_short_countdown_text 也属于过滤逻辑。 集中到 fudai_filter.py 后,douyin_fudai_core.py 保留薄包装函数 作为兼容 re-export,确保所有既有调用点继续工作。 文件行数:6393 -> 6347(减 46 行) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d6cbecf7e
commit
0031f17ebc
2 files changed
+37
-60
No files matched your search
@@ -5,10 +5,33 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import time
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
def _is_short_countdown_text(time_text: str) -> bool:
|
||||
"""检查倒计时文本是否表示剩余时间很短(应跳过)"""
|
||||
if not time_text:
|
||||
return False
|
||||
|
||||
time_text = time_text.strip()
|
||||
|
||||
# 匹配 00:00, 00:01, 00:02 等,表示剩余时间 <= 2秒
|
||||
if re.match(r"^00:0[0-2]$", time_text):
|
||||
return True
|
||||
|
||||
# 匹配 0:00, 0:01, 0:02 等(有时没有前导零)
|
||||
if re.match(r"^0:0[0-2]$", time_text):
|
||||
return True
|
||||
|
||||
# 匹配 "00秒", "01秒", "02秒" 等
|
||||
if re.match(r"^0[0-2]秒$", time_text):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def check_contain(analyser, contains: str = "") -> bool:
|
||||
"""检查福袋内容是否命中"黑名单"关键词(只保留黑名单逻辑,不再使用白名单)。
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@ import numpy as np # type: ignore[import]
|
||||
from douyin.utils.douyin_utils import extract_prize_value_yuan
|
||||
from douyin.reservation import douyin_reservation_logic
|
||||
from douyin.core import path_config
|
||||
from douyin.fudai.core.fudai_filter import (
|
||||
is_watch_task_fudai,
|
||||
_is_short_countdown_text,
|
||||
)
|
||||
|
||||
# 从新模块导入调试工具函数
|
||||
from douyin.fudai.core.fudai_debug_utils import (
|
||||
@@ -3904,70 +3908,20 @@ def get_reward(analyser, reward_y: int = 0) -> None:
|
||||
analyser.operation.delay(30)
|
||||
|
||||
|
||||
def is_watch_task_fudai(content: str) -> bool:
|
||||
"""检测是否为"观看X分钟"类任务福袋。
|
||||
def is_watch_task_fudai(content: str) -> bool: # noqa: F811 — 兼容性 re-export
|
||||
"""[兼容] 已迁移到 douyin.fudai.core.fudai_filter。"""
|
||||
from douyin.fudai.core.fudai_filter import is_watch_task_fudai as _impl
|
||||
|
||||
参数:
|
||||
content: 福袋内容文本
|
||||
|
||||
返回:
|
||||
True 表示是"观看X分钟"类任务,应放弃
|
||||
False 表示不是此类任务
|
||||
"""
|
||||
if not content:
|
||||
return False
|
||||
|
||||
try:
|
||||
|
||||
# 将内容转换为字符串并去除空白
|
||||
content_str = re.sub(r"\s+", "", str(content))
|
||||
|
||||
# 中文数字字符
|
||||
chinese_num_chars = "零一二三四五六七八九十百千两"
|
||||
|
||||
# 匹配模式1:观看/看 + (可选"直播") + 数字或中文数字 + 分钟
|
||||
patt1 = rf"(?:观看|看)(?:直播)?(?:.*?)?(?:\d+|[{chinese_num_chars}]+)\s*分钟"
|
||||
|
||||
# 匹配模式2:需要观看/需要看 + 数字或中文数字 + 分钟
|
||||
patt2 = rf"需要(?:观看|看)(?:.*?)?(?:\d+|[{chinese_num_chars}]+)\s*分钟"
|
||||
|
||||
# 匹配模式3:观看时长 + 数字或中文数字 + 分钟
|
||||
patt3 = rf"观看时长(?:.*?)?(?:\d+|[{chinese_num_chars}]+)\s*分钟"
|
||||
|
||||
# 匹配模式4:看播 + 数字或中文数字 + 分钟
|
||||
patt4 = rf"看播(?:.*?)?(?:\d+|[{chinese_num_chars}]+)\s*分钟"
|
||||
|
||||
# 检查是否匹配任一模式
|
||||
patterns = [patt1, patt2, patt3, patt4]
|
||||
for patt in patterns:
|
||||
if re.search(patt, content_str):
|
||||
return True
|
||||
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
return _impl(content)
|
||||
|
||||
|
||||
def _is_short_countdown_text(time_text: str) -> bool:
|
||||
"""检查倒计时文本是否表示剩余时间很短(应跳过)"""
|
||||
if not time_text:
|
||||
return False
|
||||
def _is_short_countdown_text(time_text: str) -> bool: # noqa: F811
|
||||
"""[兼容] 已迁移到 douyin.fudai.core.fudai_filter。"""
|
||||
from douyin.fudai.core.fudai_filter import (
|
||||
_is_short_countdown_text as _impl,
|
||||
)
|
||||
|
||||
time_text = time_text.strip()
|
||||
|
||||
# 匹配 00:00, 00:01, 00:02 等,表示剩余时间 <= 2秒
|
||||
if re.match(r"^00:0[0-2]$", time_text):
|
||||
return True
|
||||
|
||||
# 匹配 0:00, 0:01, 0:02 等(有时没有前导零)
|
||||
if re.match(r"^0:0[0-2]$", time_text):
|
||||
return True
|
||||
|
||||
# 匹配 "00秒", "01秒", "02秒" 等
|
||||
if re.match(r"^0[0-2]秒$", time_text):
|
||||
return True
|
||||
|
||||
return False
|
||||
return _impl(time_text)
|
||||
|
||||
|
||||
def should_skip_fudai_by_config(analyser: Any, detail: Tuple) -> Tuple[bool, str]:
|
||||
|
||||
Reference in new issue
Block a user