koishi-plugin-bilibili-notify 3.3.0-rc.0 → 3.3.1-alpha.0
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 +14 -5
- package/lib/index.d.ts +14 -5
- package/lib/index.js +135 -104
- package/lib/index.mjs +135 -104
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/index.js
CHANGED
|
@@ -80,6 +80,7 @@ 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("弹幕词云"),
|
|
83
84
|
platform: koishi.Schema.string().required().description("平台名"),
|
|
84
85
|
target: koishi.Schema.string().required().description("群号/频道号")
|
|
85
86
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -90,8 +91,19 @@ const BAConfigSchema = koishi.Schema.object({
|
|
|
90
91
|
pushImgsInDynamic: koishi.Schema.boolean().default(false).description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,该功能容易导致QQ风控"),
|
|
91
92
|
live: koishi.Schema.object({}).description("直播推送设置"),
|
|
92
93
|
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.
|
|
94
|
+
wordcloudStopWords: koishi.Schema.string().description("词云生成时的停用词,多个停用词请使用英文逗号分隔,例如:哔哩哔哩,弹幕,直播,词云").experimental(),
|
|
95
|
+
liveSummary: koishi.Schema.array(String).default([
|
|
96
|
+
"🔍【弹幕情报站】本场直播数据如下:",
|
|
97
|
+
"🧍♂️ 总共 -dmc 位-mdn上线",
|
|
98
|
+
"💬 共计 -dca 条弹幕飞驰而过",
|
|
99
|
+
"📊 热词云图已生成,快来看看你有没有上榜!",
|
|
100
|
+
"👑 本场顶级输出选手:",
|
|
101
|
+
"🥇 -un1 - 弹幕输出 -dc1 条",
|
|
102
|
+
"🥈 -un2 - 弹幕 -dc2 条,萌力惊人",
|
|
103
|
+
"🥉 -un3 - -dc3 条精准狙击",
|
|
104
|
+
"🎖️ 特别嘉奖:-un4 & -un5",
|
|
105
|
+
"你们的弹幕,我们都记录在案!🕵️♀️"
|
|
106
|
+
]).role("table").description("自定义直播总结语,开启弹幕词云自动发送。变量解释:-dmc代表总弹幕发送人数,-mdn代表主播粉丝牌子名,-dca代表总弹幕数,-un1到-un5代表弹幕发送条数前五名用户的用户名,-dc1到-dc5代表弹幕发送条数前五名的弹幕发送数量,数组每一行代表换行"),
|
|
95
107
|
restartPush: koishi.Schema.boolean().default(true).description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
|
|
96
108
|
pushTime: koishi.Schema.number().min(0).max(12).step(.5).default(1).description("设定间隔多长时间推送一次直播状态,单位为小时,默认为一小时"),
|
|
97
109
|
customLiveStart: koishi.Schema.string().default("-name开播啦,当前粉丝数:-follower\\n-link").description("自定义开播提示语,-name代表UP昵称,-follower代表当前粉丝数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用),\\n为换行。例如-name开播啦,会发送为xxxUP开播啦"),
|
|
@@ -179,6 +191,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
|
|
|
179
191
|
PushType$1[PushType$1["DynamicAtAll"] = 2] = "DynamicAtAll";
|
|
180
192
|
PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
|
|
181
193
|
PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
|
|
194
|
+
PushType$1[PushType$1["WordCloud"] = 5] = "WordCloud";
|
|
182
195
|
return PushType$1;
|
|
183
196
|
}({});
|
|
184
197
|
const PushTypeMsg = {
|
|
@@ -186,7 +199,8 @@ const PushTypeMsg = {
|
|
|
186
199
|
[PushType.Dynamic]: "动态推送",
|
|
187
200
|
[PushType.DynamicAtAll]: "动态推送+At全体",
|
|
188
201
|
[PushType.StartBroadcasting]: "开播推送",
|
|
189
|
-
[PushType.LiveGuardBuy]: "上舰推送"
|
|
202
|
+
[PushType.LiveGuardBuy]: "上舰推送",
|
|
203
|
+
[PushType.WordCloud]: "弹幕词云推送"
|
|
190
204
|
};
|
|
191
205
|
|
|
192
206
|
//#endregion
|
|
@@ -323,16 +337,17 @@ const stopwords = new Set([
|
|
|
323
337
|
"之前",
|
|
324
338
|
"某天"
|
|
325
339
|
]);
|
|
340
|
+
var stop_words_default = stopwords;
|
|
326
341
|
|
|
327
342
|
//#endregion
|
|
328
343
|
//#region src/command_register.tsx
|
|
329
344
|
var ComRegister = class {
|
|
330
345
|
static inject = [
|
|
331
|
-
"
|
|
332
|
-
"
|
|
333
|
-
"
|
|
334
|
-
"
|
|
335
|
-
"
|
|
346
|
+
"bilibili-notify",
|
|
347
|
+
"bilibili-notify-api",
|
|
348
|
+
"bilibili-notify-live",
|
|
349
|
+
"bilibili-notify-generate-img",
|
|
350
|
+
"database"
|
|
336
351
|
];
|
|
337
352
|
qqRelatedBotList = [
|
|
338
353
|
"qq",
|
|
@@ -358,6 +373,7 @@ var ComRegister = class {
|
|
|
358
373
|
dynamicJob;
|
|
359
374
|
liveJob;
|
|
360
375
|
_jieba = __node_rs_jieba.Jieba.withDict(__node_rs_jieba_dict.dict);
|
|
376
|
+
stopwords;
|
|
361
377
|
constructor(ctx, config) {
|
|
362
378
|
this.ctx = ctx;
|
|
363
379
|
this.init(config);
|
|
@@ -388,7 +404,7 @@ var ComRegister = class {
|
|
|
388
404
|
this.logger.info("调用bili login指令");
|
|
389
405
|
let content;
|
|
390
406
|
try {
|
|
391
|
-
content = await ctx.
|
|
407
|
+
content = await ctx["bilibili-notify-api"].getLoginQRCode();
|
|
392
408
|
} catch (_) {
|
|
393
409
|
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
394
410
|
}
|
|
@@ -413,7 +429,7 @@ var ComRegister = class {
|
|
|
413
429
|
flag = false;
|
|
414
430
|
let loginContent;
|
|
415
431
|
try {
|
|
416
|
-
loginContent = await ctx.
|
|
432
|
+
loginContent = await ctx["bilibili-notify-api"].getLoginStatus(content.data.qrcode_key);
|
|
417
433
|
} catch (e) {
|
|
418
434
|
this.logger.error(e);
|
|
419
435
|
return;
|
|
@@ -427,24 +443,19 @@ var ComRegister = class {
|
|
|
427
443
|
return await session.send("二维码已失效,请重新登录");
|
|
428
444
|
}
|
|
429
445
|
if (loginContent.data.code === 0) {
|
|
430
|
-
const encryptedCookies = ctx.
|
|
431
|
-
const encryptedRefreshToken = ctx.
|
|
446
|
+
const encryptedCookies = ctx["bilibili-notify-api"].encrypt(ctx["bilibili-notify-api"].getCookies());
|
|
447
|
+
const encryptedRefreshToken = ctx["bilibili-notify-api"].encrypt(loginContent.data.refresh_token);
|
|
432
448
|
await ctx.database.upsert("loginBili", [{
|
|
433
449
|
id: 1,
|
|
434
450
|
bili_cookies: encryptedCookies,
|
|
435
451
|
bili_refresh_token: encryptedRefreshToken
|
|
436
452
|
}]);
|
|
437
453
|
this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
|
|
438
|
-
await this.ctx.
|
|
454
|
+
await this.ctx["bilibili-notify-api"].loadCookiesFromDatabase();
|
|
439
455
|
await this.checkIfLoginInfoIsLoaded();
|
|
440
456
|
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();
|
|
457
|
+
ctx["bilibili-notify-api"].disposeNotifier();
|
|
458
|
+
await session.send("登录成功,请重启插件");
|
|
448
459
|
}
|
|
449
460
|
} finally {
|
|
450
461
|
flag = true;
|
|
@@ -460,7 +471,7 @@ var ComRegister = class {
|
|
|
460
471
|
await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
|
|
461
472
|
});
|
|
462
473
|
biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
|
|
463
|
-
const { data: { live_users } } = await ctx.
|
|
474
|
+
const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
|
|
464
475
|
const subLiveUsers = [];
|
|
465
476
|
for (const sub of this.subManager) {
|
|
466
477
|
let onLive = false;
|
|
@@ -482,10 +493,10 @@ var ComRegister = class {
|
|
|
482
493
|
});
|
|
483
494
|
biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
|
|
484
495
|
const i = index && index - 1 || 0;
|
|
485
|
-
const content = await this.ctx.
|
|
496
|
+
const content = await this.ctx["bilibili-notify-api"].getUserSpaceDynamic(uid);
|
|
486
497
|
const item = content.data.items[i];
|
|
487
498
|
const buffer = await withRetry(async () => {
|
|
488
|
-
return await this.ctx.
|
|
499
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item);
|
|
489
500
|
}, 1).catch(async (e) => {
|
|
490
501
|
if (e.message === "直播开播动态,不做处理") {
|
|
491
502
|
await session.send("直播开播动态,不做处理");
|
|
@@ -600,7 +611,7 @@ var ComRegister = class {
|
|
|
600
611
|
["初中", 4],
|
|
601
612
|
["毕业", 4]
|
|
602
613
|
];
|
|
603
|
-
await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx.
|
|
614
|
+
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
615
|
const top5DanmakuMaker = [
|
|
605
616
|
["张三", 60],
|
|
606
617
|
["李四", 48],
|
|
@@ -608,19 +619,19 @@ var ComRegister = class {
|
|
|
608
619
|
["赵六", 27],
|
|
609
620
|
["田七", 25]
|
|
610
621
|
];
|
|
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");
|
|
622
|
+
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
623
|
await session.send(danmakerRankMsg);
|
|
613
624
|
});
|
|
614
625
|
biliCom.subcommand(".cap").action(async ({ session }) => {
|
|
615
626
|
const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
|
|
616
|
-
const data$1 = await this.ctx.
|
|
627
|
+
const data$1 = await this.ctx["bilibili-notify-api"].getUserInfo("114514");
|
|
617
628
|
return {
|
|
618
629
|
code: 0,
|
|
619
630
|
data: data$1
|
|
620
631
|
};
|
|
621
632
|
}).then((content) => content.data);
|
|
622
633
|
if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
|
|
623
|
-
const { data } = await ctx.
|
|
634
|
+
const { data } = await ctx["bilibili-notify-api"].v_voucherCaptcha(userInfoData.v_voucher);
|
|
624
635
|
if (!data.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
|
|
625
636
|
await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
|
|
626
637
|
await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
|
|
@@ -629,19 +640,13 @@ var ComRegister = class {
|
|
|
629
640
|
await session.send("请直接输入validate");
|
|
630
641
|
const validate = await session.prompt();
|
|
631
642
|
const seccode = `${validate}|jordan`;
|
|
632
|
-
const { data: validateCaptchaData } = await ctx.
|
|
643
|
+
const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
|
|
633
644
|
if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
|
|
634
|
-
ctx.ba.addCookie(`x-bili-gaia-vtoken=${validateCaptchaData.grisk_id}`);
|
|
635
|
-
const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
|
|
636
|
-
await ctx.database.upsert("loginBili", [{
|
|
637
|
-
id: 1,
|
|
638
|
-
bili_cookies: encryptedCookies
|
|
639
|
-
}]);
|
|
640
645
|
return "验证成功!请重启插件";
|
|
641
646
|
});
|
|
642
647
|
}
|
|
643
648
|
async init(config) {
|
|
644
|
-
this.logger = this.ctx.logger("
|
|
649
|
+
this.logger = this.ctx.logger("bilibili-notify-core");
|
|
645
650
|
this.logger.info("初始化插件中...");
|
|
646
651
|
this.config = config;
|
|
647
652
|
this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
|
|
@@ -652,6 +657,7 @@ var ComRegister = class {
|
|
|
652
657
|
this.logger.info("账号未登录,请登录");
|
|
653
658
|
return;
|
|
654
659
|
}
|
|
660
|
+
this.mergeStopWords(config.wordcloudStopWords);
|
|
655
661
|
if (config.advancedSub) {
|
|
656
662
|
this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
|
|
657
663
|
await this.initAsyncPart(subs);
|
|
@@ -681,6 +687,14 @@ var ComRegister = class {
|
|
|
681
687
|
this.updateSubNotifier();
|
|
682
688
|
this.logger.info("插件初始化完毕!");
|
|
683
689
|
}
|
|
690
|
+
mergeStopWords(stopWordsStr) {
|
|
691
|
+
if (!stopWordsStr || stopWordsStr.trim() === "") {
|
|
692
|
+
this.stopwords = new Set(stop_words_default);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
|
|
696
|
+
this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
|
|
697
|
+
}
|
|
684
698
|
initManager() {
|
|
685
699
|
for (const sub of this.subManager) {
|
|
686
700
|
if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(luxon.DateTime.now().toSeconds()));
|
|
@@ -706,6 +720,7 @@ var ComRegister = class {
|
|
|
706
720
|
live: s.live,
|
|
707
721
|
liveAtAll: s.liveAtAll,
|
|
708
722
|
liveGuardBuy: s.liveGuardBuy,
|
|
723
|
+
wordcloud: s.wordcloud,
|
|
709
724
|
bot: null
|
|
710
725
|
}));
|
|
711
726
|
const target = [{
|
|
@@ -716,9 +731,11 @@ var ComRegister = class {
|
|
|
716
731
|
uid: s.uid,
|
|
717
732
|
dynamic: s.dynamic,
|
|
718
733
|
live: s.live,
|
|
734
|
+
wordcloud: s.wordcloud,
|
|
719
735
|
target,
|
|
720
736
|
card: { enable: false },
|
|
721
|
-
liveMsg: { enable: false }
|
|
737
|
+
liveMsg: { enable: false },
|
|
738
|
+
liveSummary: { enable: false }
|
|
722
739
|
};
|
|
723
740
|
});
|
|
724
741
|
return subs;
|
|
@@ -735,23 +752,23 @@ var ComRegister = class {
|
|
|
735
752
|
if (this.rebootCount >= 3) {
|
|
736
753
|
this.logger.error("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
737
754
|
await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
738
|
-
await this.ctx.
|
|
755
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
739
756
|
return;
|
|
740
757
|
}
|
|
741
758
|
this.rebootCount++;
|
|
742
759
|
this.logger.info("插件出现未知错误,正在重启插件");
|
|
743
|
-
const flag = await this.ctx.
|
|
760
|
+
const flag = await this.ctx["bilibili-notify"].restartPlugin();
|
|
744
761
|
if (flag) this.logger.info("重启插件成功");
|
|
745
762
|
else {
|
|
746
763
|
this.logger.error("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
747
764
|
await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
748
|
-
await this.ctx.
|
|
765
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
749
766
|
}
|
|
750
767
|
}
|
|
751
768
|
async sendPrivateMsgAndStopService() {
|
|
752
769
|
await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
753
770
|
this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
754
|
-
await this.ctx.
|
|
771
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
755
772
|
return;
|
|
756
773
|
}
|
|
757
774
|
async sendMessageWithRetry(bot, channelId, content) {
|
|
@@ -771,19 +788,22 @@ var ComRegister = class {
|
|
|
771
788
|
const liveMsg = {
|
|
772
789
|
customLiveStart: this.config.customLiveStart || "",
|
|
773
790
|
customLive: this.config.customLive || "",
|
|
774
|
-
customLiveEnd: this.config.customLiveEnd || ""
|
|
791
|
+
customLiveEnd: this.config.customLiveEnd || "",
|
|
792
|
+
liveSummary: this.config.liveSummary.join("\n") || ""
|
|
775
793
|
};
|
|
776
794
|
if (sub.liveMsg.enable) {
|
|
777
795
|
liveMsg.customLiveStart = sub.liveMsg.customLiveStart || this.config.customLiveStart;
|
|
778
796
|
liveMsg.customLive = sub.liveMsg.customLive || this.config.customLive;
|
|
779
797
|
liveMsg.customLiveEnd = sub.liveMsg.customLiveEnd || this.config.customLiveEnd;
|
|
780
798
|
}
|
|
799
|
+
if (sub.liveSummary.enable) liveMsg.liveSummary = sub.liveSummary.liveSummary || this.config.liveSummary.join("\n");
|
|
781
800
|
this.liveMsgManager.set(sub.uid, liveMsg);
|
|
782
801
|
const dynamicArr = [];
|
|
783
802
|
const dynamicAtAllArr = [];
|
|
784
803
|
const liveArr = [];
|
|
785
804
|
const liveAtAllArr = [];
|
|
786
805
|
const liveGuardBuyArr = [];
|
|
806
|
+
const wordcloudArr = [];
|
|
787
807
|
for (const platform of sub.target) for (const channel of platform.channelArr) {
|
|
788
808
|
const target = `${platform.platform}:${channel.channelId}`;
|
|
789
809
|
if (channel.dynamic) dynamicArr.push(target);
|
|
@@ -791,13 +811,15 @@ var ComRegister = class {
|
|
|
791
811
|
if (channel.live) liveArr.push(target);
|
|
792
812
|
if (channel.liveAtAll) liveAtAllArr.push(target);
|
|
793
813
|
if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
|
|
814
|
+
if (channel.wordcloud) wordcloudArr.push(target);
|
|
794
815
|
}
|
|
795
816
|
this.pushArrMap.set(sub.uid, {
|
|
796
817
|
dynamicArr,
|
|
797
818
|
dynamicAtAllArr,
|
|
798
819
|
liveArr,
|
|
799
820
|
liveAtAllArr,
|
|
800
|
-
liveGuardBuyArr
|
|
821
|
+
liveGuardBuyArr,
|
|
822
|
+
wordcloudArr
|
|
801
823
|
});
|
|
802
824
|
}
|
|
803
825
|
this.logger.info("初始化推送群组/频道信息:");
|
|
@@ -857,13 +879,21 @@ var ComRegister = class {
|
|
|
857
879
|
}, 1);
|
|
858
880
|
this.logger.info(`成功推送上舰消息:${success.length}条`);
|
|
859
881
|
}
|
|
882
|
+
if (type === PushType.WordCloud && record.wordcloudArr?.length >= 1) {
|
|
883
|
+
this.logger.info(record.wordcloudArr);
|
|
884
|
+
const wordcloudArr = structuredClone(record.wordcloudArr);
|
|
885
|
+
const success = await withRetry(async () => {
|
|
886
|
+
return await this.ctx.broadcast(wordcloudArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
|
|
887
|
+
}, 1);
|
|
888
|
+
this.logger.info(`成功推送词云消息:${success.length}条`);
|
|
889
|
+
}
|
|
860
890
|
return;
|
|
861
891
|
}
|
|
862
892
|
dynamicDetect() {
|
|
863
893
|
const handler = async () => {
|
|
864
894
|
const currentPushDyn = {};
|
|
865
895
|
const content = await withRetry(async () => {
|
|
866
|
-
return await this.ctx.
|
|
896
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
867
897
|
}, 1).catch((e) => {
|
|
868
898
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
869
899
|
});
|
|
@@ -872,13 +902,13 @@ var ComRegister = class {
|
|
|
872
902
|
case -101: {
|
|
873
903
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
874
904
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
875
|
-
await this.ctx.
|
|
905
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
876
906
|
break;
|
|
877
907
|
}
|
|
878
908
|
case -352: {
|
|
879
909
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
880
910
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
881
|
-
await this.ctx.
|
|
911
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
882
912
|
break;
|
|
883
913
|
}
|
|
884
914
|
case 4101128:
|
|
@@ -903,7 +933,7 @@ var ComRegister = class {
|
|
|
903
933
|
if (timeline < postTime) {
|
|
904
934
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
905
935
|
const buffer = await withRetry(async () => {
|
|
906
|
-
return await this.ctx.
|
|
936
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
|
|
907
937
|
}, 1).catch(async (e) => {
|
|
908
938
|
if (e.message === "直播开播动态,不做处理") return;
|
|
909
939
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -962,7 +992,7 @@ var ComRegister = class {
|
|
|
962
992
|
const currentPushDyn = {};
|
|
963
993
|
this.logger.info("开始获取动态信息...");
|
|
964
994
|
const content = await withRetry(async () => {
|
|
965
|
-
return await this.ctx.
|
|
995
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
966
996
|
}, 1).catch((e) => {
|
|
967
997
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
968
998
|
});
|
|
@@ -971,13 +1001,13 @@ var ComRegister = class {
|
|
|
971
1001
|
case -101: {
|
|
972
1002
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
973
1003
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
974
|
-
await this.ctx.
|
|
1004
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
975
1005
|
break;
|
|
976
1006
|
}
|
|
977
1007
|
case -352: {
|
|
978
1008
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
979
1009
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
980
|
-
await this.ctx.
|
|
1010
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
981
1011
|
break;
|
|
982
1012
|
}
|
|
983
1013
|
case 4101128:
|
|
@@ -1008,7 +1038,7 @@ var ComRegister = class {
|
|
|
1008
1038
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
1009
1039
|
this.logger.info("开始渲染推送卡片...");
|
|
1010
1040
|
const buffer = await withRetry(async () => {
|
|
1011
|
-
return await this.ctx.
|
|
1041
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
|
|
1012
1042
|
}, 1).catch(async (e) => {
|
|
1013
1043
|
if (e.message === "直播开播动态,不做处理") return;
|
|
1014
1044
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -1073,7 +1103,7 @@ var ComRegister = class {
|
|
|
1073
1103
|
return withLock(handler);
|
|
1074
1104
|
}
|
|
1075
1105
|
async useMasterInfo(uid, masterInfo, liveType) {
|
|
1076
|
-
const { data } = await this.ctx.
|
|
1106
|
+
const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
|
|
1077
1107
|
let liveOpenFollowerNum;
|
|
1078
1108
|
let liveEndFollowerNum;
|
|
1079
1109
|
let liveFollowerChange;
|
|
@@ -1098,7 +1128,7 @@ var ComRegister = class {
|
|
|
1098
1128
|
};
|
|
1099
1129
|
}
|
|
1100
1130
|
async useLiveRoomInfo(roomId) {
|
|
1101
|
-
const data = await withRetry(async () => await this.ctx.
|
|
1131
|
+
const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
|
|
1102
1132
|
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
1103
1133
|
return false;
|
|
1104
1134
|
});
|
|
@@ -1107,7 +1137,7 @@ var ComRegister = class {
|
|
|
1107
1137
|
}
|
|
1108
1138
|
async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
|
|
1109
1139
|
const buffer = await withRetry(async () => {
|
|
1110
|
-
return await this.ctx.
|
|
1140
|
+
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
1141
|
}, 1).catch((e) => {
|
|
1112
1142
|
this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
|
|
1113
1143
|
});
|
|
@@ -1116,14 +1146,14 @@ var ComRegister = class {
|
|
|
1116
1146
|
return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
|
|
1117
1147
|
}
|
|
1118
1148
|
async segmentDanmaku(danmaku, danmakuWeightRecord) {
|
|
1119
|
-
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !stopwords.has(word)).map((w) => {
|
|
1149
|
+
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !this.stopwords.has(word)).map((w) => {
|
|
1120
1150
|
danmakuWeightRecord[w] = (danmakuWeightRecord[w] || 0) + 1;
|
|
1121
1151
|
});
|
|
1122
1152
|
}
|
|
1123
1153
|
addUserToDanmakuMaker(username, danmakuMakerRecord) {
|
|
1124
1154
|
danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
|
|
1125
1155
|
}
|
|
1126
|
-
async liveDetectWithListener(roomId,
|
|
1156
|
+
async liveDetectWithListener(roomId, sub) {
|
|
1127
1157
|
let liveTime;
|
|
1128
1158
|
let pushAtTimeTimer;
|
|
1129
1159
|
const danmakuWeightRecord = {};
|
|
@@ -1132,24 +1162,24 @@ var ComRegister = class {
|
|
|
1132
1162
|
let liveRoomInfo;
|
|
1133
1163
|
let masterInfo;
|
|
1134
1164
|
let watchedNum;
|
|
1135
|
-
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1136
|
-
const sendDanmakuWordCloud = async () => {
|
|
1165
|
+
const liveMsgObj = this.liveMsgManager.get(sub.uid);
|
|
1166
|
+
const sendDanmakuWordCloud = async (liveSummary) => {
|
|
1137
1167
|
this.logger.info("开始制作弹幕词云");
|
|
1138
1168
|
this.logger.info("正在获取前90热词");
|
|
1139
1169
|
const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1140
1170
|
this.logger.info("弹幕词云前90词及权重:");
|
|
1141
1171
|
this.logger.info(top90Words);
|
|
1142
1172
|
this.logger.info("正在准备生成弹幕词云");
|
|
1143
|
-
const buffer = await this.ctx.
|
|
1173
|
+
const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
|
|
1144
1174
|
this.logger.info("弹幕词云生成完成,正在准备发送词云图片");
|
|
1145
|
-
await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
|
|
1175
|
+
await this.broadcastToTargets(sub.uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
|
|
1146
1176
|
this.logger.info("词云图片发送完毕!");
|
|
1147
1177
|
this.logger.info("开始构建弹幕发送排行榜消息");
|
|
1148
1178
|
const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
|
|
1149
1179
|
const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
|
|
1150
1180
|
const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
1151
|
-
const danmakuMakerMsg =
|
|
1152
|
-
await this.broadcastToTargets(uid, danmakuMakerMsg, PushType.
|
|
1181
|
+
const danmakuMakerMsg = liveSummary.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");
|
|
1182
|
+
await this.broadcastToTargets(sub.uid, danmakuMakerMsg, PushType.WordCloud);
|
|
1153
1183
|
Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
|
|
1154
1184
|
Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
|
|
1155
1185
|
};
|
|
@@ -1166,12 +1196,12 @@ var ComRegister = class {
|
|
|
1166
1196
|
}
|
|
1167
1197
|
liveTime = liveRoomInfo.live_time;
|
|
1168
1198
|
const watched = watchedNum || "暂未获取到";
|
|
1169
|
-
const liveMsg = liveMsgObj
|
|
1199
|
+
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
1200
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1171
1201
|
liveRoomInfo,
|
|
1172
1202
|
masterInfo,
|
|
1173
|
-
cardStyle
|
|
1174
|
-
}, uid, liveMsg);
|
|
1203
|
+
cardStyle: sub.card
|
|
1204
|
+
}, sub.uid, liveMsg);
|
|
1175
1205
|
};
|
|
1176
1206
|
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1177
1207
|
let flag = true;
|
|
@@ -1193,7 +1223,7 @@ var ComRegister = class {
|
|
|
1193
1223
|
onError: async () => {
|
|
1194
1224
|
liveStatus = false;
|
|
1195
1225
|
pushAtTimeTimer?.();
|
|
1196
|
-
this.ctx.
|
|
1226
|
+
this.ctx["bilibili-notify-live"].closeListener(roomId);
|
|
1197
1227
|
await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
|
|
1198
1228
|
this.logger.error(`[${roomId}]直播间连接发生错误!`);
|
|
1199
1229
|
},
|
|
@@ -1218,7 +1248,7 @@ var ComRegister = class {
|
|
|
1218
1248
|
body.gift_name,
|
|
1219
1249
|
")"
|
|
1220
1250
|
] });
|
|
1221
|
-
this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
|
|
1251
|
+
this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
|
|
1222
1252
|
},
|
|
1223
1253
|
onLiveStart: async () => {
|
|
1224
1254
|
if (liveStatus) return;
|
|
@@ -1230,12 +1260,12 @@ var ComRegister = class {
|
|
|
1230
1260
|
}
|
|
1231
1261
|
liveTime = liveRoomInfo.live_time;
|
|
1232
1262
|
const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
|
|
1233
|
-
const liveStartMsg = liveMsgObj
|
|
1263
|
+
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
1264
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1235
1265
|
liveRoomInfo,
|
|
1236
1266
|
masterInfo,
|
|
1237
|
-
cardStyle
|
|
1238
|
-
}, uid, liveStartMsg);
|
|
1267
|
+
cardStyle: sub.card
|
|
1268
|
+
}, sub.uid, liveStartMsg);
|
|
1239
1269
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1240
1270
|
},
|
|
1241
1271
|
onLiveEnd: async () => {
|
|
@@ -1250,28 +1280,28 @@ var ComRegister = class {
|
|
|
1250
1280
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1251
1281
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1252
1282
|
})();
|
|
1253
|
-
const liveEndMsg = liveMsgObj
|
|
1283
|
+
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
1284
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1255
1285
|
liveRoomInfo,
|
|
1256
1286
|
masterInfo,
|
|
1257
|
-
cardStyle
|
|
1258
|
-
}, uid, liveEndMsg);
|
|
1287
|
+
cardStyle: sub.card
|
|
1288
|
+
}, sub.uid, liveEndMsg);
|
|
1259
1289
|
pushAtTimeTimer();
|
|
1260
1290
|
pushAtTimeTimer = null;
|
|
1261
|
-
if (
|
|
1291
|
+
if (sub.wordcloud) await sendDanmakuWordCloud(liveMsgObj.liveSummary);
|
|
1262
1292
|
}
|
|
1263
1293
|
};
|
|
1264
|
-
await this.ctx.
|
|
1294
|
+
await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
|
|
1265
1295
|
if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1266
1296
|
if (liveRoomInfo.live_status === 1) {
|
|
1267
1297
|
liveTime = liveRoomInfo.live_time;
|
|
1268
1298
|
const watched = watchedNum || "暂未获取到";
|
|
1269
|
-
const liveMsg = liveMsgObj
|
|
1299
|
+
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
1300
|
if (this.config.restartPush) await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1271
1301
|
liveRoomInfo,
|
|
1272
1302
|
masterInfo,
|
|
1273
|
-
cardStyle
|
|
1274
|
-
}, uid, liveMsg);
|
|
1303
|
+
cardStyle: sub.card
|
|
1304
|
+
}, sub.uid, liveMsg);
|
|
1275
1305
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1276
1306
|
liveStatus = true;
|
|
1277
1307
|
}
|
|
@@ -1296,7 +1326,7 @@ var ComRegister = class {
|
|
|
1296
1326
|
const uids = [];
|
|
1297
1327
|
for (const [uid] of this.liveStatusManager.entries()) uids.push(uid);
|
|
1298
1328
|
const useLiveInfo = async () => {
|
|
1299
|
-
const { data: data$1 } = await withRetry(async () => await this.ctx.
|
|
1329
|
+
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1300
1330
|
return void 0;
|
|
1301
1331
|
});
|
|
1302
1332
|
if (!data$1) {
|
|
@@ -1318,7 +1348,7 @@ var ComRegister = class {
|
|
|
1318
1348
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1319
1349
|
liveStatus.liveStartTimeInit = true;
|
|
1320
1350
|
}
|
|
1321
|
-
const liveMsg = liveMsgObj
|
|
1351
|
+
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
1352
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1323
1353
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1324
1354
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1351,7 +1381,7 @@ var ComRegister = class {
|
|
|
1351
1381
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1352
1382
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1353
1383
|
})();
|
|
1354
|
-
const liveEndMsg = liveMsgObj
|
|
1384
|
+
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
1385
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1356
1386
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1357
1387
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1370,7 +1400,7 @@ var ComRegister = class {
|
|
|
1370
1400
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1371
1401
|
liveStatus.liveStartTimeInit = true;
|
|
1372
1402
|
const follower = liveStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(liveStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : liveStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1373
|
-
const liveStartMsg = liveMsgObj
|
|
1403
|
+
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
1404
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1375
1405
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1376
1406
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1391,7 +1421,7 @@ var ComRegister = class {
|
|
|
1391
1421
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1392
1422
|
liveStatus.liveStartTimeInit = true;
|
|
1393
1423
|
}
|
|
1394
|
-
const liveMsg = liveMsgObj
|
|
1424
|
+
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
1425
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1396
1426
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1397
1427
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1427,7 +1457,7 @@ var ComRegister = class {
|
|
|
1427
1457
|
async checkIfLoginInfoIsLoaded() {
|
|
1428
1458
|
return new Promise((resolve$1) => {
|
|
1429
1459
|
const check = () => {
|
|
1430
|
-
if (!this.ctx.
|
|
1460
|
+
if (!this.ctx["bilibili-notify-api"].getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
|
|
1431
1461
|
else resolve$1("success");
|
|
1432
1462
|
};
|
|
1433
1463
|
check();
|
|
@@ -1436,9 +1466,9 @@ var ComRegister = class {
|
|
|
1436
1466
|
async subUserInBili(mid) {
|
|
1437
1467
|
const checkGroupIsReady = async () => {
|
|
1438
1468
|
if (!this.loginDBData?.dynamic_group_id) {
|
|
1439
|
-
const createGroupData = await this.ctx.
|
|
1469
|
+
const createGroupData = await this.ctx["bilibili-notify-api"].createGroup("订阅");
|
|
1440
1470
|
if (createGroupData.code === 22106) {
|
|
1441
|
-
const allGroupData = await this.ctx.
|
|
1471
|
+
const allGroupData = await this.ctx["bilibili-notify-api"].getAllGroup();
|
|
1442
1472
|
for (const group of allGroupData.data) if (group.name === "订阅") {
|
|
1443
1473
|
this.loginDBData.dynamic_group_id = group.tagid.toString();
|
|
1444
1474
|
this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
|
|
@@ -1465,7 +1495,7 @@ var ComRegister = class {
|
|
|
1465
1495
|
const resp = await checkGroupIsReady();
|
|
1466
1496
|
if (resp.code !== 0) return resp;
|
|
1467
1497
|
const getGroupDetailData = async () => {
|
|
1468
|
-
const relationGroupDetailData = await this.ctx.
|
|
1498
|
+
const relationGroupDetailData = await this.ctx["bilibili-notify-api"].getRelationGroupDetail(this.loginDBData.dynamic_group_id);
|
|
1469
1499
|
if (relationGroupDetailData.code !== 0) {
|
|
1470
1500
|
if (relationGroupDetailData.code === 22104) {
|
|
1471
1501
|
this.loginDBData.dynamic_group_id = null;
|
|
@@ -1494,7 +1524,7 @@ var ComRegister = class {
|
|
|
1494
1524
|
code: 0,
|
|
1495
1525
|
msg: "订阅对象已存在于分组中"
|
|
1496
1526
|
};
|
|
1497
|
-
const subUserData = await this.ctx.
|
|
1527
|
+
const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
|
|
1498
1528
|
const subUserMatchPattern = {
|
|
1499
1529
|
[-101]: () => {
|
|
1500
1530
|
return {
|
|
@@ -1539,7 +1569,7 @@ var ComRegister = class {
|
|
|
1539
1569
|
};
|
|
1540
1570
|
},
|
|
1541
1571
|
22014: async () => {
|
|
1542
|
-
const copyUserToGroupData = await this.ctx.
|
|
1572
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1543
1573
|
if (copyUserToGroupData.code !== 0) return {
|
|
1544
1574
|
code: copyUserToGroupData.code,
|
|
1545
1575
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1550,7 +1580,7 @@ var ComRegister = class {
|
|
|
1550
1580
|
};
|
|
1551
1581
|
},
|
|
1552
1582
|
0: async () => {
|
|
1553
|
-
const copyUserToGroupData = await this.ctx.
|
|
1583
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1554
1584
|
if (copyUserToGroupData.code !== 0) return {
|
|
1555
1585
|
code: copyUserToGroupData.code,
|
|
1556
1586
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1568,7 +1598,7 @@ var ComRegister = class {
|
|
|
1568
1598
|
for (const sub of Object.values(subs)) {
|
|
1569
1599
|
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1570
1600
|
const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
|
|
1571
|
-
const data = await this.ctx.
|
|
1601
|
+
const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
|
|
1572
1602
|
return {
|
|
1573
1603
|
code: 0,
|
|
1574
1604
|
data
|
|
@@ -1597,7 +1627,7 @@ var ComRegister = class {
|
|
|
1597
1627
|
sub.live = false;
|
|
1598
1628
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1599
1629
|
}
|
|
1600
|
-
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub
|
|
1630
|
+
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
|
|
1601
1631
|
}
|
|
1602
1632
|
const subInfo = await this.subUserInBili(sub.uid);
|
|
1603
1633
|
if (subInfo.code !== 0) return subInfo;
|
|
@@ -1645,7 +1675,7 @@ var ComRegister = class {
|
|
|
1645
1675
|
}
|
|
1646
1676
|
async checkIfIsLogin() {
|
|
1647
1677
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
|
1648
|
-
if (this.ctx.
|
|
1678
|
+
if (this.ctx["bilibili-notify-api"].getCookies() !== "[]") return true;
|
|
1649
1679
|
}
|
|
1650
1680
|
return false;
|
|
1651
1681
|
}
|
|
@@ -1661,6 +1691,7 @@ var ComRegister = class {
|
|
|
1661
1691
|
live: koishi.Schema.boolean().default(true).description("直播"),
|
|
1662
1692
|
liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
|
|
1663
1693
|
liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
|
|
1694
|
+
wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
|
|
1664
1695
|
platform: koishi.Schema.string().required().description("平台名"),
|
|
1665
1696
|
target: koishi.Schema.string().required().description("群号/频道号")
|
|
1666
1697
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -1671,8 +1702,8 @@ var ComRegister = class {
|
|
|
1671
1702
|
masterAccountGuildId: koishi.Schema.string()
|
|
1672
1703
|
}),
|
|
1673
1704
|
liveDetectType: koishi.Schema.string(),
|
|
1674
|
-
|
|
1675
|
-
liveSummary: koishi.Schema.
|
|
1705
|
+
wordcloudStopWords: koishi.Schema.string(),
|
|
1706
|
+
liveSummary: koishi.Schema.array(String),
|
|
1676
1707
|
restartPush: koishi.Schema.boolean().required(),
|
|
1677
1708
|
pushTime: koishi.Schema.number().required(),
|
|
1678
1709
|
pushImgsInDynamic: koishi.Schema.boolean().required(),
|
|
@@ -1729,10 +1760,10 @@ const DYNAMIC_TYPE_LIVE_RCMD = "DYNAMIC_TYPE_LIVE_RCMD";
|
|
|
1729
1760
|
const DYNAMIC_TYPE_UGC_SEASON = "DYNAMIC_TYPE_UGC_SEASON";
|
|
1730
1761
|
const ADDITIONAL_TYPE_RESERVE = "ADDITIONAL_TYPE_RESERVE";
|
|
1731
1762
|
var GenerateImg = class extends koishi.Service {
|
|
1732
|
-
static inject = ["puppeteer"
|
|
1763
|
+
static inject = ["puppeteer"];
|
|
1733
1764
|
giConfig;
|
|
1734
1765
|
constructor(ctx, config) {
|
|
1735
|
-
super(ctx, "
|
|
1766
|
+
super(ctx, "bilibili-notify-generate-img");
|
|
1736
1767
|
this.giConfig = config;
|
|
1737
1768
|
}
|
|
1738
1769
|
async imgHandler(html) {
|
|
@@ -3312,7 +3343,7 @@ var BiliAPI = class extends koishi.Service {
|
|
|
3312
3343
|
pRetry;
|
|
3313
3344
|
AbortError;
|
|
3314
3345
|
constructor(ctx, config) {
|
|
3315
|
-
super(ctx, "
|
|
3346
|
+
super(ctx, "bilibili-notify-api");
|
|
3316
3347
|
this.apiConfig = config;
|
|
3317
3348
|
}
|
|
3318
3349
|
async start() {
|
|
@@ -3975,17 +4006,17 @@ var bili_api_default = BiliAPI;
|
|
|
3975
4006
|
//#endregion
|
|
3976
4007
|
//#region src/bili_live.ts
|
|
3977
4008
|
var BLive = class extends koishi.Service {
|
|
3978
|
-
static inject = ["
|
|
4009
|
+
static inject = ["bilibili-notify-api"];
|
|
3979
4010
|
listenerRecord = {};
|
|
3980
4011
|
constructor(ctx) {
|
|
3981
|
-
super(ctx, "
|
|
4012
|
+
super(ctx, "bilibili-notify-live");
|
|
3982
4013
|
}
|
|
3983
4014
|
stop() {
|
|
3984
4015
|
for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
|
|
3985
4016
|
}
|
|
3986
4017
|
async startLiveRoomListener(roomId, handler) {
|
|
3987
|
-
const cookiesStr = await this.ctx.
|
|
3988
|
-
const mySelfInfo = await this.ctx.
|
|
4018
|
+
const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
|
|
4019
|
+
const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
|
|
3989
4020
|
this.listenerRecord[roomId] = (0, __akokko_blive_message_listener.startListen)(Number.parseInt(roomId), handler, { ws: {
|
|
3990
4021
|
headers: { Cookie: cookiesStr },
|
|
3991
4022
|
uid: mySelfInfo.data.mid
|
|
@@ -4021,8 +4052,8 @@ let globalConfig;
|
|
|
4021
4052
|
var ServerManager = class extends koishi.Service {
|
|
4022
4053
|
servers = [];
|
|
4023
4054
|
constructor(ctx) {
|
|
4024
|
-
super(ctx, "
|
|
4025
|
-
const sysCom = ctx.command("bn", "
|
|
4055
|
+
super(ctx, "bilibili-notify");
|
|
4056
|
+
const sysCom = ctx.command("bn", "bilibili-notify 插件运行相关指令", { permissions: ["authority:5"] });
|
|
4026
4057
|
sysCom.subcommand(".restart", "重启插件").usage("重启插件").example("bn restart").action(async () => {
|
|
4027
4058
|
this.logger.info("调用 bn restart 指令");
|
|
4028
4059
|
if (await this.restartPlugin()) return "插件重启成功";
|
|
@@ -4065,7 +4096,7 @@ var ServerManager = class extends koishi.Service {
|
|
|
4065
4096
|
advancedSub: globalConfig.advancedSub,
|
|
4066
4097
|
subs: globalConfig.subs,
|
|
4067
4098
|
master: globalConfig.master,
|
|
4068
|
-
|
|
4099
|
+
wordcloudStopWords: globalConfig.wordcloudStopWords,
|
|
4069
4100
|
liveSummary: globalConfig.liveSummary,
|
|
4070
4101
|
liveDetectType: globalConfig.liveDetectType,
|
|
4071
4102
|
restartPush: globalConfig.restartPush,
|