@nestim/koishi-plugin-qq-group-manager 1.1.2 → 1.1.3

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 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('仅当 bot 在当前群是群主时开放 admin 子命令。'),
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
- if (botRole === 'owner') {
2505
- const allowed = { ok: true, message: `bot(${botId}) 在当前群是 owner,admin 子命令可用。` };
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'},未达到 owner,admin 子命令不可用。`,
2512
- userMessage: '当前群中 bot 不是群主,admin 子命令不可用。',
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
- if (!(await this.canUseAdminCommand(session)).ok)
3540
- return this.denyAdmin(session);
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
- if (!(await this.canUseAdminCommand(session)).ok)
3563
- return this.denyAdmin(session);
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
- if (!(await this.canUseAdminCommand(session)).ok)
3586
- return this.denyAdmin(session);
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
- if (!(await this.canUseAdminCommand(session)).ok)
3661
- return this.denyAdmin(session);
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
- if (!(await this.canUseAdminCommand(session)).ok)
3700
- return this.denyAdmin(session);
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.2",
4
+ "version": "1.1.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -129,9 +129,12 @@ npm i @nestim/koishi-plugin-qq-group-manager
129
129
 
130
130
  ## 权限模型
131
131
 
132
- - `allowedUserIds` 命中即通过;
133
- - 非白名单账号:在群聊中若为群主或群管理员可通过(可用 `allowGroupOwner` / `allowGroupAdmin` 关闭);
134
- - `requireBotOwnerForAdmin` 可要求 bot 本身是该群群主才放行管理动作;
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
  鉴权细节与指令执行结果只写日志,不回显到群聊。