koishi-plugin-bilibili-notify 3.2.11-alpha.9 → 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 +396 -340
- package/lib/index.mjs +396 -340
- package/package.json +4 -4
- package/readme.md +7 -0
package/lib/index.mjs
CHANGED
|
@@ -17,7 +17,6 @@ import https from "node:https";
|
|
|
17
17
|
import axios from "axios";
|
|
18
18
|
import { Cookie, CookieJar } from "tough-cookie";
|
|
19
19
|
import { JSDOM } from "jsdom";
|
|
20
|
-
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
21
20
|
import { startListen } from "@akokko/blive-message-listener";
|
|
22
21
|
|
|
23
22
|
//#region rolldown:runtime
|
|
@@ -62,6 +61,7 @@ const BAConfigSchema = Schema.object({
|
|
|
62
61
|
live: Schema.boolean().default(true).description("直播"),
|
|
63
62
|
liveAtAll: Schema.boolean().default(true).description("直播At全体"),
|
|
64
63
|
liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
|
|
64
|
+
wordcloud: Schema.boolean().default(true).description("弹幕词云"),
|
|
65
65
|
platform: Schema.string().required().description("平台名"),
|
|
66
66
|
target: Schema.string().required().description("群号/频道号")
|
|
67
67
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -72,8 +72,19 @@ const BAConfigSchema = Schema.object({
|
|
|
72
72
|
pushImgsInDynamic: Schema.boolean().default(false).description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,该功能容易导致QQ风控"),
|
|
73
73
|
live: Schema.object({}).description("直播推送设置"),
|
|
74
74
|
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检测"),
|
|
75
|
-
|
|
76
|
-
liveSummary: Schema.
|
|
75
|
+
wordcloudStopWords: Schema.string().description("词云生成时的停用词,多个停用词请使用英文逗号分隔,例如:哔哩哔哩,弹幕,直播,词云").experimental(),
|
|
76
|
+
liveSummary: Schema.array(String).default([
|
|
77
|
+
"🔍【弹幕情报站】本场直播数据如下:",
|
|
78
|
+
"🧍♂️ 总共 -dmc 位-mdn上线",
|
|
79
|
+
"💬 共计 -dca 条弹幕飞驰而过",
|
|
80
|
+
"📊 热词云图已生成,快来看看你有没有上榜!",
|
|
81
|
+
"👑 本场顶级输出选手:",
|
|
82
|
+
"🥇 -un1 - 弹幕输出 -dc1 条",
|
|
83
|
+
"🥈 -un2 - 弹幕 -dc2 条,萌力惊人",
|
|
84
|
+
"🥉 -un3 - -dc3 条精准狙击",
|
|
85
|
+
"🎖️ 特别嘉奖:-un4 & -un5",
|
|
86
|
+
"你们的弹幕,我们都记录在案!🕵️♀️"
|
|
87
|
+
]).role("table").description("自定义直播总结语,开启弹幕词云自动发送。变量解释:-dmc代表总弹幕发送人数,-mdn代表主播粉丝牌子名,-dca代表总弹幕数,-un1到-un5代表弹幕发送条数前五名用户的用户名,-dc1到-dc5代表弹幕发送条数前五名的弹幕发送数量,数组每一行代表换行"),
|
|
77
88
|
restartPush: Schema.boolean().default(true).description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
|
|
78
89
|
pushTime: Schema.number().min(0).max(12).step(.5).default(1).description("设定间隔多长时间推送一次直播状态,单位为小时,默认为一小时"),
|
|
79
90
|
customLiveStart: Schema.string().default("-name开播啦,当前粉丝数:-follower\\n-link").description("自定义开播提示语,-name代表UP昵称,-follower代表当前粉丝数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用),\\n为换行。例如-name开播啦,会发送为xxxUP开播啦"),
|
|
@@ -103,22 +114,6 @@ const BAConfigSchema = Schema.object({
|
|
|
103
114
|
|
|
104
115
|
//#endregion
|
|
105
116
|
//#region src/utils/index.ts
|
|
106
|
-
function Retry(options = { attempts: 3 }) {
|
|
107
|
-
return (_target, _propertyKey, descriptor) => {
|
|
108
|
-
const originalMethod = descriptor.value;
|
|
109
|
-
descriptor.value = async function(...args) {
|
|
110
|
-
let lastError;
|
|
111
|
-
for (let i = 0; i < options.attempts; i++) try {
|
|
112
|
-
return await originalMethod.apply(this, args);
|
|
113
|
-
} catch (error) {
|
|
114
|
-
lastError = error;
|
|
115
|
-
if (options.onFailure) await options.onFailure.call(this, lastError, i + 1);
|
|
116
|
-
}
|
|
117
|
-
throw lastError;
|
|
118
|
-
};
|
|
119
|
-
return descriptor;
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
117
|
/**
|
|
123
118
|
* 高阶函数:为函数添加锁机制
|
|
124
119
|
* @param {Function} fn - 需要包装的原始函数
|
|
@@ -177,6 +172,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
|
|
|
177
172
|
PushType$1[PushType$1["DynamicAtAll"] = 2] = "DynamicAtAll";
|
|
178
173
|
PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
|
|
179
174
|
PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
|
|
175
|
+
PushType$1[PushType$1["WordCloud"] = 5] = "WordCloud";
|
|
180
176
|
return PushType$1;
|
|
181
177
|
}({});
|
|
182
178
|
const PushTypeMsg = {
|
|
@@ -184,7 +180,8 @@ const PushTypeMsg = {
|
|
|
184
180
|
[PushType.Dynamic]: "动态推送",
|
|
185
181
|
[PushType.DynamicAtAll]: "动态推送+At全体",
|
|
186
182
|
[PushType.StartBroadcasting]: "开播推送",
|
|
187
|
-
[PushType.LiveGuardBuy]: "上舰推送"
|
|
183
|
+
[PushType.LiveGuardBuy]: "上舰推送",
|
|
184
|
+
[PushType.WordCloud]: "弹幕词云推送"
|
|
188
185
|
};
|
|
189
186
|
|
|
190
187
|
//#endregion
|
|
@@ -321,16 +318,17 @@ const stopwords = new Set([
|
|
|
321
318
|
"之前",
|
|
322
319
|
"某天"
|
|
323
320
|
]);
|
|
321
|
+
var stop_words_default = stopwords;
|
|
324
322
|
|
|
325
323
|
//#endregion
|
|
326
324
|
//#region src/command_register.tsx
|
|
327
325
|
var ComRegister = class {
|
|
328
326
|
static inject = [
|
|
329
|
-
"
|
|
330
|
-
"
|
|
331
|
-
"
|
|
332
|
-
"
|
|
333
|
-
"
|
|
327
|
+
"bilibili-notify",
|
|
328
|
+
"bilibili-notify-api",
|
|
329
|
+
"bilibili-notify-live",
|
|
330
|
+
"bilibili-notify-generate-img",
|
|
331
|
+
"database"
|
|
334
332
|
];
|
|
335
333
|
qqRelatedBotList = [
|
|
336
334
|
"qq",
|
|
@@ -356,6 +354,7 @@ var ComRegister = class {
|
|
|
356
354
|
dynamicJob;
|
|
357
355
|
liveJob;
|
|
358
356
|
_jieba = Jieba.withDict(dict);
|
|
357
|
+
stopwords;
|
|
359
358
|
constructor(ctx, config) {
|
|
360
359
|
this.ctx = ctx;
|
|
361
360
|
this.init(config);
|
|
@@ -386,7 +385,7 @@ var ComRegister = class {
|
|
|
386
385
|
this.logger.info("调用bili login指令");
|
|
387
386
|
let content;
|
|
388
387
|
try {
|
|
389
|
-
content = await ctx.
|
|
388
|
+
content = await ctx["bilibili-notify-api"].getLoginQRCode();
|
|
390
389
|
} catch (_) {
|
|
391
390
|
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
392
391
|
}
|
|
@@ -411,7 +410,7 @@ var ComRegister = class {
|
|
|
411
410
|
flag = false;
|
|
412
411
|
let loginContent;
|
|
413
412
|
try {
|
|
414
|
-
loginContent = await ctx.
|
|
413
|
+
loginContent = await ctx["bilibili-notify-api"].getLoginStatus(content.data.qrcode_key);
|
|
415
414
|
} catch (e) {
|
|
416
415
|
this.logger.error(e);
|
|
417
416
|
return;
|
|
@@ -425,24 +424,19 @@ var ComRegister = class {
|
|
|
425
424
|
return await session.send("二维码已失效,请重新登录");
|
|
426
425
|
}
|
|
427
426
|
if (loginContent.data.code === 0) {
|
|
428
|
-
const encryptedCookies = ctx.
|
|
429
|
-
const encryptedRefreshToken = ctx.
|
|
427
|
+
const encryptedCookies = ctx["bilibili-notify-api"].encrypt(ctx["bilibili-notify-api"].getCookies());
|
|
428
|
+
const encryptedRefreshToken = ctx["bilibili-notify-api"].encrypt(loginContent.data.refresh_token);
|
|
430
429
|
await ctx.database.upsert("loginBili", [{
|
|
431
430
|
id: 1,
|
|
432
431
|
bili_cookies: encryptedCookies,
|
|
433
432
|
bili_refresh_token: encryptedRefreshToken
|
|
434
433
|
}]);
|
|
435
434
|
this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
|
|
436
|
-
await this.ctx.
|
|
435
|
+
await this.ctx["bilibili-notify-api"].loadCookiesFromDatabase();
|
|
437
436
|
await this.checkIfLoginInfoIsLoaded();
|
|
438
437
|
this.loginTimer();
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (code !== 0) this.logger.error(msg);
|
|
442
|
-
ctx.ba.disposeNotifier();
|
|
443
|
-
await session.send("登录成功");
|
|
444
|
-
await session.execute("bili list");
|
|
445
|
-
ctx.ba.enableRefreshCookiesDetect();
|
|
438
|
+
ctx["bilibili-notify-api"].disposeNotifier();
|
|
439
|
+
await session.send("登录成功,请重启插件");
|
|
446
440
|
}
|
|
447
441
|
} finally {
|
|
448
442
|
flag = true;
|
|
@@ -458,7 +452,7 @@ var ComRegister = class {
|
|
|
458
452
|
await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
|
|
459
453
|
});
|
|
460
454
|
biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
|
|
461
|
-
const { data: { live_users } } = await ctx.
|
|
455
|
+
const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
|
|
462
456
|
const subLiveUsers = [];
|
|
463
457
|
for (const sub of this.subManager) {
|
|
464
458
|
let onLive = false;
|
|
@@ -480,10 +474,10 @@ var ComRegister = class {
|
|
|
480
474
|
});
|
|
481
475
|
biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
|
|
482
476
|
const i = index && index - 1 || 0;
|
|
483
|
-
const content = await this.ctx.
|
|
477
|
+
const content = await this.ctx["bilibili-notify-api"].getUserSpaceDynamic(uid);
|
|
484
478
|
const item = content.data.items[i];
|
|
485
479
|
const buffer = await withRetry(async () => {
|
|
486
|
-
return await this.ctx.
|
|
480
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item);
|
|
487
481
|
}, 1).catch(async (e) => {
|
|
488
482
|
if (e.message === "直播开播动态,不做处理") {
|
|
489
483
|
await session.send("直播开播动态,不做处理");
|
|
@@ -598,7 +592,7 @@ var ComRegister = class {
|
|
|
598
592
|
["初中", 4],
|
|
599
593
|
["毕业", 4]
|
|
600
594
|
];
|
|
601
|
-
await session.send(/* @__PURE__ */ jsx("message", { children: h.image(await this.ctx.
|
|
595
|
+
await session.send(/* @__PURE__ */ jsx("message", { children: h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg") }));
|
|
602
596
|
const top5DanmakuMaker = [
|
|
603
597
|
["张三", 60],
|
|
604
598
|
["李四", 48],
|
|
@@ -606,46 +600,34 @@ var ComRegister = class {
|
|
|
606
600
|
["赵六", 27],
|
|
607
601
|
["田七", 25]
|
|
608
602
|
];
|
|
609
|
-
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");
|
|
603
|
+
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");
|
|
610
604
|
await session.send(danmakerRankMsg);
|
|
611
605
|
});
|
|
612
606
|
biliCom.subcommand(".cap").action(async ({ session }) => {
|
|
613
607
|
const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
|
|
614
|
-
const data$1 = await this.ctx.
|
|
608
|
+
const data$1 = await this.ctx["bilibili-notify-api"].getUserInfo("114514");
|
|
615
609
|
return {
|
|
616
610
|
code: 0,
|
|
617
611
|
data: data$1
|
|
618
612
|
};
|
|
619
613
|
}).then((content) => content.data);
|
|
620
614
|
if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
|
|
621
|
-
const { data } = await ctx.
|
|
615
|
+
const { data } = await ctx["bilibili-notify-api"].v_voucherCaptcha(userInfoData.v_voucher);
|
|
622
616
|
if (!data.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
|
|
623
617
|
await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
|
|
624
618
|
await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
|
|
625
619
|
await session.send(`gt:${data.geetest.gt}`);
|
|
626
620
|
await session.send(`challenge:${data.geetest.challenge}`);
|
|
627
|
-
await session.send("
|
|
628
|
-
const validate = await (
|
|
629
|
-
while (true) {
|
|
630
|
-
const validate$1 = await session.prompt();
|
|
631
|
-
if (validate$1?.startsWith("val ")) return validate$1.slice(4);
|
|
632
|
-
else await session.send("请输入正确的validate,格式为 val <validate>");
|
|
633
|
-
}
|
|
634
|
-
})();
|
|
621
|
+
await session.send("请直接输入validate");
|
|
622
|
+
const validate = await session.prompt();
|
|
635
623
|
const seccode = `${validate}|jordan`;
|
|
636
|
-
const { data: validateCaptchaData } = await ctx.
|
|
624
|
+
const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
|
|
637
625
|
if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
|
|
638
|
-
ctx.ba.addCookie(`x-bili-gaia-vtoken=${validateCaptchaData.grisk_id}`);
|
|
639
|
-
const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
|
|
640
|
-
await ctx.database.upsert("loginBili", [{
|
|
641
|
-
id: 1,
|
|
642
|
-
bili_cookies: encryptedCookies
|
|
643
|
-
}]);
|
|
644
626
|
return "验证成功!请重启插件";
|
|
645
627
|
});
|
|
646
628
|
}
|
|
647
629
|
async init(config) {
|
|
648
|
-
this.logger = this.ctx.logger("
|
|
630
|
+
this.logger = this.ctx.logger("bilibili-notify-core");
|
|
649
631
|
this.logger.info("初始化插件中...");
|
|
650
632
|
this.config = config;
|
|
651
633
|
this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
|
|
@@ -656,6 +638,7 @@ var ComRegister = class {
|
|
|
656
638
|
this.logger.info("账号未登录,请登录");
|
|
657
639
|
return;
|
|
658
640
|
}
|
|
641
|
+
this.mergeStopWords(config.wordcloudStopWords);
|
|
659
642
|
if (config.advancedSub) {
|
|
660
643
|
this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
|
|
661
644
|
await this.initAsyncPart(subs);
|
|
@@ -685,6 +668,14 @@ var ComRegister = class {
|
|
|
685
668
|
this.updateSubNotifier();
|
|
686
669
|
this.logger.info("插件初始化完毕!");
|
|
687
670
|
}
|
|
671
|
+
mergeStopWords(stopWordsStr) {
|
|
672
|
+
if (!stopWordsStr || stopWordsStr.trim() === "") {
|
|
673
|
+
this.stopwords = new Set(stop_words_default);
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
|
|
677
|
+
this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
|
|
678
|
+
}
|
|
688
679
|
initManager() {
|
|
689
680
|
for (const sub of this.subManager) {
|
|
690
681
|
if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(DateTime.now().toSeconds()));
|
|
@@ -710,6 +701,7 @@ var ComRegister = class {
|
|
|
710
701
|
live: s.live,
|
|
711
702
|
liveAtAll: s.liveAtAll,
|
|
712
703
|
liveGuardBuy: s.liveGuardBuy,
|
|
704
|
+
wordcloud: s.wordcloud,
|
|
713
705
|
bot: null
|
|
714
706
|
}));
|
|
715
707
|
const target = [{
|
|
@@ -720,9 +712,11 @@ var ComRegister = class {
|
|
|
720
712
|
uid: s.uid,
|
|
721
713
|
dynamic: s.dynamic,
|
|
722
714
|
live: s.live,
|
|
715
|
+
wordcloud: s.wordcloud,
|
|
723
716
|
target,
|
|
724
717
|
card: { enable: false },
|
|
725
|
-
liveMsg: { enable: false }
|
|
718
|
+
liveMsg: { enable: false },
|
|
719
|
+
liveSummary: { enable: false }
|
|
726
720
|
};
|
|
727
721
|
});
|
|
728
722
|
return subs;
|
|
@@ -739,23 +733,23 @@ var ComRegister = class {
|
|
|
739
733
|
if (this.rebootCount >= 3) {
|
|
740
734
|
this.logger.error("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
741
735
|
await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
|
|
742
|
-
await this.ctx.
|
|
736
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
743
737
|
return;
|
|
744
738
|
}
|
|
745
739
|
this.rebootCount++;
|
|
746
740
|
this.logger.info("插件出现未知错误,正在重启插件");
|
|
747
|
-
const flag = await this.ctx.
|
|
741
|
+
const flag = await this.ctx["bilibili-notify"].restartPlugin();
|
|
748
742
|
if (flag) this.logger.info("重启插件成功");
|
|
749
743
|
else {
|
|
750
744
|
this.logger.error("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
751
745
|
await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
|
|
752
|
-
await this.ctx.
|
|
746
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
753
747
|
}
|
|
754
748
|
}
|
|
755
749
|
async sendPrivateMsgAndStopService() {
|
|
756
750
|
await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
757
751
|
this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
|
|
758
|
-
await this.ctx.
|
|
752
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
759
753
|
return;
|
|
760
754
|
}
|
|
761
755
|
async sendMessageWithRetry(bot, channelId, content) {
|
|
@@ -775,19 +769,22 @@ var ComRegister = class {
|
|
|
775
769
|
const liveMsg = {
|
|
776
770
|
customLiveStart: this.config.customLiveStart || "",
|
|
777
771
|
customLive: this.config.customLive || "",
|
|
778
|
-
customLiveEnd: this.config.customLiveEnd || ""
|
|
772
|
+
customLiveEnd: this.config.customLiveEnd || "",
|
|
773
|
+
liveSummary: this.config.liveSummary.join("\n") || ""
|
|
779
774
|
};
|
|
780
775
|
if (sub.liveMsg.enable) {
|
|
781
776
|
liveMsg.customLiveStart = sub.liveMsg.customLiveStart || this.config.customLiveStart;
|
|
782
777
|
liveMsg.customLive = sub.liveMsg.customLive || this.config.customLive;
|
|
783
778
|
liveMsg.customLiveEnd = sub.liveMsg.customLiveEnd || this.config.customLiveEnd;
|
|
784
779
|
}
|
|
780
|
+
if (sub.liveSummary.enable) liveMsg.liveSummary = sub.liveSummary.liveSummary || this.config.liveSummary.join("\n");
|
|
785
781
|
this.liveMsgManager.set(sub.uid, liveMsg);
|
|
786
782
|
const dynamicArr = [];
|
|
787
783
|
const dynamicAtAllArr = [];
|
|
788
784
|
const liveArr = [];
|
|
789
785
|
const liveAtAllArr = [];
|
|
790
786
|
const liveGuardBuyArr = [];
|
|
787
|
+
const wordcloudArr = [];
|
|
791
788
|
for (const platform of sub.target) for (const channel of platform.channelArr) {
|
|
792
789
|
const target = `${platform.platform}:${channel.channelId}`;
|
|
793
790
|
if (channel.dynamic) dynamicArr.push(target);
|
|
@@ -795,13 +792,15 @@ var ComRegister = class {
|
|
|
795
792
|
if (channel.live) liveArr.push(target);
|
|
796
793
|
if (channel.liveAtAll) liveAtAllArr.push(target);
|
|
797
794
|
if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
|
|
795
|
+
if (channel.wordcloud) wordcloudArr.push(target);
|
|
798
796
|
}
|
|
799
797
|
this.pushArrMap.set(sub.uid, {
|
|
800
798
|
dynamicArr,
|
|
801
799
|
dynamicAtAllArr,
|
|
802
800
|
liveArr,
|
|
803
801
|
liveAtAllArr,
|
|
804
|
-
liveGuardBuyArr
|
|
802
|
+
liveGuardBuyArr,
|
|
803
|
+
wordcloudArr
|
|
805
804
|
});
|
|
806
805
|
}
|
|
807
806
|
this.logger.info("初始化推送群组/频道信息:");
|
|
@@ -861,13 +860,21 @@ var ComRegister = class {
|
|
|
861
860
|
}, 1);
|
|
862
861
|
this.logger.info(`成功推送上舰消息:${success.length}条`);
|
|
863
862
|
}
|
|
863
|
+
if (type === PushType.WordCloud && record.wordcloudArr?.length >= 1) {
|
|
864
|
+
this.logger.info(record.wordcloudArr);
|
|
865
|
+
const wordcloudArr = structuredClone(record.wordcloudArr);
|
|
866
|
+
const success = await withRetry(async () => {
|
|
867
|
+
return await this.ctx.broadcast(wordcloudArr, /* @__PURE__ */ jsx("message", { children: content }));
|
|
868
|
+
}, 1);
|
|
869
|
+
this.logger.info(`成功推送词云消息:${success.length}条`);
|
|
870
|
+
}
|
|
864
871
|
return;
|
|
865
872
|
}
|
|
866
873
|
dynamicDetect() {
|
|
867
874
|
const handler = async () => {
|
|
868
875
|
const currentPushDyn = {};
|
|
869
876
|
const content = await withRetry(async () => {
|
|
870
|
-
return await this.ctx.
|
|
877
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
871
878
|
}, 1).catch((e) => {
|
|
872
879
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
873
880
|
});
|
|
@@ -876,13 +883,13 @@ var ComRegister = class {
|
|
|
876
883
|
case -101: {
|
|
877
884
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
878
885
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
879
|
-
await this.ctx.
|
|
886
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
880
887
|
break;
|
|
881
888
|
}
|
|
882
889
|
case -352: {
|
|
883
890
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
884
891
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
885
|
-
await this.ctx.
|
|
892
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
886
893
|
break;
|
|
887
894
|
}
|
|
888
895
|
case 4101128:
|
|
@@ -907,7 +914,7 @@ var ComRegister = class {
|
|
|
907
914
|
if (timeline < postTime) {
|
|
908
915
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
909
916
|
const buffer = await withRetry(async () => {
|
|
910
|
-
return await this.ctx.
|
|
917
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
|
|
911
918
|
}, 1).catch(async (e) => {
|
|
912
919
|
if (e.message === "直播开播动态,不做处理") return;
|
|
913
920
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -966,7 +973,7 @@ var ComRegister = class {
|
|
|
966
973
|
const currentPushDyn = {};
|
|
967
974
|
this.logger.info("开始获取动态信息...");
|
|
968
975
|
const content = await withRetry(async () => {
|
|
969
|
-
return await this.ctx.
|
|
976
|
+
return await this.ctx["bilibili-notify-api"].getAllDynamic();
|
|
970
977
|
}, 1).catch((e) => {
|
|
971
978
|
this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
|
|
972
979
|
});
|
|
@@ -975,13 +982,13 @@ var ComRegister = class {
|
|
|
975
982
|
case -101: {
|
|
976
983
|
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
977
984
|
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
|
|
978
|
-
await this.ctx.
|
|
985
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
979
986
|
break;
|
|
980
987
|
}
|
|
981
988
|
case -352: {
|
|
982
989
|
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
983
990
|
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
|
|
984
|
-
await this.ctx.
|
|
991
|
+
await this.ctx["bilibili-notify"].disposePlugin();
|
|
985
992
|
break;
|
|
986
993
|
}
|
|
987
994
|
case 4101128:
|
|
@@ -1012,7 +1019,7 @@ var ComRegister = class {
|
|
|
1012
1019
|
const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
|
|
1013
1020
|
this.logger.info("开始渲染推送卡片...");
|
|
1014
1021
|
const buffer = await withRetry(async () => {
|
|
1015
|
-
return await this.ctx.
|
|
1022
|
+
return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
|
|
1016
1023
|
}, 1).catch(async (e) => {
|
|
1017
1024
|
if (e.message === "直播开播动态,不做处理") return;
|
|
1018
1025
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
@@ -1077,7 +1084,7 @@ var ComRegister = class {
|
|
|
1077
1084
|
return withLock(handler);
|
|
1078
1085
|
}
|
|
1079
1086
|
async useMasterInfo(uid, masterInfo, liveType) {
|
|
1080
|
-
const { data } = await this.ctx.
|
|
1087
|
+
const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
|
|
1081
1088
|
let liveOpenFollowerNum;
|
|
1082
1089
|
let liveEndFollowerNum;
|
|
1083
1090
|
let liveFollowerChange;
|
|
@@ -1102,7 +1109,7 @@ var ComRegister = class {
|
|
|
1102
1109
|
};
|
|
1103
1110
|
}
|
|
1104
1111
|
async useLiveRoomInfo(roomId) {
|
|
1105
|
-
const data = await withRetry(async () => await this.ctx.
|
|
1112
|
+
const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
|
|
1106
1113
|
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
1107
1114
|
return false;
|
|
1108
1115
|
});
|
|
@@ -1111,7 +1118,7 @@ var ComRegister = class {
|
|
|
1111
1118
|
}
|
|
1112
1119
|
async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
|
|
1113
1120
|
const buffer = await withRetry(async () => {
|
|
1114
|
-
return await this.ctx.
|
|
1121
|
+
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);
|
|
1115
1122
|
}, 1).catch((e) => {
|
|
1116
1123
|
this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
|
|
1117
1124
|
});
|
|
@@ -1120,14 +1127,14 @@ var ComRegister = class {
|
|
|
1120
1127
|
return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
|
|
1121
1128
|
}
|
|
1122
1129
|
async segmentDanmaku(danmaku, danmakuWeightRecord) {
|
|
1123
|
-
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !stopwords.has(word)).map((w) => {
|
|
1130
|
+
this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !this.stopwords.has(word)).map((w) => {
|
|
1124
1131
|
danmakuWeightRecord[w] = (danmakuWeightRecord[w] || 0) + 1;
|
|
1125
1132
|
});
|
|
1126
1133
|
}
|
|
1127
1134
|
addUserToDanmakuMaker(username, danmakuMakerRecord) {
|
|
1128
1135
|
danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
|
|
1129
1136
|
}
|
|
1130
|
-
async liveDetectWithListener(roomId,
|
|
1137
|
+
async liveDetectWithListener(roomId, sub) {
|
|
1131
1138
|
let liveTime;
|
|
1132
1139
|
let pushAtTimeTimer;
|
|
1133
1140
|
const danmakuWeightRecord = {};
|
|
@@ -1136,24 +1143,24 @@ var ComRegister = class {
|
|
|
1136
1143
|
let liveRoomInfo;
|
|
1137
1144
|
let masterInfo;
|
|
1138
1145
|
let watchedNum;
|
|
1139
|
-
const liveMsgObj = this.liveMsgManager.get(uid);
|
|
1140
|
-
const sendDanmakuWordCloud = async () => {
|
|
1146
|
+
const liveMsgObj = this.liveMsgManager.get(sub.uid);
|
|
1147
|
+
const sendDanmakuWordCloud = async (liveSummary) => {
|
|
1141
1148
|
this.logger.info("开始制作弹幕词云");
|
|
1142
1149
|
this.logger.info("正在获取前90热词");
|
|
1143
1150
|
const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1144
1151
|
this.logger.info("弹幕词云前90词及权重:");
|
|
1145
1152
|
this.logger.info(top90Words);
|
|
1146
1153
|
this.logger.info("正在准备生成弹幕词云");
|
|
1147
|
-
const buffer = await this.ctx.
|
|
1154
|
+
const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
|
|
1148
1155
|
this.logger.info("弹幕词云生成完成,正在准备发送词云图片");
|
|
1149
|
-
await this.broadcastToTargets(uid, h.image(buffer, "image/jpeg"), PushType.Live);
|
|
1156
|
+
await this.broadcastToTargets(sub.uid, h.image(buffer, "image/jpeg"), PushType.Live);
|
|
1150
1157
|
this.logger.info("词云图片发送完毕!");
|
|
1151
1158
|
this.logger.info("开始构建弹幕发送排行榜消息");
|
|
1152
1159
|
const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
|
|
1153
1160
|
const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
|
|
1154
1161
|
const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
1155
|
-
const danmakuMakerMsg =
|
|
1156
|
-
await this.broadcastToTargets(uid, danmakuMakerMsg, PushType.
|
|
1162
|
+
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");
|
|
1163
|
+
await this.broadcastToTargets(sub.uid, danmakuMakerMsg, PushType.WordCloud);
|
|
1157
1164
|
Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
|
|
1158
1165
|
Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
|
|
1159
1166
|
};
|
|
@@ -1170,12 +1177,12 @@ var ComRegister = class {
|
|
|
1170
1177
|
}
|
|
1171
1178
|
liveTime = liveRoomInfo.live_time;
|
|
1172
1179
|
const watched = watchedNum || "暂未获取到";
|
|
1173
|
-
const liveMsg = liveMsgObj
|
|
1180
|
+
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}`);
|
|
1174
1181
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1175
1182
|
liveRoomInfo,
|
|
1176
1183
|
masterInfo,
|
|
1177
|
-
cardStyle
|
|
1178
|
-
}, uid, liveMsg);
|
|
1184
|
+
cardStyle: sub.card
|
|
1185
|
+
}, sub.uid, liveMsg);
|
|
1179
1186
|
};
|
|
1180
1187
|
const useMasterAndLiveRoomInfo = async (liveType) => {
|
|
1181
1188
|
let flag = true;
|
|
@@ -1197,7 +1204,7 @@ var ComRegister = class {
|
|
|
1197
1204
|
onError: async () => {
|
|
1198
1205
|
liveStatus = false;
|
|
1199
1206
|
pushAtTimeTimer?.();
|
|
1200
|
-
this.ctx.
|
|
1207
|
+
this.ctx["bilibili-notify-live"].closeListener(roomId);
|
|
1201
1208
|
await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
|
|
1202
1209
|
this.logger.error(`[${roomId}]直播间连接发生错误!`);
|
|
1203
1210
|
},
|
|
@@ -1222,7 +1229,7 @@ var ComRegister = class {
|
|
|
1222
1229
|
body.gift_name,
|
|
1223
1230
|
")"
|
|
1224
1231
|
] });
|
|
1225
|
-
this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
|
|
1232
|
+
this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
|
|
1226
1233
|
},
|
|
1227
1234
|
onLiveStart: async () => {
|
|
1228
1235
|
if (liveStatus) return;
|
|
@@ -1234,12 +1241,12 @@ var ComRegister = class {
|
|
|
1234
1241
|
}
|
|
1235
1242
|
liveTime = liveRoomInfo.live_time;
|
|
1236
1243
|
const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
|
|
1237
|
-
const liveStartMsg = liveMsgObj
|
|
1244
|
+
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}`);
|
|
1238
1245
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1239
1246
|
liveRoomInfo,
|
|
1240
1247
|
masterInfo,
|
|
1241
|
-
cardStyle
|
|
1242
|
-
}, uid, liveStartMsg);
|
|
1248
|
+
cardStyle: sub.card
|
|
1249
|
+
}, sub.uid, liveStartMsg);
|
|
1243
1250
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1244
1251
|
},
|
|
1245
1252
|
onLiveEnd: async () => {
|
|
@@ -1254,28 +1261,28 @@ var ComRegister = class {
|
|
|
1254
1261
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1255
1262
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1256
1263
|
})();
|
|
1257
|
-
const liveEndMsg = liveMsgObj
|
|
1264
|
+
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");
|
|
1258
1265
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1259
1266
|
liveRoomInfo,
|
|
1260
1267
|
masterInfo,
|
|
1261
|
-
cardStyle
|
|
1262
|
-
}, uid, liveEndMsg);
|
|
1268
|
+
cardStyle: sub.card
|
|
1269
|
+
}, sub.uid, liveEndMsg);
|
|
1263
1270
|
pushAtTimeTimer();
|
|
1264
1271
|
pushAtTimeTimer = null;
|
|
1265
|
-
if (
|
|
1272
|
+
if (sub.wordcloud) await sendDanmakuWordCloud(liveMsgObj.liveSummary);
|
|
1266
1273
|
}
|
|
1267
1274
|
};
|
|
1268
|
-
await this.ctx.
|
|
1275
|
+
await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
|
|
1269
1276
|
if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1270
1277
|
if (liveRoomInfo.live_status === 1) {
|
|
1271
1278
|
liveTime = liveRoomInfo.live_time;
|
|
1272
1279
|
const watched = watchedNum || "暂未获取到";
|
|
1273
|
-
const liveMsg = liveMsgObj
|
|
1280
|
+
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}`);
|
|
1274
1281
|
if (this.config.restartPush) await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
|
|
1275
1282
|
liveRoomInfo,
|
|
1276
1283
|
masterInfo,
|
|
1277
|
-
cardStyle
|
|
1278
|
-
}, uid, liveMsg);
|
|
1284
|
+
cardStyle: sub.card
|
|
1285
|
+
}, sub.uid, liveMsg);
|
|
1279
1286
|
if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
|
|
1280
1287
|
liveStatus = true;
|
|
1281
1288
|
}
|
|
@@ -1300,7 +1307,7 @@ var ComRegister = class {
|
|
|
1300
1307
|
const uids = [];
|
|
1301
1308
|
for (const [uid] of this.liveStatusManager.entries()) uids.push(uid);
|
|
1302
1309
|
const useLiveInfo = async () => {
|
|
1303
|
-
const { data: data$1 } = await withRetry(async () => await this.ctx.
|
|
1310
|
+
const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
|
|
1304
1311
|
return void 0;
|
|
1305
1312
|
});
|
|
1306
1313
|
if (!data$1) {
|
|
@@ -1322,7 +1329,7 @@ var ComRegister = class {
|
|
|
1322
1329
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1323
1330
|
liveStatus.liveStartTimeInit = true;
|
|
1324
1331
|
}
|
|
1325
|
-
const liveMsg = liveMsgObj
|
|
1332
|
+
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}`);
|
|
1326
1333
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1327
1334
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1328
1335
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1355,7 +1362,7 @@ var ComRegister = class {
|
|
|
1355
1362
|
if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
|
|
1356
1363
|
return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
|
|
1357
1364
|
})();
|
|
1358
|
-
const liveEndMsg = liveMsgObj
|
|
1365
|
+
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");
|
|
1359
1366
|
await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
|
|
1360
1367
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1361
1368
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1374,7 +1381,7 @@ var ComRegister = class {
|
|
|
1374
1381
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1375
1382
|
liveStatus.liveStartTimeInit = true;
|
|
1376
1383
|
const follower = liveStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(liveStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : liveStatus.masterInfo.liveOpenFollowerNum.toString();
|
|
1377
|
-
const liveStartMsg = liveMsgObj
|
|
1384
|
+
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}`);
|
|
1378
1385
|
await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
|
|
1379
1386
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1380
1387
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1395,7 +1402,7 @@ var ComRegister = class {
|
|
|
1395
1402
|
liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
|
|
1396
1403
|
liveStatus.liveStartTimeInit = true;
|
|
1397
1404
|
}
|
|
1398
|
-
const liveMsg = liveMsgObj
|
|
1405
|
+
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}`);
|
|
1399
1406
|
await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
|
|
1400
1407
|
liveRoomInfo: liveStatus.liveRoomInfo,
|
|
1401
1408
|
masterInfo: liveStatus.masterInfo,
|
|
@@ -1431,7 +1438,7 @@ var ComRegister = class {
|
|
|
1431
1438
|
async checkIfLoginInfoIsLoaded() {
|
|
1432
1439
|
return new Promise((resolve$1) => {
|
|
1433
1440
|
const check = () => {
|
|
1434
|
-
if (!this.ctx.
|
|
1441
|
+
if (!this.ctx["bilibili-notify-api"].getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
|
|
1435
1442
|
else resolve$1("success");
|
|
1436
1443
|
};
|
|
1437
1444
|
check();
|
|
@@ -1440,9 +1447,9 @@ var ComRegister = class {
|
|
|
1440
1447
|
async subUserInBili(mid) {
|
|
1441
1448
|
const checkGroupIsReady = async () => {
|
|
1442
1449
|
if (!this.loginDBData?.dynamic_group_id) {
|
|
1443
|
-
const createGroupData = await this.ctx.
|
|
1450
|
+
const createGroupData = await this.ctx["bilibili-notify-api"].createGroup("订阅");
|
|
1444
1451
|
if (createGroupData.code === 22106) {
|
|
1445
|
-
const allGroupData = await this.ctx.
|
|
1452
|
+
const allGroupData = await this.ctx["bilibili-notify-api"].getAllGroup();
|
|
1446
1453
|
for (const group of allGroupData.data) if (group.name === "订阅") {
|
|
1447
1454
|
this.loginDBData.dynamic_group_id = group.tagid.toString();
|
|
1448
1455
|
this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
|
|
@@ -1469,7 +1476,7 @@ var ComRegister = class {
|
|
|
1469
1476
|
const resp = await checkGroupIsReady();
|
|
1470
1477
|
if (resp.code !== 0) return resp;
|
|
1471
1478
|
const getGroupDetailData = async () => {
|
|
1472
|
-
const relationGroupDetailData = await this.ctx.
|
|
1479
|
+
const relationGroupDetailData = await this.ctx["bilibili-notify-api"].getRelationGroupDetail(this.loginDBData.dynamic_group_id);
|
|
1473
1480
|
if (relationGroupDetailData.code !== 0) {
|
|
1474
1481
|
if (relationGroupDetailData.code === 22104) {
|
|
1475
1482
|
this.loginDBData.dynamic_group_id = null;
|
|
@@ -1498,7 +1505,7 @@ var ComRegister = class {
|
|
|
1498
1505
|
code: 0,
|
|
1499
1506
|
msg: "订阅对象已存在于分组中"
|
|
1500
1507
|
};
|
|
1501
|
-
const subUserData = await this.ctx.
|
|
1508
|
+
const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
|
|
1502
1509
|
const subUserMatchPattern = {
|
|
1503
1510
|
[-101]: () => {
|
|
1504
1511
|
return {
|
|
@@ -1543,7 +1550,7 @@ var ComRegister = class {
|
|
|
1543
1550
|
};
|
|
1544
1551
|
},
|
|
1545
1552
|
22014: async () => {
|
|
1546
|
-
const copyUserToGroupData = await this.ctx.
|
|
1553
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1547
1554
|
if (copyUserToGroupData.code !== 0) return {
|
|
1548
1555
|
code: copyUserToGroupData.code,
|
|
1549
1556
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1554,7 +1561,7 @@ var ComRegister = class {
|
|
|
1554
1561
|
};
|
|
1555
1562
|
},
|
|
1556
1563
|
0: async () => {
|
|
1557
|
-
const copyUserToGroupData = await this.ctx.
|
|
1564
|
+
const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1558
1565
|
if (copyUserToGroupData.code !== 0) return {
|
|
1559
1566
|
code: copyUserToGroupData.code,
|
|
1560
1567
|
msg: "添加订阅对象到分组失败,请稍后重试"
|
|
@@ -1572,7 +1579,7 @@ var ComRegister = class {
|
|
|
1572
1579
|
for (const sub of Object.values(subs)) {
|
|
1573
1580
|
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1574
1581
|
const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
|
|
1575
|
-
const data = await this.ctx.
|
|
1582
|
+
const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
|
|
1576
1583
|
return {
|
|
1577
1584
|
code: 0,
|
|
1578
1585
|
data
|
|
@@ -1601,7 +1608,7 @@ var ComRegister = class {
|
|
|
1601
1608
|
sub.live = false;
|
|
1602
1609
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1603
1610
|
}
|
|
1604
|
-
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub
|
|
1611
|
+
if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
|
|
1605
1612
|
}
|
|
1606
1613
|
const subInfo = await this.subUserInBili(sub.uid);
|
|
1607
1614
|
if (subInfo.code !== 0) return subInfo;
|
|
@@ -1649,7 +1656,7 @@ var ComRegister = class {
|
|
|
1649
1656
|
}
|
|
1650
1657
|
async checkIfIsLogin() {
|
|
1651
1658
|
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
|
1652
|
-
if (this.ctx.
|
|
1659
|
+
if (this.ctx["bilibili-notify-api"].getCookies() !== "[]") return true;
|
|
1653
1660
|
}
|
|
1654
1661
|
return false;
|
|
1655
1662
|
}
|
|
@@ -1665,6 +1672,7 @@ var ComRegister = class {
|
|
|
1665
1672
|
live: Schema.boolean().default(true).description("直播"),
|
|
1666
1673
|
liveAtAll: Schema.boolean().default(true).description("直播At全体"),
|
|
1667
1674
|
liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
|
|
1675
|
+
wordcloud: Schema.boolean().default(true).description("弹幕词云"),
|
|
1668
1676
|
platform: Schema.string().required().description("平台名"),
|
|
1669
1677
|
target: Schema.string().required().description("群号/频道号")
|
|
1670
1678
|
})).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
|
|
@@ -1675,8 +1683,8 @@ var ComRegister = class {
|
|
|
1675
1683
|
masterAccountGuildId: Schema.string()
|
|
1676
1684
|
}),
|
|
1677
1685
|
liveDetectType: Schema.string(),
|
|
1678
|
-
|
|
1679
|
-
liveSummary: Schema.
|
|
1686
|
+
wordcloudStopWords: Schema.string(),
|
|
1687
|
+
liveSummary: Schema.array(String),
|
|
1680
1688
|
restartPush: Schema.boolean().required(),
|
|
1681
1689
|
pushTime: Schema.number().required(),
|
|
1682
1690
|
pushImgsInDynamic: Schema.boolean().required(),
|
|
@@ -1733,10 +1741,10 @@ const DYNAMIC_TYPE_LIVE_RCMD = "DYNAMIC_TYPE_LIVE_RCMD";
|
|
|
1733
1741
|
const DYNAMIC_TYPE_UGC_SEASON = "DYNAMIC_TYPE_UGC_SEASON";
|
|
1734
1742
|
const ADDITIONAL_TYPE_RESERVE = "ADDITIONAL_TYPE_RESERVE";
|
|
1735
1743
|
var GenerateImg = class extends Service {
|
|
1736
|
-
static inject = ["puppeteer"
|
|
1744
|
+
static inject = ["puppeteer"];
|
|
1737
1745
|
giConfig;
|
|
1738
1746
|
constructor(ctx, config) {
|
|
1739
|
-
super(ctx, "
|
|
1747
|
+
super(ctx, "bilibili-notify-generate-img");
|
|
1740
1748
|
this.giConfig = config;
|
|
1741
1749
|
}
|
|
1742
1750
|
async imgHandler(html) {
|
|
@@ -3313,11 +3321,15 @@ var BiliAPI = class extends Service {
|
|
|
3313
3321
|
sub_key: ""
|
|
3314
3322
|
};
|
|
3315
3323
|
updateJob;
|
|
3324
|
+
pRetry;
|
|
3325
|
+
AbortError;
|
|
3316
3326
|
constructor(ctx, config) {
|
|
3317
|
-
super(ctx, "
|
|
3327
|
+
super(ctx, "bilibili-notify-api");
|
|
3318
3328
|
this.apiConfig = config;
|
|
3319
3329
|
}
|
|
3320
3330
|
async start() {
|
|
3331
|
+
this.pRetry = (await import("p-retry")).default;
|
|
3332
|
+
this.AbortError = (await import("p-retry")).AbortError;
|
|
3321
3333
|
const CacheableLookup = (await import("cacheable-lookup")).default;
|
|
3322
3334
|
this.cacheable = new CacheableLookup();
|
|
3323
3335
|
this.cacheable.install(http.globalAgent);
|
|
@@ -3382,129 +3394,305 @@ var BiliAPI = class extends Service {
|
|
|
3382
3394
|
return decrypted.toString();
|
|
3383
3395
|
}
|
|
3384
3396
|
async getTheUserWhoIsLiveStreaming() {
|
|
3385
|
-
const
|
|
3386
|
-
|
|
3397
|
+
const run = async () => {
|
|
3398
|
+
const { data } = await this.client.get(GET_LATEST_UPDATED_UPS);
|
|
3399
|
+
return data;
|
|
3400
|
+
};
|
|
3401
|
+
return await this.pRetry(run, {
|
|
3402
|
+
onFailedAttempt: (error) => {
|
|
3403
|
+
this.logger.error(`getTheUserWhoIsLiveStreaming() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3404
|
+
},
|
|
3405
|
+
retries: 3
|
|
3406
|
+
});
|
|
3387
3407
|
}
|
|
3388
3408
|
async getLiveRoomInfoStreamKey(roomId) {
|
|
3389
|
-
const
|
|
3390
|
-
|
|
3409
|
+
const run = async () => {
|
|
3410
|
+
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
|
|
3411
|
+
return data;
|
|
3412
|
+
};
|
|
3413
|
+
return await this.pRetry(run, {
|
|
3414
|
+
onFailedAttempt: (error) => {
|
|
3415
|
+
this.logger.error(`getLiveRoomInfoStreamKey() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3416
|
+
},
|
|
3417
|
+
retries: 3
|
|
3418
|
+
});
|
|
3391
3419
|
}
|
|
3392
3420
|
async getLiveRoomInfoByUids(uids) {
|
|
3393
|
-
const
|
|
3394
|
-
|
|
3395
|
-
|
|
3421
|
+
const run = async () => {
|
|
3422
|
+
const params = uids.map((uid) => `uids[]=${uid}`).join("&");
|
|
3423
|
+
const { data } = await this.client.get(`${GET_LIVE_ROOMS_INFO}?${params}`);
|
|
3424
|
+
return data;
|
|
3425
|
+
};
|
|
3426
|
+
return await this.pRetry(run, {
|
|
3427
|
+
onFailedAttempt: (error) => {
|
|
3428
|
+
this.logger.error(`getLiveRoomInfoByUids() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3429
|
+
},
|
|
3430
|
+
retries: 3
|
|
3431
|
+
});
|
|
3396
3432
|
}
|
|
3397
3433
|
async getServerUTCTime() {
|
|
3398
|
-
const
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3434
|
+
const run = async () => {
|
|
3435
|
+
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
|
3436
|
+
const regex = /Date\.UTC\((.*?)\)/;
|
|
3437
|
+
const match = data.match(regex);
|
|
3438
|
+
if (match) {
|
|
3439
|
+
const timestamp = new Function(`return Date.UTC(${match[1]})`)();
|
|
3440
|
+
return timestamp / 1e3;
|
|
3441
|
+
}
|
|
3442
|
+
throw new this.AbortError("解析服务器时间失败!");
|
|
3443
|
+
};
|
|
3444
|
+
return await this.pRetry(run, {
|
|
3445
|
+
onFailedAttempt: (error) => {
|
|
3446
|
+
this.logger.error(`getServerUTCTime() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3447
|
+
},
|
|
3448
|
+
retries: 3
|
|
3449
|
+
});
|
|
3406
3450
|
}
|
|
3407
3451
|
async getTimeNow() {
|
|
3408
|
-
const
|
|
3409
|
-
|
|
3452
|
+
const run = async () => {
|
|
3453
|
+
const { data } = await this.client.get(GET_TIME_NOW);
|
|
3454
|
+
return data;
|
|
3455
|
+
};
|
|
3456
|
+
return await this.pRetry(run, {
|
|
3457
|
+
onFailedAttempt: (error) => {
|
|
3458
|
+
this.logger.error(`getTimeNow() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3459
|
+
},
|
|
3460
|
+
retries: 3
|
|
3461
|
+
});
|
|
3410
3462
|
}
|
|
3411
3463
|
async getAllGroup() {
|
|
3412
|
-
const
|
|
3413
|
-
|
|
3464
|
+
const run = async () => {
|
|
3465
|
+
const { data } = await this.client.get(GET_ALL_GROUP);
|
|
3466
|
+
return data;
|
|
3467
|
+
};
|
|
3468
|
+
return await this.pRetry(run, {
|
|
3469
|
+
onFailedAttempt: (error) => {
|
|
3470
|
+
this.logger.error(`getAllGroup() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3471
|
+
},
|
|
3472
|
+
retries: 3
|
|
3473
|
+
});
|
|
3414
3474
|
}
|
|
3415
3475
|
async removeUserFromGroup(mid) {
|
|
3416
|
-
const
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3476
|
+
const run = async () => {
|
|
3477
|
+
const csrf = this.getCSRF();
|
|
3478
|
+
const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
|
|
3479
|
+
fids: mid,
|
|
3480
|
+
tagids: 0,
|
|
3481
|
+
csrf
|
|
3482
|
+
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
3483
|
+
return data;
|
|
3484
|
+
};
|
|
3485
|
+
return await this.pRetry(run, {
|
|
3486
|
+
onFailedAttempt: (error) => {
|
|
3487
|
+
this.logger.error(`removeUserFromGroup() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3488
|
+
},
|
|
3489
|
+
retries: 3
|
|
3490
|
+
});
|
|
3423
3491
|
}
|
|
3424
3492
|
async copyUserToGroup(mid, groupId) {
|
|
3425
|
-
const
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3493
|
+
const run = async () => {
|
|
3494
|
+
const csrf = this.getCSRF();
|
|
3495
|
+
const { data } = await this.client.post(COPY_USER_TO_GROUP, {
|
|
3496
|
+
fids: mid,
|
|
3497
|
+
tagids: groupId,
|
|
3498
|
+
csrf
|
|
3499
|
+
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
3500
|
+
return data;
|
|
3501
|
+
};
|
|
3502
|
+
return await this.pRetry(run, {
|
|
3503
|
+
onFailedAttempt: (error) => {
|
|
3504
|
+
this.logger.error(`copyUserToGroup() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3505
|
+
},
|
|
3506
|
+
retries: 3
|
|
3507
|
+
});
|
|
3432
3508
|
}
|
|
3433
3509
|
async getUserSpaceDynamic(mid) {
|
|
3434
|
-
const
|
|
3435
|
-
|
|
3510
|
+
const run = async () => {
|
|
3511
|
+
const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}&host_mid=${mid}`);
|
|
3512
|
+
return data;
|
|
3513
|
+
};
|
|
3514
|
+
return await this.pRetry(run, {
|
|
3515
|
+
onFailedAttempt: (error) => {
|
|
3516
|
+
this.logger.error(`getUserSpaceDynamic() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3517
|
+
},
|
|
3518
|
+
retries: 3
|
|
3519
|
+
});
|
|
3436
3520
|
}
|
|
3437
3521
|
async createGroup(tag) {
|
|
3438
|
-
const
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3522
|
+
const run = async () => {
|
|
3523
|
+
const { data } = await this.client.post(CREATE_GROUP, {
|
|
3524
|
+
tag,
|
|
3525
|
+
csrf: this.getCSRF()
|
|
3526
|
+
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
3527
|
+
return data;
|
|
3528
|
+
};
|
|
3529
|
+
return await this.pRetry(run, {
|
|
3530
|
+
onFailedAttempt: (error) => {
|
|
3531
|
+
this.logger.error(`createGroup() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3532
|
+
},
|
|
3533
|
+
retries: 3
|
|
3534
|
+
});
|
|
3443
3535
|
}
|
|
3444
3536
|
async getAllDynamic() {
|
|
3445
|
-
const
|
|
3446
|
-
|
|
3537
|
+
const run = async () => {
|
|
3538
|
+
const { data } = await this.client.get(GET_ALL_DYNAMIC_LIST);
|
|
3539
|
+
return data;
|
|
3540
|
+
};
|
|
3541
|
+
return await this.pRetry(run, {
|
|
3542
|
+
onFailedAttempt: (error) => {
|
|
3543
|
+
this.logger.error(`getAllDynamic() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3544
|
+
},
|
|
3545
|
+
retries: 3
|
|
3546
|
+
});
|
|
3447
3547
|
}
|
|
3448
3548
|
async hasNewDynamic(updateBaseline) {
|
|
3449
|
-
const
|
|
3450
|
-
|
|
3549
|
+
const run = async () => {
|
|
3550
|
+
const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
|
|
3551
|
+
return data;
|
|
3552
|
+
};
|
|
3553
|
+
return await this.pRetry(run, {
|
|
3554
|
+
onFailedAttempt: (error) => {
|
|
3555
|
+
this.logger.error(`hasNewDynamic() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3556
|
+
},
|
|
3557
|
+
retries: 3
|
|
3558
|
+
});
|
|
3451
3559
|
}
|
|
3452
3560
|
async follow(fid) {
|
|
3453
|
-
const
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3561
|
+
const run = async () => {
|
|
3562
|
+
const { data } = await this.client.post(MODIFY_RELATION, {
|
|
3563
|
+
fid,
|
|
3564
|
+
act: 1,
|
|
3565
|
+
re_src: 11,
|
|
3566
|
+
csrf: this.getCSRF()
|
|
3567
|
+
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
3568
|
+
return data;
|
|
3569
|
+
};
|
|
3570
|
+
return await this.pRetry(run, {
|
|
3571
|
+
onFailedAttempt: (error) => {
|
|
3572
|
+
this.logger.error(`follow() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3573
|
+
},
|
|
3574
|
+
retries: 3
|
|
3575
|
+
});
|
|
3460
3576
|
}
|
|
3461
3577
|
async getRelationGroupDetail(tagid) {
|
|
3462
|
-
const
|
|
3463
|
-
|
|
3578
|
+
const run = async () => {
|
|
3579
|
+
const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
|
|
3580
|
+
return data;
|
|
3581
|
+
};
|
|
3582
|
+
return await this.pRetry(run, {
|
|
3583
|
+
onFailedAttempt: (error) => {
|
|
3584
|
+
this.logger.error(`getRelationGroupDetail() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3585
|
+
},
|
|
3586
|
+
retries: 3
|
|
3587
|
+
});
|
|
3464
3588
|
}
|
|
3465
3589
|
async getCookieInfo(refreshToken) {
|
|
3466
|
-
const
|
|
3467
|
-
this.
|
|
3468
|
-
|
|
3590
|
+
const run = async () => {
|
|
3591
|
+
const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e) => {
|
|
3592
|
+
this.logger.info(e.message);
|
|
3593
|
+
return null;
|
|
3594
|
+
});
|
|
3595
|
+
return data;
|
|
3596
|
+
};
|
|
3597
|
+
return await this.pRetry(run, {
|
|
3598
|
+
onFailedAttempt: (error) => {
|
|
3599
|
+
this.logger.error(`getCookieInfo() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3600
|
+
},
|
|
3601
|
+
retries: 3
|
|
3469
3602
|
});
|
|
3470
|
-
return data;
|
|
3471
3603
|
}
|
|
3472
3604
|
async getUserInfo(mid) {
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3605
|
+
const run = async () => {
|
|
3606
|
+
if (mid === "11783021") {
|
|
3607
|
+
console.log("检测到番剧出差UID,跳过远程用户接口访问");
|
|
3608
|
+
return bangumiTripData;
|
|
3609
|
+
}
|
|
3610
|
+
const wbi = await this.getWbi({ mid });
|
|
3611
|
+
const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
|
|
3612
|
+
return data;
|
|
3613
|
+
};
|
|
3614
|
+
return await this.pRetry(run, {
|
|
3615
|
+
onFailedAttempt: (error) => {
|
|
3616
|
+
this.logger.error(`getUserInfo() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3617
|
+
},
|
|
3618
|
+
retries: 3
|
|
3619
|
+
});
|
|
3480
3620
|
}
|
|
3481
3621
|
async getWbiKeys() {
|
|
3482
|
-
const
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3622
|
+
const run = async () => {
|
|
3623
|
+
const { data } = await this.client.get("https://api.bilibili.com/x/web-interface/nav");
|
|
3624
|
+
const { data: { wbi_img: { img_url, sub_url } } } = data;
|
|
3625
|
+
return {
|
|
3626
|
+
img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
|
|
3627
|
+
sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
|
|
3628
|
+
};
|
|
3487
3629
|
};
|
|
3630
|
+
return await this.pRetry(run, {
|
|
3631
|
+
onFailedAttempt: (error) => {
|
|
3632
|
+
this.logger.error(`getWbiKeys() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3633
|
+
},
|
|
3634
|
+
retries: 3
|
|
3635
|
+
});
|
|
3488
3636
|
}
|
|
3489
3637
|
async getMyselfInfo() {
|
|
3490
|
-
const
|
|
3491
|
-
|
|
3638
|
+
const run = async () => {
|
|
3639
|
+
const { data } = await this.client.get(GET_MYSELF_INFO);
|
|
3640
|
+
return data;
|
|
3641
|
+
};
|
|
3642
|
+
return await this.pRetry(run, {
|
|
3643
|
+
onFailedAttempt: (error) => {
|
|
3644
|
+
this.logger.error(`getMyselfInfo() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3645
|
+
},
|
|
3646
|
+
retries: 3
|
|
3647
|
+
});
|
|
3492
3648
|
}
|
|
3493
3649
|
async getLoginQRCode() {
|
|
3494
|
-
const
|
|
3495
|
-
|
|
3650
|
+
const run = async () => {
|
|
3651
|
+
const { data } = await this.client.get(GET_LOGIN_QRCODE);
|
|
3652
|
+
return data;
|
|
3653
|
+
};
|
|
3654
|
+
return await this.pRetry(run, {
|
|
3655
|
+
onFailedAttempt: (error) => {
|
|
3656
|
+
this.logger.error(`getLoginQRCode() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3657
|
+
},
|
|
3658
|
+
retries: 3
|
|
3659
|
+
});
|
|
3496
3660
|
}
|
|
3497
3661
|
async getLoginStatus(qrcodeKey) {
|
|
3498
|
-
const
|
|
3499
|
-
|
|
3662
|
+
const run = async () => {
|
|
3663
|
+
const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
|
|
3664
|
+
return data;
|
|
3665
|
+
};
|
|
3666
|
+
return await this.pRetry(run, {
|
|
3667
|
+
onFailedAttempt: (error) => {
|
|
3668
|
+
this.logger.error(`getLoginStatus() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3669
|
+
},
|
|
3670
|
+
retries: 3
|
|
3671
|
+
});
|
|
3500
3672
|
}
|
|
3501
3673
|
async getLiveRoomInfo(roomId) {
|
|
3502
|
-
const
|
|
3503
|
-
|
|
3674
|
+
const run = async () => {
|
|
3675
|
+
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
|
|
3676
|
+
return data;
|
|
3677
|
+
};
|
|
3678
|
+
return await this.pRetry(run, {
|
|
3679
|
+
onFailedAttempt: (error) => {
|
|
3680
|
+
this.logger.error(`getLiveRoomInfo() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3681
|
+
},
|
|
3682
|
+
retries: 3
|
|
3683
|
+
});
|
|
3504
3684
|
}
|
|
3505
3685
|
async getMasterInfo(mid) {
|
|
3506
|
-
const
|
|
3507
|
-
|
|
3686
|
+
const run = async () => {
|
|
3687
|
+
const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
|
|
3688
|
+
return data;
|
|
3689
|
+
};
|
|
3690
|
+
return await this.pRetry(run, {
|
|
3691
|
+
onFailedAttempt: (error) => {
|
|
3692
|
+
this.logger.error(`getMasterInfo() 第${error.attemptNumber}次失败: ${error.message}`);
|
|
3693
|
+
},
|
|
3694
|
+
retries: 3
|
|
3695
|
+
});
|
|
3508
3696
|
}
|
|
3509
3697
|
disposeNotifier() {
|
|
3510
3698
|
if (this.loginNotifier) this.loginNotifier.dispose();
|
|
@@ -3788,138 +3976,6 @@ var BiliAPI = class extends Service {
|
|
|
3788
3976
|
return { data: data.data };
|
|
3789
3977
|
}
|
|
3790
3978
|
};
|
|
3791
|
-
_decorate([Retry({
|
|
3792
|
-
attempts: 3,
|
|
3793
|
-
onFailure(error, attempts) {
|
|
3794
|
-
this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
|
|
3795
|
-
}
|
|
3796
|
-
})], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
|
|
3797
|
-
_decorate([Retry({
|
|
3798
|
-
attempts: 3,
|
|
3799
|
-
onFailure(error, attempts) {
|
|
3800
|
-
this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
|
|
3801
|
-
}
|
|
3802
|
-
})], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
|
|
3803
|
-
_decorate([Retry({
|
|
3804
|
-
attempts: 3,
|
|
3805
|
-
onFailure(error, attempts) {
|
|
3806
|
-
this.logger.error(`getLiveRoomInfoByUids() 第${attempts}次失败: ${error.message}`);
|
|
3807
|
-
}
|
|
3808
|
-
})], BiliAPI.prototype, "getLiveRoomInfoByUids", null);
|
|
3809
|
-
_decorate([Retry({
|
|
3810
|
-
attempts: 3,
|
|
3811
|
-
onFailure(error, attempts) {
|
|
3812
|
-
this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
|
|
3813
|
-
}
|
|
3814
|
-
})], BiliAPI.prototype, "getServerUTCTime", null);
|
|
3815
|
-
_decorate([Retry({
|
|
3816
|
-
attempts: 3,
|
|
3817
|
-
onFailure(error, attempts) {
|
|
3818
|
-
this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
|
|
3819
|
-
}
|
|
3820
|
-
})], BiliAPI.prototype, "getTimeNow", null);
|
|
3821
|
-
_decorate([Retry({
|
|
3822
|
-
attempts: 3,
|
|
3823
|
-
onFailure(error, attempts) {
|
|
3824
|
-
this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
|
|
3825
|
-
}
|
|
3826
|
-
})], BiliAPI.prototype, "getAllGroup", null);
|
|
3827
|
-
_decorate([Retry({
|
|
3828
|
-
attempts: 3,
|
|
3829
|
-
onFailure(error, attempts) {
|
|
3830
|
-
this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
|
|
3831
|
-
}
|
|
3832
|
-
})], BiliAPI.prototype, "removeUserFromGroup", null);
|
|
3833
|
-
_decorate([Retry({
|
|
3834
|
-
attempts: 3,
|
|
3835
|
-
onFailure(error, attempts) {
|
|
3836
|
-
this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
|
|
3837
|
-
}
|
|
3838
|
-
})], BiliAPI.prototype, "copyUserToGroup", null);
|
|
3839
|
-
_decorate([Retry({
|
|
3840
|
-
attempts: 3,
|
|
3841
|
-
onFailure(error, attempts) {
|
|
3842
|
-
this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
|
|
3843
|
-
}
|
|
3844
|
-
})], BiliAPI.prototype, "getUserSpaceDynamic", null);
|
|
3845
|
-
_decorate([Retry({
|
|
3846
|
-
attempts: 3,
|
|
3847
|
-
onFailure(error, attempts) {
|
|
3848
|
-
this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
|
|
3849
|
-
}
|
|
3850
|
-
})], BiliAPI.prototype, "createGroup", null);
|
|
3851
|
-
_decorate([Retry({
|
|
3852
|
-
attempts: 3,
|
|
3853
|
-
onFailure(error, attempts) {
|
|
3854
|
-
this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
|
|
3855
|
-
}
|
|
3856
|
-
})], BiliAPI.prototype, "getAllDynamic", null);
|
|
3857
|
-
_decorate([Retry({
|
|
3858
|
-
attempts: 3,
|
|
3859
|
-
onFailure(error, attempts) {
|
|
3860
|
-
this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
|
|
3861
|
-
}
|
|
3862
|
-
})], BiliAPI.prototype, "hasNewDynamic", null);
|
|
3863
|
-
_decorate([Retry({
|
|
3864
|
-
attempts: 3,
|
|
3865
|
-
onFailure(error, attempts) {
|
|
3866
|
-
this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
|
|
3867
|
-
}
|
|
3868
|
-
})], BiliAPI.prototype, "follow", null);
|
|
3869
|
-
_decorate([Retry({
|
|
3870
|
-
attempts: 3,
|
|
3871
|
-
onFailure(error, attempts) {
|
|
3872
|
-
this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
|
|
3873
|
-
}
|
|
3874
|
-
})], BiliAPI.prototype, "getRelationGroupDetail", null);
|
|
3875
|
-
_decorate([Retry({
|
|
3876
|
-
attempts: 3,
|
|
3877
|
-
onFailure(error, attempts) {
|
|
3878
|
-
this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
|
|
3879
|
-
}
|
|
3880
|
-
})], BiliAPI.prototype, "getCookieInfo", null);
|
|
3881
|
-
_decorate([Retry({
|
|
3882
|
-
attempts: 3,
|
|
3883
|
-
onFailure(error, attempts) {
|
|
3884
|
-
this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
|
|
3885
|
-
}
|
|
3886
|
-
})], BiliAPI.prototype, "getUserInfo", null);
|
|
3887
|
-
_decorate([Retry({
|
|
3888
|
-
attempts: 3,
|
|
3889
|
-
onFailure(error, attempts) {
|
|
3890
|
-
this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
|
|
3891
|
-
}
|
|
3892
|
-
})], BiliAPI.prototype, "getWbiKeys", null);
|
|
3893
|
-
_decorate([Retry({
|
|
3894
|
-
attempts: 3,
|
|
3895
|
-
onFailure(error, attempts) {
|
|
3896
|
-
this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
|
|
3897
|
-
}
|
|
3898
|
-
})], BiliAPI.prototype, "getMyselfInfo", null);
|
|
3899
|
-
_decorate([Retry({
|
|
3900
|
-
attempts: 3,
|
|
3901
|
-
onFailure(error, attempts) {
|
|
3902
|
-
this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
|
|
3903
|
-
}
|
|
3904
|
-
})], BiliAPI.prototype, "getLoginQRCode", null);
|
|
3905
|
-
_decorate([Retry({
|
|
3906
|
-
attempts: 3,
|
|
3907
|
-
onFailure(error, attempts) {
|
|
3908
|
-
this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
|
|
3909
|
-
}
|
|
3910
|
-
})], BiliAPI.prototype, "getLoginStatus", null);
|
|
3911
|
-
_decorate([Retry({
|
|
3912
|
-
attempts: 3,
|
|
3913
|
-
onFailure(error, attempts) {
|
|
3914
|
-
this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
|
|
3915
|
-
}
|
|
3916
|
-
})], BiliAPI.prototype, "getLiveRoomInfo", null);
|
|
3917
|
-
_decorate([Retry({
|
|
3918
|
-
attempts: 3,
|
|
3919
|
-
onFailure(error, attempts) {
|
|
3920
|
-
this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
|
|
3921
|
-
}
|
|
3922
|
-
})], BiliAPI.prototype, "getMasterInfo", null);
|
|
3923
3979
|
(function(_BiliAPI) {
|
|
3924
3980
|
const Config$1 = _BiliAPI.Config = Schema.object({
|
|
3925
3981
|
userAgent: Schema.string(),
|
|
@@ -3931,17 +3987,17 @@ var bili_api_default = BiliAPI;
|
|
|
3931
3987
|
//#endregion
|
|
3932
3988
|
//#region src/bili_live.ts
|
|
3933
3989
|
var BLive = class extends Service {
|
|
3934
|
-
static inject = ["
|
|
3990
|
+
static inject = ["bilibili-notify-api"];
|
|
3935
3991
|
listenerRecord = {};
|
|
3936
3992
|
constructor(ctx) {
|
|
3937
|
-
super(ctx, "
|
|
3993
|
+
super(ctx, "bilibili-notify-live");
|
|
3938
3994
|
}
|
|
3939
3995
|
stop() {
|
|
3940
3996
|
for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
|
|
3941
3997
|
}
|
|
3942
3998
|
async startLiveRoomListener(roomId, handler) {
|
|
3943
|
-
const cookiesStr = await this.ctx.
|
|
3944
|
-
const mySelfInfo = await this.ctx.
|
|
3999
|
+
const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
|
|
4000
|
+
const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
|
|
3945
4001
|
this.listenerRecord[roomId] = startListen(Number.parseInt(roomId), handler, { ws: {
|
|
3946
4002
|
headers: { Cookie: cookiesStr },
|
|
3947
4003
|
uid: mySelfInfo.data.mid
|
|
@@ -3977,8 +4033,8 @@ let globalConfig;
|
|
|
3977
4033
|
var ServerManager = class extends Service {
|
|
3978
4034
|
servers = [];
|
|
3979
4035
|
constructor(ctx) {
|
|
3980
|
-
super(ctx, "
|
|
3981
|
-
const sysCom = ctx.command("bn", "
|
|
4036
|
+
super(ctx, "bilibili-notify");
|
|
4037
|
+
const sysCom = ctx.command("bn", "bilibili-notify 插件运行相关指令", { permissions: ["authority:5"] });
|
|
3982
4038
|
sysCom.subcommand(".restart", "重启插件").usage("重启插件").example("bn restart").action(async () => {
|
|
3983
4039
|
this.logger.info("调用 bn restart 指令");
|
|
3984
4040
|
if (await this.restartPlugin()) return "插件重启成功";
|
|
@@ -4021,7 +4077,7 @@ var ServerManager = class extends Service {
|
|
|
4021
4077
|
advancedSub: globalConfig.advancedSub,
|
|
4022
4078
|
subs: globalConfig.subs,
|
|
4023
4079
|
master: globalConfig.master,
|
|
4024
|
-
|
|
4080
|
+
wordcloudStopWords: globalConfig.wordcloudStopWords,
|
|
4025
4081
|
liveSummary: globalConfig.liveSummary,
|
|
4026
4082
|
liveDetectType: globalConfig.liveDetectType,
|
|
4027
4083
|
restartPush: globalConfig.restartPush,
|