@mcviseron/dsh-qq-bridge 0.3.12 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bot/main.py CHANGED
@@ -4163,6 +4163,14 @@ def _heartbeat() -> None:
4163
4163
 
4164
4164
  def run_bot() -> int:
4165
4165
  """One bot process, no supervision."""
4166
+ # 单实例:两个 bot 同时连同一个 AppID,QQ 的每条消息会被它们各自回一遍
4167
+ # (实测一条消息回 6 条就是这么来的)。pid 文件里那个还活着就直接退出。
4168
+ existing = _read_pid(CHILD_PID)
4169
+ if existing and existing != os.getpid() and _alive(existing):
4170
+ print(f"[bot] already running as pid={existing}; exiting", flush=True)
4171
+ return 0
4172
+ _write_pid(CHILD_PID, os.getpid())
4173
+
4166
4174
  from dataclasses import replace as dataclass_replace
4167
4175
 
4168
4176
  from runtime_config import RuntimeConfig
package/lib/index.js CHANGED
@@ -122,10 +122,38 @@ export function apply(ctx, rawConfig) {
122
122
  // python.exe 是控制台程序,detached 时 CREATE_NO_WINDOW 会被忽略,用户就会看到黑窗、
123
123
  // 关掉窗等于把机器人杀了。所以优先用 pythonw.exe(GUI 子系统,没有控制台可弹);
124
124
  // pythonw 下 sys.stdout 是 None 会让 print 抛错,因此用 pipe 接管输出写进这里。
125
+ // 机器人自己会写 <botDir>/state/{supervisor,child}.pid;这两个还活着就不要再拉一个,
126
+ // 否则两个进程同时连同一个 AppID,一条消息会被回多遍(实测回过 6 条)。
127
+ const botAlreadyRunning = async (botDir) => {
128
+ const fs = await import('node:fs')
129
+ const { join } = await import('node:path')
130
+ for (const name of ['supervisor.pid', 'child.pid']) {
131
+ let pid = 0
132
+ try {
133
+ pid = Number.parseInt(fs.readFileSync(join(botDir, 'state', name), 'utf8').trim(), 10)
134
+ } catch (error) {
135
+ continue
136
+ }
137
+ if (!Number.isInteger(pid) || pid <= 0) continue
138
+ try {
139
+ process.kill(pid, 0)
140
+ return pid
141
+ } catch (error) {
142
+ continue
143
+ }
144
+ }
145
+ return 0
146
+ }
147
+
125
148
  const spawnSupervisor = async (pythonPath, botDir) => {
126
149
  const { spawn } = await import('node:child_process')
127
150
  const fs = await import('node:fs')
128
151
  const { join } = await import('node:path')
152
+ const running = await botAlreadyRunning(botDir)
153
+ if (running !== 0) {
154
+ log(`bot already running (pid ${running}); skip spawn`)
155
+ return { pid: running, reused: true }
156
+ }
129
157
  let exe = pythonPath
130
158
  if (/python\.exe$/i.test(pythonPath)) {
131
159
  const pyw = pythonPath.replace(/python\.exe$/i, 'pythonw.exe')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcviseron/dsh-qq-bridge",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "DeepSeek Harness plugin: bridge QQ conversations (driven by an external viseron-botpy bot) to DSH sessions — injects user messages, captures assistant replies, streams C2C answers, and relays tool approvals to the bot owner.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",