@nestim/koishi-plugin-qq-group-manager 1.0.1 → 1.0.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
@@ -20,6 +20,7 @@ exports.Config = koishi_1.Schema.intersect([
20
20
  cmdUnban: koishi_1.Schema.string().default('[unban]').description('解除拉黑指令前缀,用法:[unban] qq|@某人 [reason]。'),
21
21
  cmdBanList: koishi_1.Schema.string().default('[banlist]').description('黑名单查询指令前缀,单独发送即列出本群黑名单。'),
22
22
  cmdCustom: koishi_1.Schema.string().default('[custom]').description('自定义指令集前缀,用法:[custom]。未配置自定义指令时提示「目前还没有指令」。'),
23
+ cmdVersion: koishi_1.Schema.string().default('[Version]').description('插件信息指令前缀,用法:[Version]。返回当前版本、作者、GitHub 与 npm 地址。'),
23
24
  platformFilter: koishi_1.Schema.array(String).default(['onebot']).description('允许启用管理功能的平台列表。'),
24
25
  responseStyle: koishi_1.Schema.union([
25
26
  koishi_1.Schema.const('plain').description('普通输出'),
package/lib/service.js CHANGED
@@ -2389,6 +2389,103 @@ class QQGroupManagerService extends koishi_1.Service {
2389
2389
  this.aiInFlight.delete(groupKey);
2390
2390
  }
2391
2391
  }
2392
+ logAuth(stage, result, session) {
2393
+ if (!this.config.logAuthCheck)
2394
+ return;
2395
+ const level = result.ok ? 'info' : 'warn';
2396
+ this._logger[level](`[auth:${stage}] ${result.message} | ${this.sessionTag(session)}`);
2397
+ }
2398
+ logCommandResult(command, result, session, extra) {
2399
+ if (!this.config.logCommandResult)
2400
+ return;
2401
+ const level = result.ok ? 'info' : 'warn';
2402
+ const plan = result.plan ? JSON.stringify(result.plan) : '-';
2403
+ const payload = extra ? ` extra=${JSON.stringify(extra)}` : '';
2404
+ this._logger[level](`[cmd:${command}] ok=${result.ok} message="${result.message}" plan=${plan}${payload} | ${this.sessionTag(session)}`);
2405
+ }
2406
+ async authorizeCommand(command, session) {
2407
+ const result = await this.authorize(session);
2408
+ this.logAuth(command, result, session);
2409
+ return result;
2410
+ }
2411
+ async authorize(session) {
2412
+ if (!session) {
2413
+ return { ok: false, message: '缺少会话上下文。', userMessage: '权限不足或上下文不符合要求。' };
2414
+ }
2415
+ const platform = session.platform;
2416
+ if (!this.isPlatformAllowed(platform)) {
2417
+ return {
2418
+ ok: false,
2419
+ message: `当前平台 ${platform ?? 'unknown'} 未启用群管理。`,
2420
+ userMessage: '当前平台未启用群管理。',
2421
+ };
2422
+ }
2423
+ const userId = session.userId;
2424
+ if (!userId) {
2425
+ return { ok: false, message: '无法识别当前账号。', userMessage: '权限不足或上下文不符合要求。' };
2426
+ }
2427
+ if (this.config.allowedUserIds.includes(userId)) {
2428
+ return { ok: true, message: '账号白名单通过。' };
2429
+ }
2430
+ if (!session.guildId) {
2431
+ return {
2432
+ ok: false,
2433
+ message: '当前账号不在白名单,且仅支持在群聊中按管理员权限使用。',
2434
+ userMessage: '仅支持群聊中按管理员权限使用。',
2435
+ };
2436
+ }
2437
+ const role = await this.resolveMemberRole(session);
2438
+ if (!role) {
2439
+ return { ok: false, message: '无法获取群成员角色,权限校验失败。', userMessage: '权限校验失败。' };
2440
+ }
2441
+ if (role === 'owner' && this.config.allowGroupOwner) {
2442
+ return { ok: true, message: '群主权限通过。' };
2443
+ }
2444
+ if (role === 'admin' && this.config.allowGroupAdmin) {
2445
+ return { ok: true, message: '群管理员权限通过。' };
2446
+ }
2447
+ return {
2448
+ ok: false,
2449
+ message: '权限不足:仅账号白名单、群主或群管理员可执行。',
2450
+ userMessage: '权限不足:仅白名单、群主或群管理员可执行。',
2451
+ };
2452
+ }
2453
+ async canUseAdminCommand(session) {
2454
+ if (!this.config.requireBotOwnerForAdmin) {
2455
+ const allowed = { ok: true, message: '已关闭 bot 群主限制,admin 子命令可用。' };
2456
+ this.logAuth('admin-visibility', allowed, session);
2457
+ return allowed;
2458
+ }
2459
+ if (!session) {
2460
+ const denied = { ok: false, message: '缺少会话上下文,admin 子命令不可用。', userMessage: '当前场景不可用该子命令。' };
2461
+ this.logAuth('admin-visibility', denied, session);
2462
+ return denied;
2463
+ }
2464
+ if (!session.guildId) {
2465
+ const denied = { ok: false, message: '当前不是群聊上下文,admin 子命令不可用。', userMessage: '请在群聊中使用该子命令。' };
2466
+ this.logAuth('admin-visibility', denied, session);
2467
+ return denied;
2468
+ }
2469
+ const botId = Number(session.bot?.selfId);
2470
+ if (!Number.isFinite(botId)) {
2471
+ const denied = { ok: false, message: `bot selfId 无法解析为数字: ${session.bot?.selfId ?? 'unknown'}`, userMessage: '当前场景不可用该子命令。' };
2472
+ this.logAuth('admin-visibility', denied, session);
2473
+ return denied;
2474
+ }
2475
+ const botRole = await this.getTargetRole(session, botId);
2476
+ if (botRole === 'owner') {
2477
+ const allowed = { ok: true, message: `bot(${botId}) 在当前群是 owner,admin 子命令可用。` };
2478
+ this.logAuth('admin-visibility', allowed, session);
2479
+ return allowed;
2480
+ }
2481
+ const denied = {
2482
+ ok: false,
2483
+ message: `bot(${botId}) 在当前群角色=${botRole ?? 'unknown'},未达到 owner,admin 子命令不可用。`,
2484
+ userMessage: '当前群中 bot 不是群主,admin 子命令不可用。',
2485
+ };
2486
+ this.logAuth('admin-visibility', denied, session);
2487
+ return denied;
2488
+ }
2392
2489
  async isBotOwnerInGroup(session) {
2393
2490
  if (!session?.guildId || session.platform !== 'onebot')
2394
2491
  return false;
@@ -3279,6 +3376,11 @@ class QQGroupManagerService extends koishi_1.Service {
3279
3376
  await this.sendCustomCommandList(session);
3280
3377
  return true;
3281
3378
  }
3379
+ // 插件信息:单独发送 [Version]
3380
+ if (name === this.cmdPrefix('cmdVersion', '[Version]')) {
3381
+ await this.sendVersionInfo(session);
3382
+ return true;
3383
+ }
3282
3384
  return false;
3283
3385
  }
3284
3386
  /**
@@ -3297,6 +3399,7 @@ class QQGroupManagerService extends koishi_1.Service {
3297
3399
  '黑名单查询 ' + P('cmdBanList', '[banlist]'),
3298
3400
  '自定义指令集 ' + P('cmdCustom', '[custom]'),
3299
3401
  '踢人 ' + P('cmdKick', '[kick]') + ' qq reason',
3402
+ '插件信息 ' + P('cmdVersion', '[Version]'),
3300
3403
  ];
3301
3404
  await session.send(this.styleText(
3302
3405
  '可用指令:\n\n' + lines.join('\n')
@@ -3313,6 +3416,38 @@ class QQGroupManagerService extends koishi_1.Service {
3313
3416
  const lines = list.map((c) => `${String(c.trigger).trim()} → ${(c.replies || []).length} 条回复`);
3314
3417
  await session.send(this.styleText(`自定义指令集(共 ${list.length} 条):\n${lines.join('\n')}`));
3315
3418
  }
3419
+ /**
3420
+ * [Version]:查看插件信息(当前版本、作者、仓库与 npm 地址)。
3421
+ * 版本号与仓库地址从 package.json 读取,避免发版时忘记同步。
3422
+ */
3423
+ async sendVersionInfo(session) {
3424
+ let version = 'unknown';
3425
+ let repoUrl = '';
3426
+ let npmUrl = 'https://www.npmjs.com/package/@nestim/koishi-plugin-qq-group-manager';
3427
+ try {
3428
+ const pkg = require('../package.json');
3429
+ if (pkg && pkg.version)
3430
+ version = String(pkg.version);
3431
+ const rawRepo = (pkg && pkg.repository && pkg.repository.url) || '';
3432
+ repoUrl = String(rawRepo).replace(/^git\+/, '').replace(/\.git$/, '');
3433
+ const rawHome = (pkg && pkg.homepage) || '';
3434
+ if (!repoUrl && rawHome)
3435
+ repoUrl = String(rawHome).replace(/#.*$/, '');
3436
+ }
3437
+ catch (error) {
3438
+ this._logger.warn(`[version] 读取 package.json 失败: ${String(error)}`);
3439
+ }
3440
+ const lines = [
3441
+ '【插件信息】',
3442
+ `当前版本:${version}`,
3443
+ '作者:Nestim',
3444
+ ];
3445
+ if (repoUrl)
3446
+ lines.push(`GitHub:${repoUrl}`);
3447
+ lines.push(`npm:${npmUrl}`);
3448
+ await session.send(this.styleText(lines.join('\n')));
3449
+ this.logCommandResult('version', { ok: true, message: 'version info sent' }, session, { version });
3450
+ }
3316
3451
  /** 权限不足提示 */
3317
3452
  async denyAdmin(session) {
3318
3453
  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.0.1",
4
+ "version": "1.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -64,6 +64,7 @@ npm i @nestim/koishi-plugin-qq-group-manager
64
64
  | `[banlist]` | 列出本群黑名单 |
65
65
  | `[custom]` | 列出自定义指令;没有配置时提示「目前还没有指令。」 |
66
66
  | `[bot]` | 查看指令菜单 |
67
+ | `[Version]` | 查看插件信息(当前版本、作者、GitHub 与 npm 地址)|
67
68
 
68
69
  **入群审核**:新申请会在群里收到带 6 位编号的提示,管理员直接发文本处理:
69
70