@linjz/opencode-qqbot 0.3.18 → 0.3.20
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/PRIVACY.md +87 -0
- package/README.md +11 -1
- package/README.zh-CN.md +11 -1
- package/THIRD_PARTY_NOTICES.md +136 -0
- package/bin/openqq.js +3 -1
- package/dist/opencode-qqbot-plugin.js +9 -4
- package/dist/openqq-bot.js +565 -164
- package/dist/openqq-watchdog.js +9 -4
- package/package.json +4 -2
- package/src/bridge.ts +130 -7
- package/src/core/card-approval.ts +4 -3
- package/src/core/context-buffer.ts +6 -6
- package/src/core/cron-reminders.ts +1 -1
- package/src/core/delivery.ts +131 -37
- package/src/core/instance-lock.ts +1 -1
- package/src/core/mirror-anchors.ts +145 -0
- package/src/core/mirror.ts +112 -22
- package/src/core/notices.ts +2 -2
- package/src/core/notify-sink.ts +1 -1
- package/src/core/outbound-sanitize.ts +3 -1
- package/src/core/reply-limiter.ts +3 -2
- package/src/core/send-media.ts +6 -6
- package/src/core/stt.ts +1 -1
- package/src/core/supervisor-election.ts +22 -7
- package/src/index.ts +1 -1
- package/src/opencode/mirror.ts +54 -2
- package/src/opencode/sessions.ts +28 -2
- package/src/qq/api.ts +9 -1
- package/src/qq/gateway.ts +16 -5
- package/src/qq/media.ts +1 -1
- package/src/qq/sender.ts +64 -14
- package/src/qq/types.ts +4 -1
package/PRIVACY.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Privacy and Data Handling / 隐私与数据处理
|
|
2
|
+
|
|
3
|
+
This document describes the categories of data the bot can process and the responsibilities of deployers. It is not a guarantee that every deployment has the same behavior. Actual data flows depend on configuration, enabled features, QQ and OpenCode settings, AI providers, network paths, and local operational choices.
|
|
4
|
+
|
|
5
|
+
## English
|
|
6
|
+
|
|
7
|
+
### Data the bot may process
|
|
8
|
+
|
|
9
|
+
- QQ messages, quoted content, group or user identifiers, and interaction data.
|
|
10
|
+
- Desktop session content, including the default full-text session mirror.
|
|
11
|
+
- Voice content and speech-recognition text, images, files, filenames, and file contents selected for upload or sending.
|
|
12
|
+
- Approval decisions, commands, task history, delivery and deduplication records, gateway session/sequence state, watchdog events, and diagnostic logs.
|
|
13
|
+
- Credentials such as `QQ_APP_SECRET` and `OPENCODE_PASSWORD`, which must remain in the designated secret store and must never be printed, copied into logs, committed, or disclosed.
|
|
14
|
+
|
|
15
|
+
### Where data may go
|
|
16
|
+
|
|
17
|
+
- QQ Open Platform and QQ clients, according to the bot's messaging behavior.
|
|
18
|
+
- The OpenCode service and execution environment selected by the deployer.
|
|
19
|
+
- AI/model providers configured for the OpenCode service. Their own privacy terms, retention policies, and regional processing rules may apply.
|
|
20
|
+
- External speech-to-text providers configured through `QQ_STT_*`: when enabled, audio bytes and filenames are sent to the selected transcription endpoint. That provider's privacy, retention, and regional processing rules also apply.
|
|
21
|
+
- Local runtime storage such as `~/.openqq/`, which can contain configuration, ledgers, message-related state, and logs.
|
|
22
|
+
- Downloaded image attachments are stored in the system temporary directory under `opencode/qq-images`. Files older than seven days are only subject to a cleanup attempt when the bot starts; all other retention and deletion remains an operational responsibility.
|
|
23
|
+
|
|
24
|
+
This repository does not establish a maintainer-operated data-processing service on your behalf. Deployers must nevertheless verify actual endpoints, providers, subprocesses, log destinations, and any telemetry or external integrations in their environment.
|
|
25
|
+
|
|
26
|
+
### Retention and access
|
|
27
|
+
|
|
28
|
+
- Runtime retention varies by feature and configuration. Some delivery-deduplication records are retained for a bounded period, while other session, form, queue, and diagnostic records may persist until their configured cleanup or manual deletion.
|
|
29
|
+
- The unified log uses rolling files with a configured size budget. Retention and deletion are operational responsibilities, not automatic privacy guarantees.
|
|
30
|
+
- Deployers must restrict access to runtime files, backups, logs, screenshots, and exported files, and must define retention, archival, deletion, and incident-response procedures suitable for their users and jurisdiction.
|
|
31
|
+
|
|
32
|
+
### Deployer and user responsibilities
|
|
33
|
+
|
|
34
|
+
Deployers must, as required by applicable law and their role:
|
|
35
|
+
|
|
36
|
+
1. Inform affected users what data is collected, why it is processed, who receives it, where it is stored, and how long it is retained.
|
|
37
|
+
2. Obtain consent or establish another valid legal basis before processing personal information, sensitive information, confidential content, or employee/user communications.
|
|
38
|
+
3. Avoid collecting unnecessary secrets, sensitive personal information, or confidential material, and minimize mirrored content and attachments where possible.
|
|
39
|
+
4. Assess cross-border transfer, processor, subprocessors, and industry-specific requirements before enabling external AI providers or remote QQ services.
|
|
40
|
+
5. Provide appropriate access, correction, deletion, withdrawal, and incident-handling channels.
|
|
41
|
+
6. Keep credentials out of source control and logs, rotate them after suspected disclosure, and do not share runtime secret files.
|
|
42
|
+
|
|
43
|
+
AI output may be inaccurate. Users must independently review it, especially for dangerous operations, permissions, files, professional judgments, and decisions affecting other people.
|
|
44
|
+
|
|
45
|
+
For privacy-related questions, open an issue in the project repository. Do not include secrets or sensitive personal information in the issue.
|
|
46
|
+
|
|
47
|
+
## 中文
|
|
48
|
+
|
|
49
|
+
### 可能处理的数据
|
|
50
|
+
|
|
51
|
+
- QQ 消息、引用内容、群或用户标识以及互动数据。
|
|
52
|
+
- 桌面会话内容,包括默认的全文会话镜像。
|
|
53
|
+
- 语音及语音识别文本、图片、文件、文件名,以及选择上传或发送的文件内容。
|
|
54
|
+
- 审批决定、命令、任务历史、投递与去重记录、网关 session/sequence 状态、看门狗事件和诊断日志。
|
|
55
|
+
- `QQ_APP_SECRET`、`OPENCODE_PASSWORD` 等凭据。凭据只能存放在指定密钥存储中,不得打印、复制进日志、提交或披露。
|
|
56
|
+
|
|
57
|
+
### 数据可能流向
|
|
58
|
+
|
|
59
|
+
- QQ 开放平台及 QQ 客户端,取决于机器人的消息行为。
|
|
60
|
+
- 部署者选择的 OpenCode 服务和执行环境。
|
|
61
|
+
- OpenCode 服务配置的 AI/模型提供方;其隐私条款、留存政策和地域处理规则可能同时适用。
|
|
62
|
+
- 通过 `QQ_STT_*` 配置的外部语音识别提供方:启用后,音频字节和文件名会发送至所选转写端点,该提供方的隐私、留存及地域处理规则同时适用。
|
|
63
|
+
- `~/.openqq/` 等本地运行时存储,可能包含配置、台账、消息相关状态和日志。
|
|
64
|
+
- 下载的图片附件保存在系统临时目录的 `opencode/qq-images` 下;超过七天的文件仅在 bot 启动时尝试清理,其余保存与删除仍属运维责任。
|
|
65
|
+
|
|
66
|
+
本仓库不会替部署者建立由维护者运营的数据处理服务。部署者仍须核实其实际端点、服务提供方、子进程、日志目的地,以及环境中的遥测或外部集成。
|
|
67
|
+
|
|
68
|
+
### 保存与访问
|
|
69
|
+
|
|
70
|
+
- 各类数据的保存期限随功能和配置而异。部分投递去重记录有有界保存期,其他会话、表单、队列和诊断记录可能持续保存,直到配置的清理或人工删除。
|
|
71
|
+
- 统一日志按配置预算滚动。留存与删除属于运维责任,不能仅凭滚动机制推定已经满足隐私要求。
|
|
72
|
+
- 部署者必须限制对运行时文件、备份、日志、截图和导出文件的访问,并根据用户及适用法域制定保存、归档、删除和事件响应程序。
|
|
73
|
+
|
|
74
|
+
### 部署者与用户责任
|
|
75
|
+
|
|
76
|
+
部署者应根据适用法律及其角色:
|
|
77
|
+
|
|
78
|
+
1. 向相关用户说明收集哪些数据、处理目的、接收方、存储位置和保存期限。
|
|
79
|
+
2. 在处理个人信息、敏感信息、保密内容或员工/用户通信前,取得必要授权或具备其他合法处理依据。
|
|
80
|
+
3. 避免收集不必要的密钥、敏感个人信息或保密材料,并尽可能减少镜像内容和附件。
|
|
81
|
+
4. 启用外部 AI 服务或远程 QQ 服务前,评估跨境传输、处理者、子处理者及行业特别要求。
|
|
82
|
+
5. 提供适当的查询、更正、删除、撤回同意和事件处理渠道。
|
|
83
|
+
6. 防止凭据进入版本控制和日志,疑似泄露时及时轮换,不共享运行时密钥文件。
|
|
84
|
+
|
|
85
|
+
AI 生成内容可能不准确。用户必须独立复核,尤其是危险操作、权限、文件、专业判断及影响他人的决定。
|
|
86
|
+
|
|
87
|
+
隐私相关问题请通过项目仓库 issue 联系,提交时不得包含密钥或敏感个人信息。
|
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ Built for production, not just message bridging: a self-healing watchdog, an aud
|
|
|
38
38
|
|
|
39
39
|
### What's new in v0.3.18
|
|
40
40
|
|
|
41
|
+
- **v0.3.19 hotfix** — `bin/openqq.js` TDZ (temporal dead zone) broke every `openqq` subcommand on 0.3.16-0.3.18 with a module-eval `ReferenceError`; declaration order fixed and a bin smoke suite added to the test chain. Also fixes the supervisor lease `--once` self-deferral that diluted 5-min patrols to 10-min (channel-priority + timestamp lease, pid is diagnostics only).
|
|
41
42
|
- **`qq_send_file` first-class tool** — the AI sends local files/images to QQ via a native tool with JSON-Schema contract and precise structured errors (allowlist roots on failure); the old `QQ_SEND_FILE:` text marker survives as a fallback. No more syntax guessing.
|
|
42
43
|
- **System-level channel instructions** — QQ rendering/format rules are injected as session instructions (`<context key="qq">`), not appended to your prompt text. Session history stays clean on the desktop side.
|
|
43
44
|
- **Status cockpit** — `/status` becomes the single dashboard and the only switch entry for observation (`watch`) and digest mirror (`mirror`); standalone `/watch` `/mirror` commands retired.
|
|
@@ -311,6 +312,15 @@ The QQ bridge is an adapter from "OpenCode interaction events" to "QQ interactio
|
|
|
311
312
|
|
|
312
313
|
Principle: unsupported types always get explicit copy + desktop guidance, never silent drops; enhancements like the per-field wizard land with minimal intrusion.
|
|
313
314
|
|
|
315
|
+
## Compliance, trademarks, and data responsibility
|
|
316
|
+
|
|
317
|
+
- **Independent project**: this is an independent open-source project, not an official product of Tencent, QQ, or OpenCode. It is not sponsored, certified, or endorsed by them. References to official APIs, SDKs, semantics, or quota alignment describe platform documentation or behavioral alignment only.
|
|
318
|
+
- **Platform rules**: deployers and users must review and comply with the applicable QQ Open Platform and OpenCode agreements, API terms, bot rules, content-safety requirements, and laws. Do not bypass authentication, access controls, quotas, permission approvals, content review, or sandbox and production restrictions. Feature availability depends on current platform rules and account permissions.
|
|
319
|
+
- **Trademarks**: QQ, Tencent, OpenCode, and related marks belong to their respective owners. They are used only to identify compatibility and interoperability, not to imply official status, sponsorship, or endorsement. Do not use official logos or certification imagery without authorization.
|
|
320
|
+
- **Data and AI output**: deployers must inform affected users how messages, voice, images, files, sessions, and logs are collected, transmitted, processed, and retained, and must obtain any required authorization or have another lawful basis. Avoid unnecessary sensitive personal information, credentials, or confidential content. AI output may be incorrect and must be reviewed, especially for approvals, dangerous actions, and professional matters. See [PRIVACY.md](./PRIVACY.md).
|
|
321
|
+
- **License and liability**: this project is provided under the MIT License; the license and disclaimer in [LICENSE](./LICENSE) govern. Deployers remain responsible for their configuration, data processing, content, and use. Nothing in this section limits the rights granted by the MIT License or excludes liability that cannot be excluded by applicable law.
|
|
322
|
+
- **Third-party notices**: upstream and bundled third-party attributions are preserved in [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md), including the derived reply-limiter implementation, QQ upstream projects, and bundled `ws` code.
|
|
323
|
+
|
|
314
324
|
## License
|
|
315
325
|
|
|
316
|
-
MIT
|
|
326
|
+
MIT — see [LICENSE](./LICENSE) for the complete license and disclaimer.
|
package/README.zh-CN.md
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
### v0.3.18 新特性
|
|
37
37
|
|
|
38
|
+
- **v0.3.19 热修**:`bin/openqq.js` 的 TDZ(暂时性死区)曾致 0.3.16-0.3.18 全部 `openqq` 子命令启动即 `ReferenceError`——声明顺序已修并补 bin 冒烟套件入测试链;同批修复监督租约 `--once` 自相让贤(5min 巡检被稀释成 10min,改 channel 优先级+时间戳租约,pid 仅诊断)。
|
|
38
39
|
- **`qq_send_file` 一等工具**:AI 经原生工具发本机文件/图片到 QQ——JSON Schema 契约+结构化精确错误(白名单拒绝时直接列出可用根目录);旧 `QQ_SEND_FILE:` 文本标记保留为降级。不再猜标记。
|
|
39
40
|
- **系统级通道指令**:QQ 渲染/格式规则以会话指令注入(`<context key="qq">`),不再拼接进 prompt 正文——桌面端会话历史零污染。
|
|
40
41
|
- **驾驶舱**:`/status` 升为单点总控,观察(`watch`)与桌面摘要镜像(`mirror`)的唯一开关入口;独立 `/watch` `/mirror` 命令退役。
|
|
@@ -320,7 +321,16 @@ QQ 桥的本质是「opencode 交互事件 → QQ 交互原语」的适配器。
|
|
|
320
321
|
|
|
321
322
|
Install: `opencode plugin add @linjz/opencode-qqbot` — Chinese README below, docs/review playbook in the repo.
|
|
322
323
|
|
|
324
|
+
## 合规、商标与免责声明
|
|
325
|
+
|
|
326
|
+
- **项目独立性**:本项目为独立开源项目,不是腾讯、QQ 或 OpenCode 的官方产品,也未获得其赞助、认证或背书。文中“官方 API”“官方 SDK”“官方语义”“官方配额对齐”等表述,仅用于描述平台文档、协议或行为对齐,不表示本项目属于官方产品。
|
|
327
|
+
- **平台规则**:部署者和使用者须自行阅读并遵守 QQ 开放平台及 OpenCode 当前有效的服务协议、API 使用条款、机器人管理规范、内容安全规则及适用法律法规。不得绕过鉴权、访问控制、配额、权限审批、内容审查以及沙箱与正式环境限制。具体功能可用性以各平台当前规则和账号权限为准。
|
|
328
|
+
- **商标**:QQ、腾讯、OpenCode 及相关标识归其权利人所有,仅在说明兼容性和互操作目的下使用,不暗示官方身份、赞助或背书。未经授权,不使用官方 logo、认证形象或进行暗示官方关系的宣传。
|
|
329
|
+
- **数据与 AI 输出**:部署者应向相关用户说明消息、语音、图片、文件、会话及日志的收集、传输、处理和保存方式,并依法取得必要授权或具备其他合法处理依据。请勿提交不必要的敏感个人信息、密钥或保密信息。AI 生成内容可能不准确,使用者应自行复核,尤其是权限审批、危险操作和专业事项。详见 [PRIVACY.md](./PRIVACY.md)。
|
|
330
|
+
- **许可与责任**:本项目按 MIT 许可证发布,许可证及免责声明以 [LICENSE](./LICENSE) 为准。部署者对其配置、数据处理、内容和使用行为负责;本声明不限制 MIT 许可证授予的权利,也不排除适用法律要求承担的责任。
|
|
331
|
+
- **第三方声明**:上游及打包第三方组件的来源与许可说明见 [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md),包括派生的回复限额器、QQ 上游项目及打包的 `ws` 代码。
|
|
332
|
+
|
|
323
333
|
## License
|
|
324
334
|
|
|
325
|
-
MIT
|
|
335
|
+
MIT — 完整许可与免责声明见 [LICENSE](./LICENSE)。
|
|
326
336
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Third-Party Notices
|
|
2
|
+
|
|
3
|
+
This file records upstream code, design references, and bundled dependencies whose licenses require attribution. It supplements, and does not replace, the project's [LICENSE](./LICENSE).
|
|
4
|
+
|
|
5
|
+
## Scope notes
|
|
6
|
+
|
|
7
|
+
- `src/core/reply-limiter.ts` is a derived revision of `tencent-connect/openclaw-qqbot/src/outbound/reply-limiter.ts`. The interface, defaults, and core state machine are intentionally preserved. It is not represented as independent original work.
|
|
8
|
+
- `src/core/outbound-sanitize.ts` is a derived revision of `openclaw-qqbot/src/outbound/sanitize.ts`, retaining the principal regular expressions and stripping sequence with project-specific consolidation.
|
|
9
|
+
- `normalizeLocalPath` in `src/core/send-media.ts` is a derived revision of `openclaw-qqbot/src/outbound/local-file-router.ts`'s `normalizePath`. The rest of the send-media workflow is implemented independently by this project.
|
|
10
|
+
- `src/qq/sender.ts`, `src/core/card-approval.ts`, `src/core/context-buffer.ts`, `src/core/delivery.ts`, `src/core/notices.ts`, and `src/bridge.ts` contain independent project implementations or extensions informed by the sources below. These references do not imply that every file is copied.
|
|
11
|
+
- `dist/openqq-bot.js` contains bundled code from `ws`. The `ws` copyright and license below must remain with distributed copies of that bundle.
|
|
12
|
+
|
|
13
|
+
## tencent-connect/openclaw-qqbot
|
|
14
|
+
|
|
15
|
+
- Source: https://github.com/tencent-connect/openclaw-qqbot
|
|
16
|
+
- Reviewed source revision: `89988812442583bf47c34b89f9abf5fd4b85df0b`
|
|
17
|
+
- Used for: the derived reply limiter, outbound sanitizer, local-path normalization, and related passive-reply design references.
|
|
18
|
+
- License: MIT
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
MIT License
|
|
22
|
+
|
|
23
|
+
Copyright (c) 2026 sliverp
|
|
24
|
+
Copyright (c) 2026 Tencent Connect
|
|
25
|
+
|
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
27
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
28
|
+
in the Software without restriction, including without limitation the rights
|
|
29
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
30
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
31
|
+
furnished to do so, subject to the following conditions:
|
|
32
|
+
|
|
33
|
+
The above copyright notice and this permission notice shall be included in all
|
|
34
|
+
copies or substantial portions of the Software.
|
|
35
|
+
|
|
36
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
37
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
38
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
39
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
40
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
41
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
42
|
+
SOFTWARE.
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## tencent-connect/dsh-qqbot
|
|
46
|
+
|
|
47
|
+
- Source: https://github.com/tencent-connect/dsh-qqbot
|
|
48
|
+
- Reviewed baseline: `63abb82` (the clone also contains that baseline revision).
|
|
49
|
+
- Used for: chunking, button-data, approval-channel, and msgid-cache design references.
|
|
50
|
+
- License: MIT
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
MIT License
|
|
54
|
+
|
|
55
|
+
Copyright (c) 2026 Tencent Connect
|
|
56
|
+
|
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
58
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
59
|
+
in the Software without restriction, including without limitation the rights
|
|
60
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
61
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
62
|
+
furnished to do so, subject to the following conditions:
|
|
63
|
+
|
|
64
|
+
The above copyright notice and this permission notice shall be included in all
|
|
65
|
+
copies or substantial portions of the Software.
|
|
66
|
+
|
|
67
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
68
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
69
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
70
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
71
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
72
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
73
|
+
SOFTWARE.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## @tencent-connect/qqbot-nodejs
|
|
77
|
+
|
|
78
|
+
- Source: https://github.com/tencent-connect/qqbot-nodejs
|
|
79
|
+
- npm package: `@tencent-connect/qqbot-nodejs@1.0.5`
|
|
80
|
+
- Used for: protocol shapes and quote-reference design references.
|
|
81
|
+
- License: MIT
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
MIT License
|
|
85
|
+
|
|
86
|
+
Copyright (c) 2026 Tencent
|
|
87
|
+
|
|
88
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
89
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
90
|
+
in the Software without restriction, including without limitation the rights
|
|
91
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
92
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
93
|
+
furnished to do so, subject to the following conditions:
|
|
94
|
+
|
|
95
|
+
The above copyright notice and this permission notice shall be included in all
|
|
96
|
+
copies or substantial portions of the Software.
|
|
97
|
+
|
|
98
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
99
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
100
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
101
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
102
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
103
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
104
|
+
SOFTWARE.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## ws
|
|
108
|
+
|
|
109
|
+
- Source: https://github.com/websockets/ws
|
|
110
|
+
- Reviewed npm package: `ws@8.22.0` (declared dependency range: `^8.18.0`).
|
|
111
|
+
- Used for: WebSocket implementation bundled into `dist/openqq-bot.js`.
|
|
112
|
+
- License: MIT
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
116
|
+
Copyright (c) 2013 Arnout Kazemier and contributors
|
|
117
|
+
Copyright (c) 2016 Luigi Pinca and contributors
|
|
118
|
+
|
|
119
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
120
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
121
|
+
the Software without restriction, including without limitation the rights to
|
|
122
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
123
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
124
|
+
subject to the following conditions:
|
|
125
|
+
|
|
126
|
+
The above copyright notice and this permission notice shall be included in all
|
|
127
|
+
copies or substantial portions of the Software.
|
|
128
|
+
|
|
129
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
130
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
131
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
132
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
133
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
134
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
135
|
+
SOFTWARE.
|
|
136
|
+
```
|
package/bin/openqq.js
CHANGED
|
@@ -11,6 +11,9 @@ import { fileURLToPath } from "node:url"
|
|
|
11
11
|
import { join, dirname } from "node:path"
|
|
12
12
|
|
|
13
13
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..")
|
|
14
|
+
// argv 必须先于一切分支声明(TDZ 实证 DEF-qqbot-20261125-bin:watchdog/restart/service 分支
|
|
15
|
+
// 曾在本声明之前读取 argv[0],模块求值即 ReferenceError,全部子命令失效)。
|
|
16
|
+
const argv = process.argv.slice(2)
|
|
14
17
|
|
|
15
18
|
// 2026-11-09 架构红线:看门狗/重启/自启注册都是包内 TS 产物,经本 shim 统一分发。
|
|
16
19
|
// 传参不改变无参数行为。
|
|
@@ -27,7 +30,6 @@ if (argv[0] === "restart" || argv[0] === "service") {
|
|
|
27
30
|
|
|
28
31
|
// notify 子命令分发(不改变无参数行为):CLI 只入队 ~openqq/outbox.json,
|
|
29
32
|
// 发送由 bot 进程 notify-sink 消费;CLI 不联网不取 token 不抢锁。
|
|
30
|
-
const argv = process.argv.slice(2)
|
|
31
33
|
if (argv[0] === "notify") {
|
|
32
34
|
const notifyArgs = argv.slice(1)
|
|
33
35
|
const cliDist = join(root, "dist", "notify-cli.js")
|
|
@@ -1233,21 +1233,26 @@ import { join as join8 } from "path";
|
|
|
1233
1233
|
import { homedir as homedir6 } from "os";
|
|
1234
1234
|
var LEASE_PATH = join8(homedir6(), ".openqq", "supervisor-lease.json");
|
|
1235
1235
|
var LEASE_TTL_MS = 10 * 60000;
|
|
1236
|
+
var PRIORITY = { service: 2, plugin: 1 };
|
|
1236
1237
|
function electSupervisor(channel, opts) {
|
|
1237
1238
|
const ttlMs = opts?.ttlMs ?? LEASE_TTL_MS;
|
|
1238
1239
|
const now = opts?.now ?? Date.now();
|
|
1239
1240
|
const path = opts?.path ?? LEASE_PATH;
|
|
1241
|
+
const pid = opts?.pid ?? process.pid;
|
|
1240
1242
|
try {
|
|
1241
1243
|
let cur = null;
|
|
1242
1244
|
try {
|
|
1243
1245
|
cur = JSON.parse(readFileSync9(path, "utf-8"));
|
|
1244
1246
|
} catch {}
|
|
1245
|
-
if (cur && typeof cur.until === "number" && cur.until > now) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1247
|
+
if (cur && typeof cur.until === "number" && cur.until > now && cur.channel) {
|
|
1248
|
+
if (cur.channel !== channel) {
|
|
1249
|
+
if (PRIORITY[cur.channel] > PRIORITY[channel])
|
|
1250
|
+
return false;
|
|
1251
|
+
} else if (channel === "plugin" && cur.pid !== pid) {
|
|
1248
1252
|
return false;
|
|
1253
|
+
}
|
|
1249
1254
|
}
|
|
1250
|
-
writeFileSync5(path, JSON.stringify({ channel, pid
|
|
1255
|
+
writeFileSync5(path, JSON.stringify({ channel, pid, until: now + ttlMs }));
|
|
1251
1256
|
return true;
|
|
1252
1257
|
} catch {
|
|
1253
1258
|
return true;
|