koishi-plugin-bilibili-notify 3.3.1-rc.0 → 3.3.1-rc.1
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/index.js +82 -78
- package/lib/index.mjs +82 -78
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/index.js
CHANGED
|
@@ -366,13 +366,14 @@ var ComRegister = class {
|
|
|
366
366
|
ctx;
|
|
367
367
|
subManager;
|
|
368
368
|
dynamicTimelineManager;
|
|
369
|
-
|
|
369
|
+
liveAPIManager;
|
|
370
|
+
liveWSManager;
|
|
370
371
|
liveMsgManager;
|
|
371
372
|
pushArrMap;
|
|
372
373
|
loginDBData;
|
|
373
374
|
privateBot;
|
|
374
375
|
dynamicJob;
|
|
375
|
-
|
|
376
|
+
liveAPIJob;
|
|
376
377
|
_jieba = __node_rs_jieba.Jieba.withDict(__node_rs_jieba_dict.dict);
|
|
377
378
|
stopwords;
|
|
378
379
|
reciveSubTimes = 0;
|
|
@@ -410,7 +411,7 @@ var ComRegister = class {
|
|
|
410
411
|
} catch (_) {
|
|
411
412
|
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
412
413
|
}
|
|
413
|
-
if (content.code !== 0) return await session.send("
|
|
414
|
+
if (content.code !== 0) return await session.send("出问题咯!");
|
|
414
415
|
qrcode.default.toBuffer(content.data.url, {
|
|
415
416
|
errorCorrectionLevel: "H",
|
|
416
417
|
type: "png",
|
|
@@ -674,7 +675,11 @@ var ComRegister = class {
|
|
|
674
675
|
this.ctx.on("dispose", () => {
|
|
675
676
|
if (this.loginTimer) this.loginTimer();
|
|
676
677
|
if (this.dynamicJob) this.dynamicJob.stop();
|
|
677
|
-
if (this.
|
|
678
|
+
if (this.liveAPIJob) this.liveAPIJob.stop();
|
|
679
|
+
for (const [roomId, timer] of this.liveWSManager) {
|
|
680
|
+
this.ctx["bilibili-notify-live"].closeListener(roomId);
|
|
681
|
+
if (timer) timer();
|
|
682
|
+
}
|
|
678
683
|
});
|
|
679
684
|
this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
|
|
680
685
|
if (this.reciveSubTimes >= 1) await this.ctx["bilibili-notify"].restartPlugin();
|
|
@@ -708,7 +713,7 @@ var ComRegister = class {
|
|
|
708
713
|
initManager() {
|
|
709
714
|
for (const [uid, sub] of this.subManager) {
|
|
710
715
|
if (sub.dynamic) this.dynamicTimelineManager.set(uid, Math.floor(luxon.DateTime.now().toSeconds()));
|
|
711
|
-
if (sub.live) this.
|
|
716
|
+
if (sub.live) this.liveAPIManager.set(uid, {
|
|
712
717
|
roomId: sub.roomId,
|
|
713
718
|
live: false,
|
|
714
719
|
liveRoomInfo: void 0,
|
|
@@ -723,7 +728,8 @@ var ComRegister = class {
|
|
|
723
728
|
initAllManager() {
|
|
724
729
|
this.subManager = new Map();
|
|
725
730
|
this.dynamicTimelineManager = new Map();
|
|
726
|
-
this.
|
|
731
|
+
this.liveAPIManager = new Map();
|
|
732
|
+
this.liveWSManager = new Map();
|
|
727
733
|
this.liveMsgManager = new Map();
|
|
728
734
|
this.pushArrMap = new Map();
|
|
729
735
|
}
|
|
@@ -942,25 +948,21 @@ var ComRegister = class {
|
|
|
942
948
|
if (!content) return;
|
|
943
949
|
if (content.code !== 0) switch (content.code) {
|
|
944
950
|
case -101: {
|
|
945
|
-
this.logger.error("
|
|
946
|
-
await this.sendPrivateMsg("
|
|
951
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
952
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
947
953
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
948
954
|
break;
|
|
949
955
|
}
|
|
950
956
|
case -352: {
|
|
951
|
-
this.logger.error("
|
|
952
|
-
await this.sendPrivateMsg("
|
|
957
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
958
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
953
959
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
954
960
|
break;
|
|
955
961
|
}
|
|
956
|
-
case 4101128:
|
|
957
|
-
case 4101129: {
|
|
958
|
-
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
959
|
-
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
960
|
-
break;
|
|
961
|
-
}
|
|
962
962
|
default: {
|
|
963
|
-
|
|
963
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
964
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
965
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
964
966
|
break;
|
|
965
967
|
}
|
|
966
968
|
}
|
|
@@ -1041,25 +1043,21 @@ var ComRegister = class {
|
|
|
1041
1043
|
if (!content) return;
|
|
1042
1044
|
if (content.code !== 0) switch (content.code) {
|
|
1043
1045
|
case -101: {
|
|
1044
|
-
this.logger.error("
|
|
1045
|
-
await this.sendPrivateMsg("
|
|
1046
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
1047
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
1046
1048
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1047
1049
|
break;
|
|
1048
1050
|
}
|
|
1049
1051
|
case -352: {
|
|
1050
|
-
this.logger.error("
|
|
1051
|
-
await this.sendPrivateMsg("
|
|
1052
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1053
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1052
1054
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1053
1055
|
break;
|
|
1054
1056
|
}
|
|
1055
|
-
case 4101128:
|
|
1056
|
-
case 4101129: {
|
|
1057
|
-
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
1058
|
-
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
1059
|
-
break;
|
|
1060
|
-
}
|
|
1061
1057
|
default: {
|
|
1062
|
-
|
|
1058
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1059
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1060
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1063
1061
|
break;
|
|
1064
1062
|
}
|
|
1065
1063
|
}
|
|
@@ -1306,7 +1304,10 @@ var ComRegister = class {
|
|
|
1306
1304
|
masterInfo,
|
|
1307
1305
|
cardStyle: sub.customCardStyle
|
|
1308
1306
|
}, sub.uid, liveStartMsg);
|
|
1309
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1307
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1308
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1309
|
+
this.liveWSManager.set(roomId, pushAtTimeTimer);
|
|
1310
|
+
}
|
|
1310
1311
|
},
|
|
1311
1312
|
onLiveEnd: async () => {
|
|
1312
1313
|
liveStatus = false;
|
|
@@ -1342,29 +1343,32 @@ var ComRegister = class {
|
|
|
1342
1343
|
masterInfo,
|
|
1343
1344
|
cardStyle: sub.customCardStyle
|
|
1344
1345
|
}, sub.uid, liveMsg);
|
|
1345
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1346
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1347
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1348
|
+
this.liveWSManager.set(roomId, pushAtTimeTimer);
|
|
1349
|
+
}
|
|
1346
1350
|
liveStatus = true;
|
|
1347
1351
|
}
|
|
1348
1352
|
}
|
|
1349
1353
|
async liveDetectWithAPI() {
|
|
1350
|
-
const useMasterAndLiveRoomInfo = async (liveType,
|
|
1354
|
+
const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
|
|
1351
1355
|
let flag = true;
|
|
1352
|
-
|
|
1356
|
+
LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
|
|
1353
1357
|
flag = false;
|
|
1354
1358
|
return null;
|
|
1355
1359
|
});
|
|
1356
|
-
if (!flag || !
|
|
1360
|
+
if (!flag || !LiveAPIStatus.liveRoomInfo?.uid) {
|
|
1357
1361
|
flag = false;
|
|
1358
1362
|
return flag;
|
|
1359
1363
|
}
|
|
1360
|
-
|
|
1364
|
+
LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
|
|
1361
1365
|
flag = false;
|
|
1362
1366
|
return null;
|
|
1363
1367
|
});
|
|
1364
1368
|
return flag;
|
|
1365
1369
|
};
|
|
1366
1370
|
const uids = [];
|
|
1367
|
-
for (const [uid] of this.
|
|
1371
|
+
for (const [uid] of this.liveAPIManager.entries()) uids.push(uid);
|
|
1368
1372
|
const useLiveInfo = async () => {
|
|
1369
1373
|
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1370
1374
|
return void 0;
|
|
@@ -1378,20 +1382,20 @@ var ComRegister = class {
|
|
|
1378
1382
|
const data = await useLiveInfo();
|
|
1379
1383
|
for (const item of Object.values(data)) {
|
|
1380
1384
|
const uid = item.uid.toString();
|
|
1381
|
-
const
|
|
1385
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1382
1386
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1383
1387
|
const sub = this.subManager.get(uid);
|
|
1384
1388
|
if (item.live_status === 1) {
|
|
1385
|
-
|
|
1386
|
-
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast,
|
|
1387
|
-
if (!
|
|
1388
|
-
|
|
1389
|
-
|
|
1389
|
+
LiveAPIStatus.live = true;
|
|
1390
|
+
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, LiveAPIStatus);
|
|
1391
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1392
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1393
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1390
1394
|
}
|
|
1391
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1395
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${LiveAPIStatus.liveRoomInfo.short_id === 0 ? LiveAPIStatus.liveRoomInfo.room_id : LiveAPIStatus.liveRoomInfo.short_id}`);
|
|
1392
1396
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1393
|
-
liveRoomInfo:
|
|
1394
|
-
masterInfo:
|
|
1397
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1398
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1395
1399
|
cardStyle: sub.customCardStyle
|
|
1396
1400
|
}, uid, liveMsg);
|
|
1397
1401
|
}
|
|
@@ -1400,74 +1404,74 @@ var ComRegister = class {
|
|
|
1400
1404
|
const data$1 = await useLiveInfo();
|
|
1401
1405
|
for (const item of Object.values(data$1)) {
|
|
1402
1406
|
const uid = item.uid.toString();
|
|
1403
|
-
const
|
|
1407
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1404
1408
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1405
1409
|
const sub = this.subManager.get(uid);
|
|
1406
1410
|
if (!sub) return;
|
|
1407
1411
|
switch (item.live_status) {
|
|
1408
1412
|
case 0:
|
|
1409
1413
|
case 2: {
|
|
1410
|
-
if (
|
|
1411
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1414
|
+
if (LiveAPIStatus.live === true) {
|
|
1415
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1412
1416
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1413
1417
|
return await this.sendPrivateMsgAndStopService();
|
|
1414
1418
|
}
|
|
1415
|
-
if (
|
|
1416
|
-
|
|
1417
|
-
|
|
1419
|
+
if (LiveAPIStatus.liveStartTimeInit) {
|
|
1420
|
+
LiveAPIStatus.liveRoomInfo.live_time = LiveAPIStatus.liveStartTime;
|
|
1421
|
+
LiveAPIStatus.liveStartTimeInit = false;
|
|
1418
1422
|
}
|
|
1419
1423
|
const followerChange = (() => {
|
|
1420
|
-
const liveFollowerChangeNum =
|
|
1424
|
+
const liveFollowerChangeNum = LiveAPIStatus.masterInfo.liveFollowerChange;
|
|
1421
1425
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1422
1426
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1423
1427
|
})();
|
|
1424
|
-
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name",
|
|
1428
|
+
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
|
|
1425
1429
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1426
|
-
liveRoomInfo:
|
|
1427
|
-
masterInfo:
|
|
1430
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1431
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1428
1432
|
cardStyle: sub.customCardStyle
|
|
1429
1433
|
}, uid, liveEndMsg);
|
|
1430
|
-
|
|
1434
|
+
LiveAPIStatus.live = false;
|
|
1431
1435
|
}
|
|
1432
1436
|
break;
|
|
1433
1437
|
}
|
|
1434
1438
|
case 1: {
|
|
1435
|
-
if (
|
|
1436
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1439
|
+
if (LiveAPIStatus.live === false) {
|
|
1440
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1437
1441
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1438
1442
|
return await this.sendPrivateMsgAndStopService();
|
|
1439
1443
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
const follower =
|
|
1443
|
-
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name",
|
|
1444
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1445
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1446
|
+
const follower = LiveAPIStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(LiveAPIStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : LiveAPIStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1447
|
+
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${LiveAPIStatus.liveRoomInfo.short_id === 0 ? LiveAPIStatus.liveRoomInfo.room_id : LiveAPIStatus.liveRoomInfo.short_id}`);
|
|
1444
1448
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1445
|
-
liveRoomInfo:
|
|
1446
|
-
masterInfo:
|
|
1449
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1450
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1447
1451
|
cardStyle: sub.customCardStyle
|
|
1448
1452
|
}, uid, liveStartMsg);
|
|
1449
|
-
|
|
1453
|
+
LiveAPIStatus.live = true;
|
|
1450
1454
|
}
|
|
1451
|
-
if (
|
|
1452
|
-
if (
|
|
1453
|
-
|
|
1455
|
+
if (LiveAPIStatus.live === true) {
|
|
1456
|
+
if (LiveAPIStatus.push < this.config.pushTime * 60 * 60 / 30) {
|
|
1457
|
+
LiveAPIStatus.push++;
|
|
1454
1458
|
break;
|
|
1455
1459
|
}
|
|
1456
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast,
|
|
1460
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast, LiveAPIStatus)) {
|
|
1457
1461
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
|
|
1458
1462
|
return await this.sendPrivateMsgAndStopService();
|
|
1459
1463
|
}
|
|
1460
|
-
if (!
|
|
1461
|
-
|
|
1462
|
-
|
|
1464
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1465
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1466
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1463
1467
|
}
|
|
1464
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1468
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${LiveAPIStatus.liveRoomInfo.short_id === 0 ? LiveAPIStatus.liveRoomInfo.room_id : LiveAPIStatus.liveRoomInfo.short_id}`);
|
|
1465
1469
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1466
|
-
liveRoomInfo:
|
|
1467
|
-
masterInfo:
|
|
1470
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1471
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1468
1472
|
cardStyle: sub.customCardStyle
|
|
1469
1473
|
}, uid, liveMsg);
|
|
1470
|
-
|
|
1474
|
+
LiveAPIStatus.push = 0;
|
|
1471
1475
|
}
|
|
1472
1476
|
break;
|
|
1473
1477
|
}
|
|
@@ -1707,7 +1711,7 @@ var ComRegister = class {
|
|
|
1707
1711
|
}
|
|
1708
1712
|
checkIfLiveDetectIsNeeded() {
|
|
1709
1713
|
if (this.config.liveDetectType === "API") {
|
|
1710
|
-
if (this.
|
|
1714
|
+
if (this.liveAPIManager.size > 0) this.enableLiveDetect();
|
|
1711
1715
|
}
|
|
1712
1716
|
}
|
|
1713
1717
|
enableDynamicDetect() {
|
|
@@ -1716,9 +1720,9 @@ var ComRegister = class {
|
|
|
1716
1720
|
this.dynamicJob.start();
|
|
1717
1721
|
}
|
|
1718
1722
|
async enableLiveDetect() {
|
|
1719
|
-
this.
|
|
1723
|
+
this.liveAPIJob = new cron.CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
|
|
1720
1724
|
this.logger.info("直播监测已开启");
|
|
1721
|
-
this.
|
|
1725
|
+
this.liveAPIJob.start();
|
|
1722
1726
|
}
|
|
1723
1727
|
async checkIfIsLogin() {
|
|
1724
1728
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
package/lib/index.mjs
CHANGED
|
@@ -347,13 +347,14 @@ var ComRegister = class {
|
|
|
347
347
|
ctx;
|
|
348
348
|
subManager;
|
|
349
349
|
dynamicTimelineManager;
|
|
350
|
-
|
|
350
|
+
liveAPIManager;
|
|
351
|
+
liveWSManager;
|
|
351
352
|
liveMsgManager;
|
|
352
353
|
pushArrMap;
|
|
353
354
|
loginDBData;
|
|
354
355
|
privateBot;
|
|
355
356
|
dynamicJob;
|
|
356
|
-
|
|
357
|
+
liveAPIJob;
|
|
357
358
|
_jieba = Jieba.withDict(dict);
|
|
358
359
|
stopwords;
|
|
359
360
|
reciveSubTimes = 0;
|
|
@@ -391,7 +392,7 @@ var ComRegister = class {
|
|
|
391
392
|
} catch (_) {
|
|
392
393
|
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
393
394
|
}
|
|
394
|
-
if (content.code !== 0) return await session.send("
|
|
395
|
+
if (content.code !== 0) return await session.send("出问题咯!");
|
|
395
396
|
QRCode.toBuffer(content.data.url, {
|
|
396
397
|
errorCorrectionLevel: "H",
|
|
397
398
|
type: "png",
|
|
@@ -655,7 +656,11 @@ var ComRegister = class {
|
|
|
655
656
|
this.ctx.on("dispose", () => {
|
|
656
657
|
if (this.loginTimer) this.loginTimer();
|
|
657
658
|
if (this.dynamicJob) this.dynamicJob.stop();
|
|
658
|
-
if (this.
|
|
659
|
+
if (this.liveAPIJob) this.liveAPIJob.stop();
|
|
660
|
+
for (const [roomId, timer] of this.liveWSManager) {
|
|
661
|
+
this.ctx["bilibili-notify-live"].closeListener(roomId);
|
|
662
|
+
if (timer) timer();
|
|
663
|
+
}
|
|
659
664
|
});
|
|
660
665
|
this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
|
|
661
666
|
if (this.reciveSubTimes >= 1) await this.ctx["bilibili-notify"].restartPlugin();
|
|
@@ -689,7 +694,7 @@ var ComRegister = class {
|
|
|
689
694
|
initManager() {
|
|
690
695
|
for (const [uid, sub] of this.subManager) {
|
|
691
696
|
if (sub.dynamic) this.dynamicTimelineManager.set(uid, Math.floor(DateTime.now().toSeconds()));
|
|
692
|
-
if (sub.live) this.
|
|
697
|
+
if (sub.live) this.liveAPIManager.set(uid, {
|
|
693
698
|
roomId: sub.roomId,
|
|
694
699
|
live: false,
|
|
695
700
|
liveRoomInfo: void 0,
|
|
@@ -704,7 +709,8 @@ var ComRegister = class {
|
|
|
704
709
|
initAllManager() {
|
|
705
710
|
this.subManager = new Map();
|
|
706
711
|
this.dynamicTimelineManager = new Map();
|
|
707
|
-
this.
|
|
712
|
+
this.liveAPIManager = new Map();
|
|
713
|
+
this.liveWSManager = new Map();
|
|
708
714
|
this.liveMsgManager = new Map();
|
|
709
715
|
this.pushArrMap = new Map();
|
|
710
716
|
}
|
|
@@ -923,25 +929,21 @@ var ComRegister = class {
|
|
|
923
929
|
if (!content) return;
|
|
924
930
|
if (content.code !== 0) switch (content.code) {
|
|
925
931
|
case -101: {
|
|
926
|
-
this.logger.error("
|
|
927
|
-
await this.sendPrivateMsg("
|
|
932
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
933
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
928
934
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
929
935
|
break;
|
|
930
936
|
}
|
|
931
937
|
case -352: {
|
|
932
|
-
this.logger.error("
|
|
933
|
-
await this.sendPrivateMsg("
|
|
938
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
939
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
934
940
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
935
941
|
break;
|
|
936
942
|
}
|
|
937
|
-
case 4101128:
|
|
938
|
-
case 4101129: {
|
|
939
|
-
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
940
|
-
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
941
|
-
break;
|
|
942
|
-
}
|
|
943
943
|
default: {
|
|
944
|
-
|
|
944
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
945
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
946
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
945
947
|
break;
|
|
946
948
|
}
|
|
947
949
|
}
|
|
@@ -1022,25 +1024,21 @@ var ComRegister = class {
|
|
|
1022
1024
|
if (!content) return;
|
|
1023
1025
|
if (content.code !== 0) switch (content.code) {
|
|
1024
1026
|
case -101: {
|
|
1025
|
-
this.logger.error("
|
|
1026
|
-
await this.sendPrivateMsg("
|
|
1027
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
1028
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
1027
1029
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1028
1030
|
break;
|
|
1029
1031
|
}
|
|
1030
1032
|
case -352: {
|
|
1031
|
-
this.logger.error("
|
|
1032
|
-
await this.sendPrivateMsg("
|
|
1033
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1034
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1033
1035
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1034
1036
|
break;
|
|
1035
1037
|
}
|
|
1036
|
-
case 4101128:
|
|
1037
|
-
case 4101129: {
|
|
1038
|
-
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
1039
|
-
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
1040
|
-
break;
|
|
1041
|
-
}
|
|
1042
1038
|
default: {
|
|
1043
|
-
|
|
1039
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1040
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1041
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1044
1042
|
break;
|
|
1045
1043
|
}
|
|
1046
1044
|
}
|
|
@@ -1287,7 +1285,10 @@ var ComRegister = class {
|
|
|
1287
1285
|
masterInfo,
|
|
1288
1286
|
cardStyle: sub.customCardStyle
|
|
1289
1287
|
}, sub.uid, liveStartMsg);
|
|
1290
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1288
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1289
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1290
|
+
this.liveWSManager.set(roomId, pushAtTimeTimer);
|
|
1291
|
+
}
|
|
1291
1292
|
},
|
|
1292
1293
|
onLiveEnd: async () => {
|
|
1293
1294
|
liveStatus = false;
|
|
@@ -1323,29 +1324,32 @@ var ComRegister = class {
|
|
|
1323
1324
|
masterInfo,
|
|
1324
1325
|
cardStyle: sub.customCardStyle
|
|
1325
1326
|
}, sub.uid, liveMsg);
|
|
1326
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1327
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1328
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1329
|
+
this.liveWSManager.set(roomId, pushAtTimeTimer);
|
|
1330
|
+
}
|
|
1327
1331
|
liveStatus = true;
|
|
1328
1332
|
}
|
|
1329
1333
|
}
|
|
1330
1334
|
async liveDetectWithAPI() {
|
|
1331
|
-
const useMasterAndLiveRoomInfo = async (liveType,
|
|
1335
|
+
const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
|
|
1332
1336
|
let flag = true;
|
|
1333
|
-
|
|
1337
|
+
LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
|
|
1334
1338
|
flag = false;
|
|
1335
1339
|
return null;
|
|
1336
1340
|
});
|
|
1337
|
-
if (!flag || !
|
|
1341
|
+
if (!flag || !LiveAPIStatus.liveRoomInfo?.uid) {
|
|
1338
1342
|
flag = false;
|
|
1339
1343
|
return flag;
|
|
1340
1344
|
}
|
|
1341
|
-
|
|
1345
|
+
LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
|
|
1342
1346
|
flag = false;
|
|
1343
1347
|
return null;
|
|
1344
1348
|
});
|
|
1345
1349
|
return flag;
|
|
1346
1350
|
};
|
|
1347
1351
|
const uids = [];
|
|
1348
|
-
for (const [uid] of this.
|
|
1352
|
+
for (const [uid] of this.liveAPIManager.entries()) uids.push(uid);
|
|
1349
1353
|
const useLiveInfo = async () => {
|
|
1350
1354
|
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1351
1355
|
return void 0;
|
|
@@ -1359,20 +1363,20 @@ var ComRegister = class {
|
|
|
1359
1363
|
const data = await useLiveInfo();
|
|
1360
1364
|
for (const item of Object.values(data)) {
|
|
1361
1365
|
const uid = item.uid.toString();
|
|
1362
|
-
const
|
|
1366
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1363
1367
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1364
1368
|
const sub = this.subManager.get(uid);
|
|
1365
1369
|
if (item.live_status === 1) {
|
|
1366
|
-
|
|
1367
|
-
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast,
|
|
1368
|
-
if (!
|
|
1369
|
-
|
|
1370
|
-
|
|
1370
|
+
LiveAPIStatus.live = true;
|
|
1371
|
+
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, LiveAPIStatus);
|
|
1372
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1373
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1374
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1371
1375
|
}
|
|
1372
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1376
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${LiveAPIStatus.liveRoomInfo.short_id === 0 ? LiveAPIStatus.liveRoomInfo.room_id : LiveAPIStatus.liveRoomInfo.short_id}`);
|
|
1373
1377
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1374
|
-
liveRoomInfo:
|
|
1375
|
-
masterInfo:
|
|
1378
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1379
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1376
1380
|
cardStyle: sub.customCardStyle
|
|
1377
1381
|
}, uid, liveMsg);
|
|
1378
1382
|
}
|
|
@@ -1381,74 +1385,74 @@ var ComRegister = class {
|
|
|
1381
1385
|
const data$1 = await useLiveInfo();
|
|
1382
1386
|
for (const item of Object.values(data$1)) {
|
|
1383
1387
|
const uid = item.uid.toString();
|
|
1384
|
-
const
|
|
1388
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1385
1389
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1386
1390
|
const sub = this.subManager.get(uid);
|
|
1387
1391
|
if (!sub) return;
|
|
1388
1392
|
switch (item.live_status) {
|
|
1389
1393
|
case 0:
|
|
1390
1394
|
case 2: {
|
|
1391
|
-
if (
|
|
1392
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1395
|
+
if (LiveAPIStatus.live === true) {
|
|
1396
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1393
1397
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1394
1398
|
return await this.sendPrivateMsgAndStopService();
|
|
1395
1399
|
}
|
|
1396
|
-
if (
|
|
1397
|
-
|
|
1398
|
-
|
|
1400
|
+
if (LiveAPIStatus.liveStartTimeInit) {
|
|
1401
|
+
LiveAPIStatus.liveRoomInfo.live_time = LiveAPIStatus.liveStartTime;
|
|
1402
|
+
LiveAPIStatus.liveStartTimeInit = false;
|
|
1399
1403
|
}
|
|
1400
1404
|
const followerChange = (() => {
|
|
1401
|
-
const liveFollowerChangeNum =
|
|
1405
|
+
const liveFollowerChangeNum = LiveAPIStatus.masterInfo.liveFollowerChange;
|
|
1402
1406
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1403
1407
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1404
1408
|
})();
|
|
1405
|
-
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name",
|
|
1409
|
+
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
|
|
1406
1410
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1407
|
-
liveRoomInfo:
|
|
1408
|
-
masterInfo:
|
|
1411
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1412
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1409
1413
|
cardStyle: sub.customCardStyle
|
|
1410
1414
|
}, uid, liveEndMsg);
|
|
1411
|
-
|
|
1415
|
+
LiveAPIStatus.live = false;
|
|
1412
1416
|
}
|
|
1413
1417
|
break;
|
|
1414
1418
|
}
|
|
1415
1419
|
case 1: {
|
|
1416
|
-
if (
|
|
1417
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1420
|
+
if (LiveAPIStatus.live === false) {
|
|
1421
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1418
1422
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1419
1423
|
return await this.sendPrivateMsgAndStopService();
|
|
1420
1424
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
const follower =
|
|
1424
|
-
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name",
|
|
1425
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1426
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1427
|
+
const follower = LiveAPIStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(LiveAPIStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : LiveAPIStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1428
|
+
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${LiveAPIStatus.liveRoomInfo.short_id === 0 ? LiveAPIStatus.liveRoomInfo.room_id : LiveAPIStatus.liveRoomInfo.short_id}`);
|
|
1425
1429
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1426
|
-
liveRoomInfo:
|
|
1427
|
-
masterInfo:
|
|
1430
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1431
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1428
1432
|
cardStyle: sub.customCardStyle
|
|
1429
1433
|
}, uid, liveStartMsg);
|
|
1430
|
-
|
|
1434
|
+
LiveAPIStatus.live = true;
|
|
1431
1435
|
}
|
|
1432
|
-
if (
|
|
1433
|
-
if (
|
|
1434
|
-
|
|
1436
|
+
if (LiveAPIStatus.live === true) {
|
|
1437
|
+
if (LiveAPIStatus.push < this.config.pushTime * 60 * 60 / 30) {
|
|
1438
|
+
LiveAPIStatus.push++;
|
|
1435
1439
|
break;
|
|
1436
1440
|
}
|
|
1437
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast,
|
|
1441
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast, LiveAPIStatus)) {
|
|
1438
1442
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
|
|
1439
1443
|
return await this.sendPrivateMsgAndStopService();
|
|
1440
1444
|
}
|
|
1441
|
-
if (!
|
|
1442
|
-
|
|
1443
|
-
|
|
1445
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1446
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1447
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1444
1448
|
}
|
|
1445
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1449
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", LiveAPIStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(LiveAPIStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${LiveAPIStatus.liveRoomInfo.short_id === 0 ? LiveAPIStatus.liveRoomInfo.room_id : LiveAPIStatus.liveRoomInfo.short_id}`);
|
|
1446
1450
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1447
|
-
liveRoomInfo:
|
|
1448
|
-
masterInfo:
|
|
1451
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1452
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1449
1453
|
cardStyle: sub.customCardStyle
|
|
1450
1454
|
}, uid, liveMsg);
|
|
1451
|
-
|
|
1455
|
+
LiveAPIStatus.push = 0;
|
|
1452
1456
|
}
|
|
1453
1457
|
break;
|
|
1454
1458
|
}
|
|
@@ -1688,7 +1692,7 @@ var ComRegister = class {
|
|
|
1688
1692
|
}
|
|
1689
1693
|
checkIfLiveDetectIsNeeded() {
|
|
1690
1694
|
if (this.config.liveDetectType === "API") {
|
|
1691
|
-
if (this.
|
|
1695
|
+
if (this.liveAPIManager.size > 0) this.enableLiveDetect();
|
|
1692
1696
|
}
|
|
1693
1697
|
}
|
|
1694
1698
|
enableDynamicDetect() {
|
|
@@ -1697,9 +1701,9 @@ var ComRegister = class {
|
|
|
1697
1701
|
this.dynamicJob.start();
|
|
1698
1702
|
}
|
|
1699
1703
|
async enableLiveDetect() {
|
|
1700
|
-
this.
|
|
1704
|
+
this.liveAPIJob = new CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
|
|
1701
1705
|
this.logger.info("直播监测已开启");
|
|
1702
|
-
this.
|
|
1706
|
+
this.liveAPIJob.start();
|
|
1703
1707
|
}
|
|
1704
1708
|
async checkIfIsLogin() {
|
|
1705
1709
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -328,6 +328,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
328
328
|
> - ver 3.3.1-alpha.0 新增:弹幕词云自定义停用词、UP主弹幕词云开关; 优化:`liveSummary` 排版方式更加直观;
|
|
329
329
|
> - ver 3.3.1-alpha.1 优化:拆分 `wordcloud` 和 `liveSummary`,优化指令 `bili cap` 风控验证;
|
|
330
330
|
> - ver 3.3.1-rc.0 优化:代码结构,部分设置; 修复:启用高级订阅时,多次重载高级订阅插件会产生多个重复订阅;
|
|
331
|
+
> - ver 3.3.1-rc.1 优化:动态错误处理
|
|
331
332
|
|
|
332
333
|
## 交流群
|
|
333
334
|
|