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.mjs
CHANGED
|
@@ -61,6 +61,8 @@ const BAConfigSchema = Schema.object({
|
|
|
61
61
|
live: Schema.boolean().default(true).description("直播"),
|
|
62
62
|
liveAtAll: Schema.boolean().default(true).description("直播At全体"),
|
|
63
63
|
liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
|
|
64
|
+
wordcloud: Schema.boolean().default(true).description("弹幕词云"),
|
|
65
|
+
liveSummary: Schema.boolean().default(true).description("直播总结"),
|
|
64
66
|
platform: Schema.string().required().description("平台名"),
|
|
65
67
|
target: Schema.string().required().description("群号/频道号")
|
|
66
68
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -71,8 +73,19 @@ const BAConfigSchema = Schema.object({
|
|
|
71
73
|
pushImgsInDynamic: Schema.boolean().default(false).description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,该功能容易导致QQ风控"),
|
|
72
74
|
live: Schema.object({}).description("直播推送设置"),
|
|
73
75
|
liveDetectType: Schema.union([Schema.const("WS").description("使用WebSocket连接到B站消息服务器进行直播检测,推荐使用"), Schema.const("API").description("通过轮询API发送请求监测直播状态,此模式理论可无限订阅,但容易产生其他问题,功能没有WS模式全面").experimental()]).role("radio").default("WS").description("直播检测方式,WS为连接到B站消息服务器,API为通过轮询发送请求监测,默认使用WS检测"),
|
|
74
|
-
|
|
75
|
-
liveSummary: Schema.
|
|
76
|
+
wordcloudStopWords: Schema.string().description("词云生成时的停用词,多个停用词请使用英文逗号分隔,例如:哔哩哔哩,弹幕,直播,词云").experimental(),
|
|
77
|
+
liveSummary: Schema.array(String).default([
|
|
78
|
+
"🔍【弹幕情报站】本场直播数据如下:",
|
|
79
|
+
"🧍♂️ 总共 -dmc 位-mdn上线",
|
|
80
|
+
"💬 共计 -dca 条弹幕飞驰而过",
|
|
81
|
+
"📊 热词云图已生成,快来看看你有没有上榜!",
|
|
82
|
+
"👑 本场顶级输出选手:",
|
|
83
|
+
"🥇 -un1 - 弹幕输出 -dc1 条",
|
|
84
|
+
"🥈 -un2 - 弹幕 -dc2 条,萌力惊人",
|
|
85
|
+
"🥉 -un3 - -dc3 条精准狙击",
|
|
86
|
+
"🎖️ 特别嘉奖:-un4 & -un5",
|
|
87
|
+
"你们的弹幕,我们都记录在案!🕵️♀️"
|
|
88
|
+
]).role("table").description("自定义直播总结语,开启弹幕词云自动发送。变量解释:-dmc代表总弹幕发送人数,-mdn代表主播粉丝牌子名,-dca代表总弹幕数,-un1到-un5代表弹幕发送条数前五名用户的用户名,-dc1到-dc5代表弹幕发送条数前五名的弹幕发送数量,数组每一行代表换行"),
|
|
76
89
|
restartPush: Schema.boolean().default(true).description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
|
|
77
90
|
pushTime: Schema.number().min(0).max(12).step(.5).default(1).description("设定间隔多长时间推送一次直播状态,单位为小时,默认为一小时"),
|
|
78
91
|
customLiveStart: Schema.string().default("-name开播啦,当前粉丝数:-follower\\n-link").description("自定义开播提示语,-name代表UP昵称,-follower代表当前粉丝数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用),\\n为换行。例如-name开播啦,会发送为xxxUP开播啦"),
|
|
@@ -160,6 +173,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
|
|
|
160
173
|
PushType$1[PushType$1["DynamicAtAll"] = 2] = "DynamicAtAll";
|
|
161
174
|
PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
|
|
162
175
|
PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
|
|
176
|
+
PushType$1[PushType$1["WordCloudAndLiveSummary"] = 5] = "WordCloudAndLiveSummary";
|
|
163
177
|
return PushType$1;
|
|
164
178
|
}({});
|
|
165
179
|
const PushTypeMsg = {
|
|
@@ -167,7 +181,8 @@ const PushTypeMsg = {
|
|
|
167
181
|
[PushType.Dynamic]: "动态推送",
|
|
168
182
|
[PushType.DynamicAtAll]: "动态推送+At全体",
|
|
169
183
|
[PushType.StartBroadcasting]: "开播推送",
|
|
170
|
-
[PushType.LiveGuardBuy]: "上舰推送"
|
|
184
|
+
[PushType.LiveGuardBuy]: "上舰推送",
|
|
185
|
+
[PushType.WordCloudAndLiveSummary]: "弹幕词云和直播总结推送"
|
|
171
186
|
};
|
|
172
187
|
|
|
173
188
|
//#endregion
|
|
@@ -304,16 +319,17 @@ const stopwords = new Set([
|
|
|
304
319
|
"之前",
|
|
305
320
|
"某天"
|
|
306
321
|
]);
|
|
322
|
+
var stop_words_default = stopwords;
|
|
307
323
|
|
|
308
324
|
//#endregion
|
|
309
325
|
//#region src/command_register.tsx
|
|
310
326
|
var ComRegister = class {
|
|
311
327
|
static inject = [
|
|
312
|
-
"
|
|
313
|
-
"
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
328
|
+
"bilibili-notify",
|
|
329
|
+
"bilibili-notify-api",
|
|
330
|
+
"bilibili-notify-live",
|
|
331
|
+
"bilibili-notify-generate-img",
|
|
332
|
+
"database"
|
|
317
333
|
];
|
|
318
334
|
qqRelatedBotList = [
|
|
319
335
|
"qq",
|
|
@@ -339,6 +355,7 @@ var ComRegister = class {
|
|
|
339
355
|
dynamicJob;
|
|
340
356
|
liveJob;
|
|
341
357
|
_jieba = Jieba.withDict(dict);
|
|
358
|
+
stopwords;
|
|
342
359
|
constructor(ctx, config) {
|
|
343
360
|
this.ctx = ctx;
|
|
344
361
|
this.init(config);
|
|
@@ -369,7 +386,7 @@ var ComRegister = class {
|
|
|
369
386
|
this.logger.info("调用bili login指令");
|
|
370
387
|
let content;
|
|
371
388
|
try {
|
|
372
|
-
content = await ctx.
|
|
389
|
+
content = await ctx["bilibili-notify-api"].getLoginQRCode();
|
|
373
390
|
} catch (_) {
|
|
374
391
|
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
375
392
|
}
|
|
@@ -394,7 +411,7 @@ var ComRegister = class {
|
|
|
394
411
|
flag = false;
|
|
395
412
|
let loginContent;
|
|
396
413
|
try {
|
|
397
|
-
loginContent = await ctx.
|
|
414
|
+
loginContent = await ctx["bilibili-notify-api"].getLoginStatus(content.data.qrcode_key);
|
|
398
415
|
} catch (e) {
|
|
399
416
|
this.logger.error(e);
|
|
400
417
|
return;
|
|
@@ -408,24 +425,19 @@ var ComRegister = class {
|
|
|
408
425
|
return await session.send("二维码已失效,请重新登录");
|
|
409
426
|
}
|
|
410
427
|
if (loginContent.data.code === 0) {
|
|
411
|
-
const encryptedCookies = ctx.
|
|
412
|
-
const encryptedRefreshToken = ctx.
|
|
428
|
+
const encryptedCookies = ctx["bilibili-notify-api"].encrypt(ctx["bilibili-notify-api"].getCookies());
|
|
429
|
+
const encryptedRefreshToken = ctx["bilibili-notify-api"].encrypt(loginContent.data.refresh_token);
|
|
413
430
|
await ctx.database.upsert("loginBili", [{
|
|
414
431
|
id: 1,
|
|
415
432
|
bili_cookies: encryptedCookies,
|
|
416
433
|
bili_refresh_token: encryptedRefreshToken
|
|
417
434
|
}]);
|
|
418
435
|
this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
|
|
419
|
-
await this.ctx.
|
|
436
|
+
await this.ctx["bilibili-notify-api"].loadCookiesFromDatabase();
|
|
420
437
|
await this.checkIfLoginInfoIsLoaded();
|
|
421
438
|
this.loginTimer();
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (code !== 0) this.logger.error(msg);
|
|
425
|
-
ctx.ba.disposeNotifier();
|
|
426
|
-
await session.send("登录成功");
|
|
427
|
-
await session.execute("bili list");
|
|
428
|
-
ctx.ba.enableRefreshCookiesDetect();
|
|
439
|
+
ctx["bilibili-notify-api"].disposeNotifier();
|
|
440
|
+
await session.send("登录成功,请重启插件");
|
|
429
441
|
}
|
|
430
442
|
} finally {
|
|
431
443
|
flag = true;
|
|
@@ -441,7 +453,7 @@ var ComRegister = class {
|
|
|
441
453
|
await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
|
|
442
454
|
});
|
|
443
455
|
biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
|
|
444
|
-
const { data: { live_users } } = await ctx.
|
|
456
|
+
const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
|
|
445
457
|
const subLiveUsers = [];
|
|
446
458
|
for (const sub of this.subManager) {
|
|
447
459
|
let onLive = false;
|
|
@@ -463,10 +475,10 @@ var ComRegister = class {
|
|
|
463
475
|
});
|
|
464
476
|
biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
|
|
465
477
|
const i = index && index - 1 || 0;
|
|
466
|
-
const content = await this.ctx.
|
|
478
|
+
const content = await this.ctx["bilibili-notify-api"].getUserSpaceDynamic(uid);
|
|
467
479
|
const item = content.data.items[i];
|
|
468
480
|
const buffer = await withRetry(async () => {
|
|
469
|
-
return await this.ctx.
|
|
481
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item);
|
|
470
482
|
}, 1).catch(async (e) => {
|
|
471
483
|
if (e.message === "直播开播动态,不做处理") {
|
|
472
484
|
await session.send("直播开播动态,不做处理");
|
|
@@ -581,7 +593,7 @@ var ComRegister = class {
|
|
|
581
593
|
["初中", 4],
|
|
582
594
|
["毕业", 4]
|
|
583
595
|
];
|
|
584
|
-
await session.send(/* @__PURE__ */ jsx("message", { children: h.image(await this.ctx.
|
|
596
|
+
await session.send(/* @__PURE__ */ jsx("message", { children: h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg") }));
|
|
585
597
|
const top5DanmakuMaker = [
|
|
586
598
|
["张三", 60],
|
|
587
599
|
["李四", 48],
|
|
@@ -589,19 +601,19 @@ var ComRegister = class {
|
|
|
589
601
|
["赵六", 27],
|
|
590
602
|
["田七", 25]
|
|
591
603
|
];
|
|
592
|
-
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");
|
|
604
|
+
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");
|
|
593
605
|
await session.send(danmakerRankMsg);
|
|
594
606
|
});
|
|
595
607
|
biliCom.subcommand(".cap").action(async ({ session }) => {
|
|
596
608
|
const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
|
|
597
|
-
const data$1 = await this.ctx.
|
|
609
|
+
const data$1 = await this.ctx["bilibili-notify-api"].getUserInfo("114514");
|
|
598
610
|
return {
|
|
599
611
|
code: 0,
|
|
600
612
|
data: data$1
|
|
601
613
|
};
|
|
602
614
|
}).then((content) => content.data);
|
|
603
615
|
if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
|
|
604
|
-
const { data } = await ctx.
|
|
616
|
+
const { data } = await ctx["bilibili-notify-api"].v_voucherCaptcha(userInfoData.v_voucher);
|
|
605
617
|
if (!data.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
|
|
606
618
|
await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
|
|
607
619
|
await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
|
|
@@ -610,19 +622,14 @@ var ComRegister = class {
|
|
|
610
622
|
await session.send("请直接输入validate");
|
|
611
623
|
const validate = await session.prompt();
|
|
612
624
|
const seccode = `${validate}|jordan`;
|
|
613
|
-
const { data: validateCaptchaData } = await ctx.
|
|
625
|
+
const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
|
|
614
626
|
if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
|
|
615
|
-
ctx.
|
|
616
|
-
|
|
617
|
-
await ctx.database.upsert("loginBili", [{
|
|
618
|
-
id: 1,
|
|
619
|
-
bili_cookies: encryptedCookies
|
|
620
|
-
}]);
|
|
621
|
-
return "验证成功!请重启插件";
|
|
627
|
+
await ctx["bilibili-notify-api"].getUserInfo("114514", validateCaptchaData.grisk_id);
|
|
628
|
+
await session.send("验证成功!请重启插件");
|
|
622
629
|
});
|
|
623
630
|
}
|
|
624
631
|
async init(config) {
|
|
625
|
-
this.logger = this.ctx.logger("
|
|
632
|
+
this.logger = this.ctx.logger("bilibili-notify-core");
|
|
626
633
|
this.logger.info("初始化插件中...");
|
|
627
634
|
this.config = config;
|
|
628
635
|
this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
|
|
@@ -633,6 +640,7 @@ var ComRegister = class {
|
|
|
633
640
|
this.logger.info("账号未登录,请登录");
|
|
634
641
|
return;
|
|
635
642
|
}
|
|
643
|
+
this.mergeStopWords(config.wordcloudStopWords);
|
|
636
644
|
if (config.advancedSub) {
|
|
637
645
|
this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
|
|
638
646
|
await this.initAsyncPart(subs);
|
|
@@ -641,7 +649,7 @@ var ComRegister = class {
|
|
|
641
649
|
} else if (config.subs && config.subs.length > 0) {
|
|
642
650
|
const subs = this.configSubsToSubscription(config.subs);
|
|
643
651
|
await this.initAsyncPart(subs);
|
|
644
|
-
}
|
|
652
|
+
}
|
|
645
653
|
this.ctx.on("dispose", () => {
|
|
646
654
|
if (this.loginTimer) this.loginTimer();
|
|
647
655
|
if (this.dynamicJob) this.dynamicJob.stop();
|
|
@@ -662,6 +670,14 @@ var ComRegister = class {
|
|
|
662
670
|
this.updateSubNotifier();
|
|
663
671
|
this.logger.info("插件初始化完毕!");
|
|
664
672
|
}
|
|
673
|
+
mergeStopWords(stopWordsStr) {
|
|
674
|
+
if (!stopWordsStr || stopWordsStr.trim() === "") {
|
|
675
|
+
this.stopwords = new Set(stop_words_default);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
|
|
679
|
+
this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
|
|
680
|
+
}
|
|
665
681
|
initManager() {
|
|
666
682
|
for (const sub of this.subManager) {
|
|
667
683
|
if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(DateTime.now().toSeconds()));
|
|
@@ -687,6 +703,8 @@ var ComRegister = class {
|
|
|
687
703
|
live: s.live,
|
|
688
704
|
liveAtAll: s.liveAtAll,
|
|
689
705
|
liveGuardBuy: s.liveGuardBuy,
|
|
706
|
+
wordcloud: s.wordcloud,
|
|
707
|
+
liveSummary: s.liveSummary,
|
|
690
708
|
bot: null
|
|
691
709
|
}));
|
|
692
710
|
const target = [{
|
|
@@ -698,8 +716,9 @@ var ComRegister = class {
|
|
|
698
716
|
dynamic: s.dynamic,
|
|
699
717
|
live: s.live,
|
|
700
718
|
target,
|
|
701
|
-
|
|
702
|
-
|
|
719
|
+
customCardStyle: { enable: false },
|
|
720
|
+
customLiveMsg: { enable: false },
|
|
721
|
+
customLiveSummary: { enable: false }
|
|
703
722
|
};
|
|
704
723
|
});
|
|
705
724
|
return subs;
|
|
@@ -716,23 +735,23 @@ var ComRegister = class {
|
|
|
716
735
|
if (this.rebootCount >= 3) {
|
|
717
736
|
this.logger.error("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
718
737
|
await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
719
|
-
await this.ctx.
|
|
738
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
720
739
|
return;
|
|
721
740
|
}
|
|
722
741
|
this.rebootCount++;
|
|
723
742
|
this.logger.info("插件出现未知错误,正在重启插件");
|
|
724
|
-
const flag = await this.ctx.
|
|
743
|
+
const flag = await this.ctx["bilibili-notify"].restartPlugin();
|
|
725
744
|
if (flag) this.logger.info("重启插件成功");
|
|
726
745
|
else {
|
|
727
746
|
this.logger.error("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
728
747
|
await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
729
|
-
await this.ctx.
|
|
748
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
730
749
|
}
|
|
731
750
|
}
|
|
732
751
|
async sendPrivateMsgAndStopService() {
|
|
733
752
|
await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
734
753
|
this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
735
|
-
await this.ctx.
|
|
754
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
736
755
|
return;
|
|
737
756
|
}
|
|
738
757
|
async sendMessageWithRetry(bot, channelId, content) {
|
|
@@ -752,19 +771,23 @@ var ComRegister = class {
|
|
|
752
771
|
const liveMsg = {
|
|
753
772
|
customLiveStart: this.config.customLiveStart || "",
|
|
754
773
|
customLive: this.config.customLive || "",
|
|
755
|
-
customLiveEnd: this.config.customLiveEnd || ""
|
|
774
|
+
customLiveEnd: this.config.customLiveEnd || "",
|
|
775
|
+
liveSummary: this.config.liveSummary.join("\n") || ""
|
|
756
776
|
};
|
|
757
|
-
if (sub.
|
|
758
|
-
liveMsg.customLiveStart = sub.
|
|
759
|
-
liveMsg.customLive = sub.
|
|
760
|
-
liveMsg.customLiveEnd = sub.
|
|
777
|
+
if (sub.customLiveMsg.enable) {
|
|
778
|
+
liveMsg.customLiveStart = sub.customLiveMsg.customLiveStart || this.config.customLiveStart;
|
|
779
|
+
liveMsg.customLive = sub.customLiveMsg.customLive || this.config.customLive;
|
|
780
|
+
liveMsg.customLiveEnd = sub.customLiveMsg.customLiveEnd || this.config.customLiveEnd;
|
|
761
781
|
}
|
|
782
|
+
if (sub.customLiveSummary.enable) liveMsg.liveSummary = sub.customLiveSummary.liveSummary || this.config.liveSummary.join("\n");
|
|
762
783
|
this.liveMsgManager.set(sub.uid, liveMsg);
|
|
763
784
|
const dynamicArr = [];
|
|
764
785
|
const dynamicAtAllArr = [];
|
|
765
786
|
const liveArr = [];
|
|
766
787
|
const liveAtAllArr = [];
|
|
767
788
|
const liveGuardBuyArr = [];
|
|
789
|
+
const wordcloudArr = [];
|
|
790
|
+
const liveSummaryArr = [];
|
|
768
791
|
for (const platform of sub.target) for (const channel of platform.channelArr) {
|
|
769
792
|
const target = `${platform.platform}:${channel.channelId}`;
|
|
770
793
|
if (channel.dynamic) dynamicArr.push(target);
|
|
@@ -772,13 +795,17 @@ var ComRegister = class {
|
|
|
772
795
|
if (channel.live) liveArr.push(target);
|
|
773
796
|
if (channel.liveAtAll) liveAtAllArr.push(target);
|
|
774
797
|
if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
|
|
798
|
+
if (channel.wordcloud) wordcloudArr.push(target);
|
|
799
|
+
if (channel.liveSummary) liveSummaryArr.push(target);
|
|
775
800
|
}
|
|
776
801
|
this.pushArrMap.set(sub.uid, {
|
|
777
802
|
dynamicArr,
|
|
778
803
|
dynamicAtAllArr,
|
|
779
804
|
liveArr,
|
|
780
805
|
liveAtAllArr,
|
|
781
|
-
|
|
806
|
+
liveSummaryArr,
|
|
807
|
+
liveGuardBuyArr,
|
|
808
|
+
wordcloudArr
|
|
782
809
|
});
|
|
783
810
|
}
|
|
784
811
|
this.logger.info("初始化推送群组/频道信息:");
|
|
@@ -838,13 +865,43 @@ var ComRegister = class {
|
|
|
838
865
|
}, 1);
|
|
839
866
|
this.logger.info(`成功推送上舰消息:${success.length}条`);
|
|
840
867
|
}
|
|
841
|
-
|
|
868
|
+
if (type === PushType.WordCloudAndLiveSummary) {
|
|
869
|
+
const wordcloudArr = structuredClone(record.wordcloudArr);
|
|
870
|
+
const liveSummaryArr = structuredClone(record.liveSummaryArr);
|
|
871
|
+
const wordcloudAndLiveSummaryArr = wordcloudArr.filter((item) => liveSummaryArr.includes(item));
|
|
872
|
+
const wordcloudOnlyArr = wordcloudArr.filter((item) => !liveSummaryArr.includes(item));
|
|
873
|
+
const liveSummaryOnlyArr = liveSummaryArr.filter((item) => !wordcloudArr.includes(item));
|
|
874
|
+
if (wordcloudAndLiveSummaryArr.length > 0) {
|
|
875
|
+
this.logger.info("词云和直播总结");
|
|
876
|
+
this.logger.info(wordcloudAndLiveSummaryArr);
|
|
877
|
+
const success = await withRetry(async () => {
|
|
878
|
+
return await this.ctx.broadcast(wordcloudAndLiveSummaryArr, /* @__PURE__ */ jsxs("message", { children: [content[0], content[1]] }));
|
|
879
|
+
}, 1);
|
|
880
|
+
this.logger.info(`成功推送词云和直播总结消息:${success.length}条`);
|
|
881
|
+
}
|
|
882
|
+
if (wordcloudOnlyArr.length > 0) {
|
|
883
|
+
this.logger.info("词云");
|
|
884
|
+
this.logger.info(wordcloudOnlyArr);
|
|
885
|
+
const success = await withRetry(async () => {
|
|
886
|
+
return await this.ctx.broadcast(wordcloudOnlyArr, /* @__PURE__ */ jsx("message", { children: content[0] }));
|
|
887
|
+
}, 1);
|
|
888
|
+
this.logger.info(`成功推送词云消息:${success.length}条`);
|
|
889
|
+
}
|
|
890
|
+
if (liveSummaryOnlyArr.length > 0) {
|
|
891
|
+
this.logger.info("直播总结");
|
|
892
|
+
this.logger.info(liveSummaryOnlyArr);
|
|
893
|
+
const success = await withRetry(async () => {
|
|
894
|
+
return await this.ctx.broadcast(liveSummaryOnlyArr, /* @__PURE__ */ jsx("message", { children: content[1] }));
|
|
895
|
+
}, 1);
|
|
896
|
+
this.logger.info(`成功推送直播总结消息:${success.length}条`);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
842
899
|
}
|
|
843
900
|
dynamicDetect() {
|
|
844
901
|
const handler = async () => {
|
|
845
902
|
const currentPushDyn = {};
|
|
846
903
|
const content = await withRetry(async () => {
|
|
847
|
-
return await this.ctx.
|
|
904
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
848
905
|
}, 1).catch((e) => {
|
|
849
906
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
850
907
|
});
|
|
@@ -853,13 +910,13 @@ var ComRegister = class {
|
|
|
853
910
|
case -101: {
|
|
854
911
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
855
912
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
856
|
-
await this.ctx.
|
|
913
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
857
914
|
break;
|
|
858
915
|
}
|
|
859
916
|
case -352: {
|
|
860
917
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
861
918
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
862
|
-
await this.ctx.
|
|
919
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
863
920
|
break;
|
|
864
921
|
}
|
|
865
922
|
case 4101128:
|
|
@@ -884,7 +941,7 @@ var ComRegister = class {
|
|
|
884
941
|
if (timeline < postTime) {
|
|
885
942
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
886
943
|
const buffer = await withRetry(async () => {
|
|
887
|
-
return await this.ctx.
|
|
944
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
|
|
888
945
|
}, 1).catch(async (e) => {
|
|
889
946
|
if (e.message === "直播开播动态,不做处理") return;
|
|
890
947
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -943,7 +1000,7 @@ var ComRegister = class {
|
|
|
943
1000
|
const currentPushDyn = {};
|
|
944
1001
|
this.logger.info("开始获取动态信息...");
|
|
945
1002
|
const content = await withRetry(async () => {
|
|
946
|
-
return await this.ctx.
|
|
1003
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
947
1004
|
}, 1).catch((e) => {
|
|
948
1005
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
949
1006
|
});
|
|
@@ -952,13 +1009,13 @@ var ComRegister = class {
|
|
|
952
1009
|
case -101: {
|
|
953
1010
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
954
1011
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
955
|
-
await this.ctx.
|
|
1012
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
956
1013
|
break;
|
|
957
1014
|
}
|
|
958
1015
|
case -352: {
|
|
959
1016
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
960
1017
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
961
|
-
await this.ctx.
|
|
1018
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
962
1019
|
break;
|
|
963
1020
|
}
|
|
964
1021
|
case 4101128:
|
|
@@ -989,7 +1046,7 @@ var ComRegister = class {
|
|
|
989
1046
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
990
1047
|
this.logger.info("开始渲染推送卡片...");
|
|
991
1048
|
const buffer = await withRetry(async () => {
|
|
992
|
-
return await this.ctx.
|
|
1049
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.customCardStyle.enable ? sub.customCardStyle : void 0);
|
|
993
1050
|
}, 1).catch(async (e) => {
|
|
994
1051
|
if (e.message === "直播开播动态,不做处理") return;
|
|
995
1052
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -1054,7 +1111,7 @@ var ComRegister = class {
|
|
|
1054
1111
|
return withLock(handler);
|
|
1055
1112
|
}
|
|
1056
1113
|
async useMasterInfo(uid, masterInfo, liveType) {
|
|
1057
|
-
const { data } = await this.ctx.
|
|
1114
|
+
const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
|
|
1058
1115
|
let liveOpenFollowerNum;
|
|
1059
1116
|
let liveEndFollowerNum;
|
|
1060
1117
|
let liveFollowerChange;
|
|
@@ -1079,7 +1136,7 @@ var ComRegister = class {
|
|
|
1079
1136
|
};
|
|
1080
1137
|
}
|
|
1081
1138
|
async useLiveRoomInfo(roomId) {
|
|
1082
|
-
const data = await withRetry(async () => await this.ctx.
|
|
1139
|
+
const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
|
|
1083
1140
|
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
1084
1141
|
return false;
|
|
1085
1142
|
});
|
|
@@ -1088,7 +1145,7 @@ var ComRegister = class {
|
|
|
1088
1145
|
}
|
|
1089
1146
|
async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
|
|
1090
1147
|
const buffer = await withRetry(async () => {
|
|
1091
|
-
return await this.ctx.
|
|
1148
|
+
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);
|
|
1092
1149
|
}, 1).catch((e) => {
|
|
1093
1150
|
this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
|
|
1094
1151
|
});
|
|
@@ -1097,14 +1154,14 @@ var ComRegister = class {
|
|
|
1097
1154
|
return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
|
|
1098
1155
|
}
|
|
1099
1156
|
async segmentDanmaku(danmaku, danmakuWeightRecord) {
|
|
1100
|
-
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !stopwords.has(word)).map((w) => {
|
|
1157
|
+
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !this.stopwords.has(word)).map((w) => {
|
|
1101
1158
|
danmakuWeightRecord[w] = (danmakuWeightRecord[w] || 0) + 1;
|
|
1102
1159
|
});
|
|
1103
1160
|
}
|
|
1104
1161
|
addUserToDanmakuMaker(username, danmakuMakerRecord) {
|
|
1105
1162
|
danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
|
|
1106
1163
|
}
|
|
1107
|
-
async liveDetectWithListener(roomId,
|
|
1164
|
+
async liveDetectWithListener(roomId, sub) {
|
|
1108
1165
|
let liveTime;
|
|
1109
1166
|
let pushAtTimeTimer;
|
|
1110
1167
|
const danmakuWeightRecord = {};
|
|
@@ -1113,24 +1170,23 @@ var ComRegister = class {
|
|
|
1113
1170
|
let liveRoomInfo;
|
|
1114
1171
|
let masterInfo;
|
|
1115
1172
|
let watchedNum;
|
|
1116
|
-
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1117
|
-
const
|
|
1173
|
+
const liveMsgObj = this.liveMsgManager.get(sub.uid);
|
|
1174
|
+
const sendDanmakuWordCloudAndLiveSummary = async (customLiveSummary) => {
|
|
1118
1175
|
this.logger.info("开始制作弹幕词云");
|
|
1119
1176
|
this.logger.info("正在获取前90热词");
|
|
1120
1177
|
const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1121
1178
|
this.logger.info("弹幕词云前90词及权重:");
|
|
1122
1179
|
this.logger.info(top90Words);
|
|
1123
1180
|
this.logger.info("正在准备生成弹幕词云");
|
|
1124
|
-
const buffer = await this.ctx.
|
|
1125
|
-
|
|
1126
|
-
await this.broadcastToTargets(uid, h.image(buffer, "image/jpeg"), PushType.Live);
|
|
1127
|
-
this.logger.info("词云图片发送完毕!");
|
|
1181
|
+
const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
|
|
1182
|
+
const img = /* @__PURE__ */ jsx("message", { children: h.image(buffer, "image/jpeg") });
|
|
1128
1183
|
this.logger.info("开始构建弹幕发送排行榜消息");
|
|
1129
1184
|
const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
|
|
1130
1185
|
const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
|
|
1131
1186
|
const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
1132
|
-
const danmakuMakerMsg =
|
|
1133
|
-
|
|
1187
|
+
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");
|
|
1188
|
+
const summary = /* @__PURE__ */ jsx("message", { children: danmakuMakerMsg });
|
|
1189
|
+
await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
|
|
1134
1190
|
Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
|
|
1135
1191
|
Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
|
|
1136
1192
|
};
|
|
@@ -1147,12 +1203,12 @@ var ComRegister = class {
|
|
|
1147
1203
|
}
|
|
1148
1204
|
liveTime = liveRoomInfo.live_time;
|
|
1149
1205
|
const watched = watchedNum || "暂未获取到";
|
|
1150
|
-
const liveMsg = liveMsgObj
|
|
1206
|
+
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}`);
|
|
1151
1207
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1152
1208
|
liveRoomInfo,
|
|
1153
1209
|
masterInfo,
|
|
1154
|
-
cardStyle
|
|
1155
|
-
}, uid, liveMsg);
|
|
1210
|
+
cardStyle: sub.customCardStyle
|
|
1211
|
+
}, sub.uid, liveMsg);
|
|
1156
1212
|
};
|
|
1157
1213
|
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1158
1214
|
let flag = true;
|
|
@@ -1174,7 +1230,7 @@ var ComRegister = class {
|
|
|
1174
1230
|
onError: async () => {
|
|
1175
1231
|
liveStatus = false;
|
|
1176
1232
|
pushAtTimeTimer?.();
|
|
1177
|
-
this.ctx.
|
|
1233
|
+
this.ctx["bilibili-notify-live"].closeListener(roomId);
|
|
1178
1234
|
await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
|
|
1179
1235
|
this.logger.error(`[${roomId}]直播间连接发生错误!`);
|
|
1180
1236
|
},
|
|
@@ -1199,7 +1255,7 @@ var ComRegister = class {
|
|
|
1199
1255
|
body.gift_name,
|
|
1200
1256
|
")"
|
|
1201
1257
|
] });
|
|
1202
|
-
this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
|
|
1258
|
+
this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
|
|
1203
1259
|
},
|
|
1204
1260
|
onLiveStart: async () => {
|
|
1205
1261
|
if (liveStatus) return;
|
|
@@ -1211,12 +1267,12 @@ var ComRegister = class {
|
|
|
1211
1267
|
}
|
|
1212
1268
|
liveTime = liveRoomInfo.live_time;
|
|
1213
1269
|
const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
|
|
1214
|
-
const liveStartMsg = liveMsgObj
|
|
1270
|
+
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}`);
|
|
1215
1271
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1216
1272
|
liveRoomInfo,
|
|
1217
1273
|
masterInfo,
|
|
1218
|
-
cardStyle
|
|
1219
|
-
}, uid, liveStartMsg);
|
|
1274
|
+
cardStyle: sub.customCardStyle
|
|
1275
|
+
}, sub.uid, liveStartMsg);
|
|
1220
1276
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1221
1277
|
},
|
|
1222
1278
|
onLiveEnd: async () => {
|
|
@@ -1231,28 +1287,28 @@ var ComRegister = class {
|
|
|
1231
1287
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1232
1288
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1233
1289
|
})();
|
|
1234
|
-
const liveEndMsg = liveMsgObj
|
|
1290
|
+
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");
|
|
1235
1291
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1236
1292
|
liveRoomInfo,
|
|
1237
1293
|
masterInfo,
|
|
1238
|
-
cardStyle
|
|
1239
|
-
}, uid, liveEndMsg);
|
|
1294
|
+
cardStyle: sub.customCardStyle
|
|
1295
|
+
}, sub.uid, liveEndMsg);
|
|
1240
1296
|
pushAtTimeTimer();
|
|
1241
1297
|
pushAtTimeTimer = null;
|
|
1242
|
-
|
|
1298
|
+
await sendDanmakuWordCloudAndLiveSummary(liveMsgObj.liveSummary);
|
|
1243
1299
|
}
|
|
1244
1300
|
};
|
|
1245
|
-
await this.ctx.
|
|
1301
|
+
await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
|
|
1246
1302
|
if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1247
1303
|
if (liveRoomInfo.live_status === 1) {
|
|
1248
1304
|
liveTime = liveRoomInfo.live_time;
|
|
1249
1305
|
const watched = watchedNum || "暂未获取到";
|
|
1250
|
-
const liveMsg = liveMsgObj
|
|
1306
|
+
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}`);
|
|
1251
1307
|
if (this.config.restartPush) await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1252
1308
|
liveRoomInfo,
|
|
1253
1309
|
masterInfo,
|
|
1254
|
-
cardStyle
|
|
1255
|
-
}, uid, liveMsg);
|
|
1310
|
+
cardStyle: sub.customCardStyle
|
|
1311
|
+
}, sub.uid, liveMsg);
|
|
1256
1312
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1257
1313
|
liveStatus = true;
|
|
1258
1314
|
}
|
|
@@ -1277,7 +1333,7 @@ var ComRegister = class {
|
|
|
1277
1333
|
const uids = [];
|
|
1278
1334
|
for (const [uid] of this.liveStatusManager.entries()) uids.push(uid);
|
|
1279
1335
|
const useLiveInfo = async () => {
|
|
1280
|
-
const { data: data$1 } = await withRetry(async () => await this.ctx.
|
|
1336
|
+
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1281
1337
|
return void 0;
|
|
1282
1338
|
});
|
|
1283
1339
|
if (!data$1) {
|
|
@@ -1299,11 +1355,11 @@ var ComRegister = class {
|
|
|
1299
1355
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1300
1356
|
liveStatus.liveStartTimeInit = true;
|
|
1301
1357
|
}
|
|
1302
|
-
const liveMsg = liveMsgObj
|
|
1358
|
+
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}`);
|
|
1303
1359
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1304
1360
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1305
1361
|
masterInfo: liveStatus.masterInfo,
|
|
1306
|
-
cardStyle: sub.
|
|
1362
|
+
cardStyle: sub.customCardStyle
|
|
1307
1363
|
}, sub.uid, liveMsg);
|
|
1308
1364
|
}
|
|
1309
1365
|
}
|
|
@@ -1332,11 +1388,11 @@ var ComRegister = class {
|
|
|
1332
1388
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1333
1389
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1334
1390
|
})();
|
|
1335
|
-
const liveEndMsg = liveMsgObj
|
|
1391
|
+
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");
|
|
1336
1392
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1337
1393
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1338
1394
|
masterInfo: liveStatus.masterInfo,
|
|
1339
|
-
cardStyle: sub.
|
|
1395
|
+
cardStyle: sub.customCardStyle
|
|
1340
1396
|
}, sub.uid, liveEndMsg);
|
|
1341
1397
|
liveStatus.live = false;
|
|
1342
1398
|
}
|
|
@@ -1351,11 +1407,11 @@ var ComRegister = class {
|
|
|
1351
1407
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1352
1408
|
liveStatus.liveStartTimeInit = true;
|
|
1353
1409
|
const follower = liveStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(liveStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : liveStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1354
|
-
const liveStartMsg = liveMsgObj
|
|
1410
|
+
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}`);
|
|
1355
1411
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1356
1412
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1357
1413
|
masterInfo: liveStatus.masterInfo,
|
|
1358
|
-
cardStyle: sub.
|
|
1414
|
+
cardStyle: sub.customCardStyle
|
|
1359
1415
|
}, sub.uid, liveStartMsg);
|
|
1360
1416
|
liveStatus.live = true;
|
|
1361
1417
|
}
|
|
@@ -1372,11 +1428,11 @@ var ComRegister = class {
|
|
|
1372
1428
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1373
1429
|
liveStatus.liveStartTimeInit = true;
|
|
1374
1430
|
}
|
|
1375
|
-
const liveMsg = liveMsgObj
|
|
1431
|
+
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}`);
|
|
1376
1432
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1377
1433
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1378
1434
|
masterInfo: liveStatus.masterInfo,
|
|
1379
|
-
cardStyle: sub.
|
|
1435
|
+
cardStyle: sub.customCardStyle
|
|
1380
1436
|
}, sub.uid, liveMsg);
|
|
1381
1437
|
liveStatus.push = 0;
|
|
1382
1438
|
}
|
|
@@ -1408,7 +1464,7 @@ var ComRegister = class {
|
|
|
1408
1464
|
async checkIfLoginInfoIsLoaded() {
|
|
1409
1465
|
return new Promise((resolve$1) => {
|
|
1410
1466
|
const check = () => {
|
|
1411
|
-
if (!this.ctx.
|
|
1467
|
+
if (!this.ctx["bilibili-notify-api"].getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
|
|
1412
1468
|
else resolve$1("success");
|
|
1413
1469
|
};
|
|
1414
1470
|
check();
|
|
@@ -1417,9 +1473,9 @@ var ComRegister = class {
|
|
|
1417
1473
|
async subUserInBili(mid) {
|
|
1418
1474
|
const checkGroupIsReady = async () => {
|
|
1419
1475
|
if (!this.loginDBData?.dynamic_group_id) {
|
|
1420
|
-
const createGroupData = await this.ctx.
|
|
1476
|
+
const createGroupData = await this.ctx["bilibili-notify-api"].createGroup("订阅");
|
|
1421
1477
|
if (createGroupData.code === 22106) {
|
|
1422
|
-
const allGroupData = await this.ctx.
|
|
1478
|
+
const allGroupData = await this.ctx["bilibili-notify-api"].getAllGroup();
|
|
1423
1479
|
for (const group of allGroupData.data) if (group.name === "订阅") {
|
|
1424
1480
|
this.loginDBData.dynamic_group_id = group.tagid.toString();
|
|
1425
1481
|
this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
|
|
@@ -1446,7 +1502,7 @@ var ComRegister = class {
|
|
|
1446
1502
|
const resp = await checkGroupIsReady();
|
|
1447
1503
|
if (resp.code !== 0) return resp;
|
|
1448
1504
|
const getGroupDetailData = async () => {
|
|
1449
|
-
const relationGroupDetailData = await this.ctx.
|
|
1505
|
+
const relationGroupDetailData = await this.ctx["bilibili-notify-api"].getRelationGroupDetail(this.loginDBData.dynamic_group_id);
|
|
1450
1506
|
if (relationGroupDetailData.code !== 0) {
|
|
1451
1507
|
if (relationGroupDetailData.code === 22104) {
|
|
1452
1508
|
this.loginDBData.dynamic_group_id = null;
|
|
@@ -1475,7 +1531,7 @@ var ComRegister = class {
|
|
|
1475
1531
|
code: 0,
|
|
1476
1532
|
msg: "订阅对象已存在于分组中"
|
|
1477
1533
|
};
|
|
1478
|
-
const subUserData = await this.ctx.
|
|
1534
|
+
const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
|
|
1479
1535
|
const subUserMatchPattern = {
|
|
1480
1536
|
[-101]: () => {
|
|
1481
1537
|
return {
|
|
@@ -1520,7 +1576,7 @@ var ComRegister = class {
|
|
|
1520
1576
|
};
|
|
1521
1577
|
},
|
|
1522
1578
|
22014: async () => {
|
|
1523
|
-
const copyUserToGroupData = await this.ctx.
|
|
1579
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1524
1580
|
if (copyUserToGroupData.code !== 0) return {
|
|
1525
1581
|
code: copyUserToGroupData.code,
|
|
1526
1582
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1531,7 +1587,7 @@ var ComRegister = class {
|
|
|
1531
1587
|
};
|
|
1532
1588
|
},
|
|
1533
1589
|
0: async () => {
|
|
1534
|
-
const copyUserToGroupData = await this.ctx.
|
|
1590
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1535
1591
|
if (copyUserToGroupData.code !== 0) return {
|
|
1536
1592
|
code: copyUserToGroupData.code,
|
|
1537
1593
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1549,7 +1605,7 @@ var ComRegister = class {
|
|
|
1549
1605
|
for (const sub of Object.values(subs)) {
|
|
1550
1606
|
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1551
1607
|
const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
|
|
1552
|
-
const data = await this.ctx.
|
|
1608
|
+
const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
|
|
1553
1609
|
return {
|
|
1554
1610
|
code: 0,
|
|
1555
1611
|
data
|
|
@@ -1562,7 +1618,7 @@ var ComRegister = class {
|
|
|
1562
1618
|
};
|
|
1563
1619
|
});
|
|
1564
1620
|
if (userInfoCode === -352 && userInfoData.v_voucher) {
|
|
1565
|
-
this.logger.info("账号被风控,请使用指令 bili
|
|
1621
|
+
this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1566
1622
|
await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
|
|
1567
1623
|
return {
|
|
1568
1624
|
code: userInfoCode,
|
|
@@ -1578,21 +1634,20 @@ var ComRegister = class {
|
|
|
1578
1634
|
sub.live = false;
|
|
1579
1635
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1580
1636
|
}
|
|
1581
|
-
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub
|
|
1637
|
+
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
|
|
1582
1638
|
}
|
|
1583
1639
|
const subInfo = await this.subUserInBili(sub.uid);
|
|
1584
1640
|
if (subInfo.code !== 0) return subInfo;
|
|
1585
1641
|
this.subManager.push({
|
|
1586
|
-
id: +sub.uid,
|
|
1587
1642
|
uid: sub.uid,
|
|
1588
1643
|
uname: userInfoData.name,
|
|
1589
1644
|
roomId: sub.live ? userInfoData.live_room.roomid : "",
|
|
1590
1645
|
target: sub.target,
|
|
1591
|
-
platform: "",
|
|
1592
1646
|
live: sub.live,
|
|
1593
1647
|
dynamic: sub.dynamic,
|
|
1594
|
-
|
|
1595
|
-
|
|
1648
|
+
customCardStyle: sub.customCardStyle,
|
|
1649
|
+
customLiveMsg: sub.customLiveMsg,
|
|
1650
|
+
customLiveSummary: sub.customLiveSummary
|
|
1596
1651
|
});
|
|
1597
1652
|
this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
|
|
1598
1653
|
if (sub !== Object.values(subs).pop()) {
|
|
@@ -1626,7 +1681,7 @@ var ComRegister = class {
|
|
|
1626
1681
|
}
|
|
1627
1682
|
async checkIfIsLogin() {
|
|
1628
1683
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
|
1629
|
-
if (this.ctx.
|
|
1684
|
+
if (this.ctx["bilibili-notify-api"].getCookies() !== "[]") return true;
|
|
1630
1685
|
}
|
|
1631
1686
|
return false;
|
|
1632
1687
|
}
|
|
@@ -1642,6 +1697,8 @@ var ComRegister = class {
|
|
|
1642
1697
|
live: Schema.boolean().default(true).description("直播"),
|
|
1643
1698
|
liveAtAll: Schema.boolean().default(true).description("直播At全体"),
|
|
1644
1699
|
liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
|
|
1700
|
+
wordcloud: Schema.boolean().default(true).description("弹幕词云"),
|
|
1701
|
+
liveSummary: Schema.boolean().default(true).description("直播总结"),
|
|
1645
1702
|
platform: Schema.string().required().description("平台名"),
|
|
1646
1703
|
target: Schema.string().required().description("群号/频道号")
|
|
1647
1704
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -1652,8 +1709,8 @@ var ComRegister = class {
|
|
|
1652
1709
|
masterAccountGuildId: Schema.string()
|
|
1653
1710
|
}),
|
|
1654
1711
|
liveDetectType: Schema.string(),
|
|
1655
|
-
|
|
1656
|
-
liveSummary: Schema.
|
|
1712
|
+
wordcloudStopWords: Schema.string(),
|
|
1713
|
+
liveSummary: Schema.array(String),
|
|
1657
1714
|
restartPush: Schema.boolean().required(),
|
|
1658
1715
|
pushTime: Schema.number().required(),
|
|
1659
1716
|
pushImgsInDynamic: Schema.boolean().required(),
|
|
@@ -1710,10 +1767,10 @@ const DYNAMIC_TYPE_LIVE_RCMD = "DYNAMIC_TYPE_LIVE_RCMD";
|
|
|
1710
1767
|
const DYNAMIC_TYPE_UGC_SEASON = "DYNAMIC_TYPE_UGC_SEASON";
|
|
1711
1768
|
const ADDITIONAL_TYPE_RESERVE = "ADDITIONAL_TYPE_RESERVE";
|
|
1712
1769
|
var GenerateImg = class extends Service {
|
|
1713
|
-
static inject = ["puppeteer"
|
|
1770
|
+
static inject = ["puppeteer"];
|
|
1714
1771
|
giConfig;
|
|
1715
1772
|
constructor(ctx, config) {
|
|
1716
|
-
super(ctx, "
|
|
1773
|
+
super(ctx, "bilibili-notify-generate-img");
|
|
1717
1774
|
this.giConfig = config;
|
|
1718
1775
|
}
|
|
1719
1776
|
async imgHandler(html) {
|
|
@@ -3293,7 +3350,7 @@ var BiliAPI = class extends Service {
|
|
|
3293
3350
|
pRetry;
|
|
3294
3351
|
AbortError;
|
|
3295
3352
|
constructor(ctx, config) {
|
|
3296
|
-
super(ctx, "
|
|
3353
|
+
super(ctx, "bilibili-notify-api");
|
|
3297
3354
|
this.apiConfig = config;
|
|
3298
3355
|
}
|
|
3299
3356
|
async start() {
|
|
@@ -3570,13 +3627,15 @@ var BiliAPI = class extends Service {
|
|
|
3570
3627
|
retries: 3
|
|
3571
3628
|
});
|
|
3572
3629
|
}
|
|
3573
|
-
async getUserInfo(mid) {
|
|
3630
|
+
async getUserInfo(mid, grisk_id) {
|
|
3574
3631
|
const run = async () => {
|
|
3575
3632
|
if (mid === "11783021") {
|
|
3576
3633
|
console.log("检测到番剧出差UID,跳过远程用户接口访问");
|
|
3577
3634
|
return bangumiTripData;
|
|
3578
3635
|
}
|
|
3579
|
-
const
|
|
3636
|
+
const params = { mid };
|
|
3637
|
+
if (grisk_id) params.grisk_id = grisk_id;
|
|
3638
|
+
const wbi = await this.getWbi(params);
|
|
3580
3639
|
const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
|
|
3581
3640
|
return data;
|
|
3582
3641
|
};
|
|
@@ -3942,6 +4001,7 @@ var BiliAPI = class extends Service {
|
|
|
3942
4001
|
this.logger.info(`验证失败:错误码=${data.code},错误消息:${data.message}`);
|
|
3943
4002
|
return { data: null };
|
|
3944
4003
|
}
|
|
4004
|
+
this.addCookie(`x-bili-gaia-vtoken=${data.data.grisk_id}`);
|
|
3945
4005
|
return { data: data.data };
|
|
3946
4006
|
}
|
|
3947
4007
|
};
|
|
@@ -3956,17 +4016,17 @@ var bili_api_default = BiliAPI;
|
|
|
3956
4016
|
//#endregion
|
|
3957
4017
|
//#region src/bili_live.ts
|
|
3958
4018
|
var BLive = class extends Service {
|
|
3959
|
-
static inject = ["
|
|
4019
|
+
static inject = ["bilibili-notify-api"];
|
|
3960
4020
|
listenerRecord = {};
|
|
3961
4021
|
constructor(ctx) {
|
|
3962
|
-
super(ctx, "
|
|
4022
|
+
super(ctx, "bilibili-notify-live");
|
|
3963
4023
|
}
|
|
3964
4024
|
stop() {
|
|
3965
4025
|
for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
|
|
3966
4026
|
}
|
|
3967
4027
|
async startLiveRoomListener(roomId, handler) {
|
|
3968
|
-
const cookiesStr = await this.ctx.
|
|
3969
|
-
const mySelfInfo = await this.ctx.
|
|
4028
|
+
const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
|
|
4029
|
+
const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
|
|
3970
4030
|
this.listenerRecord[roomId] = startListen(Number.parseInt(roomId), handler, { ws: {
|
|
3971
4031
|
headers: { Cookie: cookiesStr },
|
|
3972
4032
|
uid: mySelfInfo.data.mid
|
|
@@ -4002,8 +4062,8 @@ let globalConfig;
|
|
|
4002
4062
|
var ServerManager = class extends Service {
|
|
4003
4063
|
servers = [];
|
|
4004
4064
|
constructor(ctx) {
|
|
4005
|
-
super(ctx, "
|
|
4006
|
-
const sysCom = ctx.command("bn", "
|
|
4065
|
+
super(ctx, "bilibili-notify");
|
|
4066
|
+
const sysCom = ctx.command("bn", "bilibili-notify 插件运行相关指令", { permissions: ["authority:5"] });
|
|
4007
4067
|
sysCom.subcommand(".restart", "重启插件").usage("重启插件").example("bn restart").action(async () => {
|
|
4008
4068
|
this.logger.info("调用 bn restart 指令");
|
|
4009
4069
|
if (await this.restartPlugin()) return "插件重启成功";
|
|
@@ -4046,7 +4106,7 @@ var ServerManager = class extends Service {
|
|
|
4046
4106
|
advancedSub: globalConfig.advancedSub,
|
|
4047
4107
|
subs: globalConfig.subs,
|
|
4048
4108
|
master: globalConfig.master,
|
|
4049
|
-
|
|
4109
|
+
wordcloudStopWords: globalConfig.wordcloudStopWords,
|
|
4050
4110
|
liveSummary: globalConfig.liveSummary,
|
|
4051
4111
|
liveDetectType: globalConfig.liveDetectType,
|
|
4052
4112
|
restartPush: globalConfig.restartPush,
|