koishi-plugin-bilibili-notify 3.0.0-alpha.1 → 3.0.0-alpha.10
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/biliAPI.js +260 -185
- package/lib/blive.d.ts +3 -2
- package/lib/blive.js +14 -7
- package/lib/comRegister.d.ts +28 -24
- package/lib/comRegister.js +443 -393
- package/lib/generateImg.js +4 -4
- package/lib/index.d.ts +13 -13
- package/lib/index.js +155 -154
- package/lib/utils/retry.d.ts +6 -0
- package/lib/utils/retry.js +24 -0
- package/lib/utils/withLock.d.ts +7 -0
- package/lib/utils/withLock.js +59 -0
- package/package.json +1 -1
- package/readme.md +10 -1
package/lib/biliAPI.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
10
|
};
|
|
@@ -14,6 +20,7 @@ const tough_cookie_1 = require("tough-cookie");
|
|
|
14
20
|
const axios_cookiejar_support_1 = require("axios-cookiejar-support");
|
|
15
21
|
const jsdom_1 = require("jsdom");
|
|
16
22
|
const luxon_1 = require("luxon");
|
|
23
|
+
const retry_1 = __importDefault(require("./utils/retry"));
|
|
17
24
|
const mixinKeyEncTab = [
|
|
18
25
|
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
|
|
19
26
|
33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
|
|
@@ -108,183 +115,113 @@ class BiliAPI extends koishi_1.Service {
|
|
|
108
115
|
}
|
|
109
116
|
// BA API
|
|
110
117
|
async getTheUserWhoIsLiveStreaming() {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return live_users;
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
throw new Error('网络异常,本次请求失败!');
|
|
119
|
-
}
|
|
118
|
+
// 获取直播间信息流密钥
|
|
119
|
+
const { data: { live_users } } = await this.client.get(GET_LATEST_UPDATED_UPS);
|
|
120
|
+
// 返回data
|
|
121
|
+
return live_users;
|
|
120
122
|
}
|
|
121
123
|
async getLiveRoomInfoStreamKey(roomId) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return data;
|
|
127
|
-
}
|
|
128
|
-
catch (e) {
|
|
129
|
-
throw new Error('网络异常,本次请求失败!');
|
|
130
|
-
}
|
|
124
|
+
// 获取直播间信息流密钥
|
|
125
|
+
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
|
|
126
|
+
// 返回data
|
|
127
|
+
return data;
|
|
131
128
|
}
|
|
132
129
|
async getServerUTCTime() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return timestamp / 1000;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
throw new Error('解析服务器时间失败!');
|
|
143
|
-
}
|
|
130
|
+
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
|
131
|
+
const regex = /Date\.UTC\((.*?)\)/;
|
|
132
|
+
const match = data.match(regex);
|
|
133
|
+
if (match) {
|
|
134
|
+
const timestamp = new Function(`return Date.UTC(${match[1]})`)();
|
|
135
|
+
return timestamp / 1000;
|
|
144
136
|
}
|
|
145
|
-
|
|
146
|
-
throw new Error('
|
|
137
|
+
else {
|
|
138
|
+
throw new Error('解析服务器时间失败!');
|
|
147
139
|
}
|
|
148
140
|
}
|
|
149
141
|
async getTimeNow() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return data;
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
throw new Error('网络异常,本次请求失败!');
|
|
156
|
-
}
|
|
142
|
+
const { data } = await this.client.get(GET_TIME_NOW);
|
|
143
|
+
return data;
|
|
157
144
|
}
|
|
158
145
|
async getAllGroup() {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return data;
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
throw new Error('网络异常,本次请求失败!');
|
|
165
|
-
}
|
|
146
|
+
const { data } = await this.client.get(GET_ALL_GROUP);
|
|
147
|
+
return data;
|
|
166
148
|
}
|
|
167
149
|
async removeUserFromGroup(mid) {
|
|
168
150
|
// 获取csrf
|
|
169
151
|
const csrf = this.getCSRF();
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return data;
|
|
182
|
-
}
|
|
183
|
-
catch (e) {
|
|
184
|
-
throw new Error('网络异常,本次请求失败!');
|
|
185
|
-
}
|
|
152
|
+
// 将用户mid添加到groupId
|
|
153
|
+
const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
|
|
154
|
+
fids: mid,
|
|
155
|
+
tagids: 0,
|
|
156
|
+
csrf
|
|
157
|
+
}, {
|
|
158
|
+
headers: {
|
|
159
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return data;
|
|
186
163
|
}
|
|
187
164
|
async copyUserToGroup(mid, groupId) {
|
|
188
165
|
// 获取csrf
|
|
189
166
|
const csrf = this.getCSRF();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return data;
|
|
202
|
-
}
|
|
203
|
-
catch (e) {
|
|
204
|
-
throw new Error('网络异常,本次请求失败!');
|
|
205
|
-
}
|
|
167
|
+
// 将用户mid添加到groupId
|
|
168
|
+
const { data } = await this.client.post(COPY_USER_TO_GROUP, {
|
|
169
|
+
fids: mid,
|
|
170
|
+
tagids: groupId,
|
|
171
|
+
csrf
|
|
172
|
+
}, {
|
|
173
|
+
headers: {
|
|
174
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return data;
|
|
206
178
|
}
|
|
207
179
|
async getUserSpaceDynamic(mid) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return data;
|
|
211
|
-
}
|
|
212
|
-
catch (e) {
|
|
213
|
-
throw new Error('网络异常,本次请求失败!');
|
|
214
|
-
}
|
|
180
|
+
const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}?host_mid=${mid}`);
|
|
181
|
+
return data;
|
|
215
182
|
}
|
|
216
183
|
async createGroup(tag) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return data;
|
|
227
|
-
}
|
|
228
|
-
catch (e) {
|
|
229
|
-
throw new Error('网络异常,本次请求失败!');
|
|
230
|
-
}
|
|
184
|
+
const { data } = await this.client.post(CREATE_GROUP, {
|
|
185
|
+
tag,
|
|
186
|
+
csrf: this.getCSRF()
|
|
187
|
+
}, {
|
|
188
|
+
headers: {
|
|
189
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return data;
|
|
231
193
|
}
|
|
232
194
|
async getAllDynamic(updateBaseline) {
|
|
233
195
|
let url = GET_ALL_DYNAMIC_LIST;
|
|
234
196
|
updateBaseline && (url += `?update_baseline=${updateBaseline}`);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return data;
|
|
238
|
-
}
|
|
239
|
-
catch (e) {
|
|
240
|
-
throw new Error('网络异常,本次请求失败!');
|
|
241
|
-
}
|
|
197
|
+
const { data } = await this.client.get(url);
|
|
198
|
+
return data;
|
|
242
199
|
}
|
|
243
200
|
async hasNewDynamic(updateBaseline) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return data;
|
|
247
|
-
}
|
|
248
|
-
catch (e) {
|
|
249
|
-
throw new Error('网络异常,本次请求失败!');
|
|
250
|
-
}
|
|
201
|
+
const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
|
|
202
|
+
return data;
|
|
251
203
|
}
|
|
252
204
|
async follow(fid) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return data;
|
|
265
|
-
}
|
|
266
|
-
catch (e) {
|
|
267
|
-
throw new Error('网络异常,本次请求失败!');
|
|
268
|
-
}
|
|
205
|
+
const { data } = await this.client.post(MODIFY_RELATION, {
|
|
206
|
+
fid,
|
|
207
|
+
act: 1,
|
|
208
|
+
re_src: 11,
|
|
209
|
+
csrf: this.getCSRF()
|
|
210
|
+
}, {
|
|
211
|
+
headers: {
|
|
212
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return data;
|
|
269
216
|
}
|
|
270
217
|
async getRelationGroupDetail(tagid) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
return data;
|
|
274
|
-
}
|
|
275
|
-
catch (e) {
|
|
276
|
-
throw new Error('网络异常,本次请求失败!');
|
|
277
|
-
}
|
|
218
|
+
const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
|
|
219
|
+
return data;
|
|
278
220
|
}
|
|
279
221
|
// Check if Token need refresh
|
|
280
222
|
async getCookieInfo(refreshToken) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return data;
|
|
284
|
-
}
|
|
285
|
-
catch (e) {
|
|
286
|
-
throw new Error('网络异常,本次请求失败!');
|
|
287
|
-
}
|
|
223
|
+
const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
|
|
224
|
+
return data;
|
|
288
225
|
}
|
|
289
226
|
async getUserInfo(mid) {
|
|
290
227
|
//如果为番剧出差的UID,则不从远程接口拉取数据,直接传回一段精简过的有效数据
|
|
@@ -292,14 +229,9 @@ class BiliAPI extends koishi_1.Service {
|
|
|
292
229
|
console.log("检测到番剧出差UID,跳过远程用户接口访问");
|
|
293
230
|
return bangumiTripData;
|
|
294
231
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return data;
|
|
299
|
-
}
|
|
300
|
-
catch (e) {
|
|
301
|
-
throw new Error('网络异常,本次请求失败!');
|
|
302
|
-
}
|
|
232
|
+
const wbi = await this.getWbi({ mid });
|
|
233
|
+
const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
|
|
234
|
+
return data;
|
|
303
235
|
}
|
|
304
236
|
// 获取最新的 img_key 和 sub_key
|
|
305
237
|
async getWbiKeys() {
|
|
@@ -311,49 +243,24 @@ class BiliAPI extends koishi_1.Service {
|
|
|
311
243
|
};
|
|
312
244
|
}
|
|
313
245
|
async getMyselfInfo() {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return data;
|
|
317
|
-
}
|
|
318
|
-
catch (e) {
|
|
319
|
-
throw new Error('网络异常,本次请求失败!');
|
|
320
|
-
}
|
|
246
|
+
const { data } = await this.client.get(GET_MYSELF_INFO);
|
|
247
|
+
return data;
|
|
321
248
|
}
|
|
322
249
|
async getLoginQRCode() {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return data;
|
|
326
|
-
}
|
|
327
|
-
catch (e) {
|
|
328
|
-
throw new Error('网络异常,本次请求失败!');
|
|
329
|
-
}
|
|
250
|
+
const { data } = await this.client.get(GET_LOGIN_QRCODE);
|
|
251
|
+
return data;
|
|
330
252
|
}
|
|
331
253
|
async getLoginStatus(qrcodeKey) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return data;
|
|
335
|
-
}
|
|
336
|
-
catch (e) {
|
|
337
|
-
throw new Error('网络异常,本次请求失败!');
|
|
338
|
-
}
|
|
254
|
+
const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
|
|
255
|
+
return data;
|
|
339
256
|
}
|
|
340
257
|
async getLiveRoomInfo(roomId) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return data;
|
|
344
|
-
}
|
|
345
|
-
catch (e) {
|
|
346
|
-
throw new Error('网络异常,本次请求失败!');
|
|
347
|
-
}
|
|
258
|
+
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
|
|
259
|
+
return data;
|
|
348
260
|
}
|
|
349
261
|
async getMasterInfo(mid) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
return data;
|
|
353
|
-
}
|
|
354
|
-
catch (e) {
|
|
355
|
-
throw new Error('网络异常,本次请求失败!');
|
|
356
|
-
}
|
|
262
|
+
const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
|
|
263
|
+
return data;
|
|
357
264
|
}
|
|
358
265
|
disposeNotifier() { if (this.loginNotifier)
|
|
359
266
|
this.loginNotifier.dispose(); }
|
|
@@ -643,6 +550,174 @@ class BiliAPI extends koishi_1.Service {
|
|
|
643
550
|
// 没有问题,cookies已更新完成
|
|
644
551
|
}
|
|
645
552
|
}
|
|
553
|
+
__decorate([
|
|
554
|
+
(0, retry_1.default)({
|
|
555
|
+
attempts: 3,
|
|
556
|
+
onFailure(error, attempts) {
|
|
557
|
+
this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
|
|
558
|
+
},
|
|
559
|
+
})
|
|
560
|
+
], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
|
|
561
|
+
__decorate([
|
|
562
|
+
(0, retry_1.default)({
|
|
563
|
+
attempts: 3,
|
|
564
|
+
onFailure(error, attempts) {
|
|
565
|
+
this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
|
|
566
|
+
},
|
|
567
|
+
})
|
|
568
|
+
], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
|
|
569
|
+
__decorate([
|
|
570
|
+
(0, retry_1.default)({
|
|
571
|
+
attempts: 3,
|
|
572
|
+
onFailure(error, attempts) {
|
|
573
|
+
this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
|
|
574
|
+
},
|
|
575
|
+
})
|
|
576
|
+
], BiliAPI.prototype, "getServerUTCTime", null);
|
|
577
|
+
__decorate([
|
|
578
|
+
(0, retry_1.default)({
|
|
579
|
+
attempts: 3,
|
|
580
|
+
onFailure(error, attempts) {
|
|
581
|
+
this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
|
|
582
|
+
},
|
|
583
|
+
})
|
|
584
|
+
], BiliAPI.prototype, "getTimeNow", null);
|
|
585
|
+
__decorate([
|
|
586
|
+
(0, retry_1.default)({
|
|
587
|
+
attempts: 3,
|
|
588
|
+
onFailure(error, attempts) {
|
|
589
|
+
this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
|
|
590
|
+
},
|
|
591
|
+
})
|
|
592
|
+
], BiliAPI.prototype, "getAllGroup", null);
|
|
593
|
+
__decorate([
|
|
594
|
+
(0, retry_1.default)({
|
|
595
|
+
attempts: 3,
|
|
596
|
+
onFailure(error, attempts) {
|
|
597
|
+
this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
|
|
598
|
+
},
|
|
599
|
+
})
|
|
600
|
+
], BiliAPI.prototype, "removeUserFromGroup", null);
|
|
601
|
+
__decorate([
|
|
602
|
+
(0, retry_1.default)({
|
|
603
|
+
attempts: 3,
|
|
604
|
+
onFailure(error, attempts) {
|
|
605
|
+
this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
|
|
606
|
+
},
|
|
607
|
+
})
|
|
608
|
+
], BiliAPI.prototype, "copyUserToGroup", null);
|
|
609
|
+
__decorate([
|
|
610
|
+
(0, retry_1.default)({
|
|
611
|
+
attempts: 3,
|
|
612
|
+
onFailure(error, attempts) {
|
|
613
|
+
this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
|
|
614
|
+
},
|
|
615
|
+
})
|
|
616
|
+
], BiliAPI.prototype, "getUserSpaceDynamic", null);
|
|
617
|
+
__decorate([
|
|
618
|
+
(0, retry_1.default)({
|
|
619
|
+
attempts: 3,
|
|
620
|
+
onFailure(error, attempts) {
|
|
621
|
+
this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
|
|
622
|
+
},
|
|
623
|
+
})
|
|
624
|
+
], BiliAPI.prototype, "createGroup", null);
|
|
625
|
+
__decorate([
|
|
626
|
+
(0, retry_1.default)({
|
|
627
|
+
attempts: 3,
|
|
628
|
+
onFailure(error, attempts) {
|
|
629
|
+
this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
|
|
630
|
+
},
|
|
631
|
+
})
|
|
632
|
+
], BiliAPI.prototype, "getAllDynamic", null);
|
|
633
|
+
__decorate([
|
|
634
|
+
(0, retry_1.default)({
|
|
635
|
+
attempts: 3,
|
|
636
|
+
onFailure(error, attempts) {
|
|
637
|
+
this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
|
|
638
|
+
},
|
|
639
|
+
})
|
|
640
|
+
], BiliAPI.prototype, "hasNewDynamic", null);
|
|
641
|
+
__decorate([
|
|
642
|
+
(0, retry_1.default)({
|
|
643
|
+
attempts: 3,
|
|
644
|
+
onFailure(error, attempts) {
|
|
645
|
+
this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
|
|
646
|
+
},
|
|
647
|
+
})
|
|
648
|
+
], BiliAPI.prototype, "follow", null);
|
|
649
|
+
__decorate([
|
|
650
|
+
(0, retry_1.default)({
|
|
651
|
+
attempts: 3,
|
|
652
|
+
onFailure(error, attempts) {
|
|
653
|
+
this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
|
|
654
|
+
},
|
|
655
|
+
})
|
|
656
|
+
], BiliAPI.prototype, "getRelationGroupDetail", null);
|
|
657
|
+
__decorate([
|
|
658
|
+
(0, retry_1.default)({
|
|
659
|
+
attempts: 3,
|
|
660
|
+
onFailure(error, attempts) {
|
|
661
|
+
this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
|
|
662
|
+
},
|
|
663
|
+
})
|
|
664
|
+
], BiliAPI.prototype, "getCookieInfo", null);
|
|
665
|
+
__decorate([
|
|
666
|
+
(0, retry_1.default)({
|
|
667
|
+
attempts: 3,
|
|
668
|
+
onFailure(error, attempts) {
|
|
669
|
+
this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
|
|
670
|
+
},
|
|
671
|
+
})
|
|
672
|
+
], BiliAPI.prototype, "getUserInfo", null);
|
|
673
|
+
__decorate([
|
|
674
|
+
(0, retry_1.default)({
|
|
675
|
+
attempts: 3,
|
|
676
|
+
onFailure(error, attempts) {
|
|
677
|
+
this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
|
|
678
|
+
},
|
|
679
|
+
})
|
|
680
|
+
], BiliAPI.prototype, "getWbiKeys", null);
|
|
681
|
+
__decorate([
|
|
682
|
+
(0, retry_1.default)({
|
|
683
|
+
attempts: 3,
|
|
684
|
+
onFailure(error, attempts) {
|
|
685
|
+
this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
|
|
686
|
+
},
|
|
687
|
+
})
|
|
688
|
+
], BiliAPI.prototype, "getMyselfInfo", null);
|
|
689
|
+
__decorate([
|
|
690
|
+
(0, retry_1.default)({
|
|
691
|
+
attempts: 3,
|
|
692
|
+
onFailure(error, attempts) {
|
|
693
|
+
this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
|
|
694
|
+
},
|
|
695
|
+
})
|
|
696
|
+
], BiliAPI.prototype, "getLoginQRCode", null);
|
|
697
|
+
__decorate([
|
|
698
|
+
(0, retry_1.default)({
|
|
699
|
+
attempts: 3,
|
|
700
|
+
onFailure(error, attempts) {
|
|
701
|
+
this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
|
|
702
|
+
},
|
|
703
|
+
})
|
|
704
|
+
], BiliAPI.prototype, "getLoginStatus", null);
|
|
705
|
+
__decorate([
|
|
706
|
+
(0, retry_1.default)({
|
|
707
|
+
attempts: 3,
|
|
708
|
+
onFailure(error, attempts) {
|
|
709
|
+
this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
|
|
710
|
+
},
|
|
711
|
+
})
|
|
712
|
+
], BiliAPI.prototype, "getLiveRoomInfo", null);
|
|
713
|
+
__decorate([
|
|
714
|
+
(0, retry_1.default)({
|
|
715
|
+
attempts: 3,
|
|
716
|
+
onFailure(error, attempts) {
|
|
717
|
+
this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
|
|
718
|
+
},
|
|
719
|
+
})
|
|
720
|
+
], BiliAPI.prototype, "getMasterInfo", null);
|
|
646
721
|
(function (BiliAPI) {
|
|
647
722
|
BiliAPI.Config = koishi_1.Schema.object({
|
|
648
723
|
userAgent: koishi_1.Schema.string(),
|
package/lib/blive.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ declare module 'koishi' {
|
|
|
7
7
|
}
|
|
8
8
|
declare class BLive extends Service {
|
|
9
9
|
static inject: string[];
|
|
10
|
+
private blConfig;
|
|
10
11
|
private listenerRecord;
|
|
11
12
|
private timerRecord;
|
|
12
|
-
constructor(ctx: Context);
|
|
13
|
+
constructor(ctx: Context, config: BLive.Config);
|
|
13
14
|
protected stop(): Awaitable<void>;
|
|
14
|
-
startLiveRoomListener(roomId: string, handler: MsgHandler,
|
|
15
|
+
startLiveRoomListener(roomId: string, handler: MsgHandler, danmakuPushTime: () => void): Promise<void>;
|
|
15
16
|
closeListener(roomId: string): void;
|
|
16
17
|
}
|
|
17
18
|
declare namespace BLive {
|
package/lib/blive.js
CHANGED
|
@@ -5,11 +5,16 @@ const blive_message_listener_1 = require("blive-message-listener");
|
|
|
5
5
|
class BLive extends koishi_1.Service {
|
|
6
6
|
// 必要服务
|
|
7
7
|
static inject = ['ba'];
|
|
8
|
+
// 配置
|
|
9
|
+
blConfig;
|
|
8
10
|
// 定义类属性
|
|
9
11
|
listenerRecord = {};
|
|
10
12
|
timerRecord = {};
|
|
11
|
-
constructor(ctx) {
|
|
13
|
+
constructor(ctx, config) {
|
|
14
|
+
// Extends super
|
|
12
15
|
super(ctx, 'bl');
|
|
16
|
+
// 将config赋值给类属性
|
|
17
|
+
this.blConfig = config;
|
|
13
18
|
}
|
|
14
19
|
// 注册插件dispose逻辑
|
|
15
20
|
stop() {
|
|
@@ -18,7 +23,7 @@ class BLive extends koishi_1.Service {
|
|
|
18
23
|
this.closeListener(key);
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
async startLiveRoomListener(roomId, handler,
|
|
26
|
+
async startLiveRoomListener(roomId, handler, danmakuPushTime) {
|
|
22
27
|
// 获取cookieStr
|
|
23
28
|
const cookiesStr = await this.ctx.ba.getCookiesForHeader();
|
|
24
29
|
// 获取自身信息
|
|
@@ -33,18 +38,20 @@ class BLive extends koishi_1.Service {
|
|
|
33
38
|
}
|
|
34
39
|
});
|
|
35
40
|
// 默认30s推送一次弹幕消息到群组并将dispose函数保存到Record中
|
|
36
|
-
this.timerRecord[roomId] = this.ctx.setInterval(
|
|
41
|
+
this.timerRecord[roomId] = this.ctx.setInterval(danmakuPushTime, this.blConfig.danmakuPushTime * 1000 * 60);
|
|
42
|
+
// logger
|
|
43
|
+
this.logger.info(`${roomId}直播间弹幕监听已开启`);
|
|
37
44
|
}
|
|
38
45
|
closeListener(roomId) {
|
|
39
46
|
// 判断直播间监听器是否关闭
|
|
40
47
|
if (!this.listenerRecord || !this.listenerRecord[roomId] || !this.listenerRecord[roomId].closed) {
|
|
41
48
|
// 输出logger
|
|
42
|
-
this.logger.info(
|
|
49
|
+
this.logger.info(`${roomId}直播间弹幕监听器无需关闭`);
|
|
43
50
|
}
|
|
44
51
|
// 判断消息发送定时器是否关闭
|
|
45
52
|
if (!this.timerRecord || !this.timerRecord[roomId]) {
|
|
46
53
|
// 输出logger
|
|
47
|
-
this.logger.info(
|
|
54
|
+
this.logger.info(`${roomId}直播间消息发送定时器无需关闭`);
|
|
48
55
|
}
|
|
49
56
|
// 关闭直播间监听器
|
|
50
57
|
this.listenerRecord[roomId].close();
|
|
@@ -57,12 +64,12 @@ class BLive extends koishi_1.Service {
|
|
|
57
64
|
// 删除消息发送定时器
|
|
58
65
|
delete this.timerRecord[roomId];
|
|
59
66
|
// 输出logger
|
|
60
|
-
this.logger.info(
|
|
67
|
+
this.logger.info(`${roomId}直播间弹幕监听已关闭`);
|
|
61
68
|
// 直接返回
|
|
62
69
|
return;
|
|
63
70
|
}
|
|
64
71
|
// 未关闭成功
|
|
65
|
-
this.logger.warn(
|
|
72
|
+
this.logger.warn(`${roomId}直播间弹幕监听未成功关闭`);
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|