koishi-plugin-bilibili-notify 3.0.0-alpha.6 → 3.0.0-alpha.7
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 +155 -186
- package/lib/comRegister.js +66 -57
- package/lib/utils/retry.d.ts +2 -0
- package/lib/utils/retry.js +26 -0
- package/package.json +1 -1
- package/readme.md +1 -0
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,15 +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
|
-
console.warn(e);
|
|
302
|
-
throw new Error('网络异常,本次请求失败!');
|
|
303
|
-
}
|
|
232
|
+
const wbi = await this.getWbi({ mid });
|
|
233
|
+
const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
|
|
234
|
+
return data;
|
|
304
235
|
}
|
|
305
236
|
// 获取最新的 img_key 和 sub_key
|
|
306
237
|
async getWbiKeys() {
|
|
@@ -312,49 +243,24 @@ class BiliAPI extends koishi_1.Service {
|
|
|
312
243
|
};
|
|
313
244
|
}
|
|
314
245
|
async getMyselfInfo() {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return data;
|
|
318
|
-
}
|
|
319
|
-
catch (e) {
|
|
320
|
-
throw new Error('网络异常,本次请求失败!');
|
|
321
|
-
}
|
|
246
|
+
const { data } = await this.client.get(GET_MYSELF_INFO);
|
|
247
|
+
return data;
|
|
322
248
|
}
|
|
323
249
|
async getLoginQRCode() {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return data;
|
|
327
|
-
}
|
|
328
|
-
catch (e) {
|
|
329
|
-
throw new Error('网络异常,本次请求失败!');
|
|
330
|
-
}
|
|
250
|
+
const { data } = await this.client.get(GET_LOGIN_QRCODE);
|
|
251
|
+
return data;
|
|
331
252
|
}
|
|
332
253
|
async getLoginStatus(qrcodeKey) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return data;
|
|
336
|
-
}
|
|
337
|
-
catch (e) {
|
|
338
|
-
throw new Error('网络异常,本次请求失败!');
|
|
339
|
-
}
|
|
254
|
+
const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
|
|
255
|
+
return data;
|
|
340
256
|
}
|
|
341
257
|
async getLiveRoomInfo(roomId) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return data;
|
|
345
|
-
}
|
|
346
|
-
catch (e) {
|
|
347
|
-
throw new Error('网络异常,本次请求失败!');
|
|
348
|
-
}
|
|
258
|
+
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
|
|
259
|
+
return data;
|
|
349
260
|
}
|
|
350
261
|
async getMasterInfo(mid) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return data;
|
|
354
|
-
}
|
|
355
|
-
catch (e) {
|
|
356
|
-
throw new Error('网络异常,本次请求失败!');
|
|
357
|
-
}
|
|
262
|
+
const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
|
|
263
|
+
return data;
|
|
358
264
|
}
|
|
359
265
|
disposeNotifier() { if (this.loginNotifier)
|
|
360
266
|
this.loginNotifier.dispose(); }
|
|
@@ -644,6 +550,69 @@ class BiliAPI extends koishi_1.Service {
|
|
|
644
550
|
// 没有问题,cookies已更新完成
|
|
645
551
|
}
|
|
646
552
|
}
|
|
553
|
+
__decorate([
|
|
554
|
+
(0, retry_1.default)()
|
|
555
|
+
], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
|
|
556
|
+
__decorate([
|
|
557
|
+
(0, retry_1.default)()
|
|
558
|
+
], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
|
|
559
|
+
__decorate([
|
|
560
|
+
(0, retry_1.default)()
|
|
561
|
+
], BiliAPI.prototype, "getServerUTCTime", null);
|
|
562
|
+
__decorate([
|
|
563
|
+
(0, retry_1.default)()
|
|
564
|
+
], BiliAPI.prototype, "getTimeNow", null);
|
|
565
|
+
__decorate([
|
|
566
|
+
(0, retry_1.default)()
|
|
567
|
+
], BiliAPI.prototype, "getAllGroup", null);
|
|
568
|
+
__decorate([
|
|
569
|
+
(0, retry_1.default)()
|
|
570
|
+
], BiliAPI.prototype, "removeUserFromGroup", null);
|
|
571
|
+
__decorate([
|
|
572
|
+
(0, retry_1.default)()
|
|
573
|
+
], BiliAPI.prototype, "copyUserToGroup", null);
|
|
574
|
+
__decorate([
|
|
575
|
+
(0, retry_1.default)()
|
|
576
|
+
], BiliAPI.prototype, "getUserSpaceDynamic", null);
|
|
577
|
+
__decorate([
|
|
578
|
+
(0, retry_1.default)()
|
|
579
|
+
], BiliAPI.prototype, "createGroup", null);
|
|
580
|
+
__decorate([
|
|
581
|
+
(0, retry_1.default)()
|
|
582
|
+
], BiliAPI.prototype, "getAllDynamic", null);
|
|
583
|
+
__decorate([
|
|
584
|
+
(0, retry_1.default)()
|
|
585
|
+
], BiliAPI.prototype, "hasNewDynamic", null);
|
|
586
|
+
__decorate([
|
|
587
|
+
(0, retry_1.default)()
|
|
588
|
+
], BiliAPI.prototype, "follow", null);
|
|
589
|
+
__decorate([
|
|
590
|
+
(0, retry_1.default)()
|
|
591
|
+
], BiliAPI.prototype, "getRelationGroupDetail", null);
|
|
592
|
+
__decorate([
|
|
593
|
+
(0, retry_1.default)()
|
|
594
|
+
], BiliAPI.prototype, "getCookieInfo", null);
|
|
595
|
+
__decorate([
|
|
596
|
+
(0, retry_1.default)()
|
|
597
|
+
], BiliAPI.prototype, "getUserInfo", null);
|
|
598
|
+
__decorate([
|
|
599
|
+
(0, retry_1.default)()
|
|
600
|
+
], BiliAPI.prototype, "getWbiKeys", null);
|
|
601
|
+
__decorate([
|
|
602
|
+
(0, retry_1.default)()
|
|
603
|
+
], BiliAPI.prototype, "getMyselfInfo", null);
|
|
604
|
+
__decorate([
|
|
605
|
+
(0, retry_1.default)()
|
|
606
|
+
], BiliAPI.prototype, "getLoginQRCode", null);
|
|
607
|
+
__decorate([
|
|
608
|
+
(0, retry_1.default)()
|
|
609
|
+
], BiliAPI.prototype, "getLoginStatus", null);
|
|
610
|
+
__decorate([
|
|
611
|
+
(0, retry_1.default)()
|
|
612
|
+
], BiliAPI.prototype, "getLiveRoomInfo", null);
|
|
613
|
+
__decorate([
|
|
614
|
+
(0, retry_1.default)()
|
|
615
|
+
], BiliAPI.prototype, "getMasterInfo", null);
|
|
647
616
|
(function (BiliAPI) {
|
|
648
617
|
BiliAPI.Config = koishi_1.Schema.object({
|
|
649
618
|
userAgent: koishi_1.Schema.string(),
|
package/lib/comRegister.js
CHANGED
|
@@ -439,23 +439,23 @@ class ComRegister {
|
|
|
439
439
|
this.logger.error('bili sub指令 getMasterInfo() 发生了错误,错误为:' + e.message);
|
|
440
440
|
return '订阅出错啦,请重试';
|
|
441
441
|
}
|
|
442
|
+
const liveDetectModeSelector = {
|
|
443
|
+
API: async () => {
|
|
444
|
+
// 判断是否已开启直播检测
|
|
445
|
+
if (!this.liveDispose) { // 未开启直播检测
|
|
446
|
+
// 开启直播检测并保存销毁函数
|
|
447
|
+
this.liveDispose = await this.liveDetectWithAPI();
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
WS: async () => {
|
|
451
|
+
// 连接到服务器
|
|
452
|
+
await this.liveDetectWithListener(roomId, target);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
442
455
|
// 订阅直播
|
|
443
456
|
if (liveMsg) {
|
|
444
457
|
// 判断直播订阅方式
|
|
445
|
-
|
|
446
|
-
case "API": {
|
|
447
|
-
// 判断是否已开启直播检测
|
|
448
|
-
if (!this.liveDispose) { // 未开启直播检测
|
|
449
|
-
// 开启直播检测并保存销毁函数
|
|
450
|
-
this.liveDispose = await this.liveDetectWithAPI();
|
|
451
|
-
}
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
case "WS": {
|
|
455
|
-
// 连接到服务器
|
|
456
|
-
await this.liveDetectWithListener(roomId, target);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
458
|
+
await liveDetectModeSelector[this.config.liveDetectMode]();
|
|
459
459
|
// 发送订阅消息通知
|
|
460
460
|
await session.send(`订阅${userData.info.uname}直播通知`);
|
|
461
461
|
}
|
|
@@ -463,6 +463,7 @@ class ComRegister {
|
|
|
463
463
|
if (dynamicMsg) {
|
|
464
464
|
// 判断是否开启动态监测
|
|
465
465
|
if (!this.dynamicDispose) {
|
|
466
|
+
// 开启动态监测
|
|
466
467
|
this.enableDynamicDetect();
|
|
467
468
|
}
|
|
468
469
|
// 发送订阅消息通知
|
|
@@ -1392,9 +1393,15 @@ class ComRegister {
|
|
|
1392
1393
|
const currentLiveDanmakuArr = [];
|
|
1393
1394
|
const temporaryLiveDanmakuArr = [];
|
|
1394
1395
|
// 处理target
|
|
1396
|
+
// 定义channelIdArr总长度
|
|
1397
|
+
let channelIdArrLen = 0;
|
|
1395
1398
|
// 找到频道/群组对应的
|
|
1396
1399
|
const danmakuPushTargetArr = target.map(channel => {
|
|
1400
|
+
// 获取符合条件的target
|
|
1397
1401
|
const liveDanmakuArr = channel.channelIdArr.filter(channelId => channelId.liveDanmaku);
|
|
1402
|
+
// 将当前liveDanmakuArr的长度+到channelIdArrLen中
|
|
1403
|
+
channelIdArrLen += liveDanmakuArr.length;
|
|
1404
|
+
// 返回符合的target
|
|
1398
1405
|
return {
|
|
1399
1406
|
channelIdArr: liveDanmakuArr,
|
|
1400
1407
|
platform: channel.platform
|
|
@@ -1422,7 +1429,7 @@ class ComRegister {
|
|
|
1422
1429
|
// 定义弹幕推送函数
|
|
1423
1430
|
const danmakuPushFunc = () => {
|
|
1424
1431
|
// 判断数组是否有内容
|
|
1425
|
-
if (
|
|
1432
|
+
if (channelIdArrLen > 0 && temporaryLiveDanmakuArr.length > 0) {
|
|
1426
1433
|
// 发送消息
|
|
1427
1434
|
this.sendMsg(danmakuPushTargetArr, temporaryLiveDanmakuArr.join('\n'));
|
|
1428
1435
|
// 将临时消息数组清空
|
|
@@ -1735,23 +1742,24 @@ class ComRegister {
|
|
|
1735
1742
|
// 发送提示
|
|
1736
1743
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1737
1744
|
}
|
|
1738
|
-
//
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
//
|
|
1744
|
-
|
|
1745
|
-
// 开启直播检测并保存销毁函数
|
|
1746
|
-
this.liveDispose = await this.liveDetectWithAPI();
|
|
1747
|
-
}
|
|
1748
|
-
break;
|
|
1749
|
-
}
|
|
1750
|
-
case "WS": {
|
|
1751
|
-
// 连接到服务器
|
|
1752
|
-
await this.liveDetectWithListener(data.live_room.roomid, sub.target);
|
|
1745
|
+
//
|
|
1746
|
+
const liveDetectModeSelector = {
|
|
1747
|
+
API: async () => {
|
|
1748
|
+
// 判断是否已开启直播检测
|
|
1749
|
+
if (!this.liveDispose) { // 未开启直播检测
|
|
1750
|
+
// 开启直播检测并保存销毁函数
|
|
1751
|
+
this.liveDispose = await this.liveDetectWithAPI();
|
|
1753
1752
|
}
|
|
1753
|
+
},
|
|
1754
|
+
WS: async () => {
|
|
1755
|
+
// 连接到服务器
|
|
1756
|
+
await this.liveDetectWithListener(data.live_room.roomid, sub.target);
|
|
1754
1757
|
}
|
|
1758
|
+
};
|
|
1759
|
+
// 判断是否订阅直播
|
|
1760
|
+
if (sub.live) {
|
|
1761
|
+
// 启动直播监测
|
|
1762
|
+
await liveDetectModeSelector[this.config.liveDetectMode]();
|
|
1755
1763
|
}
|
|
1756
1764
|
}
|
|
1757
1765
|
// 在B站中订阅该对象
|
|
@@ -1872,36 +1880,37 @@ class ComRegister {
|
|
|
1872
1880
|
dynamic: sub.dynamic === 1 ? true : false,
|
|
1873
1881
|
liveDispose: null
|
|
1874
1882
|
};
|
|
1875
|
-
//
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
//
|
|
1881
|
-
|
|
1882
|
-
// 开启直播检测并保存销毁函数
|
|
1883
|
-
this.liveDispose = await this.liveDetectWithAPI();
|
|
1884
|
-
}
|
|
1885
|
-
break;
|
|
1883
|
+
// 定义直播模式监测器
|
|
1884
|
+
const liveDetectModeSelector = {
|
|
1885
|
+
API: async () => {
|
|
1886
|
+
// 判断是否已开启直播检测
|
|
1887
|
+
if (!this.liveDispose) { // 未开启直播检测
|
|
1888
|
+
// 开启直播检测并保存销毁函数
|
|
1889
|
+
this.liveDispose = await this.liveDetectWithAPI();
|
|
1886
1890
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1891
|
+
},
|
|
1892
|
+
WS: async () => {
|
|
1893
|
+
// 判断订阅直播数是否超过限制
|
|
1894
|
+
if (!this.config.unlockSubLimits && liveSubNum >= 3) {
|
|
1895
|
+
// 将live改为false
|
|
1896
|
+
subManagerItem.live = false;
|
|
1897
|
+
// log
|
|
1898
|
+
this.logger.warn(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
1899
|
+
// 发送错误消息
|
|
1900
|
+
await this.sendPrivateMsg(`UID:${sub.uid} 订阅直播数超过限制,自动取消订阅`);
|
|
1901
|
+
}
|
|
1902
|
+
else {
|
|
1903
|
+
// 直播订阅数+1
|
|
1904
|
+
liveSubNum++;
|
|
1905
|
+
// 订阅直播,开始循环检测
|
|
1906
|
+
await this.liveDetectWithListener(sub.room_id, target);
|
|
1903
1907
|
}
|
|
1904
1908
|
}
|
|
1909
|
+
};
|
|
1910
|
+
// 判断是否订阅直播
|
|
1911
|
+
if (sub.live) {
|
|
1912
|
+
// 启动直播监测
|
|
1913
|
+
await liveDetectModeSelector[this.config.liveDetectMode]();
|
|
1905
1914
|
}
|
|
1906
1915
|
// 保存新订阅对象
|
|
1907
1916
|
this.subManager.push(subManagerItem);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
function Retry(attempts = 3, onFailure) {
|
|
6
|
+
return function (target, propertyKey, descriptor) {
|
|
7
|
+
const originalMethod = descriptor.value;
|
|
8
|
+
descriptor.value = async function (...args) {
|
|
9
|
+
let lastError;
|
|
10
|
+
for (let i = 0; i < attempts; i++) {
|
|
11
|
+
try {
|
|
12
|
+
return await originalMethod.apply(this, args);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
lastError = error;
|
|
16
|
+
if (onFailure) {
|
|
17
|
+
await onFailure.call(this, lastError, i + 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
throw lastError;
|
|
22
|
+
};
|
|
23
|
+
return descriptor;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.default = Retry;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -218,6 +218,7 @@
|
|
|
218
218
|
- ver 3.0.0-alpha.4 修复:使用了手动订阅,数据库中的订阅不会加载
|
|
219
219
|
- ver 3.0.0-alpha.5 修复:订阅的直播开播后,未开启弹幕推送会一直报错、主播开播推送下播卡片,直播时长显示NaN; 新增:直播检测模式选项; 优化:下播卡片内容
|
|
220
220
|
- ver 3.0.0-alpha.6 修复:连续发送两次直播中通知卡片; 优化:下播通知卡片
|
|
221
|
+
- ver 3.0.0-alpha.7 修复:`ver 3.0.0-alpha.5` 未能解决的bug; 优化:ba代码结构
|
|
221
222
|
|
|
222
223
|
## 交流群
|
|
223
224
|
|