fix(messenger): 修复hook递归——写broadcast表直接操作DB不经send(防无限循环)

This commit is contained in:
xxm
2026-08-21 22:27:53 +08:00
parent d56981d38f
commit 5e0141eb28
+11 -5
View File
@@ -148,21 +148,27 @@ class _MessengerStdout:
def _write_broadcast_from_stdout(text, script): def _write_broadcast_from_stdout(text, script):
"""把 stdout 内容写入 broadcast_messages(仅包含有意义的内容行)""" """把 stdout 内容直接写入 broadcast_messages(不经 send, 避免 xmpp 递归)"""
if not text or not text.strip(): if not text or not text.strip():
return return
# 过滤纯日志/进度(如 [DB]/[SYNC]/百分比), 只保留有信息量的行
t = text.strip() t = text.strip()
skip_prefix = ("[DB]", "[SYNC", "[guard", "[regime] ", "", "📊 ", "📥 ", "💾 ", "🔄 ") skip_prefix = ("[DB]", "[SYNC", "[guard", "[regime] ", "", "📊 ", "📥 ", "💾 ", "🔄 ", "[SILENT]")
for line in t.split("\n"): for line in t.split("\n"):
line = line.strip() line = line.strip()
if not line or len(line) < 3: if not line or len(line) < 3:
continue continue
if line.startswith(skip_prefix): if line.startswith(skip_prefix):
continue continue
# 有意义的内容行 → 写广播表 if line.startswith("") and "" in line and "MoFin·" in line:
continue # 跳过已格式化的 messenger 输出, 防递归
try: try:
send(title=f"MoFin·{_job_title(script)}", content=line, source=script) category = _classify(_job_title(script), line)
conn = sqlite3.connect(DB, timeout=30)
conn.execute(
"INSERT INTO broadcast_messages (ts, category, title, content, source) VALUES (?,?,?,?,?)",
(datetime.now().isoformat(), category, _job_title(script), line, script))
conn.commit()
conn.close()
except Exception: except Exception:
pass pass