Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 69 additions & 37 deletions src/tasks/DailyTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,44 +458,76 @@ def gongongqu(self):
if self.config.get("自主循环"):
self.auto_loop()

def _auto_loop_step_with_retry(self, step_num, match, box=None, time_out=5, after_sleep=2, **kwargs):
"""
点击OCR匹配元素,等待点击特征在 3s 内消失。
若特征未消失则重试,最多尝试 3 次。
Comment on lines +462 to +464
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Ruff confusable-character warnings are present in newly added text.

The new docstrings/comments/strings contain fullwidth punctuation flagged by Ruff (RUF001/RUF002/RUF003). If lint is gating, normalize punctuation or add an explicit rule exception for localized Chinese text.

Also applies to: 471-473, 482-483, 487-497, 507-523

🧰 Tools
🪛 Ruff (0.15.12)

[warning] 463-463: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)


[warning] 464-464: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tasks/DailyTask.py` around lines 462 - 464, The added Chinese
docstrings/comments in src/tasks/DailyTask.py use fullwidth punctuation (e.g.,
fullwidth commas/periods/quotes) which triggers Ruff confusable-character
warnings (RUF001/RUF002/RUF003); fix by normalizing those punctuation characters
to ASCII equivalents in the affected docstrings/comments (the docstring block
around the OCR click behavior and the subsequent comment blocks you added) or,
if localized fullwidth punctuation is intentional, append a per-line or
per-block Ruff noqa comment (e.g., # noqa: RUF001,RUF002,RUF003) to those
specific docstrings/comments so Ruff stops flagging them. Ensure you update the
same text blocks mentioned in the review (the OCR/docstring and the other nearby
comment blocks) rather than changing unrelated code.

"""
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False
# 等待最多 3s,检测点击特征是否消失
Comment on lines +466 to +473
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Retry loop exits on first OCR miss, so retries are skipped.

When wait_click_ocr returns falsy, the function returns immediately instead of trying remaining attempts. This bypasses retry behavior for transient OCR misses.

🔧 Proposed fix
         for attempt in range(3):
             result = self.wait_click_ocr(
                 match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
             )
             if not result:
-                self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
-                return False
+                if attempt < 2:
+                    self.log_info(
+                        f"自主循环步骤{step_num}未识别到目标,重试 ({attempt + 2}/3)",
+                        notify=True
+                    )
+                    continue
+                self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
+                return False
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False
# 等待最多 3s,检测点击特征是否消失
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
if attempt < 2:
self.log_info(
f"自主循环步骤{step_num}未识别到目标,重试 ({attempt + 2}/3)",
notify=True
)
continue
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False
# 等待最多 3s,检测点击特征是否消失
🧰 Tools
🪛 Ruff (0.15.12)

[warning] 471-471: String contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF001)


[warning] 473-473: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tasks/DailyTask.py` around lines 466 - 473, The retry loop currently
returns immediately on the first falsy result from wait_click_ocr, skipping
remaining attempts; change the logic in the loop that iterates "for attempt in
range(3)" so that when wait_click_ocr(...) returns falsy you log the attempt
failure (using self.log_info and step_num) and continue to the next iteration
instead of returning False, and after the loop completes (if all attempts fail)
return False once—this preserves retries for transient OCR misses while keeping
the final failure behavior.

start = time.time()
while time.time() - start < 3:
self.next_frame()
if not self.ocr(box=box, match=match):
self.sleep(after_sleep)
return result
self.sleep(0.3)
if attempt < 2:
self.log_info(f"自主循环步骤{step_num}点击后特征未消失,重试 ({attempt + 2}/3)", notify=True)
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False

def auto_loop(self):
steps = [
[
lambda: self.wait_click_ocr(
match=[re.compile("自主循环")],
box=self.box.bottom_left,
time_out=5,
after_sleep=2,
log=True,
),
],
[
lambda: self.wait_click_ocr(
match="开始循环",
box=self.box.bottom_left,
time_out=5,
after_sleep=2,
log=True,
),
],
[
lambda: self.wait_click_ocr(match=["确认"], settle_time=2, after_sleep=2, log=True),
],
[
lambda: self.wait_click_ocr(
match=re.compile("循环结束"), time_out=600, box=self.box.top, after_sleep=2, log=True
),
],
[
lambda: self.wait_click_ocr(match=["确认"], settle_time=2, after_sleep=2, log=True),
],
]
# 执行
for i in range(len(steps)):
for step in steps[i]:
if not step():
self.log_info(f"自主循环步骤{i + 1}未完成,退出循环", notify=True)
return
# 步骤 1: 点击"自主循环",带重试
if not self._auto_loop_step_with_retry(
step_num=1,
match=[re.compile("自主循环")],
box=self.box.bottom_left,
time_out=5,
after_sleep=2,
):
return

# 步骤 2: 点击"开始循环",带重试
if not self._auto_loop_step_with_retry(
step_num=2,
match="开始循环",
box=self.box.bottom_left,
time_out=5,
after_sleep=2,
):
return

# 步骤 3: 点击"确认",带重试
if not self._auto_loop_step_with_retry(
step_num=3,
match=["确认"],
settle_time=2,
after_sleep=2,
):
return

# 步骤 4: 等待"循环结束"出现并点击(仅作为一次识别完成的角色,不需要重试)
if not self.wait_click_ocr(
match=re.compile("循环结束"), time_out=600, box=self.box.top, after_sleep=2, log=True
):
self.log_info("自主循环步骤4未完成,退出循环", notify=True)
return

# 步骤 5: 点击"确认",带重试
if not self._auto_loop_step_with_retry(
step_num=5,
match=["确认"],
settle_time=2,
after_sleep=2,
):
return

def shopping(self):
self.info_set('current_task', 'shopping')
Expand Down