@nestim/koishi-plugin-qq-group-manager 1.1.3 → 1.2.0
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/CHANGELOG.md +299 -0
- package/lib/ai/engine.d.ts +74 -0
- package/lib/ai/engine.js +525 -0
- package/lib/ai/memory.d.ts +30 -0
- package/lib/ai/memory.js +89 -0
- package/lib/ai/prompt.d.ts +36 -0
- package/lib/ai/prompt.js +125 -0
- package/lib/ai/provider.d.ts +48 -0
- package/lib/ai/provider.js +194 -0
- package/lib/ai/state.d.ts +53 -0
- package/lib/ai/state.js +62 -0
- package/lib/ai/trigger.d.ts +28 -0
- package/lib/ai/trigger.js +41 -0
- package/lib/ai/vision.d.ts +15 -0
- package/lib/ai/vision.js +64 -0
- package/lib/core/names.d.ts +48 -0
- package/lib/core/names.js +144 -0
- package/lib/core/text.d.ts +47 -0
- package/lib/core/text.js +284 -0
- package/lib/index.d.ts +263 -54
- package/lib/index.js +19 -13
- package/lib/service.d.ts +574 -153
- package/lib/service.js +56 -1221
- package/package.json +20 -7
- package/readme.md +149 -11
- package/src/ai/engine.ts +568 -0
- package/src/ai/memory.ts +104 -0
- package/src/ai/prompt.ts +142 -0
- package/src/ai/provider.ts +221 -0
- package/src/ai/state.ts +91 -0
- package/src/ai/trigger.ts +60 -0
- package/src/ai/vision.ts +81 -0
- package/src/core/names.ts +158 -0
- package/src/core/text.ts +332 -0
- package/src/index.ts +186 -0
- package/src/service.js +3327 -0
- package/tsconfig.json +24 -0
- package/lib/commands.d.ts +0 -4
- package/lib/commands.js +0 -18
- package/lib/types.d.ts +0 -23
- package/lib/types.js +0 -2
package/package.json
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestim/koishi-plugin-qq-group-manager",
|
|
3
3
|
"description": "Koishi QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、图片菜单、状态卡片、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib",
|
|
9
|
-
"
|
|
9
|
+
"src",
|
|
10
|
+
"tsconfig.json",
|
|
11
|
+
"CHANGELOG.md"
|
|
10
12
|
],
|
|
11
13
|
"license": "MIT",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
12
17
|
"scripts": {
|
|
13
|
-
"build": "
|
|
14
|
-
"clean": "
|
|
15
|
-
"rebuild": "npm run
|
|
18
|
+
"build": "node scripts/build.mjs",
|
|
19
|
+
"clean": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\"",
|
|
20
|
+
"rebuild": "npm run build",
|
|
21
|
+
"test": "node --test \"test/*.test.mjs\"",
|
|
22
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
16
23
|
},
|
|
17
24
|
"keywords": [
|
|
18
25
|
"qq",
|
|
19
26
|
"group",
|
|
20
27
|
"onebot",
|
|
21
28
|
"llonebot",
|
|
29
|
+
"napcat",
|
|
22
30
|
"koishi",
|
|
23
31
|
"koishi-plugin",
|
|
24
32
|
"chatbot",
|
|
@@ -27,12 +35,17 @@
|
|
|
27
35
|
"vision",
|
|
28
36
|
"ai"
|
|
29
37
|
],
|
|
30
|
-
"devDependencies": {
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.20.5",
|
|
40
|
+
"koishi": "4.18.11",
|
|
41
|
+
"typescript": "5.6.3"
|
|
42
|
+
},
|
|
31
43
|
"peerDependencies": {
|
|
32
44
|
"koishi": "^4.18.7"
|
|
33
45
|
},
|
|
34
46
|
"koishi": {
|
|
35
|
-
"description": "QQ群管理插件(群管、自动管控、记忆、识图、AI回复)。"
|
|
47
|
+
"description": "QQ群管理插件(群管、自动管控、记忆、识图、AI回复)。",
|
|
48
|
+
"category": "manage"
|
|
36
49
|
},
|
|
37
50
|
"repository": {
|
|
38
51
|
"type": "git",
|
package/readme.md
CHANGED
|
@@ -29,7 +29,7 @@ Koishi 控制台「探索器 Explorer」里查看和手改。
|
|
|
29
29
|
| **黑名单** | 按群独立存储(`banMember_<群号>.md`);入群自动比对并踢出,可选踢人时自动记录 |
|
|
30
30
|
| **入群审核** | 新申请推送到群内,管理员用 `approve` / `reject` 放行或拒绝;待审单落盘,**重启不丢** |
|
|
31
31
|
| **记忆库** | `[memory]` 保存 / 列出 / 查询 / 删除,落盘 `Memory.md`;开启后 AI 回复会检索并引用相关记忆 |
|
|
32
|
-
| **AI 群聊回复** |
|
|
32
|
+
| **AI 群聊回复** | 三道闸门(阈值 / 概率 / 冷却)+ 模型自行 `<pass/>` 决定是否接话;群名片、引用、@ 目标、自己历史发言都进上下文;记忆按相关度注入;图片并发解析并限时。多人格、点名后话题跟随、温度与输出上限 |
|
|
33
33
|
| **AI 识图** | 图片下载转 data URL 后送入模型,兼容 CQ 码 / HTML `<img>` / 元素三种形态与表情包 |
|
|
34
34
|
| **复读** | 连续相同消息达阈值复读,支持图片引用回查;复读事件会进入 AI 上下文 |
|
|
35
35
|
| **娱乐** | 自我约束(口球)与违规禁言惩罚,可开关与调节参数 |
|
|
@@ -97,25 +97,39 @@ npm i @nestim/koishi-plugin-qq-group-manager
|
|
|
97
97
|
| `enableJoinRequestReview` | `true` | 是否发起入群审核 |
|
|
98
98
|
| `enableAiReply` | `false` | AI 回复总开关(建议配合 `aiReplyRequireGroupRule` 逐群开启) |
|
|
99
99
|
| `aiReplyRequireGroupRule` | `true` | 仅对已在 `groupRules` 中单独配置的群启用 AI 回复 |
|
|
100
|
+
| `aiContextWindow` | `30` | 进入提示词的消息条数(建议 20~40) |
|
|
101
|
+
| `aiReplyDecision` | `single` | `single` 一次调用(推荐)/ `two-stage` 两次调用 |
|
|
102
|
+
| `aiMaxReplyChars` | `120` | 单条回复最大字符数 |
|
|
103
|
+
| `aiImageBudgetMs` | `6000` | 图片解析总预算(毫秒),超时跳过 |
|
|
104
|
+
| `aiDebugPrompt` | `false` | 把最终提示词写入日志,排查"答非所问" |
|
|
100
105
|
| `dryRun` | `false` | 演练模式:只输出计划动作,不真正执行 |
|
|
101
106
|
|
|
102
107
|
## AI 回复与识图
|
|
103
108
|
|
|
104
109
|
- **接口**:`openai-compatible`(OpenAI 兼容 Chat Completions)与 `gemini`(原生 `generateContent`)两类。
|
|
105
|
-
-
|
|
106
|
-
1. `aiMessageThreshold` 消息阈值(`threshold` / `hybrid
|
|
110
|
+
- **触发**:先过三道闸门,任一不过都不产生模型调用:
|
|
111
|
+
1. `aiMessageThreshold` 消息阈值(`threshold` / `hybrid`)——累计未达阈值不触发;
|
|
107
112
|
2. `aiRandomReplyProbability` 随机概率(`random` / `hybrid`)——每条消息掷一次骰,未掷中直接跳过;
|
|
108
|
-
3. `
|
|
113
|
+
3. 冷却:同一群两次真正调用模型之间至少间隔 `aiMinReplyIntervalSeconds`。
|
|
109
114
|
|
|
110
115
|
`hybrid` 表示**两者都需满足**(先够消息数,再掷中概率)。消息中命中智能体自称或直接 `@bot` 时,
|
|
111
|
-
|
|
116
|
+
越过上述全部闸门直接触发。点名与点名后跟随不受冷却限制。
|
|
117
|
+
- **接话决策**:默认 `aiReplyDecision: single`——模型在回复时自行判断,不值得接话就只输出 `<pass/>`,
|
|
118
|
+
此时不会发消息并重置计数。这样「要不要回」和「回什么」是同一次判断,不会出现
|
|
119
|
+
「判定说该回、生成却回了另一条」的错位。设为 `two-stage` 则先判定再生成(多一次延迟)。
|
|
120
|
+
- **上下文**:`aiContextWindow` 条消息按**时间顺序**进入提示词,包含 @ 目标(渲染成群昵称)、
|
|
121
|
+
引用消息原文、图片/表情/卡片占位,以及**机器人自己的历史发言**——不会"说完就忘"。
|
|
122
|
+
只回应当前消息,引用与回答始终指向同一条。
|
|
123
|
+
- **群名片**:优先取群名片,为空时调用 `getGroupMemberInfo` 补齐并缓存,最后才退回 QQ 昵称/QQ 号。
|
|
124
|
+
- **记忆**:只有与当前消息(或最近三条)真正有词面交集的记忆才会注入,并且提示词明确允许忽略;
|
|
125
|
+
旧版「搜不到就注入最近 6 条」的行为已移除,不会再出现"聊什么都能扯回某条旧记忆"。
|
|
112
126
|
- **多人格**:`aiPersonas` 保存多套「自称 + 系统提示词」,用 `aiActivePersona` 切换。
|
|
113
|
-
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
-
|
|
118
|
-
|
|
127
|
+
- **识图**:开启 `aiEnableImageRecognition` 后,图片并发下载并转为 data URL 再送入模型;
|
|
128
|
+
总预算由 `aiImageBudgetMs` 控制(默认 6 秒),超时直接跳过,不再把回复拖到几十秒。
|
|
129
|
+
模型不支持图片时会自动降级为纯文本并记住该结论,后续不再重复尝试。
|
|
130
|
+
- **输出**:单条消息,`aiMaxReplyChars`(默认 120)限制长度;推荐 `aiTemperature` 0.7~0.9。
|
|
131
|
+
- **调试**:`aiDebugPrompt` 打开后会把最终提示词写进日志,便于排查"到底看到了什么"。
|
|
132
|
+
|
|
119
133
|
|
|
120
134
|
## 数据文件
|
|
121
135
|
|
|
@@ -139,6 +153,130 @@ npm i @nestim/koishi-plugin-qq-group-manager
|
|
|
139
153
|
|
|
140
154
|
鉴权细节与指令执行结果只写日志,不回显到群聊。
|
|
141
155
|
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## English
|
|
159
|
+
|
|
160
|
+
A QQ group-management plugin for [Koishi](https://koishi.chat) (OneBot / NapCat / LLOneBot).
|
|
161
|
+
|
|
162
|
+
Bracket-style commands plus layered per-group configuration. Covers moderation actions,
|
|
163
|
+
message filtering, automatic punishment, a memory store, blacklists, join-request review,
|
|
164
|
+
repeat (echo) and AI group-chat replies. **No database required** — all state is persisted
|
|
165
|
+
as Markdown files that you can read and edit directly in the Koishi console (Explorer).
|
|
166
|
+
|
|
167
|
+
- Commands use a uniform `[prefix] args` form; targets accept a QQ number or `@mention`
|
|
168
|
+
- Command names are English; menu lines are labelled in Chinese (e.g. `禁言 [mute] ...`)
|
|
169
|
+
- Menus are plain text — **no puppeteer / image rendering**
|
|
170
|
+
- Troubleshooting means opening the `.md` files in the Koishi data directory, no DB queries
|
|
171
|
+
|
|
172
|
+
### Features
|
|
173
|
+
|
|
174
|
+
| Group | Capability |
|
|
175
|
+
| --- | --- |
|
|
176
|
+
| **Moderation** | Mute / unmute / kick (optionally rejecting future join requests). Durations `10`, `10m`, `1h`, `1d`, `1w`, capped at 30 days |
|
|
177
|
+
| **Authorization** | Account allowlist plus group owner / admin checks; can require the bot itself to hold owner or admin rights |
|
|
178
|
+
| **Message filtering** | Whole-message scoring for banned words (fuzzy ordered matching, confidence decay, per-word weights); intercepts card messages and merged forwards; optional auto-recall with a group notice |
|
|
179
|
+
| **Strong keywords** | `strongKeywords` triggers moderation on match and **ignores allowlist exemptions**, closing the "append an allowlisted word to bypass" hole. Evaluation order: strong keyword → allowlist → banned word |
|
|
180
|
+
| **Per-group overrides** | `groupRules` sets banned words, strong keywords, allowlist keywords and toggles per group; unset values fall back to global |
|
|
181
|
+
| **Auto punishment** | Accumulated violations inside a window reaching a threshold trigger auto-mute / auto-kick; threshold, duration and window are all configurable |
|
|
182
|
+
| **Blacklist** | Stored per group (`banMember_<groupId>.md`); join requests are matched automatically and rejected |
|
|
183
|
+
| **Join review** | New requests are pushed to the group; admins use `approve` / `reject`. Pending requests are persisted and **survive restarts** |
|
|
184
|
+
| **Memory store** | `[memory]` save / list / search / delete into `Memory.md`; when enabled, AI replies retrieve and cite relevant memories |
|
|
185
|
+
| **AI replies** | Three gates (threshold / probability / cooldown) plus a model-decided `<pass/>` opt-out. Group cards, quoted text, @ targets and the bot's own history all enter the prompt; memories are injected only when relevant; images are resolved concurrently with a time budget. Multiple personas, follow-up window, temperature and output limits |
|
|
186
|
+
| **AI vision** | Images are downloaded concurrently and converted to data URLs before being sent to the model; handles CQ codes, HTML `<img>` and message elements, including stickers. Models without vision support degrade to text automatically |
|
|
187
|
+
| **Repeat (echo)** | Echoes a message once consecutive repeats reach a threshold; repeat events feed into the AI context |
|
|
188
|
+
|
|
189
|
+
### Install
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
npm i @nestim/koishi-plugin-qq-group-manager
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Or search `qq-group-manager` in the Koishi console plugin market.
|
|
196
|
+
|
|
197
|
+
Requires `koishi >= 4.18.7` and a OneBot implementation (NapCat / LLOneBot, etc.) providing
|
|
198
|
+
`setGroupBan` / `setGroupKick` / `getGroupMemberInfo`.
|
|
199
|
+
|
|
200
|
+
### Commands
|
|
201
|
+
|
|
202
|
+
All commands use `[prefix] args`; targets accept a QQ number or `@mention`.
|
|
203
|
+
Send `[bot]` on its own to show the menu.
|
|
204
|
+
|
|
205
|
+
| Command | Description |
|
|
206
|
+
| --- | --- |
|
|
207
|
+
| `[mute] QQ duration [reason]` | Mute. Duration `10` / `10m` / `1h` / `1d` / `1w`, max 30 days |
|
|
208
|
+
| `[unmute] QQ [reason]` | Unmute |
|
|
209
|
+
| `[kick] QQ [reason]` | Remove from the group (optionally reject future join requests and record to the blacklist) |
|
|
210
|
+
| `[memory] content` | Save a memory |
|
|
211
|
+
| `[memory] list` | List the 10 most recent memories |
|
|
212
|
+
| `[memory] search keyword` | Search memories (`query` / `find` are synonyms) |
|
|
213
|
+
| `[memory] delete keyword` | Delete memories containing the keyword (`del` is a synonym) |
|
|
214
|
+
| `[ban] QQ [reason]` | Add to this group's blacklist |
|
|
215
|
+
| `[unban] QQ [reason]` | Remove from this group's blacklist |
|
|
216
|
+
| `[banlist]` | List this group's blacklist |
|
|
217
|
+
| `[custom]` | List custom commands |
|
|
218
|
+
| `[bot]` | Show the command menu |
|
|
219
|
+
| `[Version]` | Show plugin info (version, author, GitHub and npm links) |
|
|
220
|
+
|
|
221
|
+
**Join review**: a new request posts a 6-digit ID to the group. Admins reply with plain text —
|
|
222
|
+
`approve [id] [reason]` or `reject [id] [reason]`. The ID may be omitted, in which case the
|
|
223
|
+
most recent pending request in that group is used.
|
|
224
|
+
|
|
225
|
+
### Configuration groups
|
|
226
|
+
|
|
227
|
+
The plugin's config page is organised into 11 groups:
|
|
228
|
+
`基础设置` · `消息管控` · `自动管控` · `记忆库` · `黑名单` · `娱乐设置` · `群聊互动` ·
|
|
229
|
+
`自定义命令` · `AI 回复` · `权限设置` · `日志设置` (Basics · Message filtering · Auto
|
|
230
|
+
punishment · Memory · Blacklist · Entertainment · Group interaction · Custom commands ·
|
|
231
|
+
AI replies · Permissions · Logging).
|
|
232
|
+
|
|
233
|
+
A few commonly used options:
|
|
234
|
+
|
|
235
|
+
| Option | Default | Description |
|
|
236
|
+
| --- | --- | --- |
|
|
237
|
+
| `command` | `[bot]` | Menu entry prefix |
|
|
238
|
+
| `allowedUserIds` | `[]` | Accounts allowed to use moderation commands directly |
|
|
239
|
+
| `bannedWords` | `[]` | Banned words; supports `keyword\|score` for custom weights |
|
|
240
|
+
| `bannedWordScoreThreshold` | `70` | Score threshold for banned words (shared with strong keywords) |
|
|
241
|
+
| `strongKeywords` | `[]` | Strong keywords: match triggers moderation and **ignores allowlist exemptions**; supports `keyword\|score` |
|
|
242
|
+
| `groupRules` | `[]` | Per-group overrides (banned words, strong keywords, allowlist keywords, AI toggles, auto-punishment thresholds) |
|
|
243
|
+
| `enableJoinRequestReview` | `true` | Whether to enable join review |
|
|
244
|
+
| `enableAiReply` | `false` | Master switch for AI replies (pair with `aiReplyRequireGroupRule` to enable per group) |
|
|
245
|
+
| `dryRun` | `false` | Dry-run mode: log planned actions without executing them |
|
|
246
|
+
|
|
247
|
+
### Data files
|
|
248
|
+
|
|
249
|
+
All stored in the Koishi data directory (`ctx.baseDir`), readable and editable through the
|
|
250
|
+
console Explorer:
|
|
251
|
+
|
|
252
|
+
| File | Contents |
|
|
253
|
+
| --- | --- |
|
|
254
|
+
| `Memory.md` | Memory store, entries separated by `---` |
|
|
255
|
+
| `banMember_<groupId>.md` | Per-group blacklist, `## QQ · note` plus join time |
|
|
256
|
+
| `JoinRequests.md` | Pending join requests (human-readable table + machine-readable section); restored on restart, expired entries cleaned up automatically |
|
|
257
|
+
|
|
258
|
+
### Permission model
|
|
259
|
+
|
|
260
|
+
Moderation commands (`[mute]` `[unmute]` `[kick]` `[ban]` `[unban]` `[banlist]`) use
|
|
261
|
+
**two-step authorization**:
|
|
262
|
+
|
|
263
|
+
1. **Actor identity** — passes if the sender is in `allowedUserIds`; otherwise they must be
|
|
264
|
+
the group owner (`allowGroupOwner`) or a group admin (`allowGroupAdmin`).
|
|
265
|
+
2. **Execution capability** — when `requireBotOwnerForAdmin` is on, the bot must itself be
|
|
266
|
+
owner or admin in that group.
|
|
267
|
+
|
|
268
|
+
Both steps must pass. Authorization details and command results are written to logs only and
|
|
269
|
+
are never echoed into the group.
|
|
270
|
+
|
|
142
271
|
## License
|
|
143
272
|
|
|
144
273
|
MIT
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
📖 **完整文档请前往 GitHub / Full documentation on GitHub:**
|
|
278
|
+
<https://github.com/Miseat/koishi-plugin-qq-group-manager#readme>
|
|
279
|
+
|
|
280
|
+
- 🐛 Issues / 问题反馈:<https://github.com/Miseat/koishi-plugin-qq-group-manager/issues>
|
|
281
|
+
- 📦 npm:<https://www.npmjs.com/package/@nestim/koishi-plugin-qq-group-manager>
|
|
282
|
+
- 📝 更新日志 / Changelog:[CHANGELOG.md](https://github.com/Miseat/koishi-plugin-qq-group-manager/blob/master/CHANGELOG.md)
|