koishi-plugin-bind-bot 2.2.5 → 2.2.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.
|
@@ -21,13 +21,9 @@ export declare class BuidHandler extends BaseHandler {
|
|
|
21
21
|
*/
|
|
22
22
|
private handleFindUser;
|
|
23
23
|
/**
|
|
24
|
-
* 处理
|
|
24
|
+
* 处理 buid.unbind 命令
|
|
25
25
|
*/
|
|
26
|
-
private
|
|
27
|
-
/**
|
|
28
|
-
* 处理 mcid.unbindbuid 命令
|
|
29
|
-
*/
|
|
30
|
-
private handleUnbindBuid;
|
|
26
|
+
private handleUnbind;
|
|
31
27
|
/**
|
|
32
28
|
* 解析UID输入(支持多种格式)
|
|
33
29
|
*/
|
|
@@ -37,17 +37,11 @@ class BuidHandler extends base_handler_1.BaseHandler {
|
|
|
37
37
|
.action(async ({ session }, uid) => {
|
|
38
38
|
return this.handleFindUser(session, uid);
|
|
39
39
|
});
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.
|
|
45
|
-
.action(async ({ session }, buid) => {
|
|
46
|
-
return this.handleBindBuid(session, buid);
|
|
47
|
-
});
|
|
48
|
-
// 解绑B站账号(mcid.unbindbuid)
|
|
49
|
-
mcidCmd.subcommand('.unbindbuid', '解绑B站账号').action(async ({ session }) => {
|
|
50
|
-
return this.handleUnbindBuid(session);
|
|
40
|
+
// 解绑BUID
|
|
41
|
+
buidCmd
|
|
42
|
+
.subcommand('.unbind', '解绑B站账号')
|
|
43
|
+
.action(async ({ session }) => {
|
|
44
|
+
return this.handleUnbind(session);
|
|
51
45
|
});
|
|
52
46
|
}
|
|
53
47
|
/**
|
|
@@ -71,12 +65,16 @@ class BuidHandler extends base_handler_1.BaseHandler {
|
|
|
71
65
|
: `您尚未绑定B站账号,请使用 ${this.deps.formatCommand('buid bind <UID>')} 进行绑定`)
|
|
72
66
|
]);
|
|
73
67
|
}
|
|
74
|
-
//
|
|
68
|
+
// 每次查询都必须从API获取最新数据
|
|
75
69
|
const buidUser = await this.validateBUID(bind.buidUid);
|
|
76
|
-
if (buidUser) {
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
if (!buidUser) {
|
|
71
|
+
return this.deps.sendMessage(session, [
|
|
72
|
+
koishi_1.h.text(`无法从API获取B站UID ${bind.buidUid} 的最新数据,该用户可能不存在或API服务暂时不可用`)
|
|
73
|
+
]);
|
|
79
74
|
}
|
|
75
|
+
// 更新本地数据库中的信息
|
|
76
|
+
await this.updateBuidInfoOnly(bind.qqId, buidUser);
|
|
77
|
+
bind = await this.repos.mcidbind.findByQQId(bind.qqId);
|
|
80
78
|
const userInfo = `${target ? `用户 ${bind.qqId} 的` : '您的'}B站账号信息:\nB站UID: ${bind.buidUid}\n用户名: ${bind.buidUsername}`;
|
|
81
79
|
let detailInfo = '';
|
|
82
80
|
if (bind.guardLevel > 0) {
|
|
@@ -192,68 +190,9 @@ class BuidHandler extends base_handler_1.BaseHandler {
|
|
|
192
190
|
}
|
|
193
191
|
}
|
|
194
192
|
/**
|
|
195
|
-
* 处理
|
|
196
|
-
*/
|
|
197
|
-
async handleBindBuid(session, buid) {
|
|
198
|
-
try {
|
|
199
|
-
const normalizedUserId = this.deps.normalizeQQId(session.userId);
|
|
200
|
-
this.logger.info('绑定', `QQ(${normalizedUserId})尝试绑定B站UID(${buid})`);
|
|
201
|
-
// 验证格式
|
|
202
|
-
if (!buid || !/^\d+$/.test(buid)) {
|
|
203
|
-
this.logger.warn('绑定', `QQ(${normalizedUserId})尝试绑定无效的B站UID格式: ${buid}`);
|
|
204
|
-
return this.deps.sendMessage(session, [koishi_1.h.text('无效的B站UID格式,请输入正确的B站UID')]);
|
|
205
|
-
}
|
|
206
|
-
// 检查是否已被他人绑定
|
|
207
|
-
const existingBind = await this.repos.mcidbind.findByBuidUid(buid);
|
|
208
|
-
if (existingBind) {
|
|
209
|
-
const existingQQId = existingBind.qqId;
|
|
210
|
-
this.logger.warn('绑定', `QQ(${normalizedUserId})尝试绑定已被QQ(${existingQQId})绑定的B站UID(${buid})`);
|
|
211
|
-
return this.deps.sendMessage(session, [koishi_1.h.text('该B站UID已被其他用户绑定')]);
|
|
212
|
-
}
|
|
213
|
-
// 验证B站UID
|
|
214
|
-
const buidUser = await this.validateBUID(buid);
|
|
215
|
-
if (!buidUser) {
|
|
216
|
-
this.logger.warn('绑定', `QQ(${normalizedUserId})尝试绑定不存在的B站UID(${buid})`);
|
|
217
|
-
return this.deps.sendMessage(session, [koishi_1.h.text('无法验证B站UID,请确认输入正确')]);
|
|
218
|
-
}
|
|
219
|
-
// 创建或更新绑定
|
|
220
|
-
const success = await this.createOrUpdateBuidBind(normalizedUserId, buidUser);
|
|
221
|
-
if (success) {
|
|
222
|
-
this.logger.info('绑定', `QQ(${normalizedUserId})成功绑定B站UID(${buid})`);
|
|
223
|
-
return this.deps.sendMessage(session, [
|
|
224
|
-
koishi_1.h.text('成功绑定B站账号!\n'),
|
|
225
|
-
koishi_1.h.text(`B站UID: ${buidUser.uid}\n`),
|
|
226
|
-
koishi_1.h.text(`用户名: ${buidUser.username}\n`),
|
|
227
|
-
buidUser.guard_level > 0
|
|
228
|
-
? koishi_1.h.text(`舰长等级: ${buidUser.guard_level_text} (${buidUser.guard_level})\n`)
|
|
229
|
-
: null,
|
|
230
|
-
buidUser.medal
|
|
231
|
-
? koishi_1.h.text(`粉丝牌: ${buidUser.medal.name} Lv.${buidUser.medal.level}\n`)
|
|
232
|
-
: null,
|
|
233
|
-
buidUser.wealthMedalLevel > 0
|
|
234
|
-
? koishi_1.h.text(`荣耀等级: ${buidUser.wealthMedalLevel}\n`)
|
|
235
|
-
: null,
|
|
236
|
-
...(this.config?.showAvatar
|
|
237
|
-
? [koishi_1.h.image(`https://workers.vrp.moe/bilibili/avatar/${buidUser.uid}?size=160`)]
|
|
238
|
-
: [])
|
|
239
|
-
].filter(Boolean));
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
this.logger.error('绑定', normalizedUserId, `QQ(${normalizedUserId})绑定B站UID(${buid})失败`);
|
|
243
|
-
return this.deps.sendMessage(session, [koishi_1.h.text('绑定失败,请稍后重试')]);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
this.logger.error('绑定', session.userId, error);
|
|
248
|
-
return this.deps.sendMessage(session, [
|
|
249
|
-
koishi_1.h.text(`绑定失败:${this.getFriendlyErrorMessage(error)}`)
|
|
250
|
-
]);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* 处理 mcid.unbindbuid 命令
|
|
193
|
+
* 处理 buid.unbind 命令
|
|
255
194
|
*/
|
|
256
|
-
async
|
|
195
|
+
async handleUnbind(session) {
|
|
257
196
|
try {
|
|
258
197
|
const normalizedUserId = this.deps.normalizeQQId(session.userId);
|
|
259
198
|
this.logger.info('解绑', `QQ(${normalizedUserId})尝试解绑B站账号`);
|