koishi-plugin-bilibili-notify 3.3.1-rc.0 → 3.3.1-rc.2
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.d.mts +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +131 -112
- package/lib/index.mjs +131 -112
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/index.d.mts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -74,7 +74,7 @@ const BAConfigSchema = koishi.Schema.object({
|
|
|
74
74
|
advancedSub: koishi.Schema.boolean().default(false).description("是否开启高级订阅,若开启高级订阅,请打开该选项并下载插件 bilibili-notify-advanced-subscription"),
|
|
75
75
|
subs: koishi.Schema.array(koishi.Schema.object({
|
|
76
76
|
name: koishi.Schema.string().required().description("备注"),
|
|
77
|
-
uid: koishi.Schema.string().required().description("UID"),
|
|
77
|
+
uid: koishi.Schema.string().required().description("UID和roomid"),
|
|
78
78
|
dynamic: koishi.Schema.boolean().default(true).description("动态"),
|
|
79
79
|
dynamicAtAll: koishi.Schema.boolean().default(false).description("动态At全体"),
|
|
80
80
|
live: koishi.Schema.boolean().default(true).description("直播"),
|
|
@@ -84,7 +84,7 @@ const BAConfigSchema = koishi.Schema.object({
|
|
|
84
84
|
liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
|
|
85
85
|
platform: koishi.Schema.string().required().description("平台名"),
|
|
86
86
|
target: koishi.Schema.string().required().description("群号/频道号")
|
|
87
|
-
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
87
|
+
})).role("table").description("输入订阅信息,自定义订阅内容; UID和roomid,如果经常在初始化插件遇到风控问题,请补充直播间房间号,使用英文逗号分隔例如,1234567,114514 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
88
88
|
dynamic: koishi.Schema.object({}).description("动态推送设置"),
|
|
89
89
|
dynamicUrl: koishi.Schema.boolean().default(false).description("发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!"),
|
|
90
90
|
dynamicCron: koishi.Schema.string().default("*/2 * * * *").description("动态监测时间,请填入cron表达式,请勿填入过短时间"),
|
|
@@ -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
|
}
|
|
@@ -745,8 +751,11 @@ var ComRegister = class {
|
|
|
745
751
|
channelArr,
|
|
746
752
|
platform: s.platform
|
|
747
753
|
}];
|
|
754
|
+
const [uid, roomid] = s.uid.split(",");
|
|
748
755
|
subs[s.name] = {
|
|
749
|
-
|
|
756
|
+
uname: s.name,
|
|
757
|
+
uid,
|
|
758
|
+
roomid,
|
|
750
759
|
dynamic: s.dynamic,
|
|
751
760
|
live: s.live,
|
|
752
761
|
target,
|
|
@@ -942,25 +951,21 @@ var ComRegister = class {
|
|
|
942
951
|
if (!content) return;
|
|
943
952
|
if (content.code !== 0) switch (content.code) {
|
|
944
953
|
case -101: {
|
|
945
|
-
this.logger.error("
|
|
946
|
-
await this.sendPrivateMsg("
|
|
954
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
955
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
947
956
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
948
957
|
break;
|
|
949
958
|
}
|
|
950
959
|
case -352: {
|
|
951
|
-
this.logger.error("
|
|
952
|
-
await this.sendPrivateMsg("
|
|
960
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
961
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
953
962
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
954
963
|
break;
|
|
955
964
|
}
|
|
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
965
|
default: {
|
|
963
|
-
|
|
966
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
967
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
968
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
964
969
|
break;
|
|
965
970
|
}
|
|
966
971
|
}
|
|
@@ -1041,25 +1046,21 @@ var ComRegister = class {
|
|
|
1041
1046
|
if (!content) return;
|
|
1042
1047
|
if (content.code !== 0) switch (content.code) {
|
|
1043
1048
|
case -101: {
|
|
1044
|
-
this.logger.error("
|
|
1045
|
-
await this.sendPrivateMsg("
|
|
1049
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
1050
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
1046
1051
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1047
1052
|
break;
|
|
1048
1053
|
}
|
|
1049
1054
|
case -352: {
|
|
1050
|
-
this.logger.error("
|
|
1051
|
-
await this.sendPrivateMsg("
|
|
1055
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1056
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1052
1057
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1053
1058
|
break;
|
|
1054
1059
|
}
|
|
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
1060
|
default: {
|
|
1062
|
-
|
|
1061
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1062
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1063
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1063
1064
|
break;
|
|
1064
1065
|
}
|
|
1065
1066
|
}
|
|
@@ -1195,7 +1196,7 @@ var ComRegister = class {
|
|
|
1195
1196
|
addUserToDanmakuMaker(username, danmakuMakerRecord) {
|
|
1196
1197
|
danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
|
|
1197
1198
|
}
|
|
1198
|
-
async liveDetectWithListener(
|
|
1199
|
+
async liveDetectWithListener(sub) {
|
|
1199
1200
|
let liveTime;
|
|
1200
1201
|
let pushAtTimeTimer;
|
|
1201
1202
|
const danmakuWeightRecord = {};
|
|
@@ -1208,7 +1209,17 @@ var ComRegister = class {
|
|
|
1208
1209
|
const sendDanmakuWordCloudAndLiveSummary = async (customLiveSummary) => {
|
|
1209
1210
|
this.logger.info("开始制作弹幕词云");
|
|
1210
1211
|
this.logger.info("正在获取前90热词");
|
|
1211
|
-
const
|
|
1212
|
+
const words = Object.entries(danmakuWeightRecord);
|
|
1213
|
+
const danmaker = Object.entries(danmakuMakerRecord);
|
|
1214
|
+
if (words.length < 50) {
|
|
1215
|
+
this.logger.info("热词不足50个,本次弹幕词云放弃");
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
if (danmaker.length < 5) {
|
|
1219
|
+
this.logger.info("发言人数不足5位,本次弹幕词云放弃");
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1212
1223
|
this.logger.info("弹幕词云前90词及权重:");
|
|
1213
1224
|
this.logger.info(top90Words);
|
|
1214
1225
|
this.logger.info("正在准备生成弹幕词云");
|
|
@@ -1245,7 +1256,7 @@ var ComRegister = class {
|
|
|
1245
1256
|
};
|
|
1246
1257
|
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1247
1258
|
let flag = true;
|
|
1248
|
-
liveRoomInfo = await this.useLiveRoomInfo(
|
|
1259
|
+
liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
|
|
1249
1260
|
flag = false;
|
|
1250
1261
|
return null;
|
|
1251
1262
|
});
|
|
@@ -1263,9 +1274,9 @@ var ComRegister = class {
|
|
|
1263
1274
|
onError: async () => {
|
|
1264
1275
|
liveStatus = false;
|
|
1265
1276
|
pushAtTimeTimer?.();
|
|
1266
|
-
this.ctx["bilibili-notify-live"].closeListener(
|
|
1267
|
-
await this.sendPrivateMsg(`[${
|
|
1268
|
-
this.logger.error(`[${
|
|
1277
|
+
this.ctx["bilibili-notify-live"].closeListener(sub.roomid);
|
|
1278
|
+
await this.sendPrivateMsg(`[${sub.roomid}]直播间连接发生错误!`);
|
|
1279
|
+
this.logger.error(`[${sub.roomid}]直播间连接发生错误!`);
|
|
1269
1280
|
},
|
|
1270
1281
|
onIncomeDanmu: ({ body }) => {
|
|
1271
1282
|
this.segmentDanmaku(body.content, danmakuWeightRecord);
|
|
@@ -1306,7 +1317,10 @@ var ComRegister = class {
|
|
|
1306
1317
|
masterInfo,
|
|
1307
1318
|
cardStyle: sub.customCardStyle
|
|
1308
1319
|
}, sub.uid, liveStartMsg);
|
|
1309
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1320
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1321
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1322
|
+
this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
|
|
1323
|
+
}
|
|
1310
1324
|
},
|
|
1311
1325
|
onLiveEnd: async () => {
|
|
1312
1326
|
liveStatus = false;
|
|
@@ -1331,7 +1345,7 @@ var ComRegister = class {
|
|
|
1331
1345
|
await sendDanmakuWordCloudAndLiveSummary(liveMsgObj.liveSummary);
|
|
1332
1346
|
}
|
|
1333
1347
|
};
|
|
1334
|
-
await this.ctx["bilibili-notify-live"].startLiveRoomListener(
|
|
1348
|
+
await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
|
|
1335
1349
|
if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1336
1350
|
if (liveRoomInfo.live_status === 1) {
|
|
1337
1351
|
liveTime = liveRoomInfo.live_time;
|
|
@@ -1342,29 +1356,32 @@ var ComRegister = class {
|
|
|
1342
1356
|
masterInfo,
|
|
1343
1357
|
cardStyle: sub.customCardStyle
|
|
1344
1358
|
}, sub.uid, liveMsg);
|
|
1345
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1359
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1360
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1361
|
+
this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
|
|
1362
|
+
}
|
|
1346
1363
|
liveStatus = true;
|
|
1347
1364
|
}
|
|
1348
1365
|
}
|
|
1349
1366
|
async liveDetectWithAPI() {
|
|
1350
|
-
const useMasterAndLiveRoomInfo = async (liveType,
|
|
1367
|
+
const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
|
|
1351
1368
|
let flag = true;
|
|
1352
|
-
|
|
1369
|
+
LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
|
|
1353
1370
|
flag = false;
|
|
1354
1371
|
return null;
|
|
1355
1372
|
});
|
|
1356
|
-
if (!flag || !
|
|
1373
|
+
if (!flag || !LiveAPIStatus.liveRoomInfo?.uid) {
|
|
1357
1374
|
flag = false;
|
|
1358
1375
|
return flag;
|
|
1359
1376
|
}
|
|
1360
|
-
|
|
1377
|
+
LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
|
|
1361
1378
|
flag = false;
|
|
1362
1379
|
return null;
|
|
1363
1380
|
});
|
|
1364
1381
|
return flag;
|
|
1365
1382
|
};
|
|
1366
1383
|
const uids = [];
|
|
1367
|
-
for (const [uid] of this.
|
|
1384
|
+
for (const [uid] of this.liveAPIManager.entries()) uids.push(uid);
|
|
1368
1385
|
const useLiveInfo = async () => {
|
|
1369
1386
|
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1370
1387
|
return void 0;
|
|
@@ -1378,20 +1395,20 @@ var ComRegister = class {
|
|
|
1378
1395
|
const data = await useLiveInfo();
|
|
1379
1396
|
for (const item of Object.values(data)) {
|
|
1380
1397
|
const uid = item.uid.toString();
|
|
1381
|
-
const
|
|
1398
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1382
1399
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1383
1400
|
const sub = this.subManager.get(uid);
|
|
1384
1401
|
if (item.live_status === 1) {
|
|
1385
|
-
|
|
1386
|
-
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast,
|
|
1387
|
-
if (!
|
|
1388
|
-
|
|
1389
|
-
|
|
1402
|
+
LiveAPIStatus.live = true;
|
|
1403
|
+
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, LiveAPIStatus);
|
|
1404
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1405
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1406
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1390
1407
|
}
|
|
1391
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1408
|
+
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
1409
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1393
|
-
liveRoomInfo:
|
|
1394
|
-
masterInfo:
|
|
1410
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1411
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1395
1412
|
cardStyle: sub.customCardStyle
|
|
1396
1413
|
}, uid, liveMsg);
|
|
1397
1414
|
}
|
|
@@ -1400,74 +1417,74 @@ var ComRegister = class {
|
|
|
1400
1417
|
const data$1 = await useLiveInfo();
|
|
1401
1418
|
for (const item of Object.values(data$1)) {
|
|
1402
1419
|
const uid = item.uid.toString();
|
|
1403
|
-
const
|
|
1420
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1404
1421
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1405
1422
|
const sub = this.subManager.get(uid);
|
|
1406
1423
|
if (!sub) return;
|
|
1407
1424
|
switch (item.live_status) {
|
|
1408
1425
|
case 0:
|
|
1409
1426
|
case 2: {
|
|
1410
|
-
if (
|
|
1411
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1427
|
+
if (LiveAPIStatus.live === true) {
|
|
1428
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1412
1429
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1413
1430
|
return await this.sendPrivateMsgAndStopService();
|
|
1414
1431
|
}
|
|
1415
|
-
if (
|
|
1416
|
-
|
|
1417
|
-
|
|
1432
|
+
if (LiveAPIStatus.liveStartTimeInit) {
|
|
1433
|
+
LiveAPIStatus.liveRoomInfo.live_time = LiveAPIStatus.liveStartTime;
|
|
1434
|
+
LiveAPIStatus.liveStartTimeInit = false;
|
|
1418
1435
|
}
|
|
1419
1436
|
const followerChange = (() => {
|
|
1420
|
-
const liveFollowerChangeNum =
|
|
1437
|
+
const liveFollowerChangeNum = LiveAPIStatus.masterInfo.liveFollowerChange;
|
|
1421
1438
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1422
1439
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1423
1440
|
})();
|
|
1424
|
-
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name",
|
|
1441
|
+
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
1442
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1426
|
-
liveRoomInfo:
|
|
1427
|
-
masterInfo:
|
|
1443
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1444
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1428
1445
|
cardStyle: sub.customCardStyle
|
|
1429
1446
|
}, uid, liveEndMsg);
|
|
1430
|
-
|
|
1447
|
+
LiveAPIStatus.live = false;
|
|
1431
1448
|
}
|
|
1432
1449
|
break;
|
|
1433
1450
|
}
|
|
1434
1451
|
case 1: {
|
|
1435
|
-
if (
|
|
1436
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1452
|
+
if (LiveAPIStatus.live === false) {
|
|
1453
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1437
1454
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1438
1455
|
return await this.sendPrivateMsgAndStopService();
|
|
1439
1456
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
const follower =
|
|
1443
|
-
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name",
|
|
1457
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1458
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1459
|
+
const follower = LiveAPIStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(LiveAPIStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : LiveAPIStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1460
|
+
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
1461
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1445
|
-
liveRoomInfo:
|
|
1446
|
-
masterInfo:
|
|
1462
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1463
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1447
1464
|
cardStyle: sub.customCardStyle
|
|
1448
1465
|
}, uid, liveStartMsg);
|
|
1449
|
-
|
|
1466
|
+
LiveAPIStatus.live = true;
|
|
1450
1467
|
}
|
|
1451
|
-
if (
|
|
1452
|
-
if (
|
|
1453
|
-
|
|
1468
|
+
if (LiveAPIStatus.live === true) {
|
|
1469
|
+
if (LiveAPIStatus.push < this.config.pushTime * 60 * 60 / 30) {
|
|
1470
|
+
LiveAPIStatus.push++;
|
|
1454
1471
|
break;
|
|
1455
1472
|
}
|
|
1456
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast,
|
|
1473
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast, LiveAPIStatus)) {
|
|
1457
1474
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
|
|
1458
1475
|
return await this.sendPrivateMsgAndStopService();
|
|
1459
1476
|
}
|
|
1460
|
-
if (!
|
|
1461
|
-
|
|
1462
|
-
|
|
1477
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1478
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1479
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1463
1480
|
}
|
|
1464
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1481
|
+
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
1482
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1466
|
-
liveRoomInfo:
|
|
1467
|
-
masterInfo:
|
|
1483
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1484
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1468
1485
|
cardStyle: sub.customCardStyle
|
|
1469
1486
|
}, uid, liveMsg);
|
|
1470
|
-
|
|
1487
|
+
LiveAPIStatus.push = 0;
|
|
1471
1488
|
}
|
|
1472
1489
|
break;
|
|
1473
1490
|
}
|
|
@@ -1649,40 +1666,42 @@ var ComRegister = class {
|
|
|
1649
1666
|
this.preInitConfig(subs);
|
|
1650
1667
|
for (const sub of Object.values(subs)) {
|
|
1651
1668
|
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1669
|
+
if (!sub.roomid) {
|
|
1670
|
+
this.logger.info(`UID:${sub.uid}请求了用户接口~`);
|
|
1671
|
+
const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
|
|
1672
|
+
const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
|
|
1673
|
+
return data;
|
|
1674
|
+
}).catch((e) => {
|
|
1675
|
+
this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
1676
|
+
return {
|
|
1677
|
+
code: -1,
|
|
1678
|
+
message: `加载订阅UID:${sub.uid}失败!`
|
|
1679
|
+
};
|
|
1680
|
+
});
|
|
1681
|
+
if (userInfoCode === -352 && userInfoData.v_voucher) {
|
|
1682
|
+
this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1683
|
+
await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1684
|
+
return {
|
|
1685
|
+
code: userInfoCode,
|
|
1686
|
+
message: userInfoMsg
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
if (userInfoCode !== 0) return {
|
|
1666
1690
|
code: userInfoCode,
|
|
1667
1691
|
message: userInfoMsg
|
|
1668
1692
|
};
|
|
1669
|
-
|
|
1670
|
-
if (userInfoCode !== 0) return {
|
|
1671
|
-
code: userInfoCode,
|
|
1672
|
-
message: userInfoMsg
|
|
1673
|
-
};
|
|
1674
|
-
if (this.config.liveDetectType === "WS" && sub.live) {
|
|
1675
|
-
if (!userInfoData.live_room) {
|
|
1693
|
+
if (sub.live && !userInfoData.live_room) {
|
|
1676
1694
|
sub.live = false;
|
|
1677
1695
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1678
1696
|
}
|
|
1679
|
-
|
|
1697
|
+
sub.roomid = userInfoData.live_room.roomid;
|
|
1680
1698
|
}
|
|
1699
|
+
if (sub.live && sub.roomid && this.config.liveDetectType === "WS") await this.liveDetectWithListener(sub);
|
|
1681
1700
|
const subInfo = await this.subUserInBili(sub.uid);
|
|
1682
1701
|
if (subInfo.code !== 0) return subInfo;
|
|
1683
1702
|
this.subManager.set(sub.uid, {
|
|
1684
|
-
uname:
|
|
1685
|
-
roomId: sub.
|
|
1703
|
+
uname: sub.uname,
|
|
1704
|
+
roomId: sub.roomid,
|
|
1686
1705
|
target: sub.target,
|
|
1687
1706
|
live: sub.live,
|
|
1688
1707
|
dynamic: sub.dynamic,
|
|
@@ -1707,7 +1726,7 @@ var ComRegister = class {
|
|
|
1707
1726
|
}
|
|
1708
1727
|
checkIfLiveDetectIsNeeded() {
|
|
1709
1728
|
if (this.config.liveDetectType === "API") {
|
|
1710
|
-
if (this.
|
|
1729
|
+
if (this.liveAPIManager.size > 0) this.enableLiveDetect();
|
|
1711
1730
|
}
|
|
1712
1731
|
}
|
|
1713
1732
|
enableDynamicDetect() {
|
|
@@ -1716,9 +1735,9 @@ var ComRegister = class {
|
|
|
1716
1735
|
this.dynamicJob.start();
|
|
1717
1736
|
}
|
|
1718
1737
|
async enableLiveDetect() {
|
|
1719
|
-
this.
|
|
1738
|
+
this.liveAPIJob = new cron.CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
|
|
1720
1739
|
this.logger.info("直播监测已开启");
|
|
1721
|
-
this.
|
|
1740
|
+
this.liveAPIJob.start();
|
|
1722
1741
|
}
|
|
1723
1742
|
async checkIfIsLogin() {
|
|
1724
1743
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
package/lib/index.mjs
CHANGED
|
@@ -55,7 +55,7 @@ const BAConfigSchema = Schema.object({
|
|
|
55
55
|
advancedSub: Schema.boolean().default(false).description("是否开启高级订阅,若开启高级订阅,请打开该选项并下载插件 bilibili-notify-advanced-subscription"),
|
|
56
56
|
subs: Schema.array(Schema.object({
|
|
57
57
|
name: Schema.string().required().description("备注"),
|
|
58
|
-
uid: Schema.string().required().description("UID"),
|
|
58
|
+
uid: Schema.string().required().description("UID和roomid"),
|
|
59
59
|
dynamic: Schema.boolean().default(true).description("动态"),
|
|
60
60
|
dynamicAtAll: Schema.boolean().default(false).description("动态At全体"),
|
|
61
61
|
live: Schema.boolean().default(true).description("直播"),
|
|
@@ -65,7 +65,7 @@ const BAConfigSchema = Schema.object({
|
|
|
65
65
|
liveSummary: Schema.boolean().default(true).description("直播总结"),
|
|
66
66
|
platform: Schema.string().required().description("平台名"),
|
|
67
67
|
target: Schema.string().required().description("群号/频道号")
|
|
68
|
-
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
68
|
+
})).role("table").description("输入订阅信息,自定义订阅内容; UID和roomid,如果经常在初始化插件遇到风控问题,请补充直播间房间号,使用英文逗号分隔例如,1234567,114514 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
69
69
|
dynamic: Schema.object({}).description("动态推送设置"),
|
|
70
70
|
dynamicUrl: Schema.boolean().default(false).description("发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!"),
|
|
71
71
|
dynamicCron: Schema.string().default("*/2 * * * *").description("动态监测时间,请填入cron表达式,请勿填入过短时间"),
|
|
@@ -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
|
}
|
|
@@ -726,8 +732,11 @@ var ComRegister = class {
|
|
|
726
732
|
channelArr,
|
|
727
733
|
platform: s.platform
|
|
728
734
|
}];
|
|
735
|
+
const [uid, roomid] = s.uid.split(",");
|
|
729
736
|
subs[s.name] = {
|
|
730
|
-
|
|
737
|
+
uname: s.name,
|
|
738
|
+
uid,
|
|
739
|
+
roomid,
|
|
731
740
|
dynamic: s.dynamic,
|
|
732
741
|
live: s.live,
|
|
733
742
|
target,
|
|
@@ -923,25 +932,21 @@ var ComRegister = class {
|
|
|
923
932
|
if (!content) return;
|
|
924
933
|
if (content.code !== 0) switch (content.code) {
|
|
925
934
|
case -101: {
|
|
926
|
-
this.logger.error("
|
|
927
|
-
await this.sendPrivateMsg("
|
|
935
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
936
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
928
937
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
929
938
|
break;
|
|
930
939
|
}
|
|
931
940
|
case -352: {
|
|
932
|
-
this.logger.error("
|
|
933
|
-
await this.sendPrivateMsg("
|
|
941
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
942
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
934
943
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
935
944
|
break;
|
|
936
945
|
}
|
|
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
946
|
default: {
|
|
944
|
-
|
|
947
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
948
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
949
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
945
950
|
break;
|
|
946
951
|
}
|
|
947
952
|
}
|
|
@@ -1022,25 +1027,21 @@ var ComRegister = class {
|
|
|
1022
1027
|
if (!content) return;
|
|
1023
1028
|
if (content.code !== 0) switch (content.code) {
|
|
1024
1029
|
case -101: {
|
|
1025
|
-
this.logger.error("
|
|
1026
|
-
await this.sendPrivateMsg("
|
|
1030
|
+
this.logger.error("账号未登录,插件已停止工作,请登录");
|
|
1031
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录");
|
|
1027
1032
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1028
1033
|
break;
|
|
1029
1034
|
}
|
|
1030
1035
|
case -352: {
|
|
1031
|
-
this.logger.error("
|
|
1032
|
-
await this.sendPrivateMsg("
|
|
1036
|
+
this.logger.error("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1037
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请输入指令 bili cap 根据提示解除风控");
|
|
1033
1038
|
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1034
1039
|
break;
|
|
1035
1040
|
}
|
|
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
1041
|
default: {
|
|
1043
|
-
|
|
1042
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1043
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message},请排除错误后输入指令 bn restart 重启插件`);
|
|
1044
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
1044
1045
|
break;
|
|
1045
1046
|
}
|
|
1046
1047
|
}
|
|
@@ -1176,7 +1177,7 @@ var ComRegister = class {
|
|
|
1176
1177
|
addUserToDanmakuMaker(username, danmakuMakerRecord) {
|
|
1177
1178
|
danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
|
|
1178
1179
|
}
|
|
1179
|
-
async liveDetectWithListener(
|
|
1180
|
+
async liveDetectWithListener(sub) {
|
|
1180
1181
|
let liveTime;
|
|
1181
1182
|
let pushAtTimeTimer;
|
|
1182
1183
|
const danmakuWeightRecord = {};
|
|
@@ -1189,7 +1190,17 @@ var ComRegister = class {
|
|
|
1189
1190
|
const sendDanmakuWordCloudAndLiveSummary = async (customLiveSummary) => {
|
|
1190
1191
|
this.logger.info("开始制作弹幕词云");
|
|
1191
1192
|
this.logger.info("正在获取前90热词");
|
|
1192
|
-
const
|
|
1193
|
+
const words = Object.entries(danmakuWeightRecord);
|
|
1194
|
+
const danmaker = Object.entries(danmakuMakerRecord);
|
|
1195
|
+
if (words.length < 50) {
|
|
1196
|
+
this.logger.info("热词不足50个,本次弹幕词云放弃");
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
if (danmaker.length < 5) {
|
|
1200
|
+
this.logger.info("发言人数不足5位,本次弹幕词云放弃");
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1193
1204
|
this.logger.info("弹幕词云前90词及权重:");
|
|
1194
1205
|
this.logger.info(top90Words);
|
|
1195
1206
|
this.logger.info("正在准备生成弹幕词云");
|
|
@@ -1226,7 +1237,7 @@ var ComRegister = class {
|
|
|
1226
1237
|
};
|
|
1227
1238
|
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1228
1239
|
let flag = true;
|
|
1229
|
-
liveRoomInfo = await this.useLiveRoomInfo(
|
|
1240
|
+
liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
|
|
1230
1241
|
flag = false;
|
|
1231
1242
|
return null;
|
|
1232
1243
|
});
|
|
@@ -1244,9 +1255,9 @@ var ComRegister = class {
|
|
|
1244
1255
|
onError: async () => {
|
|
1245
1256
|
liveStatus = false;
|
|
1246
1257
|
pushAtTimeTimer?.();
|
|
1247
|
-
this.ctx["bilibili-notify-live"].closeListener(
|
|
1248
|
-
await this.sendPrivateMsg(`[${
|
|
1249
|
-
this.logger.error(`[${
|
|
1258
|
+
this.ctx["bilibili-notify-live"].closeListener(sub.roomid);
|
|
1259
|
+
await this.sendPrivateMsg(`[${sub.roomid}]直播间连接发生错误!`);
|
|
1260
|
+
this.logger.error(`[${sub.roomid}]直播间连接发生错误!`);
|
|
1250
1261
|
},
|
|
1251
1262
|
onIncomeDanmu: ({ body }) => {
|
|
1252
1263
|
this.segmentDanmaku(body.content, danmakuWeightRecord);
|
|
@@ -1287,7 +1298,10 @@ var ComRegister = class {
|
|
|
1287
1298
|
masterInfo,
|
|
1288
1299
|
cardStyle: sub.customCardStyle
|
|
1289
1300
|
}, sub.uid, liveStartMsg);
|
|
1290
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1301
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1302
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1303
|
+
this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
|
|
1304
|
+
}
|
|
1291
1305
|
},
|
|
1292
1306
|
onLiveEnd: async () => {
|
|
1293
1307
|
liveStatus = false;
|
|
@@ -1312,7 +1326,7 @@ var ComRegister = class {
|
|
|
1312
1326
|
await sendDanmakuWordCloudAndLiveSummary(liveMsgObj.liveSummary);
|
|
1313
1327
|
}
|
|
1314
1328
|
};
|
|
1315
|
-
await this.ctx["bilibili-notify-live"].startLiveRoomListener(
|
|
1329
|
+
await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
|
|
1316
1330
|
if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1317
1331
|
if (liveRoomInfo.live_status === 1) {
|
|
1318
1332
|
liveTime = liveRoomInfo.live_time;
|
|
@@ -1323,29 +1337,32 @@ var ComRegister = class {
|
|
|
1323
1337
|
masterInfo,
|
|
1324
1338
|
cardStyle: sub.customCardStyle
|
|
1325
1339
|
}, sub.uid, liveMsg);
|
|
1326
|
-
if (this.config.pushTime !== 0 && !pushAtTimeTimer)
|
|
1340
|
+
if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
|
|
1341
|
+
pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1342
|
+
this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
|
|
1343
|
+
}
|
|
1327
1344
|
liveStatus = true;
|
|
1328
1345
|
}
|
|
1329
1346
|
}
|
|
1330
1347
|
async liveDetectWithAPI() {
|
|
1331
|
-
const useMasterAndLiveRoomInfo = async (liveType,
|
|
1348
|
+
const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
|
|
1332
1349
|
let flag = true;
|
|
1333
|
-
|
|
1350
|
+
LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
|
|
1334
1351
|
flag = false;
|
|
1335
1352
|
return null;
|
|
1336
1353
|
});
|
|
1337
|
-
if (!flag || !
|
|
1354
|
+
if (!flag || !LiveAPIStatus.liveRoomInfo?.uid) {
|
|
1338
1355
|
flag = false;
|
|
1339
1356
|
return flag;
|
|
1340
1357
|
}
|
|
1341
|
-
|
|
1358
|
+
LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
|
|
1342
1359
|
flag = false;
|
|
1343
1360
|
return null;
|
|
1344
1361
|
});
|
|
1345
1362
|
return flag;
|
|
1346
1363
|
};
|
|
1347
1364
|
const uids = [];
|
|
1348
|
-
for (const [uid] of this.
|
|
1365
|
+
for (const [uid] of this.liveAPIManager.entries()) uids.push(uid);
|
|
1349
1366
|
const useLiveInfo = async () => {
|
|
1350
1367
|
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1351
1368
|
return void 0;
|
|
@@ -1359,20 +1376,20 @@ var ComRegister = class {
|
|
|
1359
1376
|
const data = await useLiveInfo();
|
|
1360
1377
|
for (const item of Object.values(data)) {
|
|
1361
1378
|
const uid = item.uid.toString();
|
|
1362
|
-
const
|
|
1379
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1363
1380
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1364
1381
|
const sub = this.subManager.get(uid);
|
|
1365
1382
|
if (item.live_status === 1) {
|
|
1366
|
-
|
|
1367
|
-
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast,
|
|
1368
|
-
if (!
|
|
1369
|
-
|
|
1370
|
-
|
|
1383
|
+
LiveAPIStatus.live = true;
|
|
1384
|
+
await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast, LiveAPIStatus);
|
|
1385
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1386
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1387
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1371
1388
|
}
|
|
1372
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1389
|
+
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
1390
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1374
|
-
liveRoomInfo:
|
|
1375
|
-
masterInfo:
|
|
1391
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1392
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1376
1393
|
cardStyle: sub.customCardStyle
|
|
1377
1394
|
}, uid, liveMsg);
|
|
1378
1395
|
}
|
|
@@ -1381,74 +1398,74 @@ var ComRegister = class {
|
|
|
1381
1398
|
const data$1 = await useLiveInfo();
|
|
1382
1399
|
for (const item of Object.values(data$1)) {
|
|
1383
1400
|
const uid = item.uid.toString();
|
|
1384
|
-
const
|
|
1401
|
+
const LiveAPIStatus = this.liveAPIManager.get(uid);
|
|
1385
1402
|
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1386
1403
|
const sub = this.subManager.get(uid);
|
|
1387
1404
|
if (!sub) return;
|
|
1388
1405
|
switch (item.live_status) {
|
|
1389
1406
|
case 0:
|
|
1390
1407
|
case 2: {
|
|
1391
|
-
if (
|
|
1392
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1408
|
+
if (LiveAPIStatus.live === true) {
|
|
1409
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1393
1410
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1394
1411
|
return await this.sendPrivateMsgAndStopService();
|
|
1395
1412
|
}
|
|
1396
|
-
if (
|
|
1397
|
-
|
|
1398
|
-
|
|
1413
|
+
if (LiveAPIStatus.liveStartTimeInit) {
|
|
1414
|
+
LiveAPIStatus.liveRoomInfo.live_time = LiveAPIStatus.liveStartTime;
|
|
1415
|
+
LiveAPIStatus.liveStartTimeInit = false;
|
|
1399
1416
|
}
|
|
1400
1417
|
const followerChange = (() => {
|
|
1401
|
-
const liveFollowerChangeNum =
|
|
1418
|
+
const liveFollowerChangeNum = LiveAPIStatus.masterInfo.liveFollowerChange;
|
|
1402
1419
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1403
1420
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1404
1421
|
})();
|
|
1405
|
-
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name",
|
|
1422
|
+
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
1423
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1407
|
-
liveRoomInfo:
|
|
1408
|
-
masterInfo:
|
|
1424
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1425
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1409
1426
|
cardStyle: sub.customCardStyle
|
|
1410
1427
|
}, uid, liveEndMsg);
|
|
1411
|
-
|
|
1428
|
+
LiveAPIStatus.live = false;
|
|
1412
1429
|
}
|
|
1413
1430
|
break;
|
|
1414
1431
|
}
|
|
1415
1432
|
case 1: {
|
|
1416
|
-
if (
|
|
1417
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast,
|
|
1433
|
+
if (LiveAPIStatus.live === false) {
|
|
1434
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.StopBroadcast, LiveAPIStatus)) {
|
|
1418
1435
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1419
1436
|
return await this.sendPrivateMsgAndStopService();
|
|
1420
1437
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
const follower =
|
|
1424
|
-
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name",
|
|
1438
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1439
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1440
|
+
const follower = LiveAPIStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(LiveAPIStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : LiveAPIStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1441
|
+
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
1442
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1426
|
-
liveRoomInfo:
|
|
1427
|
-
masterInfo:
|
|
1443
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1444
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1428
1445
|
cardStyle: sub.customCardStyle
|
|
1429
1446
|
}, uid, liveStartMsg);
|
|
1430
|
-
|
|
1447
|
+
LiveAPIStatus.live = true;
|
|
1431
1448
|
}
|
|
1432
|
-
if (
|
|
1433
|
-
if (
|
|
1434
|
-
|
|
1449
|
+
if (LiveAPIStatus.live === true) {
|
|
1450
|
+
if (LiveAPIStatus.push < this.config.pushTime * 60 * 60 / 30) {
|
|
1451
|
+
LiveAPIStatus.push++;
|
|
1435
1452
|
break;
|
|
1436
1453
|
}
|
|
1437
|
-
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast,
|
|
1454
|
+
if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast, LiveAPIStatus)) {
|
|
1438
1455
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
|
|
1439
1456
|
return await this.sendPrivateMsgAndStopService();
|
|
1440
1457
|
}
|
|
1441
|
-
if (!
|
|
1442
|
-
|
|
1443
|
-
|
|
1458
|
+
if (!LiveAPIStatus.liveStartTimeInit) {
|
|
1459
|
+
LiveAPIStatus.liveStartTime = LiveAPIStatus.liveRoomInfo.live_time;
|
|
1460
|
+
LiveAPIStatus.liveStartTimeInit = true;
|
|
1444
1461
|
}
|
|
1445
|
-
const liveMsg = liveMsgObj.customLive.replace("-name",
|
|
1462
|
+
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
1463
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1447
|
-
liveRoomInfo:
|
|
1448
|
-
masterInfo:
|
|
1464
|
+
liveRoomInfo: LiveAPIStatus.liveRoomInfo,
|
|
1465
|
+
masterInfo: LiveAPIStatus.masterInfo,
|
|
1449
1466
|
cardStyle: sub.customCardStyle
|
|
1450
1467
|
}, uid, liveMsg);
|
|
1451
|
-
|
|
1468
|
+
LiveAPIStatus.push = 0;
|
|
1452
1469
|
}
|
|
1453
1470
|
break;
|
|
1454
1471
|
}
|
|
@@ -1630,40 +1647,42 @@ var ComRegister = class {
|
|
|
1630
1647
|
this.preInitConfig(subs);
|
|
1631
1648
|
for (const sub of Object.values(subs)) {
|
|
1632
1649
|
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1650
|
+
if (!sub.roomid) {
|
|
1651
|
+
this.logger.info(`UID:${sub.uid}请求了用户接口~`);
|
|
1652
|
+
const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
|
|
1653
|
+
const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
|
|
1654
|
+
return data;
|
|
1655
|
+
}).catch((e) => {
|
|
1656
|
+
this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
1657
|
+
return {
|
|
1658
|
+
code: -1,
|
|
1659
|
+
message: `加载订阅UID:${sub.uid}失败!`
|
|
1660
|
+
};
|
|
1661
|
+
});
|
|
1662
|
+
if (userInfoCode === -352 && userInfoData.v_voucher) {
|
|
1663
|
+
this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1664
|
+
await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1665
|
+
return {
|
|
1666
|
+
code: userInfoCode,
|
|
1667
|
+
message: userInfoMsg
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
if (userInfoCode !== 0) return {
|
|
1647
1671
|
code: userInfoCode,
|
|
1648
1672
|
message: userInfoMsg
|
|
1649
1673
|
};
|
|
1650
|
-
|
|
1651
|
-
if (userInfoCode !== 0) return {
|
|
1652
|
-
code: userInfoCode,
|
|
1653
|
-
message: userInfoMsg
|
|
1654
|
-
};
|
|
1655
|
-
if (this.config.liveDetectType === "WS" && sub.live) {
|
|
1656
|
-
if (!userInfoData.live_room) {
|
|
1674
|
+
if (sub.live && !userInfoData.live_room) {
|
|
1657
1675
|
sub.live = false;
|
|
1658
1676
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1659
1677
|
}
|
|
1660
|
-
|
|
1678
|
+
sub.roomid = userInfoData.live_room.roomid;
|
|
1661
1679
|
}
|
|
1680
|
+
if (sub.live && sub.roomid && this.config.liveDetectType === "WS") await this.liveDetectWithListener(sub);
|
|
1662
1681
|
const subInfo = await this.subUserInBili(sub.uid);
|
|
1663
1682
|
if (subInfo.code !== 0) return subInfo;
|
|
1664
1683
|
this.subManager.set(sub.uid, {
|
|
1665
|
-
uname:
|
|
1666
|
-
roomId: sub.
|
|
1684
|
+
uname: sub.uname,
|
|
1685
|
+
roomId: sub.roomid,
|
|
1667
1686
|
target: sub.target,
|
|
1668
1687
|
live: sub.live,
|
|
1669
1688
|
dynamic: sub.dynamic,
|
|
@@ -1688,7 +1707,7 @@ var ComRegister = class {
|
|
|
1688
1707
|
}
|
|
1689
1708
|
checkIfLiveDetectIsNeeded() {
|
|
1690
1709
|
if (this.config.liveDetectType === "API") {
|
|
1691
|
-
if (this.
|
|
1710
|
+
if (this.liveAPIManager.size > 0) this.enableLiveDetect();
|
|
1692
1711
|
}
|
|
1693
1712
|
}
|
|
1694
1713
|
enableDynamicDetect() {
|
|
@@ -1697,9 +1716,9 @@ var ComRegister = class {
|
|
|
1697
1716
|
this.dynamicJob.start();
|
|
1698
1717
|
}
|
|
1699
1718
|
async enableLiveDetect() {
|
|
1700
|
-
this.
|
|
1719
|
+
this.liveAPIJob = new CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
|
|
1701
1720
|
this.logger.info("直播监测已开启");
|
|
1702
|
-
this.
|
|
1721
|
+
this.liveAPIJob.start();
|
|
1703
1722
|
}
|
|
1704
1723
|
async checkIfIsLogin() {
|
|
1705
1724
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -328,6 +328,8 @@ 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 优化:动态错误处理
|
|
332
|
+
> - ver 3.3.1-rc.2 新增:订阅UID项可填写roomid,在目前版本可以极大降低风控概率;
|
|
331
333
|
|
|
332
334
|
## 交流群
|
|
333
335
|
|