|
|
@@ -35,6 +35,9 @@ sys.stderr = sys.stdout
|
|
|
|
|
|
import requests
|
|
|
|
|
|
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
+import opencode_client # opencode 4090 HTTP 会话交互
|
|
|
+
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
OPERATION_DIR = SCRIPT_DIR # 本脚本位于 运营文案/ 目录,配置文件也在这
|
|
|
CFC_ROOT = os.path.dirname(OPERATION_DIR) # C:\code\cfc
|
|
|
@@ -266,17 +269,33 @@ def on_message_receive(data):
|
|
|
try:
|
|
|
feishu = FeishuChat(_load_config())
|
|
|
cmd = _mention_text(msg).lower()
|
|
|
- # 去掉可能的 at 前缀后解析指令
|
|
|
+
|
|
|
+ # 需要执行采集脚本的指令 -> 本地路由
|
|
|
+ # (opencode 会话为只读,无法代为运行 CDP 采集,故保留本地执行)
|
|
|
if any(k in cmd for k in ("看数据", "日报", "数据", "stats", "status")):
|
|
|
_handle_data_command(msg.message_id, feishu)
|
|
|
- elif any(k in cmd for k in ("help", "帮助", "?")):
|
|
|
+ return
|
|
|
+ if any(k in cmd for k in ("help", "帮助", "?")):
|
|
|
feishu.reply_text(msg.message_id, HELP_TEXT)
|
|
|
- elif cmd:
|
|
|
- feishu.reply_text(msg.message_id, f"未识别指令: {cmd}\n发送 help 查看可用命令。")
|
|
|
+ return
|
|
|
+
|
|
|
+ # 其余消息 -> 转发到该群的 opencode 会话处理(只读分析 + 生成回复)
|
|
|
+ user_text = _mention_text(msg)
|
|
|
+ _log(f"[opencode] chat={chat_id} 转发到 opencode 会话处理")
|
|
|
+ reply_text = opencode_client.ask(chat_id, user_text)
|
|
|
+ _log(f"[opencode] 得到回复: {reply_text[:120]!r}")
|
|
|
+ if reply_text and reply_text.strip():
|
|
|
+ feishu.reply_text(msg.message_id, reply_text)
|
|
|
else:
|
|
|
- feishu.reply_text(msg.message_id, "你好!@我并发送「看数据」即可查看最新小红书数据。")
|
|
|
+ feishu.reply_text(msg.message_id, "(opencode 未返回有效回复,请稍后再试)")
|
|
|
except Exception as e:
|
|
|
_log(f"[worker] {e}")
|
|
|
+ try:
|
|
|
+ feishu.reply_text(
|
|
|
+ msg.message_id, f"❌ 处理出错:{e}\n请稍后再试,或发送「help」查看可用命令。"
|
|
|
+ )
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
|
|
|
threading.Thread(target=_worker, daemon=True).start()
|
|
|
except Exception as e:
|