koishi-plugin-bilibili-notify 3.3.6-alpha.0 → 3.3.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/index.js +24 -9
- package/lib/index.mjs +24 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -70,7 +70,7 @@ const BAConfigSchema = koishi.Schema.object({
|
|
|
70
70
|
basicSettings: koishi.Schema.object({}).description("基本设置"),
|
|
71
71
|
userAgent: koishi.Schema.string().description("设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111"),
|
|
72
72
|
subTitle: koishi.Schema.object({}).description("订阅配置"),
|
|
73
|
-
advancedSub: koishi.Schema.boolean().default(false).description("
|
|
73
|
+
advancedSub: koishi.Schema.boolean().default(false).description("是否开启高级订阅,高级订阅是独立于本插件的一个专门用于订阅配置的插件,用于高度自定义订阅消息。若开启高级订阅,请打开该选项并下载插件 bilibili-notify-advanced-subscription"),
|
|
74
74
|
subs: koishi.Schema.array(koishi.Schema.object({
|
|
75
75
|
name: koishi.Schema.string().required().description("备注"),
|
|
76
76
|
uid: koishi.Schema.string().required().description("UID和roomid"),
|
|
@@ -490,7 +490,8 @@ var ComRegister = class {
|
|
|
490
490
|
});
|
|
491
491
|
}
|
|
492
492
|
let table = "";
|
|
493
|
-
|
|
493
|
+
if (subLiveUsers.length === 0) table += "当前没有正在直播的订阅对象";
|
|
494
|
+
else for (const user of subLiveUsers) table += `[UID:${user.uid}] 「${user.uname}」 ${user.onLive ? "正在直播" : "未开播"}\n`;
|
|
494
495
|
return table;
|
|
495
496
|
});
|
|
496
497
|
biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
|
|
@@ -663,6 +664,7 @@ var ComRegister = class {
|
|
|
663
664
|
return;
|
|
664
665
|
}
|
|
665
666
|
this.mergeStopWords(config.wordcloudStopWords);
|
|
667
|
+
this.initAllManager();
|
|
666
668
|
this.registeringForEvents();
|
|
667
669
|
if (config.advancedSub) {
|
|
668
670
|
this.logger.info("开启高级订阅,等待加载订阅...");
|
|
@@ -693,7 +695,6 @@ var ComRegister = class {
|
|
|
693
695
|
});
|
|
694
696
|
}
|
|
695
697
|
async initAsyncPart(subs) {
|
|
696
|
-
this.initAllManager();
|
|
697
698
|
this.logger.info("获取到订阅信息,开始加载订阅...");
|
|
698
699
|
const { code, message } = await this.loadSubFromConfig(subs);
|
|
699
700
|
if (code !== 0) {
|
|
@@ -702,7 +703,7 @@ var ComRegister = class {
|
|
|
702
703
|
await this.sendPrivateMsg("订阅对象加载失败,插件初始化失败!");
|
|
703
704
|
return;
|
|
704
705
|
}
|
|
705
|
-
this.
|
|
706
|
+
this.initManagerAfterLoadSub();
|
|
706
707
|
this.checkIfDynamicDetectIsNeeded();
|
|
707
708
|
this.checkIfLiveDetectIsNeeded();
|
|
708
709
|
this.updateSubNotifier();
|
|
@@ -716,7 +717,7 @@ var ComRegister = class {
|
|
|
716
717
|
const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
|
|
717
718
|
this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
|
|
718
719
|
}
|
|
719
|
-
|
|
720
|
+
initManagerAfterLoadSub() {
|
|
720
721
|
for (const [uid, sub] of this.subManager) {
|
|
721
722
|
if (sub.dynamic) this.dynamicTimelineManager.set(uid, Math.floor(luxon.DateTime.now().toSeconds()));
|
|
722
723
|
if (sub.live) this.liveAPIManager.set(uid, {
|
|
@@ -879,6 +880,10 @@ var ComRegister = class {
|
|
|
879
880
|
for (const bot of this.ctx.bots) if (bot.platform === platform) bots.push(bot);
|
|
880
881
|
let num = 0;
|
|
881
882
|
const sendMessageByBot = async (channelId, botIndex = 0) => {
|
|
883
|
+
if (!bots[botIndex]) {
|
|
884
|
+
this.logger.warn(`${platform} 没有配置对应机器人,无法进行推送!`);
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
882
887
|
if (bots[botIndex].status !== koishi.Universal.Status.ONLINE) {
|
|
883
888
|
this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
|
|
884
889
|
this.ctx.setTimeout(async () => {
|
|
@@ -1293,6 +1298,10 @@ var ComRegister = class {
|
|
|
1293
1298
|
const now = Date.now();
|
|
1294
1299
|
if (now - lastLiveStart < LIVE_EVENT_COOLDOWN) {
|
|
1295
1300
|
this.logger.warn(`[${sub.roomid}] 开播事件冷却期内被忽略`);
|
|
1301
|
+
if (!liveTime) {
|
|
1302
|
+
await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting);
|
|
1303
|
+
liveTime = liveRoomInfo?.live_time || Date.now();
|
|
1304
|
+
}
|
|
1296
1305
|
return;
|
|
1297
1306
|
}
|
|
1298
1307
|
lastLiveStart = now;
|
|
@@ -1306,9 +1315,10 @@ var ComRegister = class {
|
|
|
1306
1315
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1307
1316
|
return await this.sendPrivateMsgAndStopService();
|
|
1308
1317
|
}
|
|
1309
|
-
liveTime = liveRoomInfo.
|
|
1318
|
+
liveTime = liveRoomInfo?.live_time || Date.now();
|
|
1319
|
+
const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
|
|
1310
1320
|
const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
|
|
1311
|
-
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", masterInfo.username).replace("-time",
|
|
1321
|
+
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", masterInfo.username).replace("-time", diffTime).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
|
|
1312
1322
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1313
1323
|
liveRoomInfo,
|
|
1314
1324
|
masterInfo,
|
|
@@ -1323,6 +1333,10 @@ var ComRegister = class {
|
|
|
1323
1333
|
const now = Date.now();
|
|
1324
1334
|
if (now - lastLiveEnd < LIVE_EVENT_COOLDOWN) {
|
|
1325
1335
|
this.logger.warn(`[${sub.roomid}] 下播事件冷却期内被忽略`);
|
|
1336
|
+
if (!liveTime) {
|
|
1337
|
+
await useMasterAndLiveRoomInfo(LiveType.StopBroadcast);
|
|
1338
|
+
liveTime = liveRoomInfo?.live_time || Date.now();
|
|
1339
|
+
}
|
|
1326
1340
|
return;
|
|
1327
1341
|
}
|
|
1328
1342
|
lastLiveEnd = now;
|
|
@@ -1335,13 +1349,14 @@ var ComRegister = class {
|
|
|
1335
1349
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1336
1350
|
return await this.sendPrivateMsgAndStopService();
|
|
1337
1351
|
}
|
|
1338
|
-
liveRoomInfo
|
|
1352
|
+
liveTime = liveTime || liveRoomInfo?.live_time || Date.now();
|
|
1353
|
+
const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
|
|
1339
1354
|
const followerChange = (() => {
|
|
1340
1355
|
const liveFollowerChangeNum = masterInfo.liveFollowerChange;
|
|
1341
1356
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${(liveFollowerChangeNum / 1e4).toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1342
1357
|
return liveFollowerChangeNum <= -1e4 ? `${(liveFollowerChangeNum / 1e4).toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1343
1358
|
})();
|
|
1344
|
-
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", masterInfo.username).replace("-time",
|
|
1359
|
+
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", masterInfo.username).replace("-time", diffTime).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
|
|
1345
1360
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1346
1361
|
liveRoomInfo,
|
|
1347
1362
|
masterInfo,
|
package/lib/index.mjs
CHANGED
|
@@ -52,7 +52,7 @@ const BAConfigSchema = Schema.object({
|
|
|
52
52
|
basicSettings: Schema.object({}).description("基本设置"),
|
|
53
53
|
userAgent: Schema.string().description("设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111"),
|
|
54
54
|
subTitle: Schema.object({}).description("订阅配置"),
|
|
55
|
-
advancedSub: Schema.boolean().default(false).description("
|
|
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
58
|
uid: Schema.string().required().description("UID和roomid"),
|
|
@@ -472,7 +472,8 @@ var ComRegister = class {
|
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
474
|
let table = "";
|
|
475
|
-
|
|
475
|
+
if (subLiveUsers.length === 0) table += "当前没有正在直播的订阅对象";
|
|
476
|
+
else for (const user of subLiveUsers) table += `[UID:${user.uid}] 「${user.uname}」 ${user.onLive ? "正在直播" : "未开播"}\n`;
|
|
476
477
|
return table;
|
|
477
478
|
});
|
|
478
479
|
biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
|
|
@@ -645,6 +646,7 @@ var ComRegister = class {
|
|
|
645
646
|
return;
|
|
646
647
|
}
|
|
647
648
|
this.mergeStopWords(config.wordcloudStopWords);
|
|
649
|
+
this.initAllManager();
|
|
648
650
|
this.registeringForEvents();
|
|
649
651
|
if (config.advancedSub) {
|
|
650
652
|
this.logger.info("开启高级订阅,等待加载订阅...");
|
|
@@ -675,7 +677,6 @@ var ComRegister = class {
|
|
|
675
677
|
});
|
|
676
678
|
}
|
|
677
679
|
async initAsyncPart(subs) {
|
|
678
|
-
this.initAllManager();
|
|
679
680
|
this.logger.info("获取到订阅信息,开始加载订阅...");
|
|
680
681
|
const { code, message } = await this.loadSubFromConfig(subs);
|
|
681
682
|
if (code !== 0) {
|
|
@@ -684,7 +685,7 @@ var ComRegister = class {
|
|
|
684
685
|
await this.sendPrivateMsg("订阅对象加载失败,插件初始化失败!");
|
|
685
686
|
return;
|
|
686
687
|
}
|
|
687
|
-
this.
|
|
688
|
+
this.initManagerAfterLoadSub();
|
|
688
689
|
this.checkIfDynamicDetectIsNeeded();
|
|
689
690
|
this.checkIfLiveDetectIsNeeded();
|
|
690
691
|
this.updateSubNotifier();
|
|
@@ -698,7 +699,7 @@ var ComRegister = class {
|
|
|
698
699
|
const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
|
|
699
700
|
this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
|
|
700
701
|
}
|
|
701
|
-
|
|
702
|
+
initManagerAfterLoadSub() {
|
|
702
703
|
for (const [uid, sub] of this.subManager) {
|
|
703
704
|
if (sub.dynamic) this.dynamicTimelineManager.set(uid, Math.floor(DateTime.now().toSeconds()));
|
|
704
705
|
if (sub.live) this.liveAPIManager.set(uid, {
|
|
@@ -861,6 +862,10 @@ var ComRegister = class {
|
|
|
861
862
|
for (const bot of this.ctx.bots) if (bot.platform === platform) bots.push(bot);
|
|
862
863
|
let num = 0;
|
|
863
864
|
const sendMessageByBot = async (channelId, botIndex = 0) => {
|
|
865
|
+
if (!bots[botIndex]) {
|
|
866
|
+
this.logger.warn(`${platform} 没有配置对应机器人,无法进行推送!`);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
864
869
|
if (bots[botIndex].status !== Universal.Status.ONLINE) {
|
|
865
870
|
this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
|
|
866
871
|
this.ctx.setTimeout(async () => {
|
|
@@ -1275,6 +1280,10 @@ var ComRegister = class {
|
|
|
1275
1280
|
const now = Date.now();
|
|
1276
1281
|
if (now - lastLiveStart < LIVE_EVENT_COOLDOWN) {
|
|
1277
1282
|
this.logger.warn(`[${sub.roomid}] 开播事件冷却期内被忽略`);
|
|
1283
|
+
if (!liveTime) {
|
|
1284
|
+
await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting);
|
|
1285
|
+
liveTime = liveRoomInfo?.live_time || Date.now();
|
|
1286
|
+
}
|
|
1278
1287
|
return;
|
|
1279
1288
|
}
|
|
1280
1289
|
lastLiveStart = now;
|
|
@@ -1288,9 +1297,10 @@ var ComRegister = class {
|
|
|
1288
1297
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1289
1298
|
return await this.sendPrivateMsgAndStopService();
|
|
1290
1299
|
}
|
|
1291
|
-
liveTime = liveRoomInfo.
|
|
1300
|
+
liveTime = liveRoomInfo?.live_time || Date.now();
|
|
1301
|
+
const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
|
|
1292
1302
|
const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
|
|
1293
|
-
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", masterInfo.username).replace("-time",
|
|
1303
|
+
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", masterInfo.username).replace("-time", diffTime).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
|
|
1294
1304
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1295
1305
|
liveRoomInfo,
|
|
1296
1306
|
masterInfo,
|
|
@@ -1305,6 +1315,10 @@ var ComRegister = class {
|
|
|
1305
1315
|
const now = Date.now();
|
|
1306
1316
|
if (now - lastLiveEnd < LIVE_EVENT_COOLDOWN) {
|
|
1307
1317
|
this.logger.warn(`[${sub.roomid}] 下播事件冷却期内被忽略`);
|
|
1318
|
+
if (!liveTime) {
|
|
1319
|
+
await useMasterAndLiveRoomInfo(LiveType.StopBroadcast);
|
|
1320
|
+
liveTime = liveRoomInfo?.live_time || Date.now();
|
|
1321
|
+
}
|
|
1308
1322
|
return;
|
|
1309
1323
|
}
|
|
1310
1324
|
lastLiveEnd = now;
|
|
@@ -1317,13 +1331,14 @@ var ComRegister = class {
|
|
|
1317
1331
|
await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1318
1332
|
return await this.sendPrivateMsgAndStopService();
|
|
1319
1333
|
}
|
|
1320
|
-
liveRoomInfo
|
|
1334
|
+
liveTime = liveTime || liveRoomInfo?.live_time || Date.now();
|
|
1335
|
+
const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
|
|
1321
1336
|
const followerChange = (() => {
|
|
1322
1337
|
const liveFollowerChangeNum = masterInfo.liveFollowerChange;
|
|
1323
1338
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${(liveFollowerChangeNum / 1e4).toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1324
1339
|
return liveFollowerChangeNum <= -1e4 ? `${(liveFollowerChangeNum / 1e4).toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1325
1340
|
})();
|
|
1326
|
-
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", masterInfo.username).replace("-time",
|
|
1341
|
+
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", masterInfo.username).replace("-time", diffTime).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
|
|
1327
1342
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1328
1343
|
liveRoomInfo,
|
|
1329
1344
|
masterInfo,
|