koishi-plugin-bind-bot 2.0.5 → 2.1.1

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.
@@ -63,15 +63,15 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
63
63
  return this.deps.sendMessage(session, [koishi_1.h.text('❌ 目标用户ID无效\n请提供有效的QQ号或使用@功能选择用户')]);
64
64
  }
65
65
  this.logger.info('查询', `QQ(${normalizedUserId})查询QQ(${normalizedTargetId})的MC账号信息`);
66
- const targetBind = await this.deps.getMcBindByQQId(normalizedTargetId);
66
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
67
67
  if (!targetBind || !targetBind.mcUsername || targetBind.mcUsername.startsWith('_temp_')) {
68
68
  this.logger.info('查询', `QQ(${normalizedTargetId})未绑定MC账号`);
69
69
  // 检查是否绑定了B站
70
70
  if (targetBind && targetBind.buidUid) {
71
- const buidUser = await this.deps.validateBUID(targetBind.buidUid);
71
+ const buidUser = await this.deps.apiService.validateBUID(targetBind.buidUid);
72
72
  if (buidUser) {
73
- await this.deps.updateBuidInfoOnly(targetBind.qqId, buidUser);
74
- const refreshedBind = await this.deps.getMcBindByQQId(normalizedTargetId);
73
+ await this.deps.databaseService.updateBuidInfoOnly(targetBind.qqId, buidUser);
74
+ const refreshedBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
75
75
  if (refreshedBind) {
76
76
  let buidInfo = `该用户尚未绑定MC账号\n\nB站账号信息:\nB站UID: ${refreshedBind.buidUid}\n用户名: ${refreshedBind.buidUsername}`;
77
77
  if (refreshedBind.guardLevel > 0) {
@@ -97,20 +97,20 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
97
97
  return this.deps.sendMessage(session, [koishi_1.h.text('该用户尚未绑定MC账号')]);
98
98
  }
99
99
  // 显示MC绑定信息(使用智能缓存检测,避免频繁API调用)
100
- const updatedBind = await this.deps.checkAndUpdateUsernameWithCache(targetBind);
100
+ const updatedBind = await this.deps.databaseService.checkAndUpdateUsernameWithCache(targetBind);
101
101
  return this.buildQueryResponse(session, updatedBind, normalizedTargetId);
102
102
  }
103
103
  // 查询自己
104
104
  this.logger.info('查询', `QQ(${normalizedUserId})查询自己的MC账号信息`);
105
- const selfBind = await this.deps.getMcBindByQQId(normalizedUserId);
105
+ const selfBind = await this.deps.databaseService.getMcBindByQQId(normalizedUserId);
106
106
  if (!selfBind || !selfBind.mcUsername || selfBind.mcUsername.startsWith('_temp_')) {
107
107
  this.logger.info('查询', `QQ(${normalizedUserId})未绑定MC账号`);
108
108
  // 检查是否绑定了B站
109
109
  if (selfBind && selfBind.buidUid) {
110
- const buidUser = await this.deps.validateBUID(selfBind.buidUid);
110
+ const buidUser = await this.deps.apiService.validateBUID(selfBind.buidUid);
111
111
  if (buidUser) {
112
- await this.deps.updateBuidInfoOnly(selfBind.qqId, buidUser);
113
- const refreshedBind = await this.deps.getMcBindByQQId(normalizedUserId);
112
+ await this.deps.databaseService.updateBuidInfoOnly(selfBind.qqId, buidUser);
113
+ const refreshedBind = await this.deps.databaseService.getMcBindByQQId(normalizedUserId);
114
114
  if (refreshedBind) {
115
115
  let buidInfo = `您尚未绑定MC账号\n\nB站账号信息:\nB站UID: ${refreshedBind.buidUid}\n用户名: ${refreshedBind.buidUsername}`;
116
116
  if (refreshedBind.guardLevel > 0) {
@@ -137,7 +137,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
137
137
  return this.deps.sendMessage(session, [koishi_1.h.text('您尚未绑定MC账号,请使用 ' + this.deps.formatCommand('mcid bind <用户名>') + ' 进行绑定')]);
138
138
  }
139
139
  // 使用智能缓存检测,避免频繁API调用
140
- const updatedBind = await this.deps.checkAndUpdateUsernameWithCache(selfBind);
140
+ const updatedBind = await this.deps.databaseService.checkAndUpdateUsernameWithCache(selfBind);
141
141
  return this.buildQueryResponse(session, updatedBind, null);
142
142
  }
143
143
  catch (error) {
@@ -150,15 +150,15 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
150
150
  * 构建查询响应消息
151
151
  */
152
152
  async buildQueryResponse(session, bind, targetId) {
153
- const formattedUuid = this.deps.formatUuid(bind.mcUuid);
153
+ const formattedUuid = this.deps.apiService.formatUuid(bind.mcUuid);
154
154
  // MC头像
155
155
  let mcAvatarUrl = null;
156
156
  if (this.config.showAvatar) {
157
157
  if (this.config.showMcSkin) {
158
- mcAvatarUrl = this.deps.getStarlightSkinUrl(bind.mcUsername);
158
+ mcAvatarUrl = this.deps.apiService.getStarlightSkinUrl(bind.mcUsername);
159
159
  }
160
160
  else {
161
- mcAvatarUrl = this.deps.getCrafatarUrl(bind.mcUuid);
161
+ mcAvatarUrl = this.deps.apiService.getCrafatarUrl(bind.mcUuid);
162
162
  }
163
163
  }
164
164
  // 白名单信息
@@ -224,7 +224,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
224
224
  // 异步设置群昵称
225
225
  if (bind.buidUid && bind.buidUsername) {
226
226
  const mcName = bind.mcUsername && !bind.mcUsername.startsWith('_temp_') ? bind.mcUsername : null;
227
- this.deps.autoSetGroupNickname(session, mcName, bind.buidUsername, bind.buidUid, targetId || undefined)
227
+ this.deps.nicknameService.autoSetGroupNickname(session, mcName, bind.buidUsername, bind.buidUid, targetId || undefined)
228
228
  .catch(err => this.logger.warn('查询', `群昵称设置失败: ${err.message}`));
229
229
  }
230
230
  else {
@@ -248,7 +248,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
248
248
  return this.deps.sendMessage(session, [koishi_1.h.text('请提供要查询的MC用户名')]);
249
249
  }
250
250
  this.logger.info('反向查询', `QQ(${normalizedUserId})尝试通过MC用户名"${username}"查询绑定的QQ账号`);
251
- const bind = await this.deps.getMcBindByUsername(username);
251
+ const bind = await this.deps.databaseService.getMcBindByUsername(username);
252
252
  if (!bind || !bind.qqId) {
253
253
  this.logger.info('反向查询', `MC用户名"${username}"未被任何QQ账号绑定`);
254
254
  return this.deps.sendMessage(session, [koishi_1.h.text(`未找到绑定MC用户名"${username}"的QQ账号`)]);
@@ -257,13 +257,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
257
257
  let mcAvatarUrl = null;
258
258
  if (this.config.showAvatar) {
259
259
  if (this.config.showMcSkin) {
260
- mcAvatarUrl = this.deps.getStarlightSkinUrl(bind.mcUsername);
260
+ mcAvatarUrl = this.deps.apiService.getStarlightSkinUrl(bind.mcUsername);
261
261
  }
262
262
  else {
263
- mcAvatarUrl = this.deps.getCrafatarUrl(bind.mcUuid);
263
+ mcAvatarUrl = this.deps.apiService.getCrafatarUrl(bind.mcUuid);
264
264
  }
265
265
  }
266
- const formattedUuid = this.deps.formatUuid(bind.mcUuid);
266
+ const formattedUuid = this.deps.apiService.formatUuid(bind.mcUuid);
267
267
  // 管理员信息
268
268
  let adminInfo = '';
269
269
  if (await this.deps.isAdmin(session.userId)) {
@@ -305,7 +305,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
305
305
  return this.deps.sendMessage(session, [koishi_1.h.text('请提供有效的Minecraft用户名(3-16位字母、数字、下划线)')]);
306
306
  }
307
307
  // 验证用户名是否存在
308
- const profile = await this.deps.validateUsername(username);
308
+ const profile = await this.deps.apiService.validateUsername(username);
309
309
  if (!profile) {
310
310
  this.logger.warn('绑定', `QQ(${normalizedUserId})提供的用户名"${username}"不存在`);
311
311
  return this.deps.sendMessage(session, [koishi_1.h.text(`无法验证用户名: ${username},该用户可能不存在`)]);
@@ -341,12 +341,12 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
341
341
  return this.deps.sendMessage(session, [koishi_1.h.text('只有管理员才能为其他用户绑定MC账号')]);
342
342
  }
343
343
  // 检查用户名是否已被占用(支持改名检测)
344
- if (await this.deps.checkUsernameExists(username, target, uuid)) {
344
+ if (await this.deps.databaseService.checkUsernameExists(username, target, uuid)) {
345
345
  this.logger.warn('绑定', `MC用户名"${username}"已被其他QQ号绑定`);
346
346
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户名 ${username} 已被其他用户绑定`)]);
347
347
  }
348
348
  // 绑定
349
- const bindResult = await this.deps.createOrUpdateMcBind(target, username, uuid);
349
+ const bindResult = await this.deps.databaseService.createOrUpdateMcBind(target, username, uuid);
350
350
  if (!bindResult) {
351
351
  this.logger.error('绑定', `管理员QQ(${operatorId})为QQ(${normalizedTargetId})绑定MC账号"${username}"失败`);
352
352
  return this.deps.sendMessage(session, [koishi_1.h.text(`为用户 ${normalizedTargetId} 绑定MC账号失败: 数据库操作出错,请联系管理员`)]);
@@ -358,9 +358,9 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
358
358
  // 尝试设置群昵称
359
359
  let targetBuidStatus = '';
360
360
  try {
361
- const latestTargetBind = await this.deps.getMcBindByQQId(normalizedTargetId);
361
+ const latestTargetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
362
362
  if (latestTargetBind && latestTargetBind.buidUid && latestTargetBind.buidUsername) {
363
- await this.deps.autoSetGroupNickname(session, username, latestTargetBind.buidUsername, latestTargetBind.buidUid, normalizedTargetId);
363
+ await this.deps.nicknameService.autoSetGroupNickname(session, username, latestTargetBind.buidUsername, latestTargetBind.buidUid, normalizedTargetId);
364
364
  this.logger.info('绑定', `管理员QQ(${operatorId})为QQ(${normalizedTargetId})MC绑定完成,已尝试设置群昵称`);
365
365
  targetBuidStatus = '\n✅ 该用户已绑定B站账号,群昵称已更新';
366
366
  }
@@ -376,13 +376,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
376
376
  let mcAvatarUrl = null;
377
377
  if (this.config.showAvatar) {
378
378
  if (this.config.showMcSkin) {
379
- mcAvatarUrl = this.deps.getStarlightSkinUrl(username);
379
+ mcAvatarUrl = this.deps.apiService.getStarlightSkinUrl(username);
380
380
  }
381
381
  else {
382
- mcAvatarUrl = this.deps.getCrafatarUrl(uuid);
382
+ mcAvatarUrl = this.deps.apiService.getCrafatarUrl(uuid);
383
383
  }
384
384
  }
385
- const formattedUuid = this.deps.formatUuid(uuid);
385
+ const formattedUuid = this.deps.apiService.formatUuid(uuid);
386
386
  return this.deps.sendMessage(session, [
387
387
  koishi_1.h.text(`已成功为用户 ${normalizedTargetId} 绑定MC账号\n用户名: ${username}\nUUID: ${formattedUuid}${targetBuidStatus}`),
388
388
  ...(mcAvatarUrl ? [koishi_1.h.image(mcAvatarUrl)] : [])
@@ -391,7 +391,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
391
391
  async handleBindForSelf(session, username, uuid, operatorId) {
392
392
  this.logger.debug('绑定', `QQ(${operatorId})尝试绑定MC账号: ${username}(${uuid})`);
393
393
  // 检查是否已绑定
394
- const selfBind = await this.deps.getMcBindByQQId(operatorId);
394
+ const selfBind = await this.deps.databaseService.getMcBindByQQId(operatorId);
395
395
  if (selfBind && selfBind.mcUsername) {
396
396
  const isTempUsername = selfBind.mcUsername.startsWith('_temp_');
397
397
  if (!isTempUsername) {
@@ -415,12 +415,12 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
415
415
  }
416
416
  }
417
417
  // 检查用户名是否已被占用(支持改名检测)
418
- if (await this.deps.checkUsernameExists(username, session.userId, uuid)) {
418
+ if (await this.deps.databaseService.checkUsernameExists(username, session.userId, uuid)) {
419
419
  this.logger.warn('绑定', `MC用户名"${username}"已被其他QQ号绑定`);
420
420
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户名 ${username} 已被其他用户绑定`)]);
421
421
  }
422
422
  // 绑定
423
- const bindResult = await this.deps.createOrUpdateMcBind(session.userId, username, uuid);
423
+ const bindResult = await this.deps.databaseService.createOrUpdateMcBind(session.userId, username, uuid);
424
424
  if (!bindResult) {
425
425
  this.logger.error('绑定', `QQ(${operatorId})绑定MC账号"${username}"失败`);
426
426
  return this.deps.sendMessage(session, [koishi_1.h.text('绑定失败,数据库操作出错,请联系管理员')]);
@@ -429,9 +429,9 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
429
429
  // 尝试设置群昵称
430
430
  let buidReminder = '';
431
431
  try {
432
- const latestBind = await this.deps.getMcBindByQQId(operatorId);
432
+ const latestBind = await this.deps.databaseService.getMcBindByQQId(operatorId);
433
433
  if (latestBind && latestBind.buidUid && latestBind.buidUsername) {
434
- await this.deps.autoSetGroupNickname(session, username, latestBind.buidUsername, latestBind.buidUid);
434
+ await this.deps.nicknameService.autoSetGroupNickname(session, username, latestBind.buidUsername, latestBind.buidUid);
435
435
  this.logger.info('绑定', `QQ(${operatorId})MC绑定完成,已尝试设置群昵称`);
436
436
  }
437
437
  else {
@@ -446,13 +446,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
446
446
  let mcAvatarUrl = null;
447
447
  if (this.config.showAvatar) {
448
448
  if (this.config.showMcSkin) {
449
- mcAvatarUrl = this.deps.getStarlightSkinUrl(username);
449
+ mcAvatarUrl = this.deps.apiService.getStarlightSkinUrl(username);
450
450
  }
451
451
  else {
452
- mcAvatarUrl = this.deps.getCrafatarUrl(uuid);
452
+ mcAvatarUrl = this.deps.apiService.getCrafatarUrl(uuid);
453
453
  }
454
454
  }
455
- const formattedUuid = this.deps.formatUuid(uuid);
455
+ const formattedUuid = this.deps.apiService.formatUuid(uuid);
456
456
  return this.deps.sendMessage(session, [
457
457
  koishi_1.h.text(`已成功绑定MC账号\n用户名: ${username}\nUUID: ${formattedUuid}${buidReminder}`),
458
458
  ...(mcAvatarUrl ? [koishi_1.h.image(mcAvatarUrl)] : [])
@@ -470,7 +470,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
470
470
  return this.deps.sendMessage(session, [koishi_1.h.text('请提供有效的Minecraft用户名(3-16位字母、数字、下划线)')]);
471
471
  }
472
472
  // 验证用户名是否存在
473
- const profile = await this.deps.validateUsername(username);
473
+ const profile = await this.deps.apiService.validateUsername(username);
474
474
  if (!profile) {
475
475
  this.logger.warn('修改', `QQ(${normalizedUserId})提供的用户名"${username}"不存在`);
476
476
  return this.deps.sendMessage(session, [koishi_1.h.text(`无法验证用户名: ${username},该用户可能不存在`)]);
@@ -506,7 +506,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
506
506
  return this.deps.sendMessage(session, [koishi_1.h.text('只有管理员才能修改其他用户的MC账号')]);
507
507
  }
508
508
  // 获取目标用户信息
509
- const targetBind = await this.deps.getMcBindByQQId(normalizedTargetId);
509
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
510
510
  if (!targetBind || !targetBind.mcUsername) {
511
511
  this.logger.warn('修改', `QQ(${normalizedTargetId})尚未绑定MC账号`);
512
512
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 尚未绑定MC账号,请先使用 ` + this.deps.formatCommand('mcid bind') + ` 命令进行绑定`)]);
@@ -517,13 +517,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
517
517
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 当前已绑定此用户名: ${username}`)]);
518
518
  }
519
519
  // 检查用户名是否已被占用(支持改名检测)
520
- if (await this.deps.checkUsernameExists(username, target, uuid)) {
520
+ if (await this.deps.databaseService.checkUsernameExists(username, target, uuid)) {
521
521
  this.logger.warn('修改', `MC用户名"${username}"已被其他QQ号绑定`);
522
522
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户名 ${username} 已被其他用户绑定`)]);
523
523
  }
524
524
  const oldUsername = targetBind.mcUsername;
525
525
  // 更新绑定信息
526
- const bindResult = await this.deps.createOrUpdateMcBind(target, username, uuid);
526
+ const bindResult = await this.deps.databaseService.createOrUpdateMcBind(target, username, uuid);
527
527
  if (!bindResult) {
528
528
  this.logger.error('修改', `管理员QQ(${operatorId})修改QQ(${normalizedTargetId})的MC账号失败`);
529
529
  return this.deps.sendMessage(session, [koishi_1.h.text(`修改用户 ${normalizedTargetId} 的MC账号失败: 数据库操作出错,请联系管理员`)]);
@@ -533,20 +533,20 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
533
533
  let mcAvatarUrl = null;
534
534
  if (this.config.showAvatar) {
535
535
  if (this.config.showMcSkin) {
536
- mcAvatarUrl = this.deps.getStarlightSkinUrl(username);
536
+ mcAvatarUrl = this.deps.apiService.getStarlightSkinUrl(username);
537
537
  }
538
538
  else {
539
- mcAvatarUrl = this.deps.getCrafatarUrl(uuid);
539
+ mcAvatarUrl = this.deps.apiService.getCrafatarUrl(uuid);
540
540
  }
541
541
  }
542
- const formattedUuid = this.deps.formatUuid(uuid);
542
+ const formattedUuid = this.deps.apiService.formatUuid(uuid);
543
543
  return this.deps.sendMessage(session, [
544
544
  koishi_1.h.text(`已成功将用户 ${normalizedTargetId} 的MC账号从 ${oldUsername} 修改为 ${username}\nUUID: ${formattedUuid}`),
545
545
  ...(mcAvatarUrl ? [koishi_1.h.image(mcAvatarUrl)] : [])
546
546
  ]);
547
547
  }
548
548
  async handleChangeForSelf(session, username, uuid, operatorId) {
549
- const selfBind = await this.deps.getMcBindByQQId(operatorId);
549
+ const selfBind = await this.deps.databaseService.getMcBindByQQId(operatorId);
550
550
  // 检查是否已绑定
551
551
  if (!selfBind || !selfBind.mcUsername) {
552
552
  this.logger.warn('修改', `QQ(${operatorId})尚未绑定MC账号`);
@@ -568,13 +568,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
568
568
  return this.deps.sendMessage(session, [koishi_1.h.text(`您的MC账号绑定在冷却期内,还需${remainingDays}天才能修改。如需立即修改,请联系管理员。`)]);
569
569
  }
570
570
  // 检查用户名是否已被占用(支持改名检测)
571
- if (await this.deps.checkUsernameExists(username, session.userId, uuid)) {
571
+ if (await this.deps.databaseService.checkUsernameExists(username, session.userId, uuid)) {
572
572
  this.logger.warn('修改', `MC用户名"${username}"已被其他QQ号绑定`);
573
573
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户名 ${username} 已被其他用户绑定`)]);
574
574
  }
575
575
  const oldUsername = selfBind.mcUsername;
576
576
  // 更新绑定信息
577
- const bindResult = await this.deps.createOrUpdateMcBind(session.userId, username, uuid);
577
+ const bindResult = await this.deps.databaseService.createOrUpdateMcBind(session.userId, username, uuid);
578
578
  if (!bindResult) {
579
579
  this.logger.error('修改', `QQ(${operatorId})修改MC账号失败`);
580
580
  return this.deps.sendMessage(session, [koishi_1.h.text('修改失败,数据库操作出错,请联系管理员')]);
@@ -584,13 +584,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
584
584
  let mcAvatarUrl = null;
585
585
  if (this.config.showAvatar) {
586
586
  if (this.config.showMcSkin) {
587
- mcAvatarUrl = this.deps.getStarlightSkinUrl(username);
587
+ mcAvatarUrl = this.deps.apiService.getStarlightSkinUrl(username);
588
588
  }
589
589
  else {
590
- mcAvatarUrl = this.deps.getCrafatarUrl(uuid);
590
+ mcAvatarUrl = this.deps.apiService.getCrafatarUrl(uuid);
591
591
  }
592
592
  }
593
- const formattedUuid = this.deps.formatUuid(uuid);
593
+ const formattedUuid = this.deps.apiService.formatUuid(uuid);
594
594
  return this.deps.sendMessage(session, [
595
595
  koishi_1.h.text(`已成功将MC账号从 ${oldUsername} 修改为 ${username}\nUUID: ${formattedUuid}`),
596
596
  ...(mcAvatarUrl ? [koishi_1.h.image(mcAvatarUrl)] : [])
@@ -632,7 +632,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
632
632
  return this.deps.sendMessage(session, [koishi_1.h.text('只有管理员才能为其他用户解绑MC账号')]);
633
633
  }
634
634
  // 获取目标用户信息
635
- const targetBind = await this.deps.getMcBindByQQId(normalizedTargetId);
635
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
636
636
  if (!targetBind || !targetBind.mcUsername) {
637
637
  this.logger.warn('解绑', `QQ(${normalizedTargetId})尚未绑定MC账号`);
638
638
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 尚未绑定MC账号`)]);
@@ -640,13 +640,13 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
640
640
  const oldUsername = targetBind.mcUsername && !targetBind.mcUsername.startsWith('_temp_') ? targetBind.mcUsername : '未绑定';
641
641
  const oldBuidInfo = targetBind.buidUid ? ` 和 B站账号: ${targetBind.buidUsername}(${targetBind.buidUid})` : '';
642
642
  // 删除绑定记录
643
- await this.deps.deleteMcBind(target);
643
+ await this.deps.databaseService.deleteMcBind(target);
644
644
  this.logger.info('解绑', `成功: 管理员QQ(${operatorId})为QQ(${normalizedTargetId})解绑MC账号: ${oldUsername}${oldBuidInfo}`);
645
645
  return this.deps.sendMessage(session, [koishi_1.h.text(`已成功为用户 ${normalizedTargetId} 解绑MC账号: ${oldUsername}${oldBuidInfo}`)]);
646
646
  }
647
647
  async handleUnbindForSelf(session, operatorId) {
648
648
  this.logger.info('解绑', `QQ(${operatorId})尝试解绑自己的MC账号`);
649
- const selfBind = await this.deps.getMcBindByQQId(operatorId);
649
+ const selfBind = await this.deps.databaseService.getMcBindByQQId(operatorId);
650
650
  if (!selfBind || !selfBind.mcUsername) {
651
651
  this.logger.warn('解绑', `QQ(${operatorId})尚未绑定MC账号`);
652
652
  return this.deps.sendMessage(session, [koishi_1.h.text('您尚未绑定MC账号')]);
@@ -654,7 +654,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
654
654
  const oldUsername = selfBind.mcUsername && !selfBind.mcUsername.startsWith('_temp_') ? selfBind.mcUsername : '未绑定';
655
655
  const oldBuidInfo = selfBind.buidUid ? ` 和 B站账号: ${selfBind.buidUsername}(${selfBind.buidUid})` : '';
656
656
  // 删除绑定记录
657
- await this.deps.deleteMcBind(operatorId);
657
+ await this.deps.databaseService.deleteMcBind(operatorId);
658
658
  this.logger.info('解绑', `成功: QQ(${operatorId})解绑MC账号: ${oldUsername}${oldBuidInfo}`);
659
659
  return this.deps.sendMessage(session, [koishi_1.h.text(`已成功解绑MC账号: ${oldUsername}${oldBuidInfo}`)]);
660
660
  }
@@ -672,7 +672,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
672
672
  return this.deps.sendMessage(session, [koishi_1.h.text('只有主人才能设置管理员')]);
673
673
  }
674
674
  // 检查目标用户是否已经是管理员
675
- const targetBind = await this.deps.getMcBindByQQId(normalizedTargetId);
675
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
676
676
  const isAlreadyAdmin = targetBind && targetBind.isAdmin === true;
677
677
  if (isAlreadyAdmin) {
678
678
  this.logger.warn('管理员', `QQ(${normalizedTargetId})已经是管理员`);
@@ -727,7 +727,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
727
727
  return this.deps.sendMessage(session, [koishi_1.h.text('只有主人才能撤销管理员权限')]);
728
728
  }
729
729
  // 检查目标用户是否是管理员
730
- const targetBind = await this.deps.getMcBindByQQId(normalizedTargetId);
730
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
731
731
  const isAdmin = targetBind && targetBind.isAdmin === true;
732
732
  if (!isAdmin) {
733
733
  this.logger.warn('管理员', `QQ(${normalizedTargetId})不是管理员`);
@@ -873,10 +873,10 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
873
873
  }
874
874
  // 检查昵称格式
875
875
  const mcInfo = bind.mcUsername && !bind.mcUsername.startsWith('_temp_') ? bind.mcUsername : null;
876
- const isCorrect = this.deps.checkNicknameFormat(currentNickname, bind.buidUsername, mcInfo);
876
+ const isCorrect = this.deps.nicknameService.checkNicknameFormat(currentNickname, bind.buidUsername, mcInfo);
877
877
  if (!isCorrect) {
878
878
  // 修复群昵称
879
- await this.deps.autoSetGroupNickname(session, mcInfo, bind.buidUsername, bind.buidUid, bind.qqId, targetGroupId);
879
+ await this.deps.nicknameService.autoSetGroupNickname(session, mcInfo, bind.buidUsername, bind.buidUid, bind.qqId, targetGroupId);
880
880
  fixedCount++;
881
881
  const expectedFormat = `${bind.buidUsername}(ID:${mcInfo || '未绑定'})`;
882
882
  results.push(`✅ ${bind.qqId}: "${currentNickname}" → "${expectedFormat}"`);
@@ -935,7 +935,7 @@ class McidCommandHandler extends base_handler_1.BaseHandler {
935
935
  // 这里简化处理,只更新数据库
936
936
  if (target) {
937
937
  const normalizedTargetId = this.deps.normalizeQQId(target);
938
- const bind = await this.deps.getMcBindByQQId(normalizedTargetId);
938
+ const bind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
939
939
  if (bind) {
940
940
  await this.repos.mcidbind.update(normalizedTargetId, { reminderCount: 0 });
941
941
  }
@@ -26,7 +26,7 @@ class TagHandler extends base_handler_1.BaseHandler {
26
26
  if (normalizedUserId === normalizedMasterId)
27
27
  return true;
28
28
  try {
29
- const bind = await this.deps.getBindInfo(normalizedUserId);
29
+ const bind = await this.deps.databaseService.getMcBindByQQId(normalizedUserId);
30
30
  return bind && bind.isAdmin === true;
31
31
  }
32
32
  catch (error) {
@@ -68,11 +68,11 @@ class TagHandler extends base_handler_1.BaseHandler {
68
68
  const target = targets[0];
69
69
  const normalizedTargetId = this.deps.normalizeQQId(target);
70
70
  this.logger.info('标签', `管理员QQ(${normalizedUserId})尝试为QQ(${normalizedTargetId})添加标签"${tagName}"`, true);
71
- let targetBind = await this.deps.getBindInfo(normalizedTargetId);
71
+ let targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
72
72
  if (!targetBind) {
73
73
  const tempUsername = `_temp_${normalizedTargetId}`;
74
74
  await this.repos.mcidbind.create({ qqId: normalizedTargetId, mcUsername: tempUsername, mcUuid: '', lastModified: new Date(), isAdmin: false, whitelist: [], tags: [] });
75
- targetBind = await this.deps.getBindInfo(normalizedTargetId);
75
+ targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
76
76
  }
77
77
  if (targetBind.tags && targetBind.tags.includes(tagName)) {
78
78
  this.logger.warn('标签', `QQ(${normalizedTargetId})已有标签"${tagName}"`);
@@ -91,11 +91,11 @@ class TagHandler extends base_handler_1.BaseHandler {
91
91
  const target = targets[i];
92
92
  const normalizedTargetId = this.deps.normalizeQQId(target);
93
93
  try {
94
- let targetBind = await this.deps.getBindInfo(normalizedTargetId);
94
+ let targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
95
95
  if (!targetBind) {
96
96
  const tempUsername = `_temp_${normalizedTargetId}`;
97
97
  await this.repos.mcidbind.create({ qqId: normalizedTargetId, mcUsername: tempUsername, mcUuid: '', lastModified: new Date(), isAdmin: false, whitelist: [], tags: [] });
98
- targetBind = await this.deps.getBindInfo(normalizedTargetId);
98
+ targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
99
99
  }
100
100
  if (targetBind.tags && targetBind.tags.includes(tagName)) {
101
101
  skipCount++;
@@ -148,7 +148,7 @@ class TagHandler extends base_handler_1.BaseHandler {
148
148
  const target = targets[0];
149
149
  const normalizedTargetId = this.deps.normalizeQQId(target);
150
150
  this.logger.info('标签', `管理员QQ(${normalizedUserId})尝试为QQ(${normalizedTargetId})移除标签"${tagName}"`, true);
151
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
151
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
152
152
  if (!targetBind) {
153
153
  this.logger.warn('标签', `QQ(${normalizedTargetId})无记录`);
154
154
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 无记录`)]);
@@ -170,7 +170,7 @@ class TagHandler extends base_handler_1.BaseHandler {
170
170
  const target = targets[i];
171
171
  const normalizedTargetId = this.deps.normalizeQQId(target);
172
172
  try {
173
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
173
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
174
174
  if (!targetBind) {
175
175
  failCount++;
176
176
  results.push(`❌ ${normalizedTargetId}: 无记录`);
@@ -219,7 +219,7 @@ class TagHandler extends base_handler_1.BaseHandler {
219
219
  if (target) {
220
220
  const normalizedTargetId = this.deps.normalizeQQId(target);
221
221
  this.logger.info('标签', `管理员QQ(${normalizedUserId})查看QQ(${normalizedTargetId})的标签`, true);
222
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
222
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
223
223
  if (!targetBind) {
224
224
  this.logger.info('标签', `QQ(${normalizedTargetId})无记录`);
225
225
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 无记录`)]);
@@ -39,7 +39,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
39
39
  return this.deps.sendMessage(session, [koishi_1.h.text('当前未配置或启用任何服务器')]);
40
40
  }
41
41
  // 检查用户是否绑定了MC账号
42
- const userBind = await this.deps.getBindInfo(normalizedUserId);
42
+ const userBind = await this.deps.databaseService.getMcBindByQQId(normalizedUserId);
43
43
  if (!userBind || !userBind.mcUsername) {
44
44
  this.logger.warn('白名单', `QQ(${normalizedUserId})未绑定MC账号,无法显示白名单状态`);
45
45
  return this.deps.sendMessage(session, [koishi_1.h.text(`您尚未绑定MC账号,请先使用 ${this.deps.formatCommand('mcid bind <用户名>')} 命令绑定账号,然后再查看服务器列表。`)]);
@@ -140,7 +140,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
140
140
  const normalizedTargetId = this.deps.normalizeQQId(target);
141
141
  this.logger.info('白名单', `QQ(${normalizedUserId})尝试为QQ(${normalizedTargetId})添加服务器"${server.name}"白名单`);
142
142
  // 获取目标用户的绑定信息
143
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
143
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
144
144
  if (!targetBind || !targetBind.mcUsername) {
145
145
  this.logger.warn('白名单', `QQ(${normalizedTargetId})未绑定MC账号`);
146
146
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 尚未绑定MC账号,无法添加白名单`)]);
@@ -176,7 +176,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
176
176
  const normalizedTargetId = this.deps.normalizeQQId(target);
177
177
  try {
178
178
  // 获取目标用户的绑定信息
179
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
179
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
180
180
  if (!targetBind || !targetBind.mcUsername) {
181
181
  failCount++;
182
182
  results.push(`❌ ${normalizedTargetId}: 未绑定MC账号`);
@@ -235,7 +235,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
235
235
  return this.deps.sendMessage(session, [koishi_1.h.text(`服务器"${server.name}"不允许自助申请白名单,请联系管理员`)]);
236
236
  }
237
237
  // 获取自己的绑定信息
238
- const selfBind = await this.deps.getBindInfo(normalizedUserId);
238
+ const selfBind = await this.deps.databaseService.getMcBindByQQId(normalizedUserId);
239
239
  if (!selfBind || !selfBind.mcUsername) {
240
240
  this.logger.warn('白名单', `QQ(${normalizedUserId})未绑定MC账号`);
241
241
  return this.deps.sendMessage(session, [koishi_1.h.text('您尚未绑定MC账号,请先使用 ' + this.deps.formatCommand('mcid bind <用户名>') + ' 进行绑定')]);
@@ -312,7 +312,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
312
312
  const normalizedTargetId = this.deps.normalizeQQId(target);
313
313
  this.logger.info('白名单', `管理员QQ(${normalizedUserId})尝试为QQ(${normalizedTargetId})移除服务器"${server.name}"白名单`);
314
314
  // 获取目标用户的绑定信息
315
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
315
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
316
316
  if (!targetBind || !targetBind.mcUsername) {
317
317
  this.logger.warn('白名单', `QQ(${normalizedTargetId})未绑定MC账号`);
318
318
  return this.deps.sendMessage(session, [koishi_1.h.text(`用户 ${normalizedTargetId} 尚未绑定MC账号,无法移除白名单`)]);
@@ -348,7 +348,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
348
348
  const normalizedTargetId = this.deps.normalizeQQId(target);
349
349
  try {
350
350
  // 获取目标用户的绑定信息
351
- const targetBind = await this.deps.getBindInfo(normalizedTargetId);
351
+ const targetBind = await this.deps.databaseService.getMcBindByQQId(normalizedTargetId);
352
352
  if (!targetBind || !targetBind.mcUsername) {
353
353
  failCount++;
354
354
  results.push(`❌ ${normalizedTargetId}: 未绑定MC账号`);
@@ -402,7 +402,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
402
402
  // 为自己移除白名单(原有逻辑保持不变)
403
403
  this.logger.info('白名单', `管理员QQ(${normalizedUserId})尝试为自己移除服务器"${server.name}"白名单`);
404
404
  // 获取自己的绑定信息
405
- const selfBind = await this.deps.getBindInfo(normalizedUserId);
405
+ const selfBind = await this.deps.databaseService.getMcBindByQQId(normalizedUserId);
406
406
  if (!selfBind || !selfBind.mcUsername) {
407
407
  this.logger.warn('白名单', `QQ(${normalizedUserId})未绑定MC账号`);
408
408
  return this.deps.sendMessage(session, [koishi_1.h.text('您尚未绑定MC账号,请先使用 ' + this.deps.formatCommand('mcid bind <用户名>') + ' 进行绑定')]);
@@ -660,7 +660,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
660
660
  return true;
661
661
  // 查询MCIDBIND表中是否是管理员
662
662
  try {
663
- const bind = await this.deps.getBindInfo(normalizedQQId);
663
+ const bind = await this.deps.databaseService.getMcBindByQQId(normalizedQQId);
664
664
  return bind && bind.isAdmin === true;
665
665
  }
666
666
  catch (error) {
@@ -779,13 +779,13 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
779
779
  return false;
780
780
  }
781
781
  // 重新获取最新的用户绑定信息
782
- let freshBind = await this.deps.getBindInfo(mcBind.qqId);
782
+ let freshBind = await this.deps.databaseService.getMcBindByQQId(mcBind.qqId);
783
783
  if (!freshBind || !freshBind.mcUsername) {
784
784
  this.logger.warn('白名单', `用户QQ(${mcBind.qqId})可能在操作过程中解绑了MC账号`);
785
785
  return false;
786
786
  }
787
787
  // 智能检测用户名变更(带缓存,避免频繁API调用)
788
- freshBind = await this.deps.checkAndUpdateUsernameWithCache(freshBind);
788
+ freshBind = await this.deps.databaseService.checkAndUpdateUsernameWithCache(freshBind);
789
789
  // 检查最新状态是否已在白名单中
790
790
  if (freshBind.whitelist && freshBind.whitelist.includes(server.id)) {
791
791
  this.logger.info('白名单', `用户QQ(${mcBind.qqId})已在服务器${server.name}的白名单中`);
@@ -831,7 +831,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
831
831
  }
832
832
  if (success) {
833
833
  // 更新数据库
834
- const currentBind = await this.deps.getBindInfo(freshBind.qqId);
834
+ const currentBind = await this.deps.databaseService.getMcBindByQQId(freshBind.qqId);
835
835
  if (currentBind) {
836
836
  const whitelistSet = new Set(currentBind.whitelist || []);
837
837
  whitelistSet.add(server.id);
@@ -862,13 +862,13 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
862
862
  return false;
863
863
  }
864
864
  // 重新获取最新的用户绑定信息
865
- let freshBind = await this.deps.getBindInfo(mcBind.qqId);
865
+ let freshBind = await this.deps.databaseService.getMcBindByQQId(mcBind.qqId);
866
866
  if (!freshBind || !freshBind.mcUsername) {
867
867
  this.logger.warn('白名单', `用户QQ(${mcBind.qqId})可能在操作过程中解绑了MC账号`);
868
868
  return false;
869
869
  }
870
870
  // 智能检测用户名变更(带缓存,避免频繁API调用)
871
- freshBind = await this.deps.checkAndUpdateUsernameWithCache(freshBind);
871
+ freshBind = await this.deps.databaseService.checkAndUpdateUsernameWithCache(freshBind);
872
872
  // 检查最新状态是否在白名单中
873
873
  if (!freshBind.whitelist || !freshBind.whitelist.includes(server.id)) {
874
874
  this.logger.info('白名单', `用户QQ(${mcBind.qqId})不在服务器${server.name}的白名单中`);
@@ -917,7 +917,7 @@ class WhitelistHandler extends base_handler_1.BaseHandler {
917
917
  }
918
918
  if (success) {
919
919
  // 更新数据库
920
- const currentBind = await this.deps.getBindInfo(freshBind.qqId);
920
+ const currentBind = await this.deps.databaseService.getMcBindByQQId(freshBind.qqId);
921
921
  if (currentBind && currentBind.whitelist && currentBind.whitelist.includes(server.id)) {
922
922
  currentBind.whitelist = currentBind.whitelist.filter(id => id !== server.id);
923
923
  await this.repos.mcidbind.update(freshBind.qqId, {