@linjz/opencode-qqbot 0.3.11 → 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/bin/openqq-setup.mjs +50 -50
- package/bin/openqq.js +47 -47
- package/dist/opencode-qqbot-plugin.js +3 -3
- package/dist/openqq-bot.js +1056 -194
- package/package.json +2 -2
- package/src/_FOLDER.md +19 -19
- package/src/bridge.ts +154 -18
- package/src/commands.ts +554 -554
- package/src/config.ts +121 -121
- package/src/core/bot-launcher.ts +146 -146
- package/src/core/card-approval.ts +146 -146
- package/src/core/context-buffer.ts +78 -78
- package/src/core/delivery.ts +105 -13
- package/src/core/discovery.ts +151 -151
- package/src/core/error-rescue.ts +33 -33
- package/src/core/file-log.ts +45 -45
- package/src/core/form-bridge.ts +388 -72
- package/src/core/form-journal.ts +214 -0
- package/src/core/gateway-state.ts +68 -0
- package/src/core/inbound-dedupe.ts +43 -0
- package/src/core/inflight-journal.ts +148 -21
- package/src/core/instance-lock.ts +28 -1
- package/src/core/linkwatch.ts +195 -195
- package/src/core/message-queue.ts +11 -0
- package/src/core/mirror.ts +182 -182
- package/src/core/outbox.ts +522 -0
- package/src/core/permission.ts +301 -301
- package/src/core/reply-limiter.ts +106 -106
- package/src/core/send-media.ts +90 -90
- package/src/core/util.ts +8 -8
- package/src/index.ts +162 -162
- package/src/opencode/_FOLDER.md +11 -11
- package/src/opencode/client.ts +98 -10
- package/src/opencode/eventstream.ts +138 -138
- package/src/opencode/history.ts +143 -143
- package/src/opencode/mirror.ts +85 -85
- package/src/opencode/sessions.ts +158 -158
- package/src/plugin-entry.ts +112 -112
- package/src/qq/_FOLDER.md +13 -13
- package/src/qq/api.ts +539 -539
- package/src/qq/gateway.ts +69 -20
- package/src/qq/media.ts +219 -219
- package/src/qq/sender.ts +300 -300
- package/src/qq/types.ts +154 -154
- package/tsconfig.json +24 -24
package/bin/openqq-setup.mjs
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// F 项(2026-10-30,吸收竞品 opencode-qq bin/setup.mjs 的零依赖思路):
|
|
3
|
-
// 扫码绑定引导——动态 import 官方 @tencent-connect/qqbot-connector(不进
|
|
4
|
-
// dependencies,守红线:官方包只做参考/用户自选安装),手机 QQ 扫码拿到
|
|
5
|
-
// appId/appSecret 后合并写入 ~/.openqq/.env(保留其余既有配置行)。
|
|
6
|
-
import fs from "node:fs"
|
|
7
|
-
import path from "node:path"
|
|
8
|
-
import os from "node:os"
|
|
9
|
-
|
|
10
|
-
const CONFIG_DIR = path.join(os.homedir(), ".openqq")
|
|
11
|
-
const ENV_FILE = path.join(CONFIG_DIR, ".env")
|
|
12
|
-
|
|
13
|
-
let connector
|
|
14
|
-
try {
|
|
15
|
-
connector = await import("@tencent-connect/qqbot-connector")
|
|
16
|
-
} catch {
|
|
17
|
-
console.error("缺少依赖 @tencent-connect/qqbot-connector")
|
|
18
|
-
console.error("请先执行: npm install -g @tencent-connect/qqbot-connector")
|
|
19
|
-
process.exit(1)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
console.log("请使用手机 QQ 扫描终端二维码完成绑定…")
|
|
23
|
-
const credsList = await connector.qrConnect({ source: "opencode-qqbot" })
|
|
24
|
-
const creds = credsList?.[0]
|
|
25
|
-
if (!creds?.appId || !creds?.appSecret) {
|
|
26
|
-
console.error("扫码未返回凭据")
|
|
27
|
-
process.exit(1)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 合并写入 .env:替换已有 QQ_APP_ID/QQ_APP_SECRET 行,其余行原样保留
|
|
31
|
-
let lines = []
|
|
32
|
-
try {
|
|
33
|
-
lines = fs.readFileSync(ENV_FILE, "utf8").split("\n")
|
|
34
|
-
} catch {
|
|
35
|
-
/* 首次运行无文件 */
|
|
36
|
-
}
|
|
37
|
-
const seen = new Set()
|
|
38
|
-
const merged = lines.map((line) => {
|
|
39
|
-
const m = /^\s*(QQ_APP_ID|QQ_APP_SECRET)\s*=/.exec(line)
|
|
40
|
-
if (!m) return line
|
|
41
|
-
seen.add(m[1])
|
|
42
|
-
return m[1] === "QQ_APP_ID" ? `QQ_APP_ID=${creds.appId}` : `QQ_APP_SECRET=${creds.appSecret}`
|
|
43
|
-
})
|
|
44
|
-
if (!seen.has("QQ_APP_ID")) merged.push(`QQ_APP_ID=${creds.appId}`)
|
|
45
|
-
if (!seen.has("QQ_APP_SECRET")) merged.push(`QQ_APP_SECRET=${creds.appSecret}`)
|
|
46
|
-
|
|
47
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 })
|
|
48
|
-
fs.writeFileSync(ENV_FILE, merged.join("\n"), { mode: 0o600 })
|
|
49
|
-
console.log(`凭据已写入 ${ENV_FILE}`)
|
|
50
|
-
console.log("现在可以运行 openqq 启动 bot 了。")
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// F 项(2026-10-30,吸收竞品 opencode-qq bin/setup.mjs 的零依赖思路):
|
|
3
|
+
// 扫码绑定引导——动态 import 官方 @tencent-connect/qqbot-connector(不进
|
|
4
|
+
// dependencies,守红线:官方包只做参考/用户自选安装),手机 QQ 扫码拿到
|
|
5
|
+
// appId/appSecret 后合并写入 ~/.openqq/.env(保留其余既有配置行)。
|
|
6
|
+
import fs from "node:fs"
|
|
7
|
+
import path from "node:path"
|
|
8
|
+
import os from "node:os"
|
|
9
|
+
|
|
10
|
+
const CONFIG_DIR = path.join(os.homedir(), ".openqq")
|
|
11
|
+
const ENV_FILE = path.join(CONFIG_DIR, ".env")
|
|
12
|
+
|
|
13
|
+
let connector
|
|
14
|
+
try {
|
|
15
|
+
connector = await import("@tencent-connect/qqbot-connector")
|
|
16
|
+
} catch {
|
|
17
|
+
console.error("缺少依赖 @tencent-connect/qqbot-connector")
|
|
18
|
+
console.error("请先执行: npm install -g @tencent-connect/qqbot-connector")
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log("请使用手机 QQ 扫描终端二维码完成绑定…")
|
|
23
|
+
const credsList = await connector.qrConnect({ source: "opencode-qqbot" })
|
|
24
|
+
const creds = credsList?.[0]
|
|
25
|
+
if (!creds?.appId || !creds?.appSecret) {
|
|
26
|
+
console.error("扫码未返回凭据")
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 合并写入 .env:替换已有 QQ_APP_ID/QQ_APP_SECRET 行,其余行原样保留
|
|
31
|
+
let lines = []
|
|
32
|
+
try {
|
|
33
|
+
lines = fs.readFileSync(ENV_FILE, "utf8").split("\n")
|
|
34
|
+
} catch {
|
|
35
|
+
/* 首次运行无文件 */
|
|
36
|
+
}
|
|
37
|
+
const seen = new Set()
|
|
38
|
+
const merged = lines.map((line) => {
|
|
39
|
+
const m = /^\s*(QQ_APP_ID|QQ_APP_SECRET)\s*=/.exec(line)
|
|
40
|
+
if (!m) return line
|
|
41
|
+
seen.add(m[1])
|
|
42
|
+
return m[1] === "QQ_APP_ID" ? `QQ_APP_ID=${creds.appId}` : `QQ_APP_SECRET=${creds.appSecret}`
|
|
43
|
+
})
|
|
44
|
+
if (!seen.has("QQ_APP_ID")) merged.push(`QQ_APP_ID=${creds.appId}`)
|
|
45
|
+
if (!seen.has("QQ_APP_SECRET")) merged.push(`QQ_APP_SECRET=${creds.appSecret}`)
|
|
46
|
+
|
|
47
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 })
|
|
48
|
+
fs.writeFileSync(ENV_FILE, merged.join("\n"), { mode: 0o600 })
|
|
49
|
+
console.log(`凭据已写入 ${ENV_FILE}`)
|
|
50
|
+
console.log("现在可以运行 openqq 启动 bot 了。")
|
package/bin/openqq.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// openqq 入口(2026-11-02 应用者体验补齐):运行时自适应——
|
|
3
|
-
// 有 bun → bun run src/index.ts(源码语义,dev 友好)
|
|
4
|
-
// 无 bun → node dist/openqq-bot.js(发布 bundle,零额外依赖)
|
|
5
|
-
// 应用者 npm i -g 后只有 node 也能跑;开发者有 bun 时始终跑源码。
|
|
6
|
-
// 注意:本文件必须保持纯 JS(无类型标注)——node 用户直接执行它。
|
|
7
|
-
import { spawnSync } from "node:child_process"
|
|
8
|
-
import { existsSync } from "node:fs"
|
|
9
|
-
import { fileURLToPath } from "node:url"
|
|
10
|
-
import { join, dirname } from "node:path"
|
|
11
|
-
|
|
12
|
-
const root = join(dirname(fileURLToPath(import.meta.url)), "..")
|
|
13
|
-
|
|
14
|
-
// bun 探测要覆盖全形态:npm 装的 bun 在 PATH 上只有 bun.ps1(CreateProcess 起不来),
|
|
15
|
-
// 真正可执行体在 npm\bun 包内 bin\bun.exe;官方安装则直接是 bun/bun.exe。
|
|
16
|
-
function detectBun() {
|
|
17
|
-
const candidates = ["bun", "bun.exe", "bun.cmd", "bun.bat"]
|
|
18
|
-
if (process.platform === "win32") {
|
|
19
|
-
const appdata = process.env.APPDATA || join(process.env.USERPROFILE || "", "AppData", "Roaming")
|
|
20
|
-
candidates.push(join(appdata, "npm", "node_modules", "bun", "bin", "bun.exe"))
|
|
21
|
-
} else {
|
|
22
|
-
candidates.push("/usr/local/bin/bun", "/opt/homebrew/bin/bun", join(process.env.HOME || "", ".bun", "bin", "bun"))
|
|
23
|
-
}
|
|
24
|
-
for (const c of candidates) {
|
|
25
|
-
try {
|
|
26
|
-
const r = spawnSync(c, ["--version"], { stdio: "ignore" })
|
|
27
|
-
if (r.status === 0) return c
|
|
28
|
-
} catch {
|
|
29
|
-
/* 下一个 */
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return null
|
|
33
|
-
}
|
|
34
|
-
const bunCmd = detectBun()
|
|
35
|
-
|
|
36
|
-
const entry = bunCmd && existsSync(join(root, "src", "index.ts"))
|
|
37
|
-
? join(root, "src", "index.ts")
|
|
38
|
-
: join(root, "dist", "openqq-bot.js")
|
|
39
|
-
const cmd = bunCmd && entry.endsWith(".ts") ? bunCmd : "node"
|
|
40
|
-
const args = entry.endsWith(".ts") ? ["run", entry] : [entry]
|
|
41
|
-
|
|
42
|
-
if (!existsSync(entry)) {
|
|
43
|
-
console.error(`[openqq] 入口不存在:${entry}(包安装不完整,请重装 @linjz/opencode-qqbot)`)
|
|
44
|
-
process.exit(1)
|
|
45
|
-
}
|
|
46
|
-
const r = spawnSync(cmd, args, { stdio: "inherit" })
|
|
47
|
-
process.exit(r.status ?? 1)
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// openqq 入口(2026-11-02 应用者体验补齐):运行时自适应——
|
|
3
|
+
// 有 bun → bun run src/index.ts(源码语义,dev 友好)
|
|
4
|
+
// 无 bun → node dist/openqq-bot.js(发布 bundle,零额外依赖)
|
|
5
|
+
// 应用者 npm i -g 后只有 node 也能跑;开发者有 bun 时始终跑源码。
|
|
6
|
+
// 注意:本文件必须保持纯 JS(无类型标注)——node 用户直接执行它。
|
|
7
|
+
import { spawnSync } from "node:child_process"
|
|
8
|
+
import { existsSync } from "node:fs"
|
|
9
|
+
import { fileURLToPath } from "node:url"
|
|
10
|
+
import { join, dirname } from "node:path"
|
|
11
|
+
|
|
12
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..")
|
|
13
|
+
|
|
14
|
+
// bun 探测要覆盖全形态:npm 装的 bun 在 PATH 上只有 bun.ps1(CreateProcess 起不来),
|
|
15
|
+
// 真正可执行体在 npm\bun 包内 bin\bun.exe;官方安装则直接是 bun/bun.exe。
|
|
16
|
+
function detectBun() {
|
|
17
|
+
const candidates = ["bun", "bun.exe", "bun.cmd", "bun.bat"]
|
|
18
|
+
if (process.platform === "win32") {
|
|
19
|
+
const appdata = process.env.APPDATA || join(process.env.USERPROFILE || "", "AppData", "Roaming")
|
|
20
|
+
candidates.push(join(appdata, "npm", "node_modules", "bun", "bin", "bun.exe"))
|
|
21
|
+
} else {
|
|
22
|
+
candidates.push("/usr/local/bin/bun", "/opt/homebrew/bin/bun", join(process.env.HOME || "", ".bun", "bin", "bun"))
|
|
23
|
+
}
|
|
24
|
+
for (const c of candidates) {
|
|
25
|
+
try {
|
|
26
|
+
const r = spawnSync(c, ["--version"], { stdio: "ignore" })
|
|
27
|
+
if (r.status === 0) return c
|
|
28
|
+
} catch {
|
|
29
|
+
/* 下一个 */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
const bunCmd = detectBun()
|
|
35
|
+
|
|
36
|
+
const entry = bunCmd && existsSync(join(root, "src", "index.ts"))
|
|
37
|
+
? join(root, "src", "index.ts")
|
|
38
|
+
: join(root, "dist", "openqq-bot.js")
|
|
39
|
+
const cmd = bunCmd && entry.endsWith(".ts") ? bunCmd : "node"
|
|
40
|
+
const args = entry.endsWith(".ts") ? ["run", entry] : [entry]
|
|
41
|
+
|
|
42
|
+
if (!existsSync(entry)) {
|
|
43
|
+
console.error(`[openqq] 入口不存在:${entry}(包安装不完整,请重装 @linjz/opencode-qqbot)`)
|
|
44
|
+
process.exit(1)
|
|
45
|
+
}
|
|
46
|
+
const r = spawnSync(cmd, args, { stdio: "inherit" })
|
|
47
|
+
process.exit(r.status ?? 1)
|
|
@@ -7,7 +7,7 @@ import { appendFileSync, existsSync as existsSync2, renameSync, statSync as stat
|
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
|
|
9
9
|
// src/core/instance-lock.ts
|
|
10
|
-
import { openSync, writeFileSync, closeSync, unlinkSync, statSync, utimesSync, mkdirSync } from "fs";
|
|
10
|
+
import { openSync, readFileSync, writeFileSync, closeSync, unlinkSync, statSync, utimesSync, mkdirSync } from "fs";
|
|
11
11
|
import { join } from "path";
|
|
12
12
|
import { homedir } from "os";
|
|
13
13
|
var LOCK_STALE_MS = 30000;
|
|
@@ -27,7 +27,7 @@ function isInstanceAliveAt(path, staleMs = LOCK_STALE_MS) {
|
|
|
27
27
|
|
|
28
28
|
// src/core/bot-launcher.ts
|
|
29
29
|
import { spawn, spawnSync } from "child_process";
|
|
30
|
-
import { existsSync, readFileSync } from "fs";
|
|
30
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
31
31
|
import { join as join2, dirname } from "path";
|
|
32
32
|
import { homedir as homedir2 } from "os";
|
|
33
33
|
function resolveRuntime(probe = defaultProbe) {
|
|
@@ -116,7 +116,7 @@ function readDotEnvField(envPath, key) {
|
|
|
116
116
|
try {
|
|
117
117
|
if (!existsSync(envPath))
|
|
118
118
|
return null;
|
|
119
|
-
for (const line of
|
|
119
|
+
for (const line of readFileSync2(envPath, "utf-8").split(`
|
|
120
120
|
`)) {
|
|
121
121
|
const trimmed = line.trim();
|
|
122
122
|
if (!trimmed || trimmed.startsWith("#"))
|