koishi-plugin-bind-bot 2.1.5 → 2.1.6

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.
@@ -79,7 +79,7 @@ export declare class GroupRequestReviewHandler extends BaseHandler {
79
79
  */
80
80
  private checkAdminPermission;
81
81
  /**
82
- * 解析UID(支持多种格式)
82
+ * 解析UID(支持多种格式,参考BuidHandler.parseUidInput实现)
83
83
  */
84
84
  private parseUID;
85
85
  /**
@@ -110,22 +110,18 @@ class GroupRequestReviewHandler extends base_handler_1.BaseHandler {
110
110
  this.logger.info('入群审批', `[DEBUG] 跳过: guildId不匹配 (收到: ${session.guildId}, 需要: ${this.reviewConfig.reviewGroupId})`, true);
111
111
  return;
112
112
  }
113
- // 获取原始事件数据(使用类型断言访问 onebot 扩展属性)
114
- const onebotSession = session;
115
- const onebotData = onebotSession.onebot;
116
- this.logger.info('入群审批', `[DEBUG] onebot数据: ${JSON.stringify(onebotData)}`, true);
117
- if (!onebotData?.likes || onebotData.likes.length === 0) {
118
- this.logger.info('入群审批', '[DEBUG] 跳过: 没有likes数据', true);
119
- return;
120
- }
121
- // 从原始 OneBot 数据中读取(更可靠)
122
- const msgId = onebotData.message_id?.toString() || session.messageId;
123
- const userId = onebotData.user_id?.toString() || session.userId;
124
- const emojiData = onebotData.likes;
125
- if (!msgId || !userId) {
126
- this.logger.warn('入群审批', '表情回应事件缺少必要数据: messageId 或 userId');
113
+ // 获取原始事件数据(直接访问 session.onebot,参考luckydraw实现)
114
+ const data = session.onebot;
115
+ this.logger.info('入群审批', `[DEBUG] onebot数据: ${JSON.stringify(data)}`, true);
116
+ const messageId = data?.message_id;
117
+ const userId = data?.user_id?.toString();
118
+ const likes = data?.likes || [];
119
+ if (!messageId || !userId || likes.length === 0) {
120
+ this.logger.info('入群审批', '[DEBUG] 跳过: 缺少必要数据或likes为空', true);
127
121
  return;
128
122
  }
123
+ const msgId = messageId.toString();
124
+ const emojiData = likes;
129
125
  const operatorId = this.deps.normalizeQQId(userId);
130
126
  this.logger.info('入群审批', `收到表情回应 - 消息: ${msgId}, 操作者: ${operatorId}, 表情数: ${emojiData.length}`, true);
131
127
  // 检查是否是待审批的消息
@@ -185,7 +181,9 @@ class GroupRequestReviewHandler extends base_handler_1.BaseHandler {
185
181
  let buidUsername = null;
186
182
  let medalInfo = null;
187
183
  let bindStatus = '❌ UID 未提供';
184
+ this.logger.debug('入群审批', `[DEBUG] 准备解析UID - 原始answer: "${answer}"`);
188
185
  const parsedUid = this.parseUID(answer);
186
+ this.logger.debug('入群审批', `[DEBUG] parseUID结果: ${parsedUid ? parsedUid : 'null'}`);
189
187
  if (parsedUid) {
190
188
  buidUid = parsedUid;
191
189
  // 并行查询官方API和ZMINFO API
@@ -520,26 +518,59 @@ class GroupRequestReviewHandler extends base_handler_1.BaseHandler {
520
518
  }
521
519
  }
522
520
  /**
523
- * 解析UID(支持多种格式)
521
+ * 解析UID(支持多种格式,参考BuidHandler.parseUidInput实现)
524
522
  */
525
523
  parseUID(input) {
526
524
  if (!input)
527
525
  return null;
528
526
  input = input.trim();
529
- // 格式1: 纯数字
527
+ // 格式1: 纯数字(整行都是数字)
530
528
  if (/^\d+$/.test(input)) {
529
+ this.logger.debug('入群审批', `parseUID: 识别为纯数字 -> ${input}`);
531
530
  return input;
532
531
  }
533
- // 格式2: UID:123456789
534
- const uidMatch = input.match(/^UID:(\d+)$/i);
535
- if (uidMatch) {
536
- return uidMatch[1];
532
+ // 格式2: 包含"答案:"标记的多行文本(如:问题\n答案:123456789
533
+ const answerMatch = input.match(/答案[::]\s*(\d+)/i);
534
+ if (answerMatch) {
535
+ this.logger.debug('入群审批', `parseUID: 从"答案:"提取 -> ${answerMatch[1]}`);
536
+ return answerMatch[1];
537
+ }
538
+ // 格式3: UID:123456789(参考BuidHandler)
539
+ if (input.toLowerCase().startsWith('uid:')) {
540
+ const uid = input.substring(4).trim();
541
+ if (/^\d+$/.test(uid)) {
542
+ this.logger.debug('入群审批', `parseUID: 从"UID:"前缀提取 -> ${uid}`);
543
+ return uid;
544
+ }
545
+ }
546
+ // 格式4: https://space.bilibili.com/123456789(参考BuidHandler的完善处理)
547
+ if (input.includes('space.bilibili.com/')) {
548
+ try {
549
+ let urlPart = input.replace(/^https?:\/\/space\.bilibili\.com\//, '');
550
+ // 移除查询参数
551
+ if (urlPart.includes('?')) {
552
+ urlPart = urlPart.split('?')[0];
553
+ }
554
+ // 移除路径
555
+ if (urlPart.includes('/')) {
556
+ urlPart = urlPart.split('/')[0];
557
+ }
558
+ if (/^\d+$/.test(urlPart)) {
559
+ this.logger.debug('入群审批', `parseUID: 从B站空间URL提取 -> ${urlPart}`);
560
+ return urlPart;
561
+ }
562
+ }
563
+ catch (error) {
564
+ this.logger.warn('入群审批', `parseUID: URL解析失败 - ${error.message}`);
565
+ }
537
566
  }
538
- // 格式3: https://space.bilibili.com/123456789
539
- const urlMatch = input.match(/space\.bilibili\.com\/(\d+)/);
540
- if (urlMatch) {
541
- return urlMatch[1];
567
+ // 格式5: 从文本中提取第一个长数字串(8-12位,B站UID的典型长度)
568
+ const numberMatch = input.match(/\b(\d{8,12})\b/);
569
+ if (numberMatch) {
570
+ this.logger.debug('入群审批', `parseUID: 从文本提取长数字串 -> ${numberMatch[1]}`);
571
+ return numberMatch[1];
542
572
  }
573
+ this.logger.warn('入群审批', `parseUID: 无法解析 - "${input}"`);
543
574
  return null;
544
575
  }
545
576
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bind-bot",
3
3
  "description": "[WittF自用] BIND-BOT - 账号绑定管理机器人,支持Minecraft账号和B站账号绑定与管理。",
4
- "version": "2.1.5",
4
+ "version": "2.1.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [