koishi-plugin-bilibili-notify 3.3.0-rc.0 → 3.3.1-alpha.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.d.mts +19 -9
- package/lib/index.d.ts +19 -9
- package/lib/index.js +185 -125
- package/lib/index.mjs +185 -125
- package/package.json +1 -1
- package/readme.md +3 -1
package/lib/index.js
CHANGED
|
@@ -80,6 +80,8 @@ const BAConfigSchema = koishi.Schema.object({
|
|
|
80
80
|
live: koishi.Schema.boolean().default(true).description("直播"),
|
|
81
81
|
liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
|
|
82
82
|
liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
|
|
83
|
+
wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
|
|
84
|
+
liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
|
|
83
85
|
platform: koishi.Schema.string().required().description("平台名"),
|
|
84
86
|
target: koishi.Schema.string().required().description("群号/频道号")
|
|
85
87
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -90,8 +92,19 @@ const BAConfigSchema = koishi.Schema.object({
|
|
|
90
92
|
pushImgsInDynamic: koishi.Schema.boolean().default(false).description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,该功能容易导致QQ风控"),
|
|
91
93
|
live: koishi.Schema.object({}).description("直播推送设置"),
|
|
92
94
|
liveDetectType: koishi.Schema.union([koishi.Schema.const("WS").description("使用WebSocket连接到B站消息服务器进行直播检测,推荐使用"), koishi.Schema.const("API").description("通过轮询API发送请求监测直播状态,此模式理论可无限订阅,但容易产生其他问题,功能没有WS模式全面").experimental()]).role("radio").default("WS").description("直播检测方式,WS为连接到B站消息服务器,API为通过轮询发送请求监测,默认使用WS检测"),
|
|
93
|
-
|
|
94
|
-
liveSummary: koishi.Schema.
|
|
95
|
+
wordcloudStopWords: koishi.Schema.string().description("词云生成时的停用词,多个停用词请使用英文逗号分隔,例如:哔哩哔哩,弹幕,直播,词云").experimental(),
|
|
96
|
+
liveSummary: koishi.Schema.array(String).default([
|
|
97
|
+
"🔍【弹幕情报站】本场直播数据如下:",
|
|
98
|
+
"🧍♂️ 总共 -dmc 位-mdn上线",
|
|
99
|
+
"💬 共计 -dca 条弹幕飞驰而过",
|
|
100
|
+
"📊 热词云图已生成,快来看看你有没有上榜!",
|
|
101
|
+
"👑 本场顶级输出选手:",
|
|
102
|
+
"🥇 -un1 - 弹幕输出 -dc1 条",
|
|
103
|
+
"🥈 -un2 - 弹幕 -dc2 条,萌力惊人",
|
|
104
|
+
"🥉 -un3 - -dc3 条精准狙击",
|
|
105
|
+
"🎖️ 特别嘉奖:-un4 & -un5",
|
|
106
|
+
"你们的弹幕,我们都记录在案!🕵️♀️"
|
|
107
|
+
]).role("table").description("自定义直播总结语,开启弹幕词云自动发送。变量解释:-dmc代表总弹幕发送人数,-mdn代表主播粉丝牌子名,-dca代表总弹幕数,-un1到-un5代表弹幕发送条数前五名用户的用户名,-dc1到-dc5代表弹幕发送条数前五名的弹幕发送数量,数组每一行代表换行"),
|
|
95
108
|
restartPush: koishi.Schema.boolean().default(true).description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
|
|
96
109
|
pushTime: koishi.Schema.number().min(0).max(12).step(.5).default(1).description("设定间隔多长时间推送一次直播状态,单位为小时,默认为一小时"),
|
|
97
110
|
customLiveStart: koishi.Schema.string().default("-name开播啦,当前粉丝数:-follower\\n-link").description("自定义开播提示语,-name代表UP昵称,-follower代表当前粉丝数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用),\\n为换行。例如-name开播啦,会发送为xxxUP开播啦"),
|
|
@@ -179,6 +192,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
|
|
|
179
192
|
PushType$1[PushType$1["DynamicAtAll"] = 2] = "DynamicAtAll";
|
|
180
193
|
PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
|
|
181
194
|
PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
|
|
195
|
+
PushType$1[PushType$1["WordCloudAndLiveSummary"] = 5] = "WordCloudAndLiveSummary";
|
|
182
196
|
return PushType$1;
|
|
183
197
|
}({});
|
|
184
198
|
const PushTypeMsg = {
|
|
@@ -186,7 +200,8 @@ const PushTypeMsg = {
|
|
|
186
200
|
[PushType.Dynamic]: "动态推送",
|
|
187
201
|
[PushType.DynamicAtAll]: "动态推送+At全体",
|
|
188
202
|
[PushType.StartBroadcasting]: "开播推送",
|
|
189
|
-
[PushType.LiveGuardBuy]: "上舰推送"
|
|
203
|
+
[PushType.LiveGuardBuy]: "上舰推送",
|
|
204
|
+
[PushType.WordCloudAndLiveSummary]: "弹幕词云和直播总结推送"
|
|
190
205
|
};
|
|
191
206
|
|
|
192
207
|
//#endregion
|
|
@@ -323,16 +338,17 @@ const stopwords = new Set([
|
|
|
323
338
|
"之前",
|
|
324
339
|
"某天"
|
|
325
340
|
]);
|
|
341
|
+
var stop_words_default = stopwords;
|
|
326
342
|
|
|
327
343
|
//#endregion
|
|
328
344
|
//#region src/command_register.tsx
|
|
329
345
|
var ComRegister = class {
|
|
330
346
|
static inject = [
|
|
331
|
-
"
|
|
332
|
-
"
|
|
333
|
-
"
|
|
334
|
-
"
|
|
335
|
-
"
|
|
347
|
+
"bilibili-notify",
|
|
348
|
+
"bilibili-notify-api",
|
|
349
|
+
"bilibili-notify-live",
|
|
350
|
+
"bilibili-notify-generate-img",
|
|
351
|
+
"database"
|
|
336
352
|
];
|
|
337
353
|
qqRelatedBotList = [
|
|
338
354
|
"qq",
|
|
@@ -358,6 +374,7 @@ var ComRegister = class {
|
|
|
358
374
|
dynamicJob;
|
|
359
375
|
liveJob;
|
|
360
376
|
_jieba = __node_rs_jieba.Jieba.withDict(__node_rs_jieba_dict.dict);
|
|
377
|
+
stopwords;
|
|
361
378
|
constructor(ctx, config) {
|
|
362
379
|
this.ctx = ctx;
|
|
363
380
|
this.init(config);
|
|
@@ -388,7 +405,7 @@ var ComRegister = class {
|
|
|
388
405
|
this.logger.info("调用bili login指令");
|
|
389
406
|
let content;
|
|
390
407
|
try {
|
|
391
|
-
content = await ctx.
|
|
408
|
+
content = await ctx["bilibili-notify-api"].getLoginQRCode();
|
|
392
409
|
} catch (_) {
|
|
393
410
|
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
394
411
|
}
|
|
@@ -413,7 +430,7 @@ var ComRegister = class {
|
|
|
413
430
|
flag = false;
|
|
414
431
|
let loginContent;
|
|
415
432
|
try {
|
|
416
|
-
loginContent = await ctx.
|
|
433
|
+
loginContent = await ctx["bilibili-notify-api"].getLoginStatus(content.data.qrcode_key);
|
|
417
434
|
} catch (e) {
|
|
418
435
|
this.logger.error(e);
|
|
419
436
|
return;
|
|
@@ -427,24 +444,19 @@ var ComRegister = class {
|
|
|
427
444
|
return await session.send("二维码已失效,请重新登录");
|
|
428
445
|
}
|
|
429
446
|
if (loginContent.data.code === 0) {
|
|
430
|
-
const encryptedCookies = ctx.
|
|
431
|
-
const encryptedRefreshToken = ctx.
|
|
447
|
+
const encryptedCookies = ctx["bilibili-notify-api"].encrypt(ctx["bilibili-notify-api"].getCookies());
|
|
448
|
+
const encryptedRefreshToken = ctx["bilibili-notify-api"].encrypt(loginContent.data.refresh_token);
|
|
432
449
|
await ctx.database.upsert("loginBili", [{
|
|
433
450
|
id: 1,
|
|
434
451
|
bili_cookies: encryptedCookies,
|
|
435
452
|
bili_refresh_token: encryptedRefreshToken
|
|
436
453
|
}]);
|
|
437
454
|
this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
|
|
438
|
-
await this.ctx.
|
|
455
|
+
await this.ctx["bilibili-notify-api"].loadCookiesFromDatabase();
|
|
439
456
|
await this.checkIfLoginInfoIsLoaded();
|
|
440
457
|
this.loginTimer();
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (code !== 0) this.logger.error(msg);
|
|
444
|
-
ctx.ba.disposeNotifier();
|
|
445
|
-
await session.send("登录成功");
|
|
446
|
-
await session.execute("bili list");
|
|
447
|
-
ctx.ba.enableRefreshCookiesDetect();
|
|
458
|
+
ctx["bilibili-notify-api"].disposeNotifier();
|
|
459
|
+
await session.send("登录成功,请重启插件");
|
|
448
460
|
}
|
|
449
461
|
} finally {
|
|
450
462
|
flag = true;
|
|
@@ -460,7 +472,7 @@ var ComRegister = class {
|
|
|
460
472
|
await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
|
|
461
473
|
});
|
|
462
474
|
biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
|
|
463
|
-
const { data: { live_users } } = await ctx.
|
|
475
|
+
const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
|
|
464
476
|
const subLiveUsers = [];
|
|
465
477
|
for (const sub of this.subManager) {
|
|
466
478
|
let onLive = false;
|
|
@@ -482,10 +494,10 @@ var ComRegister = class {
|
|
|
482
494
|
});
|
|
483
495
|
biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
|
|
484
496
|
const i = index && index - 1 || 0;
|
|
485
|
-
const content = await this.ctx.
|
|
497
|
+
const content = await this.ctx["bilibili-notify-api"].getUserSpaceDynamic(uid);
|
|
486
498
|
const item = content.data.items[i];
|
|
487
499
|
const buffer = await withRetry(async () => {
|
|
488
|
-
return await this.ctx.
|
|
500
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item);
|
|
489
501
|
}, 1).catch(async (e) => {
|
|
490
502
|
if (e.message === "直播开播动态,不做处理") {
|
|
491
503
|
await session.send("直播开播动态,不做处理");
|
|
@@ -600,7 +612,7 @@ var ComRegister = class {
|
|
|
600
612
|
["初中", 4],
|
|
601
613
|
["毕业", 4]
|
|
602
614
|
];
|
|
603
|
-
await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx.
|
|
615
|
+
await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg") }));
|
|
604
616
|
const top5DanmakuMaker = [
|
|
605
617
|
["张三", 60],
|
|
606
618
|
["李四", 48],
|
|
@@ -608,19 +620,19 @@ var ComRegister = class {
|
|
|
608
620
|
["赵六", 27],
|
|
609
621
|
["田七", 25]
|
|
610
622
|
];
|
|
611
|
-
const danmakerRankMsg = this.config.liveSummary.replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
|
|
623
|
+
const danmakerRankMsg = this.config.liveSummary.join("\n").replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
|
|
612
624
|
await session.send(danmakerRankMsg);
|
|
613
625
|
});
|
|
614
626
|
biliCom.subcommand(".cap").action(async ({ session }) => {
|
|
615
627
|
const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
|
|
616
|
-
const data$1 = await this.ctx.
|
|
628
|
+
const data$1 = await this.ctx["bilibili-notify-api"].getUserInfo("114514");
|
|
617
629
|
return {
|
|
618
630
|
code: 0,
|
|
619
631
|
data: data$1
|
|
620
632
|
};
|
|
621
633
|
}).then((content) => content.data);
|
|
622
634
|
if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
|
|
623
|
-
const { data } = await ctx.
|
|
635
|
+
const { data } = await ctx["bilibili-notify-api"].v_voucherCaptcha(userInfoData.v_voucher);
|
|
624
636
|
if (!data.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
|
|
625
637
|
await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
|
|
626
638
|
await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
|
|
@@ -629,19 +641,14 @@ var ComRegister = class {
|
|
|
629
641
|
await session.send("请直接输入validate");
|
|
630
642
|
const validate = await session.prompt();
|
|
631
643
|
const seccode = `${validate}|jordan`;
|
|
632
|
-
const { data: validateCaptchaData } = await ctx.
|
|
644
|
+
const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
|
|
633
645
|
if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
|
|
634
|
-
ctx.
|
|
635
|
-
|
|
636
|
-
await ctx.database.upsert("loginBili", [{
|
|
637
|
-
id: 1,
|
|
638
|
-
bili_cookies: encryptedCookies
|
|
639
|
-
}]);
|
|
640
|
-
return "验证成功!请重启插件";
|
|
646
|
+
await ctx["bilibili-notify-api"].getUserInfo("114514", validateCaptchaData.grisk_id);
|
|
647
|
+
await session.send("验证成功!请重启插件");
|
|
641
648
|
});
|
|
642
649
|
}
|
|
643
650
|
async init(config) {
|
|
644
|
-
this.logger = this.ctx.logger("
|
|
651
|
+
this.logger = this.ctx.logger("bilibili-notify-core");
|
|
645
652
|
this.logger.info("初始化插件中...");
|
|
646
653
|
this.config = config;
|
|
647
654
|
this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
|
|
@@ -652,6 +659,7 @@ var ComRegister = class {
|
|
|
652
659
|
this.logger.info("账号未登录,请登录");
|
|
653
660
|
return;
|
|
654
661
|
}
|
|
662
|
+
this.mergeStopWords(config.wordcloudStopWords);
|
|
655
663
|
if (config.advancedSub) {
|
|
656
664
|
this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
|
|
657
665
|
await this.initAsyncPart(subs);
|
|
@@ -660,7 +668,7 @@ var ComRegister = class {
|
|
|
660
668
|
} else if (config.subs && config.subs.length > 0) {
|
|
661
669
|
const subs = this.configSubsToSubscription(config.subs);
|
|
662
670
|
await this.initAsyncPart(subs);
|
|
663
|
-
}
|
|
671
|
+
}
|
|
664
672
|
this.ctx.on("dispose", () => {
|
|
665
673
|
if (this.loginTimer) this.loginTimer();
|
|
666
674
|
if (this.dynamicJob) this.dynamicJob.stop();
|
|
@@ -681,6 +689,14 @@ var ComRegister = class {
|
|
|
681
689
|
this.updateSubNotifier();
|
|
682
690
|
this.logger.info("插件初始化完毕!");
|
|
683
691
|
}
|
|
692
|
+
mergeStopWords(stopWordsStr) {
|
|
693
|
+
if (!stopWordsStr || stopWordsStr.trim() === "") {
|
|
694
|
+
this.stopwords = new Set(stop_words_default);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
|
|
698
|
+
this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
|
|
699
|
+
}
|
|
684
700
|
initManager() {
|
|
685
701
|
for (const sub of this.subManager) {
|
|
686
702
|
if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(luxon.DateTime.now().toSeconds()));
|
|
@@ -706,6 +722,8 @@ var ComRegister = class {
|
|
|
706
722
|
live: s.live,
|
|
707
723
|
liveAtAll: s.liveAtAll,
|
|
708
724
|
liveGuardBuy: s.liveGuardBuy,
|
|
725
|
+
wordcloud: s.wordcloud,
|
|
726
|
+
liveSummary: s.liveSummary,
|
|
709
727
|
bot: null
|
|
710
728
|
}));
|
|
711
729
|
const target = [{
|
|
@@ -717,8 +735,9 @@ var ComRegister = class {
|
|
|
717
735
|
dynamic: s.dynamic,
|
|
718
736
|
live: s.live,
|
|
719
737
|
target,
|
|
720
|
-
|
|
721
|
-
|
|
738
|
+
customCardStyle: { enable: false },
|
|
739
|
+
customLiveMsg: { enable: false },
|
|
740
|
+
customLiveSummary: { enable: false }
|
|
722
741
|
};
|
|
723
742
|
});
|
|
724
743
|
return subs;
|
|
@@ -735,23 +754,23 @@ var ComRegister = class {
|
|
|
735
754
|
if (this.rebootCount >= 3) {
|
|
736
755
|
this.logger.error("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
737
756
|
await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
738
|
-
await this.ctx.
|
|
757
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
739
758
|
return;
|
|
740
759
|
}
|
|
741
760
|
this.rebootCount++;
|
|
742
761
|
this.logger.info("插件出现未知错误,正在重启插件");
|
|
743
|
-
const flag = await this.ctx.
|
|
762
|
+
const flag = await this.ctx["bilibili-notify"].restartPlugin();
|
|
744
763
|
if (flag) this.logger.info("重启插件成功");
|
|
745
764
|
else {
|
|
746
765
|
this.logger.error("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
747
766
|
await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
748
|
-
await this.ctx.
|
|
767
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
749
768
|
}
|
|
750
769
|
}
|
|
751
770
|
async sendPrivateMsgAndStopService() {
|
|
752
771
|
await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
753
772
|
this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
754
|
-
await this.ctx.
|
|
773
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
755
774
|
return;
|
|
756
775
|
}
|
|
757
776
|
async sendMessageWithRetry(bot, channelId, content) {
|
|
@@ -771,19 +790,23 @@ var ComRegister = class {
|
|
|
771
790
|
const liveMsg = {
|
|
772
791
|
customLiveStart: this.config.customLiveStart || "",
|
|
773
792
|
customLive: this.config.customLive || "",
|
|
774
|
-
customLiveEnd: this.config.customLiveEnd || ""
|
|
793
|
+
customLiveEnd: this.config.customLiveEnd || "",
|
|
794
|
+
liveSummary: this.config.liveSummary.join("\n") || ""
|
|
775
795
|
};
|
|
776
|
-
if (sub.
|
|
777
|
-
liveMsg.customLiveStart = sub.
|
|
778
|
-
liveMsg.customLive = sub.
|
|
779
|
-
liveMsg.customLiveEnd = sub.
|
|
796
|
+
if (sub.customLiveMsg.enable) {
|
|
797
|
+
liveMsg.customLiveStart = sub.customLiveMsg.customLiveStart || this.config.customLiveStart;
|
|
798
|
+
liveMsg.customLive = sub.customLiveMsg.customLive || this.config.customLive;
|
|
799
|
+
liveMsg.customLiveEnd = sub.customLiveMsg.customLiveEnd || this.config.customLiveEnd;
|
|
780
800
|
}
|
|
801
|
+
if (sub.customLiveSummary.enable) liveMsg.liveSummary = sub.customLiveSummary.liveSummary || this.config.liveSummary.join("\n");
|
|
781
802
|
this.liveMsgManager.set(sub.uid, liveMsg);
|
|
782
803
|
const dynamicArr = [];
|
|
783
804
|
const dynamicAtAllArr = [];
|
|
784
805
|
const liveArr = [];
|
|
785
806
|
const liveAtAllArr = [];
|
|
786
807
|
const liveGuardBuyArr = [];
|
|
808
|
+
const wordcloudArr = [];
|
|
809
|
+
const liveSummaryArr = [];
|
|
787
810
|
for (const platform of sub.target) for (const channel of platform.channelArr) {
|
|
788
811
|
const target = `${platform.platform}:${channel.channelId}`;
|
|
789
812
|
if (channel.dynamic) dynamicArr.push(target);
|
|
@@ -791,13 +814,17 @@ var ComRegister = class {
|
|
|
791
814
|
if (channel.live) liveArr.push(target);
|
|
792
815
|
if (channel.liveAtAll) liveAtAllArr.push(target);
|
|
793
816
|
if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
|
|
817
|
+
if (channel.wordcloud) wordcloudArr.push(target);
|
|
818
|
+
if (channel.liveSummary) liveSummaryArr.push(target);
|
|
794
819
|
}
|
|
795
820
|
this.pushArrMap.set(sub.uid, {
|
|
796
821
|
dynamicArr,
|
|
797
822
|
dynamicAtAllArr,
|
|
798
823
|
liveArr,
|
|
799
824
|
liveAtAllArr,
|
|
800
|
-
|
|
825
|
+
liveSummaryArr,
|
|
826
|
+
liveGuardBuyArr,
|
|
827
|
+
wordcloudArr
|
|
801
828
|
});
|
|
802
829
|
}
|
|
803
830
|
this.logger.info("初始化推送群组/频道信息:");
|
|
@@ -857,13 +884,43 @@ var ComRegister = class {
|
|
|
857
884
|
}, 1);
|
|
858
885
|
this.logger.info(`成功推送上舰消息:${success.length}条`);
|
|
859
886
|
}
|
|
860
|
-
|
|
887
|
+
if (type === PushType.WordCloudAndLiveSummary) {
|
|
888
|
+
const wordcloudArr = structuredClone(record.wordcloudArr);
|
|
889
|
+
const liveSummaryArr = structuredClone(record.liveSummaryArr);
|
|
890
|
+
const wordcloudAndLiveSummaryArr = wordcloudArr.filter((item) => liveSummaryArr.includes(item));
|
|
891
|
+
const wordcloudOnlyArr = wordcloudArr.filter((item) => !liveSummaryArr.includes(item));
|
|
892
|
+
const liveSummaryOnlyArr = liveSummaryArr.filter((item) => !wordcloudArr.includes(item));
|
|
893
|
+
if (wordcloudAndLiveSummaryArr.length > 0) {
|
|
894
|
+
this.logger.info("词云和直播总结");
|
|
895
|
+
this.logger.info(wordcloudAndLiveSummaryArr);
|
|
896
|
+
const success = await withRetry(async () => {
|
|
897
|
+
return await this.ctx.broadcast(wordcloudAndLiveSummaryArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [content[0], content[1]] }));
|
|
898
|
+
}, 1);
|
|
899
|
+
this.logger.info(`成功推送词云和直播总结消息:${success.length}条`);
|
|
900
|
+
}
|
|
901
|
+
if (wordcloudOnlyArr.length > 0) {
|
|
902
|
+
this.logger.info("词云");
|
|
903
|
+
this.logger.info(wordcloudOnlyArr);
|
|
904
|
+
const success = await withRetry(async () => {
|
|
905
|
+
return await this.ctx.broadcast(wordcloudOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[0] }));
|
|
906
|
+
}, 1);
|
|
907
|
+
this.logger.info(`成功推送词云消息:${success.length}条`);
|
|
908
|
+
}
|
|
909
|
+
if (liveSummaryOnlyArr.length > 0) {
|
|
910
|
+
this.logger.info("直播总结");
|
|
911
|
+
this.logger.info(liveSummaryOnlyArr);
|
|
912
|
+
const success = await withRetry(async () => {
|
|
913
|
+
return await this.ctx.broadcast(liveSummaryOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[1] }));
|
|
914
|
+
}, 1);
|
|
915
|
+
this.logger.info(`成功推送直播总结消息:${success.length}条`);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
861
918
|
}
|
|
862
919
|
dynamicDetect() {
|
|
863
920
|
const handler = async () => {
|
|
864
921
|
const currentPushDyn = {};
|
|
865
922
|
const content = await withRetry(async () => {
|
|
866
|
-
return await this.ctx.
|
|
923
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
867
924
|
}, 1).catch((e) => {
|
|
868
925
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
869
926
|
});
|
|
@@ -872,13 +929,13 @@ var ComRegister = class {
|
|
|
872
929
|
case -101: {
|
|
873
930
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
874
931
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
875
|
-
await this.ctx.
|
|
932
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
876
933
|
break;
|
|
877
934
|
}
|
|
878
935
|
case -352: {
|
|
879
936
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
880
937
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
881
|
-
await this.ctx.
|
|
938
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
882
939
|
break;
|
|
883
940
|
}
|
|
884
941
|
case 4101128:
|
|
@@ -903,7 +960,7 @@ var ComRegister = class {
|
|
|
903
960
|
if (timeline < postTime) {
|
|
904
961
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
905
962
|
const buffer = await withRetry(async () => {
|
|
906
|
-
return await this.ctx.
|
|
963
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
|
|
907
964
|
}, 1).catch(async (e) => {
|
|
908
965
|
if (e.message === "直播开播动态,不做处理") return;
|
|
909
966
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -962,7 +1019,7 @@ var ComRegister = class {
|
|
|
962
1019
|
const currentPushDyn = {};
|
|
963
1020
|
this.logger.info("开始获取动态信息...");
|
|
964
1021
|
const content = await withRetry(async () => {
|
|
965
|
-
return await this.ctx.
|
|
1022
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
966
1023
|
}, 1).catch((e) => {
|
|
967
1024
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
968
1025
|
});
|
|
@@ -971,13 +1028,13 @@ var ComRegister = class {
|
|
|
971
1028
|
case -101: {
|
|
972
1029
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
973
1030
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
974
|
-
await this.ctx.
|
|
1031
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
975
1032
|
break;
|
|
976
1033
|
}
|
|
977
1034
|
case -352: {
|
|
978
1035
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
979
1036
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
980
|
-
await this.ctx.
|
|
1037
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
981
1038
|
break;
|
|
982
1039
|
}
|
|
983
1040
|
case 4101128:
|
|
@@ -1008,7 +1065,7 @@ var ComRegister = class {
|
|
|
1008
1065
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
1009
1066
|
this.logger.info("开始渲染推送卡片...");
|
|
1010
1067
|
const buffer = await withRetry(async () => {
|
|
1011
|
-
return await this.ctx.
|
|
1068
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
|
|
1012
1069
|
}, 1).catch(async (e) => {
|
|
1013
1070
|
if (e.message === "直播开播动态,不做处理") return;
|
|
1014
1071
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -1073,7 +1130,7 @@ var ComRegister = class {
|
|
|
1073
1130
|
return withLock(handler);
|
|
1074
1131
|
}
|
|
1075
1132
|
async useMasterInfo(uid, masterInfo, liveType) {
|
|
1076
|
-
const { data } = await this.ctx.
|
|
1133
|
+
const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
|
|
1077
1134
|
let liveOpenFollowerNum;
|
|
1078
1135
|
let liveEndFollowerNum;
|
|
1079
1136
|
let liveFollowerChange;
|
|
@@ -1098,7 +1155,7 @@ var ComRegister = class {
|
|
|
1098
1155
|
};
|
|
1099
1156
|
}
|
|
1100
1157
|
async useLiveRoomInfo(roomId) {
|
|
1101
|
-
const data = await withRetry(async () => await this.ctx.
|
|
1158
|
+
const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
|
|
1102
1159
|
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
1103
1160
|
return false;
|
|
1104
1161
|
});
|
|
@@ -1107,7 +1164,7 @@ var ComRegister = class {
|
|
|
1107
1164
|
}
|
|
1108
1165
|
async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
|
|
1109
1166
|
const buffer = await withRetry(async () => {
|
|
1110
|
-
return await this.ctx.
|
|
1167
|
+
return await this.ctx["bilibili-notify-generate-img"].generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
|
|
1111
1168
|
}, 1).catch((e) => {
|
|
1112
1169
|
this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
|
|
1113
1170
|
});
|
|
@@ -1116,14 +1173,14 @@ var ComRegister = class {
|
|
|
1116
1173
|
return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
|
|
1117
1174
|
}
|
|
1118
1175
|
async segmentDanmaku(danmaku, danmakuWeightRecord) {
|
|
1119
|
-
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !stopwords.has(word)).map((w) => {
|
|
1176
|
+
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !this.stopwords.has(word)).map((w) => {
|
|
1120
1177
|
danmakuWeightRecord[w] = (danmakuWeightRecord[w] || 0) + 1;
|
|
1121
1178
|
});
|
|
1122
1179
|
}
|
|
1123
1180
|
addUserToDanmakuMaker(username, danmakuMakerRecord) {
|
|
1124
1181
|
danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
|
|
1125
1182
|
}
|
|
1126
|
-
async liveDetectWithListener(roomId,
|
|
1183
|
+
async liveDetectWithListener(roomId, sub) {
|
|
1127
1184
|
let liveTime;
|
|
1128
1185
|
let pushAtTimeTimer;
|
|
1129
1186
|
const danmakuWeightRecord = {};
|
|
@@ -1132,24 +1189,23 @@ var ComRegister = class {
|
|
|
1132
1189
|
let liveRoomInfo;
|
|
1133
1190
|
let masterInfo;
|
|
1134
1191
|
let watchedNum;
|
|
1135
|
-
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1136
|
-
const
|
|
1192
|
+
const liveMsgObj = this.liveMsgManager.get(sub.uid);
|
|
1193
|
+
const sendDanmakuWordCloudAndLiveSummary = async (customLiveSummary) => {
|
|
1137
1194
|
this.logger.info("开始制作弹幕词云");
|
|
1138
1195
|
this.logger.info("正在获取前90热词");
|
|
1139
1196
|
const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1140
1197
|
this.logger.info("弹幕词云前90词及权重:");
|
|
1141
1198
|
this.logger.info(top90Words);
|
|
1142
1199
|
this.logger.info("正在准备生成弹幕词云");
|
|
1143
|
-
const buffer = await this.ctx.
|
|
1144
|
-
|
|
1145
|
-
await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
|
|
1146
|
-
this.logger.info("词云图片发送完毕!");
|
|
1200
|
+
const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
|
|
1201
|
+
const img = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(buffer, "image/jpeg") });
|
|
1147
1202
|
this.logger.info("开始构建弹幕发送排行榜消息");
|
|
1148
1203
|
const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
|
|
1149
1204
|
const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
|
|
1150
1205
|
const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
1151
|
-
const danmakuMakerMsg =
|
|
1152
|
-
|
|
1206
|
+
const danmakuMakerMsg = customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
|
|
1207
|
+
const summary = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: danmakuMakerMsg });
|
|
1208
|
+
await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
|
|
1153
1209
|
Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
|
|
1154
1210
|
Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
|
|
1155
1211
|
};
|
|
@@ -1166,12 +1222,12 @@ var ComRegister = class {
|
|
|
1166
1222
|
}
|
|
1167
1223
|
liveTime = liveRoomInfo.live_time;
|
|
1168
1224
|
const watched = watchedNum || "暂未获取到";
|
|
1169
|
-
const liveMsg = liveMsgObj
|
|
1225
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-watched", watched).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
|
|
1170
1226
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1171
1227
|
liveRoomInfo,
|
|
1172
1228
|
masterInfo,
|
|
1173
|
-
cardStyle
|
|
1174
|
-
}, uid, liveMsg);
|
|
1229
|
+
cardStyle: sub.customCardStyle
|
|
1230
|
+
}, sub.uid, liveMsg);
|
|
1175
1231
|
};
|
|
1176
1232
|
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1177
1233
|
let flag = true;
|
|
@@ -1193,7 +1249,7 @@ var ComRegister = class {
|
|
|
1193
1249
|
onError: async () => {
|
|
1194
1250
|
liveStatus = false;
|
|
1195
1251
|
pushAtTimeTimer?.();
|
|
1196
|
-
this.ctx.
|
|
1252
|
+
this.ctx["bilibili-notify-live"].closeListener(roomId);
|
|
1197
1253
|
await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
|
|
1198
1254
|
this.logger.error(`[${roomId}]直播间连接发生错误!`);
|
|
1199
1255
|
},
|
|
@@ -1218,7 +1274,7 @@ var ComRegister = class {
|
|
|
1218
1274
|
body.gift_name,
|
|
1219
1275
|
")"
|
|
1220
1276
|
] });
|
|
1221
|
-
this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
|
|
1277
|
+
this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
|
|
1222
1278
|
},
|
|
1223
1279
|
onLiveStart: async () => {
|
|
1224
1280
|
if (liveStatus) return;
|
|
@@ -1230,12 +1286,12 @@ var ComRegister = class {
|
|
|
1230
1286
|
}
|
|
1231
1287
|
liveTime = liveRoomInfo.live_time;
|
|
1232
1288
|
const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
|
|
1233
|
-
const liveStartMsg = liveMsgObj
|
|
1289
|
+
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
|
|
1234
1290
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1235
1291
|
liveRoomInfo,
|
|
1236
1292
|
masterInfo,
|
|
1237
|
-
cardStyle
|
|
1238
|
-
}, uid, liveStartMsg);
|
|
1293
|
+
cardStyle: sub.customCardStyle
|
|
1294
|
+
}, sub.uid, liveStartMsg);
|
|
1239
1295
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1240
1296
|
},
|
|
1241
1297
|
onLiveEnd: async () => {
|
|
@@ -1250,28 +1306,28 @@ var ComRegister = class {
|
|
|
1250
1306
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1251
1307
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1252
1308
|
})();
|
|
1253
|
-
const liveEndMsg = liveMsgObj
|
|
1309
|
+
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
|
|
1254
1310
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1255
1311
|
liveRoomInfo,
|
|
1256
1312
|
masterInfo,
|
|
1257
|
-
cardStyle
|
|
1258
|
-
}, uid, liveEndMsg);
|
|
1313
|
+
cardStyle: sub.customCardStyle
|
|
1314
|
+
}, sub.uid, liveEndMsg);
|
|
1259
1315
|
pushAtTimeTimer();
|
|
1260
1316
|
pushAtTimeTimer = null;
|
|
1261
|
-
|
|
1317
|
+
await sendDanmakuWordCloudAndLiveSummary(liveMsgObj.liveSummary);
|
|
1262
1318
|
}
|
|
1263
1319
|
};
|
|
1264
|
-
await this.ctx.
|
|
1320
|
+
await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
|
|
1265
1321
|
if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1266
1322
|
if (liveRoomInfo.live_status === 1) {
|
|
1267
1323
|
liveTime = liveRoomInfo.live_time;
|
|
1268
1324
|
const watched = watchedNum || "暂未获取到";
|
|
1269
|
-
const liveMsg = liveMsgObj
|
|
1325
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-watched", watched).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
|
|
1270
1326
|
if (this.config.restartPush) await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1271
1327
|
liveRoomInfo,
|
|
1272
1328
|
masterInfo,
|
|
1273
|
-
cardStyle
|
|
1274
|
-
}, uid, liveMsg);
|
|
1329
|
+
cardStyle: sub.customCardStyle
|
|
1330
|
+
}, sub.uid, liveMsg);
|
|
1275
1331
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1276
1332
|
liveStatus = true;
|
|
1277
1333
|
}
|
|
@@ -1296,7 +1352,7 @@ var ComRegister = class {
|
|
|
1296
1352
|
const uids = [];
|
|
1297
1353
|
for (const [uid] of this.liveStatusManager.entries()) uids.push(uid);
|
|
1298
1354
|
const useLiveInfo = async () => {
|
|
1299
|
-
const { data: data$1 } = await withRetry(async () => await this.ctx.
|
|
1355
|
+
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1300
1356
|
return void 0;
|
|
1301
1357
|
});
|
|
1302
1358
|
if (!data$1) {
|
|
@@ -1318,11 +1374,11 @@ var ComRegister = class {
|
|
|
1318
1374
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1319
1375
|
liveStatus.liveStartTimeInit = true;
|
|
1320
1376
|
}
|
|
1321
|
-
const liveMsg = liveMsgObj
|
|
1377
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`);
|
|
1322
1378
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1323
1379
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1324
1380
|
masterInfo: liveStatus.masterInfo,
|
|
1325
|
-
cardStyle: sub.
|
|
1381
|
+
cardStyle: sub.customCardStyle
|
|
1326
1382
|
}, sub.uid, liveMsg);
|
|
1327
1383
|
}
|
|
1328
1384
|
}
|
|
@@ -1351,11 +1407,11 @@ var ComRegister = class {
|
|
|
1351
1407
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1352
1408
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1353
1409
|
})();
|
|
1354
|
-
const liveEndMsg = liveMsgObj
|
|
1410
|
+
const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
|
|
1355
1411
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1356
1412
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1357
1413
|
masterInfo: liveStatus.masterInfo,
|
|
1358
|
-
cardStyle: sub.
|
|
1414
|
+
cardStyle: sub.customCardStyle
|
|
1359
1415
|
}, sub.uid, liveEndMsg);
|
|
1360
1416
|
liveStatus.live = false;
|
|
1361
1417
|
}
|
|
@@ -1370,11 +1426,11 @@ var ComRegister = class {
|
|
|
1370
1426
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1371
1427
|
liveStatus.liveStartTimeInit = true;
|
|
1372
1428
|
const follower = liveStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(liveStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : liveStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1373
|
-
const liveStartMsg = liveMsgObj
|
|
1429
|
+
const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`);
|
|
1374
1430
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1375
1431
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1376
1432
|
masterInfo: liveStatus.masterInfo,
|
|
1377
|
-
cardStyle: sub.
|
|
1433
|
+
cardStyle: sub.customCardStyle
|
|
1378
1434
|
}, sub.uid, liveStartMsg);
|
|
1379
1435
|
liveStatus.live = true;
|
|
1380
1436
|
}
|
|
@@ -1391,11 +1447,11 @@ var ComRegister = class {
|
|
|
1391
1447
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1392
1448
|
liveStatus.liveStartTimeInit = true;
|
|
1393
1449
|
}
|
|
1394
|
-
const liveMsg = liveMsgObj
|
|
1450
|
+
const liveMsg = liveMsgObj.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`);
|
|
1395
1451
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1396
1452
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1397
1453
|
masterInfo: liveStatus.masterInfo,
|
|
1398
|
-
cardStyle: sub.
|
|
1454
|
+
cardStyle: sub.customCardStyle
|
|
1399
1455
|
}, sub.uid, liveMsg);
|
|
1400
1456
|
liveStatus.push = 0;
|
|
1401
1457
|
}
|
|
@@ -1427,7 +1483,7 @@ var ComRegister = class {
|
|
|
1427
1483
|
async checkIfLoginInfoIsLoaded() {
|
|
1428
1484
|
return new Promise((resolve$1) => {
|
|
1429
1485
|
const check = () => {
|
|
1430
|
-
if (!this.ctx.
|
|
1486
|
+
if (!this.ctx["bilibili-notify-api"].getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
|
|
1431
1487
|
else resolve$1("success");
|
|
1432
1488
|
};
|
|
1433
1489
|
check();
|
|
@@ -1436,9 +1492,9 @@ var ComRegister = class {
|
|
|
1436
1492
|
async subUserInBili(mid) {
|
|
1437
1493
|
const checkGroupIsReady = async () => {
|
|
1438
1494
|
if (!this.loginDBData?.dynamic_group_id) {
|
|
1439
|
-
const createGroupData = await this.ctx.
|
|
1495
|
+
const createGroupData = await this.ctx["bilibili-notify-api"].createGroup("订阅");
|
|
1440
1496
|
if (createGroupData.code === 22106) {
|
|
1441
|
-
const allGroupData = await this.ctx.
|
|
1497
|
+
const allGroupData = await this.ctx["bilibili-notify-api"].getAllGroup();
|
|
1442
1498
|
for (const group of allGroupData.data) if (group.name === "订阅") {
|
|
1443
1499
|
this.loginDBData.dynamic_group_id = group.tagid.toString();
|
|
1444
1500
|
this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
|
|
@@ -1465,7 +1521,7 @@ var ComRegister = class {
|
|
|
1465
1521
|
const resp = await checkGroupIsReady();
|
|
1466
1522
|
if (resp.code !== 0) return resp;
|
|
1467
1523
|
const getGroupDetailData = async () => {
|
|
1468
|
-
const relationGroupDetailData = await this.ctx.
|
|
1524
|
+
const relationGroupDetailData = await this.ctx["bilibili-notify-api"].getRelationGroupDetail(this.loginDBData.dynamic_group_id);
|
|
1469
1525
|
if (relationGroupDetailData.code !== 0) {
|
|
1470
1526
|
if (relationGroupDetailData.code === 22104) {
|
|
1471
1527
|
this.loginDBData.dynamic_group_id = null;
|
|
@@ -1494,7 +1550,7 @@ var ComRegister = class {
|
|
|
1494
1550
|
code: 0,
|
|
1495
1551
|
msg: "订阅对象已存在于分组中"
|
|
1496
1552
|
};
|
|
1497
|
-
const subUserData = await this.ctx.
|
|
1553
|
+
const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
|
|
1498
1554
|
const subUserMatchPattern = {
|
|
1499
1555
|
[-101]: () => {
|
|
1500
1556
|
return {
|
|
@@ -1539,7 +1595,7 @@ var ComRegister = class {
|
|
|
1539
1595
|
};
|
|
1540
1596
|
},
|
|
1541
1597
|
22014: async () => {
|
|
1542
|
-
const copyUserToGroupData = await this.ctx.
|
|
1598
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1543
1599
|
if (copyUserToGroupData.code !== 0) return {
|
|
1544
1600
|
code: copyUserToGroupData.code,
|
|
1545
1601
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1550,7 +1606,7 @@ var ComRegister = class {
|
|
|
1550
1606
|
};
|
|
1551
1607
|
},
|
|
1552
1608
|
0: async () => {
|
|
1553
|
-
const copyUserToGroupData = await this.ctx.
|
|
1609
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1554
1610
|
if (copyUserToGroupData.code !== 0) return {
|
|
1555
1611
|
code: copyUserToGroupData.code,
|
|
1556
1612
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1568,7 +1624,7 @@ var ComRegister = class {
|
|
|
1568
1624
|
for (const sub of Object.values(subs)) {
|
|
1569
1625
|
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1570
1626
|
const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
|
|
1571
|
-
const data = await this.ctx.
|
|
1627
|
+
const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
|
|
1572
1628
|
return {
|
|
1573
1629
|
code: 0,
|
|
1574
1630
|
data
|
|
@@ -1581,7 +1637,7 @@ var ComRegister = class {
|
|
|
1581
1637
|
};
|
|
1582
1638
|
});
|
|
1583
1639
|
if (userInfoCode === -352 && userInfoData.v_voucher) {
|
|
1584
|
-
this.logger.info("账号被风控,请使用指令 bili
|
|
1640
|
+
this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1585
1641
|
await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1586
1642
|
return {
|
|
1587
1643
|
code: userInfoCode,
|
|
@@ -1597,21 +1653,20 @@ var ComRegister = class {
|
|
|
1597
1653
|
sub.live = false;
|
|
1598
1654
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1599
1655
|
}
|
|
1600
|
-
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub
|
|
1656
|
+
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
|
|
1601
1657
|
}
|
|
1602
1658
|
const subInfo = await this.subUserInBili(sub.uid);
|
|
1603
1659
|
if (subInfo.code !== 0) return subInfo;
|
|
1604
1660
|
this.subManager.push({
|
|
1605
|
-
id: +sub.uid,
|
|
1606
1661
|
uid: sub.uid,
|
|
1607
1662
|
uname: userInfoData.name,
|
|
1608
1663
|
roomId: sub.live ? userInfoData.live_room.roomid : "",
|
|
1609
1664
|
target: sub.target,
|
|
1610
|
-
platform: "",
|
|
1611
1665
|
live: sub.live,
|
|
1612
1666
|
dynamic: sub.dynamic,
|
|
1613
|
-
|
|
1614
|
-
|
|
1667
|
+
customCardStyle: sub.customCardStyle,
|
|
1668
|
+
customLiveMsg: sub.customLiveMsg,
|
|
1669
|
+
customLiveSummary: sub.customLiveSummary
|
|
1615
1670
|
});
|
|
1616
1671
|
this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
|
|
1617
1672
|
if (sub !== Object.values(subs).pop()) {
|
|
@@ -1645,7 +1700,7 @@ var ComRegister = class {
|
|
|
1645
1700
|
}
|
|
1646
1701
|
async checkIfIsLogin() {
|
|
1647
1702
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
|
1648
|
-
if (this.ctx.
|
|
1703
|
+
if (this.ctx["bilibili-notify-api"].getCookies() !== "[]") return true;
|
|
1649
1704
|
}
|
|
1650
1705
|
return false;
|
|
1651
1706
|
}
|
|
@@ -1661,6 +1716,8 @@ var ComRegister = class {
|
|
|
1661
1716
|
live: koishi.Schema.boolean().default(true).description("直播"),
|
|
1662
1717
|
liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
|
|
1663
1718
|
liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
|
|
1719
|
+
wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
|
|
1720
|
+
liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
|
|
1664
1721
|
platform: koishi.Schema.string().required().description("平台名"),
|
|
1665
1722
|
target: koishi.Schema.string().required().description("群号/频道号")
|
|
1666
1723
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -1671,8 +1728,8 @@ var ComRegister = class {
|
|
|
1671
1728
|
masterAccountGuildId: koishi.Schema.string()
|
|
1672
1729
|
}),
|
|
1673
1730
|
liveDetectType: koishi.Schema.string(),
|
|
1674
|
-
|
|
1675
|
-
liveSummary: koishi.Schema.
|
|
1731
|
+
wordcloudStopWords: koishi.Schema.string(),
|
|
1732
|
+
liveSummary: koishi.Schema.array(String),
|
|
1676
1733
|
restartPush: koishi.Schema.boolean().required(),
|
|
1677
1734
|
pushTime: koishi.Schema.number().required(),
|
|
1678
1735
|
pushImgsInDynamic: koishi.Schema.boolean().required(),
|
|
@@ -1729,10 +1786,10 @@ const DYNAMIC_TYPE_LIVE_RCMD = "DYNAMIC_TYPE_LIVE_RCMD";
|
|
|
1729
1786
|
const DYNAMIC_TYPE_UGC_SEASON = "DYNAMIC_TYPE_UGC_SEASON";
|
|
1730
1787
|
const ADDITIONAL_TYPE_RESERVE = "ADDITIONAL_TYPE_RESERVE";
|
|
1731
1788
|
var GenerateImg = class extends koishi.Service {
|
|
1732
|
-
static inject = ["puppeteer"
|
|
1789
|
+
static inject = ["puppeteer"];
|
|
1733
1790
|
giConfig;
|
|
1734
1791
|
constructor(ctx, config) {
|
|
1735
|
-
super(ctx, "
|
|
1792
|
+
super(ctx, "bilibili-notify-generate-img");
|
|
1736
1793
|
this.giConfig = config;
|
|
1737
1794
|
}
|
|
1738
1795
|
async imgHandler(html) {
|
|
@@ -3312,7 +3369,7 @@ var BiliAPI = class extends koishi.Service {
|
|
|
3312
3369
|
pRetry;
|
|
3313
3370
|
AbortError;
|
|
3314
3371
|
constructor(ctx, config) {
|
|
3315
|
-
super(ctx, "
|
|
3372
|
+
super(ctx, "bilibili-notify-api");
|
|
3316
3373
|
this.apiConfig = config;
|
|
3317
3374
|
}
|
|
3318
3375
|
async start() {
|
|
@@ -3589,13 +3646,15 @@ var BiliAPI = class extends koishi.Service {
|
|
|
3589
3646
|
retries: 3
|
|
3590
3647
|
});
|
|
3591
3648
|
}
|
|
3592
|
-
async getUserInfo(mid) {
|
|
3649
|
+
async getUserInfo(mid, grisk_id) {
|
|
3593
3650
|
const run = async () => {
|
|
3594
3651
|
if (mid === "11783021") {
|
|
3595
3652
|
console.log("检测到番剧出差UID,跳过远程用户接口访问");
|
|
3596
3653
|
return bangumiTripData;
|
|
3597
3654
|
}
|
|
3598
|
-
const
|
|
3655
|
+
const params = { mid };
|
|
3656
|
+
if (grisk_id) params.grisk_id = grisk_id;
|
|
3657
|
+
const wbi = await this.getWbi(params);
|
|
3599
3658
|
const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
|
|
3600
3659
|
return data;
|
|
3601
3660
|
};
|
|
@@ -3961,6 +4020,7 @@ var BiliAPI = class extends koishi.Service {
|
|
|
3961
4020
|
this.logger.info(`验证失败:错误码=${data.code},错误消息:${data.message}`);
|
|
3962
4021
|
return { data: null };
|
|
3963
4022
|
}
|
|
4023
|
+
this.addCookie(`x-bili-gaia-vtoken=${data.data.grisk_id}`);
|
|
3964
4024
|
return { data: data.data };
|
|
3965
4025
|
}
|
|
3966
4026
|
};
|
|
@@ -3975,17 +4035,17 @@ var bili_api_default = BiliAPI;
|
|
|
3975
4035
|
//#endregion
|
|
3976
4036
|
//#region src/bili_live.ts
|
|
3977
4037
|
var BLive = class extends koishi.Service {
|
|
3978
|
-
static inject = ["
|
|
4038
|
+
static inject = ["bilibili-notify-api"];
|
|
3979
4039
|
listenerRecord = {};
|
|
3980
4040
|
constructor(ctx) {
|
|
3981
|
-
super(ctx, "
|
|
4041
|
+
super(ctx, "bilibili-notify-live");
|
|
3982
4042
|
}
|
|
3983
4043
|
stop() {
|
|
3984
4044
|
for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
|
|
3985
4045
|
}
|
|
3986
4046
|
async startLiveRoomListener(roomId, handler) {
|
|
3987
|
-
const cookiesStr = await this.ctx.
|
|
3988
|
-
const mySelfInfo = await this.ctx.
|
|
4047
|
+
const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
|
|
4048
|
+
const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
|
|
3989
4049
|
this.listenerRecord[roomId] = (0, __akokko_blive_message_listener.startListen)(Number.parseInt(roomId), handler, { ws: {
|
|
3990
4050
|
headers: { Cookie: cookiesStr },
|
|
3991
4051
|
uid: mySelfInfo.data.mid
|
|
@@ -4021,8 +4081,8 @@ let globalConfig;
|
|
|
4021
4081
|
var ServerManager = class extends koishi.Service {
|
|
4022
4082
|
servers = [];
|
|
4023
4083
|
constructor(ctx) {
|
|
4024
|
-
super(ctx, "
|
|
4025
|
-
const sysCom = ctx.command("bn", "
|
|
4084
|
+
super(ctx, "bilibili-notify");
|
|
4085
|
+
const sysCom = ctx.command("bn", "bilibili-notify 插件运行相关指令", { permissions: ["authority:5"] });
|
|
4026
4086
|
sysCom.subcommand(".restart", "重启插件").usage("重启插件").example("bn restart").action(async () => {
|
|
4027
4087
|
this.logger.info("调用 bn restart 指令");
|
|
4028
4088
|
if (await this.restartPlugin()) return "插件重启成功";
|
|
@@ -4065,7 +4125,7 @@ var ServerManager = class extends koishi.Service {
|
|
|
4065
4125
|
advancedSub: globalConfig.advancedSub,
|
|
4066
4126
|
subs: globalConfig.subs,
|
|
4067
4127
|
master: globalConfig.master,
|
|
4068
|
-
|
|
4128
|
+
wordcloudStopWords: globalConfig.wordcloudStopWords,
|
|
4069
4129
|
liveSummary: globalConfig.liveSummary,
|
|
4070
4130
|
liveDetectType: globalConfig.liveDetectType,
|
|
4071
4131
|
restartPush: globalConfig.restartPush,
|