@nestim/koishi-plugin-qq-group-manager 0.1.13 → 0.1.14

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.
Files changed (2) hide show
  1. package/lib/service.js +40 -0
  2. package/package.json +1 -1
package/lib/service.js CHANGED
@@ -232,6 +232,37 @@ class QQGroupManagerService extends koishi_1.Service {
232
232
  }
233
233
  return out;
234
234
  }
235
+ /**
236
+ * 判断某个 QQ 是否豁免「耳目处罚」。
237
+ *
238
+ * 为什么要豁免:耳目号只能通过「被谁拉进群」来发现拉人者,所以
239
+ * **把耳目号拉进自己群的人**也会被上报。自己人(白名单、bot 自身、
240
+ * 处罚群的群主/管理员)拉小号进自己的群属于正常操作,不该被处罚。
241
+ *
242
+ * 返回豁免原因字符串;返回 '' 表示不豁免。
243
+ */
244
+ async isEyeExemptAccount(qq, groups) {
245
+ const id = String(qq || '').replace(/\D/g, '');
246
+ if (!id) return '无法识别';
247
+ // 1) 账号白名单
248
+ const allow = Array.isArray(this.config.allowedUserIds) ? this.config.allowedUserIds : [];
249
+ if (allow.some((x) => String(x).replace(/\D/g, '') === id)) return 'allowedUserIds 白名单';
250
+ // 2) bot 自身(含主号与耳目号)
251
+ const bots = Array.from(this.ctx.bots || []);
252
+ if (bots.some((b) => String(b.selfId || '').replace(/\D/g, '') === id)) return 'bot 自身';
253
+ // 3) 处罚群里的群主/管理员
254
+ const bot = this.resolveMainBot();
255
+ if (bot) {
256
+ for (const guildId of groups) {
257
+ try {
258
+ const role = await this.resolveMemberRole({ guildId, platform: 'onebot', userId: id, bot });
259
+ if (role === 'owner' || role === 'admin') return `群 ${guildId} 的${role === 'owner' ? '群主' : '管理员'}`;
260
+ }
261
+ catch { /* 查询失败就不豁免,交给后续流程 */ }
262
+ }
263
+ }
264
+ return '';
265
+ }
235
266
  /**
236
267
  * 处理耳目号上报的拉人事件 → 由主号**直接执行处罚**。
237
268
  *
@@ -254,6 +285,15 @@ class QQGroupManagerService extends koishi_1.Service {
254
285
  this._logger.info(`[eye] 收到上报 type=${kind} qq=${qq} 目标群=${(payload && payload.guildId) || '-'} 证据="${evidence}",但 eyePunishGroups 为空 → 不执行处罚`);
255
286
  return;
256
287
  }
288
+ // 白名单豁免:自己人永远不该被当成「拉人者」处罚。
289
+ // 覆盖三种身份:allowedUserIds 白名单、bot 自身、以及处罚群的群主/管理员。
290
+ // (注意:不是把「拉耳目号进群的人」当好人——而是这些人本来就有权限,
291
+ // 他们拉小号进自己的群属于正常操作。)
292
+ const exempt = await this.isEyeExemptAccount(qq, groups);
293
+ if (exempt) {
294
+ this._logger.info(`[eye] qq=${qq} 命中白名单/管理员豁免(${exempt}),跳过处罚 | 证据="${evidence}"`);
295
+ return;
296
+ }
257
297
  // 冷却:同一个人短时间内不重复处罚
258
298
  const cooldownMs = Math.max(0, Number(this.config.eyePunishCooldownMinutes ?? 10)) * 60 * 1000;
259
299
  const last = this._eyePunishAt.get(qq) || 0;
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": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [