fix: @提及昵称+正文拼凑吞消息+GUI冻结(主线程sleep)
问题1: '@咱想了解一下咱那个登录插件去哪儿下载?' 只剩'?'
- 根因: _at_user_pattern贪婪吞18字符当username, rest='?'
- is_clean_at=False只拦了入库, 但ts已被覆盖成rest('?')→整条问句丢失
- 修复: 不干净时仅剥@保留全部正文(宁留脏昵称不吞消息)
问题2: 跟踪日志时GUI冻结必须ctrl+c
- 根因: _execute_reply跑在Tk主线程, _paste_and_send失败后
time.sleep(5)×3次=主线程冻结15秒(QQ窗不前置时必失败)
- 修复: after()异步重试+data['_attempt']计数, 主线程不阻塞
This commit is contained in:
@@ -1145,6 +1145,7 @@ class MsgBotApp(ctk.CTk):
|
||||
msg = data.get("msg", "")
|
||||
max_retries = 3
|
||||
retry_delay = 5 # 秒
|
||||
attempt = data.get("_attempt", 0) # ⭐ 主线程异步重试计数(不阻塞GUI)
|
||||
|
||||
# ⭐ 发送前强制检查时间戳:≤300秒则发送,≥300秒则丢弃
|
||||
msg_age = self._check_message_freshness(msg)
|
||||
@@ -1161,19 +1162,21 @@ class MsgBotApp(ctk.CTk):
|
||||
if not found:
|
||||
self._log(f"[{platform}] ⚠ 找不到联系人 {sender},当前会话回复")
|
||||
|
||||
# 带重试的发送逻辑
|
||||
for attempt in range(max_retries):
|
||||
# 首次正常发送,重试时 force_retry 跳过60秒冷却
|
||||
ok = self.monitor._paste_and_send(platform, answer, force_retry=(attempt > 0))
|
||||
if ok:
|
||||
self._log(f"[{platform}] 🤖 已自动回复: {answer[:60]}...")
|
||||
return # 成功直接退出
|
||||
# 首次正常发送,重试时 force_retry 跳过60秒冷却
|
||||
ok = self.monitor._paste_and_send(platform, answer, force_retry=(attempt > 0))
|
||||
if ok:
|
||||
self._log(f"[{platform}] 🤖 已自动回复: {answer[:60]}...")
|
||||
return # 成功直接退出
|
||||
else:
|
||||
if attempt < max_retries - 1:
|
||||
self._log(f"[{platform}] ⚠ 自动回复发送失败,{retry_delay}秒后重试({attempt+1}/{max_retries})")
|
||||
# ⭐ 2026-08-17 修复GUI冻结:原实现主线程 time.sleep(5) ×3 = 界面冻结15秒+
|
||||
# 窗口不前置时 _paste_and_send 必失败,用户跟踪日志时 GUI 无响应。
|
||||
# 改为 after() 异步重试:主线程立即返回,5秒后再执行,界面保持流畅。
|
||||
data["_attempt"] = attempt + 1
|
||||
self.after(int(retry_delay * 1000), lambda d=data: self._execute_reply(d))
|
||||
else:
|
||||
if attempt < max_retries - 1:
|
||||
self._log(f"[{platform}] ⚠ 自动回复发送失败,{retry_delay}秒后重试({attempt+1}/{max_retries})")
|
||||
time.sleep(retry_delay)
|
||||
else:
|
||||
self._log(f"[{platform}] ⚠ 自动回复发送失败(连续{max_retries}次),用户可能在接管,本轮跳过")
|
||||
self._log(f"[{platform}] ⚠ 自动回复发送失败(连续{max_retries}次),用户可能在接管,本轮跳过")
|
||||
finally:
|
||||
self.monitor._sending_event.clear()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user