koishi-plugin-bind-bot 2.1.4 → 2.1.5
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.
|
@@ -98,18 +98,24 @@ class GroupRequestReviewHandler extends base_handler_1.BaseHandler {
|
|
|
98
98
|
*/
|
|
99
99
|
async handleNotice(session) {
|
|
100
100
|
try {
|
|
101
|
+
// 调试日志:记录所有notice事件
|
|
102
|
+
this.logger.info('入群审批', `[DEBUG] 收到notice事件 - type: ${session.type}, subtype: ${session.subtype}, guildId: ${session.guildId}`, true);
|
|
101
103
|
// 只处理群表情回应事件
|
|
102
104
|
if (session.subtype !== 'group-msg-emoji-like') {
|
|
105
|
+
this.logger.info('入群审批', `[DEBUG] 跳过: subtype不匹配 (${session.subtype})`, true);
|
|
103
106
|
return;
|
|
104
107
|
}
|
|
105
108
|
// 只处理管理群的表情
|
|
106
109
|
if (session.guildId !== this.reviewConfig.reviewGroupId) {
|
|
110
|
+
this.logger.info('入群审批', `[DEBUG] 跳过: guildId不匹配 (收到: ${session.guildId}, 需要: ${this.reviewConfig.reviewGroupId})`, true);
|
|
107
111
|
return;
|
|
108
112
|
}
|
|
109
113
|
// 获取原始事件数据(使用类型断言访问 onebot 扩展属性)
|
|
110
114
|
const onebotSession = session;
|
|
111
115
|
const onebotData = onebotSession.onebot;
|
|
116
|
+
this.logger.info('入群审批', `[DEBUG] onebot数据: ${JSON.stringify(onebotData)}`, true);
|
|
112
117
|
if (!onebotData?.likes || onebotData.likes.length === 0) {
|
|
118
|
+
this.logger.info('入群审批', '[DEBUG] 跳过: 没有likes数据', true);
|
|
113
119
|
return;
|
|
114
120
|
}
|
|
115
121
|
// 从原始 OneBot 数据中读取(更可靠)
|
|
@@ -121,10 +127,12 @@ class GroupRequestReviewHandler extends base_handler_1.BaseHandler {
|
|
|
121
127
|
return;
|
|
122
128
|
}
|
|
123
129
|
const operatorId = this.deps.normalizeQQId(userId);
|
|
124
|
-
this.logger.
|
|
130
|
+
this.logger.info('入群审批', `收到表情回应 - 消息: ${msgId}, 操作者: ${operatorId}, 表情数: ${emojiData.length}`, true);
|
|
125
131
|
// 检查是否是待审批的消息
|
|
126
132
|
const pendingReq = this.pendingRequests.get(msgId);
|
|
127
133
|
if (!pendingReq) {
|
|
134
|
+
this.logger.info('入群审批', `[DEBUG] 跳过: 消息${msgId}不在待审批列表中`, true);
|
|
135
|
+
this.logger.info('入群审批', `[DEBUG] 当前待审批列表: ${Array.from(this.pendingRequests.keys()).join(', ')}`, true);
|
|
128
136
|
return;
|
|
129
137
|
}
|
|
130
138
|
// 检查是否已处理
|
|
@@ -172,25 +180,93 @@ class GroupRequestReviewHandler extends base_handler_1.BaseHandler {
|
|
|
172
180
|
catch (error) {
|
|
173
181
|
this.logger.warn('入群审批', `获取用户信息失败,使用默认值: ${error.message}`);
|
|
174
182
|
}
|
|
175
|
-
|
|
183
|
+
// 解析并查询 B 站信息
|
|
184
|
+
let buidUid = null;
|
|
185
|
+
let buidUsername = null;
|
|
186
|
+
let medalInfo = null;
|
|
187
|
+
let bindStatus = '❌ UID 未提供';
|
|
188
|
+
const parsedUid = this.parseUID(answer);
|
|
189
|
+
if (parsedUid) {
|
|
190
|
+
buidUid = parsedUid;
|
|
191
|
+
// 并行查询官方API和ZMINFO API
|
|
192
|
+
const [officialInfo, zminfoData] = await Promise.all([
|
|
193
|
+
this.deps.apiService.getBilibiliOfficialUserInfo(parsedUid).catch(() => null),
|
|
194
|
+
this.deps.apiService.validateBUID(parsedUid).catch(() => null)
|
|
195
|
+
]);
|
|
196
|
+
// 用户名:优先使用官方API(最准确),降级到ZMINFO
|
|
197
|
+
if (officialInfo?.name) {
|
|
198
|
+
buidUsername = officialInfo.name;
|
|
199
|
+
this.logger.debug('入群审批', `✅ 使用官方API用户名: ${buidUsername}`);
|
|
200
|
+
}
|
|
201
|
+
else if (zminfoData?.username) {
|
|
202
|
+
buidUsername = zminfoData.username;
|
|
203
|
+
this.logger.debug('入群审批', `⚠️ 官方API失败,使用ZMINFO用户名: ${buidUsername}`);
|
|
204
|
+
}
|
|
205
|
+
// 粉丝牌信息:只能从ZMINFO获取(官方API不提供)
|
|
206
|
+
if (zminfoData) {
|
|
207
|
+
const medalLevel = zminfoData.medal?.level || 0;
|
|
208
|
+
const medalName = zminfoData.medal?.name || '';
|
|
209
|
+
if (medalName === this.config.forceBindTargetMedalName) {
|
|
210
|
+
medalInfo = `🎖️ ${medalName} Lv.${medalLevel}`;
|
|
211
|
+
}
|
|
212
|
+
else if (medalLevel > 0) {
|
|
213
|
+
medalInfo = `⚠️ 佩戴其他粉丝牌: ${medalName} Lv.${medalLevel}`;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
medalInfo = `⚠️ 未获取到 "${this.config.forceBindTargetMedalName}" 粉丝牌`;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.logger.warn('入群审批', 'ZMINFO API查询失败,无法获取粉丝牌信息');
|
|
221
|
+
}
|
|
222
|
+
// 绑定状态:查询数据库
|
|
223
|
+
if (buidUsername) {
|
|
224
|
+
const existingBind = await this.repos.mcidbind.findByBuidUid(parsedUid);
|
|
225
|
+
if (existingBind) {
|
|
226
|
+
if (existingBind.qqId === qq) {
|
|
227
|
+
bindStatus = '✅ 该 UID 已绑定到此 QQ';
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
bindStatus = `⚠️ 该 UID 已被 ${existingBind.qqId} 绑定`;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
bindStatus = '✅ UID 未被绑定';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
bindStatus = '❌ UID 查询失败(官方API和ZMINFO均失败)';
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return { qq, nickname, avatar, answer, buidUid, buidUsername, medalInfo, bindStatus };
|
|
176
242
|
}
|
|
177
243
|
/**
|
|
178
244
|
* 发送播报消息到管理群
|
|
179
245
|
*/
|
|
180
246
|
async sendBroadcastMessage(applicantInfo, session) {
|
|
181
|
-
const { qq, nickname, avatar, answer } = applicantInfo;
|
|
247
|
+
const { qq, nickname, avatar, answer, buidUid, buidUsername, medalInfo, bindStatus } = applicantInfo;
|
|
182
248
|
const elements = [
|
|
183
249
|
koishi_1.h.text('📢 收到新的入群申请\n\n'),
|
|
184
250
|
koishi_1.h.image(avatar),
|
|
185
|
-
koishi_1.h.text(`\n👤 昵称:${nickname}\n`),
|
|
186
|
-
koishi_1.h.text(`🆔 QQ号:${qq}\n`),
|
|
187
|
-
koishi_1.h.text(`💬
|
|
188
|
-
koishi_1.h.text('━━━━━━━━━━━━━━━\n'),
|
|
189
|
-
koishi_1.h.text('请管理员点击表情回应:\n'),
|
|
190
|
-
koishi_1.h.text('👍 /太赞了 - 通过并自动绑定\n'),
|
|
191
|
-
koishi_1.h.text('😊 /偷感 - 通过并交互式绑定\n'),
|
|
192
|
-
koishi_1.h.text('❌ /NO - 拒绝申请')
|
|
251
|
+
koishi_1.h.text(`\n👤 QQ 昵称:${nickname}\n`),
|
|
252
|
+
koishi_1.h.text(`🆔 QQ 号:${qq}\n`),
|
|
253
|
+
koishi_1.h.text(`💬 入群问题:${answer}\n\n`)
|
|
193
254
|
];
|
|
255
|
+
// B 站信息
|
|
256
|
+
if (buidUid) {
|
|
257
|
+
elements.push(koishi_1.h.text(`🎬 B 站 UID:${buidUid}\n`));
|
|
258
|
+
if (buidUsername) {
|
|
259
|
+
elements.push(koishi_1.h.text(`👑 B 站昵称:${buidUsername}\n`));
|
|
260
|
+
}
|
|
261
|
+
if (medalInfo) {
|
|
262
|
+
elements.push(koishi_1.h.text(`${medalInfo}\n`));
|
|
263
|
+
}
|
|
264
|
+
elements.push(koishi_1.h.text(`${bindStatus}\n\n`));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
elements.push(koishi_1.h.text(`⚠️ 未提供有效的 B 站 UID\n\n`));
|
|
268
|
+
}
|
|
269
|
+
elements.push(koishi_1.h.text('━━━━━━━━━━━━━━━\n'), koishi_1.h.text('请管理员点击表情回应:\n'), koishi_1.h.text('👍 /太赞了 - 通过并自动绑定\n'), koishi_1.h.text('😊 /偷感 - 通过并交互式绑定\n'), koishi_1.h.text('❌ /NO - 拒绝申请'));
|
|
194
270
|
try {
|
|
195
271
|
const result = await session.bot.sendMessage(this.reviewConfig.reviewGroupId, elements);
|
|
196
272
|
// result 通常是数组,第一个元素是消息ID
|