@nestim/koishi-plugin-qq-group-manager 1.1.2 → 1.1.4
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/lib/index.js +2 -2
- package/lib/service.js +50 -16
- package/package.json +3 -2
- package/readme.md +130 -3
package/lib/index.js
CHANGED
|
@@ -152,10 +152,10 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
152
152
|
aiInterestMaxTokens: koishi_1.Schema.natural().min(256).max(16384).default(2048).description('兴趣判定的最大输出 token(默认 2048)。带思考的推理模型会先消耗 reasoning token,额度太小会导致正文为空、finish_reason=length,判定静默失效——表现为「该回的消息也不回」。'),
|
|
153
153
|
}).description('AI 回复'),
|
|
154
154
|
koishi_1.Schema.object({
|
|
155
|
-
allowedUserIds: koishi_1.Schema.array(String).role('table').default([]).description('允许直接使用群管理命令的账号 ID
|
|
155
|
+
allowedUserIds: koishi_1.Schema.array(String).role('table').default([]).description('允许直接使用群管理命令的账号 ID 白名单。命中即通过,不再校验群内角色。'),
|
|
156
156
|
allowGroupOwner: koishi_1.Schema.boolean().default(true).description('是否允许群主使用管理命令。'),
|
|
157
157
|
allowGroupAdmin: koishi_1.Schema.boolean().default(true).description('是否允许群管理员使用管理命令。'),
|
|
158
|
-
requireBotOwnerForAdmin: koishi_1.Schema.boolean().default(true).description('
|
|
158
|
+
requireBotOwnerForAdmin: koishi_1.Schema.boolean().default(true).description('是否要求 bot 在当前群具备群主或管理员身份才放行群管指令(默认开启)。这是「执行能力」校验,与操作者身份无关;关闭后跳过该步。'),
|
|
159
159
|
allowAdminBypassWhitelistMute: koishi_1.Schema.boolean().default(true).description('白名单目标禁言保护开关:开启后允许群主/管理员对其执行禁言。'),
|
|
160
160
|
}).description('权限设置'),
|
|
161
161
|
koishi_1.Schema.object({
|
package/lib/service.js
CHANGED
|
@@ -2501,15 +2501,17 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
2501
2501
|
return denied;
|
|
2502
2502
|
}
|
|
2503
2503
|
const botRole = await this.getTargetRole(session, botId);
|
|
2504
|
-
|
|
2505
|
-
|
|
2504
|
+
// bot 只要具备群主或管理员身份,就有能力执行禁言/踢人等操作。
|
|
2505
|
+
// 此前要求必须是 owner,导致绝大多数群(bot 只是管理员)里群管指令全部不可用。
|
|
2506
|
+
if (botRole === 'owner' || botRole === 'admin') {
|
|
2507
|
+
const allowed = { ok: true, message: `bot(${botId}) 在当前群角色=${botRole},具备管理能力。` };
|
|
2506
2508
|
this.logAuth('admin-visibility', allowed, session);
|
|
2507
2509
|
return allowed;
|
|
2508
2510
|
}
|
|
2509
2511
|
const denied = {
|
|
2510
2512
|
ok: false,
|
|
2511
|
-
message: `bot(${botId}) 在当前群角色=${botRole ?? 'unknown'}
|
|
2512
|
-
userMessage: '当前群中 bot
|
|
2513
|
+
message: `bot(${botId}) 在当前群角色=${botRole ?? 'unknown'},既不是群主也不是管理员,无法执行群管操作。`,
|
|
2514
|
+
userMessage: '当前群中 bot 既不是群主也不是管理员,无法执行群管操作。',
|
|
2513
2515
|
};
|
|
2514
2516
|
this.logAuth('admin-visibility', denied, session);
|
|
2515
2517
|
return denied;
|
|
@@ -3497,10 +3499,32 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3497
3499
|
this.logCommandResult('version', { ok: true, message: 'version info sent' }, session, { version });
|
|
3498
3500
|
}
|
|
3499
3501
|
/** 权限不足提示 */
|
|
3500
|
-
async denyAdmin(session) {
|
|
3501
|
-
await session.send(this.styleText('你没有权限执行该操作。'));
|
|
3502
|
+
async denyAdmin(session, message) {
|
|
3503
|
+
await session.send(this.styleText(message || '你没有权限执行该操作。'));
|
|
3502
3504
|
return true;
|
|
3503
3505
|
}
|
|
3506
|
+
/**
|
|
3507
|
+
* 群管指令的统一鉴权(两步):
|
|
3508
|
+
* ① authorizeCommand —— 判定「谁在操作」:账号白名单 / 群主 / 群管理员;
|
|
3509
|
+
* ② canUseAdminCommand —— 确认「bot 在该群是否具备管理能力」。
|
|
3510
|
+
*
|
|
3511
|
+
* 此前方括号指令只做了第②步,导致 allowedUserIds / allowGroupOwner /
|
|
3512
|
+
* allowGroupAdmin 对 mute/unmute/kick/ban/unban 完全失效:配置里允许群主操作,
|
|
3513
|
+
* 但只要 bot 不是群主就会被拒;反过来当 bot 是群主时,任何群成员都能踢人。
|
|
3514
|
+
*/
|
|
3515
|
+
async authorizeModerationAction(command, session) {
|
|
3516
|
+
const auth = await this.authorizeCommand(command, session);
|
|
3517
|
+
if (!auth.ok) {
|
|
3518
|
+
this._logger.warn(`[auth:${command}] 拒绝(操作者权限不足): ${auth.message} | ${this.sessionTag(session)}`);
|
|
3519
|
+
return { ok: false, message: auth.userMessage || '你没有权限执行该操作。' };
|
|
3520
|
+
}
|
|
3521
|
+
const capability = await this.canUseAdminCommand(session);
|
|
3522
|
+
if (!capability.ok) {
|
|
3523
|
+
this._logger.warn(`[auth:${command}] 拒绝(bot 无管理能力): ${capability.message} | ${this.sessionTag(session)}`);
|
|
3524
|
+
return { ok: false, message: capability.userMessage || '你没有权限执行该操作。' };
|
|
3525
|
+
}
|
|
3526
|
+
return { ok: true, message: auth.message };
|
|
3527
|
+
}
|
|
3504
3528
|
/** [mute] qq号|@某人 时长 [原因] */
|
|
3505
3529
|
async execMute(session, rest, mentions = []) {
|
|
3506
3530
|
const tokens = rest.split(/\s+/).filter(Boolean);
|
|
@@ -3536,8 +3560,9 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3536
3560
|
await session.send(this.styleText('请给出有效的禁言时长,例如:10 / 10m / 1h / 1d。'));
|
|
3537
3561
|
return true;
|
|
3538
3562
|
}
|
|
3539
|
-
|
|
3540
|
-
|
|
3563
|
+
const auth = await this.authorizeModerationAction('mute', session);
|
|
3564
|
+
if (!auth.ok)
|
|
3565
|
+
return this.denyAdmin(session, auth.message);
|
|
3541
3566
|
const r = await this.mute(session, target, minutes, reason);
|
|
3542
3567
|
await session.send(this.styleText(r.message));
|
|
3543
3568
|
this._logger.info(`[cmd:mute] target=${target} minutes=${minutes} byMention=${consumed === 0 && !!mentions.length} | ${this.sessionTag(session)}`);
|
|
@@ -3559,8 +3584,9 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3559
3584
|
await session.send(this.styleText(`用法:${this.cmdPrefix('cmdUnmute', '[unmute]')} qq号|@某人 原因(原因选填)`));
|
|
3560
3585
|
return true;
|
|
3561
3586
|
}
|
|
3562
|
-
|
|
3563
|
-
|
|
3587
|
+
const auth = await this.authorizeModerationAction('unmute', session);
|
|
3588
|
+
if (!auth.ok)
|
|
3589
|
+
return this.denyAdmin(session, auth.message);
|
|
3564
3590
|
const r = await this.unmute(session, target, tokens.slice(consumed).join(' '));
|
|
3565
3591
|
await session.send(this.styleText(r.message));
|
|
3566
3592
|
this._logger.info(`[cmd:unmute] target=${target} | ${this.sessionTag(session)}`);
|
|
@@ -3582,8 +3608,9 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3582
3608
|
await session.send(this.styleText(`用法:${this.cmdPrefix('cmdKick', '[kick]')} qq号|@某人 原因(原因选填)`));
|
|
3583
3609
|
return true;
|
|
3584
3610
|
}
|
|
3585
|
-
|
|
3586
|
-
|
|
3611
|
+
const auth = await this.authorizeModerationAction('kick', session);
|
|
3612
|
+
if (!auth.ok)
|
|
3613
|
+
return this.denyAdmin(session, auth.message);
|
|
3587
3614
|
const r = await this.kick(session, target, false, tokens.slice(consumed).join(' '));
|
|
3588
3615
|
await session.send(this.styleText(r.message));
|
|
3589
3616
|
this._logger.info(`[cmd:kick] target=${target} | ${this.sessionTag(session)}`);
|
|
@@ -3657,8 +3684,9 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3657
3684
|
await session.send(this.styleText('本群未启用黑名单系统。'));
|
|
3658
3685
|
return true;
|
|
3659
3686
|
}
|
|
3660
|
-
|
|
3661
|
-
|
|
3687
|
+
const auth = await this.authorizeModerationAction('ban', session);
|
|
3688
|
+
if (!auth.ok)
|
|
3689
|
+
return this.denyAdmin(session, auth.message);
|
|
3662
3690
|
const tokens = rest.split(/\s+/).filter(Boolean);
|
|
3663
3691
|
let qq = '';
|
|
3664
3692
|
let reason = '';
|
|
@@ -3696,8 +3724,9 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3696
3724
|
await session.send(this.styleText('本群未启用黑名单系统。'));
|
|
3697
3725
|
return true;
|
|
3698
3726
|
}
|
|
3699
|
-
|
|
3700
|
-
|
|
3727
|
+
const auth = await this.authorizeModerationAction('unban', session);
|
|
3728
|
+
if (!auth.ok)
|
|
3729
|
+
return this.denyAdmin(session, auth.message);
|
|
3701
3730
|
const tokens = rest.split(/\s+/).filter(Boolean);
|
|
3702
3731
|
let qq = '';
|
|
3703
3732
|
let reason = '';
|
|
@@ -3724,6 +3753,11 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
3724
3753
|
await session.send(this.styleText('本群未启用黑名单系统。'));
|
|
3725
3754
|
return;
|
|
3726
3755
|
}
|
|
3756
|
+
const auth = await this.authorizeCommand('banlist', session);
|
|
3757
|
+
if (!auth.ok) {
|
|
3758
|
+
await session.send(this.styleText(auth.userMessage || '你没有权限执行该操作。'));
|
|
3759
|
+
return;
|
|
3760
|
+
}
|
|
3727
3761
|
const list = await this.getBlacklist(session);
|
|
3728
3762
|
if (!list.length) {
|
|
3729
3763
|
await session.send(this.styleText('本群黑名单为空。'));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestim/koishi-plugin-qq-group-manager",
|
|
3
3
|
"description": "Koishi QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、图片菜单、状态卡片、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.4",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"koishi": "^4.18.7"
|
|
33
33
|
},
|
|
34
34
|
"koishi": {
|
|
35
|
-
"description": "QQ群管理插件(群管、自动管控、记忆、识图、AI回复)。"
|
|
35
|
+
"description": "QQ群管理插件(群管、自动管控、记忆、识图、AI回复)。",
|
|
36
|
+
"category": "manage"
|
|
36
37
|
},
|
|
37
38
|
"repository": {
|
|
38
39
|
"type": "git",
|
package/readme.md
CHANGED
|
@@ -129,13 +129,140 @@ npm i @nestim/koishi-plugin-qq-group-manager
|
|
|
129
129
|
|
|
130
130
|
## 权限模型
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
群管指令(`[mute]` `[unmute]` `[kick]` `[ban]` `[unban]` `[banlist]`)采用**两步鉴权**:
|
|
133
|
+
|
|
134
|
+
1. **操作者身份**:`allowedUserIds` 命中即通过;否则要求是群主(`allowGroupOwner`)或群管理员(`allowGroupAdmin`)。
|
|
135
|
+
2. **执行能力**:`requireBotOwnerForAdmin` 开启时,要求 bot 在该群是群主或管理员,否则无法执行。
|
|
136
|
+
|
|
137
|
+
- 两步都通过才放行。
|
|
135
138
|
- 白名单目标默认受禁言保护,`allowAdminBypassWhitelistMute` 决定群主/管理员能否绕过。
|
|
136
139
|
|
|
137
140
|
鉴权细节与指令执行结果只写日志,不回显到群聊。
|
|
138
141
|
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## English
|
|
145
|
+
|
|
146
|
+
A QQ group-management plugin for [Koishi](https://koishi.chat) (OneBot / NapCat / LLOneBot).
|
|
147
|
+
|
|
148
|
+
Bracket-style commands plus layered per-group configuration. Covers moderation actions,
|
|
149
|
+
message filtering, automatic punishment, a memory store, blacklists, join-request review,
|
|
150
|
+
repeat (echo) and AI group-chat replies. **No database required** — all state is persisted
|
|
151
|
+
as Markdown files that you can read and edit directly in the Koishi console (Explorer).
|
|
152
|
+
|
|
153
|
+
- Commands use a uniform `[prefix] args` form; targets accept a QQ number or `@mention`
|
|
154
|
+
- Command names are English; menu lines are labelled in Chinese (e.g. `禁言 [mute] ...`)
|
|
155
|
+
- Menus are plain text — **no puppeteer / image rendering**
|
|
156
|
+
- Troubleshooting means opening the `.md` files in the Koishi data directory, no DB queries
|
|
157
|
+
|
|
158
|
+
### Features
|
|
159
|
+
|
|
160
|
+
| Group | Capability |
|
|
161
|
+
| --- | --- |
|
|
162
|
+
| **Moderation** | Mute / unmute / kick (optionally rejecting future join requests). Durations `10`, `10m`, `1h`, `1d`, `1w`, capped at 30 days |
|
|
163
|
+
| **Authorization** | Account allowlist plus group owner / admin checks; can require the bot itself to hold owner or admin rights |
|
|
164
|
+
| **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 |
|
|
165
|
+
| **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 |
|
|
166
|
+
| **Per-group overrides** | `groupRules` sets banned words, strong keywords, allowlist keywords and toggles per group; unset values fall back to global |
|
|
167
|
+
| **Auto punishment** | Accumulated violations inside a window reaching a threshold trigger auto-mute / auto-kick; threshold, duration and window are all configurable |
|
|
168
|
+
| **Blacklist** | Stored per group (`banMember_<groupId>.md`); join requests are matched automatically and rejected |
|
|
169
|
+
| **Join review** | New requests are pushed to the group; admins use `approve` / `reject`. Pending requests are persisted and **survive restarts** |
|
|
170
|
+
| **Memory store** | `[memory]` save / list / search / delete into `Memory.md`; when enabled, AI replies retrieve and cite relevant memories |
|
|
171
|
+
| **AI replies** | Three sequential gates: ① message threshold ② random probability ③ interest scoring. Failing any gate means no reply and no model call; an `@mention` bypasses every gate. Multiple personas, context window, temperature and output limits |
|
|
172
|
+
| **AI vision** | Images are downloaded and converted to data URLs before being sent to the model; handles CQ codes, HTML `<img>` and message elements, including stickers |
|
|
173
|
+
| **Repeat (echo)** | Echoes a message once consecutive repeats reach a threshold; repeat events feed into the AI context |
|
|
174
|
+
|
|
175
|
+
### Install
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
npm i @nestim/koishi-plugin-qq-group-manager
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Or search `qq-group-manager` in the Koishi console plugin market.
|
|
182
|
+
|
|
183
|
+
Requires `koishi >= 4.18.7` and a OneBot implementation (NapCat / LLOneBot, etc.) providing
|
|
184
|
+
`setGroupBan` / `setGroupKick` / `getGroupMemberInfo`.
|
|
185
|
+
|
|
186
|
+
### Commands
|
|
187
|
+
|
|
188
|
+
All commands use `[prefix] args`; targets accept a QQ number or `@mention`.
|
|
189
|
+
Send `[bot]` on its own to show the menu.
|
|
190
|
+
|
|
191
|
+
| Command | Description |
|
|
192
|
+
| --- | --- |
|
|
193
|
+
| `[mute] QQ duration [reason]` | Mute. Duration `10` / `10m` / `1h` / `1d` / `1w`, max 30 days |
|
|
194
|
+
| `[unmute] QQ [reason]` | Unmute |
|
|
195
|
+
| `[kick] QQ [reason]` | Remove from the group (optionally reject future join requests and record to the blacklist) |
|
|
196
|
+
| `[memory] content` | Save a memory |
|
|
197
|
+
| `[memory] list` | List the 10 most recent memories |
|
|
198
|
+
| `[memory] search keyword` | Search memories (`query` / `find` are synonyms) |
|
|
199
|
+
| `[memory] delete keyword` | Delete memories containing the keyword (`del` is a synonym) |
|
|
200
|
+
| `[ban] QQ [reason]` | Add to this group's blacklist |
|
|
201
|
+
| `[unban] QQ [reason]` | Remove from this group's blacklist |
|
|
202
|
+
| `[banlist]` | List this group's blacklist |
|
|
203
|
+
| `[custom]` | List custom commands |
|
|
204
|
+
| `[bot]` | Show the command menu |
|
|
205
|
+
| `[Version]` | Show plugin info (version, author, GitHub and npm links) |
|
|
206
|
+
|
|
207
|
+
**Join review**: a new request posts a 6-digit ID to the group. Admins reply with plain text —
|
|
208
|
+
`approve [id] [reason]` or `reject [id] [reason]`. The ID may be omitted, in which case the
|
|
209
|
+
most recent pending request in that group is used.
|
|
210
|
+
|
|
211
|
+
### Configuration groups
|
|
212
|
+
|
|
213
|
+
The plugin's config page is organised into 11 groups:
|
|
214
|
+
`基础设置` · `消息管控` · `自动管控` · `记忆库` · `黑名单` · `娱乐设置` · `群聊互动` ·
|
|
215
|
+
`自定义命令` · `AI 回复` · `权限设置` · `日志设置` (Basics · Message filtering · Auto
|
|
216
|
+
punishment · Memory · Blacklist · Entertainment · Group interaction · Custom commands ·
|
|
217
|
+
AI replies · Permissions · Logging).
|
|
218
|
+
|
|
219
|
+
A few commonly used options:
|
|
220
|
+
|
|
221
|
+
| Option | Default | Description |
|
|
222
|
+
| --- | --- | --- |
|
|
223
|
+
| `command` | `[bot]` | Menu entry prefix |
|
|
224
|
+
| `allowedUserIds` | `[]` | Accounts allowed to use moderation commands directly |
|
|
225
|
+
| `bannedWords` | `[]` | Banned words; supports `keyword\|score` for custom weights |
|
|
226
|
+
| `bannedWordScoreThreshold` | `70` | Score threshold for banned words (shared with strong keywords) |
|
|
227
|
+
| `strongKeywords` | `[]` | Strong keywords: match triggers moderation and **ignores allowlist exemptions**; supports `keyword\|score` |
|
|
228
|
+
| `groupRules` | `[]` | Per-group overrides (banned words, strong keywords, allowlist keywords, AI toggles, auto-punishment thresholds) |
|
|
229
|
+
| `enableJoinRequestReview` | `true` | Whether to enable join review |
|
|
230
|
+
| `enableAiReply` | `false` | Master switch for AI replies (pair with `aiReplyRequireGroupRule` to enable per group) |
|
|
231
|
+
| `dryRun` | `false` | Dry-run mode: log planned actions without executing them |
|
|
232
|
+
|
|
233
|
+
### Data files
|
|
234
|
+
|
|
235
|
+
All stored in the Koishi data directory (`ctx.baseDir`), readable and editable through the
|
|
236
|
+
console Explorer:
|
|
237
|
+
|
|
238
|
+
| File | Contents |
|
|
239
|
+
| --- | --- |
|
|
240
|
+
| `Memory.md` | Memory store, entries separated by `---` |
|
|
241
|
+
| `banMember_<groupId>.md` | Per-group blacklist, `## QQ · note` plus join time |
|
|
242
|
+
| `JoinRequests.md` | Pending join requests (human-readable table + machine-readable section); restored on restart, expired entries cleaned up automatically |
|
|
243
|
+
|
|
244
|
+
### Permission model
|
|
245
|
+
|
|
246
|
+
Moderation commands (`[mute]` `[unmute]` `[kick]` `[ban]` `[unban]` `[banlist]`) use
|
|
247
|
+
**two-step authorization**:
|
|
248
|
+
|
|
249
|
+
1. **Actor identity** — passes if the sender is in `allowedUserIds`; otherwise they must be
|
|
250
|
+
the group owner (`allowGroupOwner`) or a group admin (`allowGroupAdmin`).
|
|
251
|
+
2. **Execution capability** — when `requireBotOwnerForAdmin` is on, the bot must itself be
|
|
252
|
+
owner or admin in that group.
|
|
253
|
+
|
|
254
|
+
Both steps must pass. Authorization details and command results are written to logs only and
|
|
255
|
+
are never echoed into the group.
|
|
256
|
+
|
|
139
257
|
## License
|
|
140
258
|
|
|
141
259
|
MIT
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
📖 **完整文档请前往 GitHub / Full documentation on GitHub:**
|
|
264
|
+
<https://github.com/Miseat/koishi-plugin-qq-group-manager#readme>
|
|
265
|
+
|
|
266
|
+
- 🐛 Issues / 问题反馈:<https://github.com/Miseat/koishi-plugin-qq-group-manager/issues>
|
|
267
|
+
- 📦 npm:<https://www.npmjs.com/package/@nestim/koishi-plugin-qq-group-manager>
|
|
268
|
+
- 📝 更新日志 / Changelog:[CHANGELOG.md](https://github.com/Miseat/koishi-plugin-qq-group-manager/blob/master/CHANGELOG.md)
|