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.js CHANGED
@@ -46,7 +46,6 @@ const node_https = __toESM(require("node:https"));
46
46
  const axios = __toESM(require("axios"));
47
47
  const tough_cookie = __toESM(require("tough-cookie"));
48
48
  const jsdom = __toESM(require("jsdom"));
49
- const __oxc_project_runtime_helpers_decorate = __toESM(require("@oxc-project/runtime/helpers/decorate"));
50
49
  const __akokko_blive_message_listener = __toESM(require("@akokko/blive-message-listener"));
51
50
 
52
51
  //#region src/config.ts
@@ -81,6 +80,7 @@ const BAConfigSchema = koishi.Schema.object({
81
80
  live: koishi.Schema.boolean().default(true).description("直播"),
82
81
  liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
83
82
  liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
83
+ wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
84
84
  platform: koishi.Schema.string().required().description("平台名"),
85
85
  target: koishi.Schema.string().required().description("群号/频道号")
86
86
  })).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
@@ -91,8 +91,19 @@ const BAConfigSchema = koishi.Schema.object({
91
91
  pushImgsInDynamic: koishi.Schema.boolean().default(false).description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,该功能容易导致QQ风控"),
92
92
  live: koishi.Schema.object({}).description("直播推送设置"),
93
93
  liveDetectType: koishi.Schema.union([koishi.Schema.const("WS").description("使用WebSocket连接到B站消息服务器进行直播检测,推荐使用"), koishi.Schema.const("API").description("通过轮询API发送请求监测直播状态,此模式理论可无限订阅,但容易产生其他问题,功能没有WS模式全面").experimental()]).role("radio").default("WS").description("直播检测方式,WS为连接到B站消息服务器,API为通过轮询发送请求监测,默认使用WS检测"),
94
- wordcloud: koishi.Schema.boolean().default(false).description("直播结束后,是否生成本场直播弹幕词云").experimental(),
95
- liveSummary: koishi.Schema.string().default("🔍【弹幕情报站】本场直播数据如下:\\n🧍‍♂️ 总共 -dmc 位-mdn上线\\n💬 共计 -dca 条弹幕飞驰而过\\n📊 热词云图已生成,快来看看你有没有上榜!\\n\\n👑 本场顶级输出选手:\\n🥇 -un1 - 弹幕输出 -dc1 条\\n🥈 -un2 - 弹幕 -dc2 条,萌力惊人\\n🥉 -un3 - -dc3 条精准狙击\\n\\n🎖️ 特别嘉奖:-un4 & -un5\\n你们的弹幕,我们都记录在案!🕵️‍♀️").description("自定义直播总结语,开启弹幕词云自动发送。变量解释:-dmc代表总弹幕发送人数,-mdn代表主播粉丝牌子名,-dca代表总弹幕数,-un1到-un5代表弹幕发送条数前五名用户的用户名,-dc1到-dc5代表弹幕发送条数前五名的弹幕发送数量"),
94
+ wordcloudStopWords: koishi.Schema.string().description("词云生成时的停用词,多个停用词请使用英文逗号分隔,例如:哔哩哔哩,弹幕,直播,词云").experimental(),
95
+ liveSummary: koishi.Schema.array(String).default([
96
+ "🔍【弹幕情报站】本场直播数据如下:",
97
+ "🧍‍♂️ 总共 -dmc 位-mdn上线",
98
+ "💬 共计 -dca 条弹幕飞驰而过",
99
+ "📊 热词云图已生成,快来看看你有没有上榜!",
100
+ "👑 本场顶级输出选手:",
101
+ "🥇 -un1 - 弹幕输出 -dc1 条",
102
+ "🥈 -un2 - 弹幕 -dc2 条,萌力惊人",
103
+ "🥉 -un3 - -dc3 条精准狙击",
104
+ "🎖️ 特别嘉奖:-un4 & -un5",
105
+ "你们的弹幕,我们都记录在案!🕵️‍♀️"
106
+ ]).role("table").description("自定义直播总结语,开启弹幕词云自动发送。变量解释:-dmc代表总弹幕发送人数,-mdn代表主播粉丝牌子名,-dca代表总弹幕数,-un1到-un5代表弹幕发送条数前五名用户的用户名,-dc1到-dc5代表弹幕发送条数前五名的弹幕发送数量,数组每一行代表换行"),
96
107
  restartPush: koishi.Schema.boolean().default(true).description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
97
108
  pushTime: koishi.Schema.number().min(0).max(12).step(.5).default(1).description("设定间隔多长时间推送一次直播状态,单位为小时,默认为一小时"),
98
109
  customLiveStart: koishi.Schema.string().default("-name开播啦,当前粉丝数:-follower\\n-link").description("自定义开播提示语,-name代表UP昵称,-follower代表当前粉丝数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用),\\n为换行。例如-name开播啦,会发送为xxxUP开播啦"),
@@ -122,22 +133,6 @@ const BAConfigSchema = koishi.Schema.object({
122
133
 
123
134
  //#endregion
124
135
  //#region src/utils/index.ts
125
- function Retry(options = { attempts: 3 }) {
126
- return (_target, _propertyKey, descriptor) => {
127
- const originalMethod = descriptor.value;
128
- descriptor.value = async function(...args) {
129
- let lastError;
130
- for (let i = 0; i < options.attempts; i++) try {
131
- return await originalMethod.apply(this, args);
132
- } catch (error) {
133
- lastError = error;
134
- if (options.onFailure) await options.onFailure.call(this, lastError, i + 1);
135
- }
136
- throw lastError;
137
- };
138
- return descriptor;
139
- };
140
- }
141
136
  /**
142
137
  * 高阶函数:为函数添加锁机制
143
138
  * @param {Function} fn - 需要包装的原始函数
@@ -196,6 +191,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
196
191
  PushType$1[PushType$1["DynamicAtAll"] = 2] = "DynamicAtAll";
197
192
  PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
198
193
  PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
194
+ PushType$1[PushType$1["WordCloud"] = 5] = "WordCloud";
199
195
  return PushType$1;
200
196
  }({});
201
197
  const PushTypeMsg = {
@@ -203,7 +199,8 @@ const PushTypeMsg = {
203
199
  [PushType.Dynamic]: "动态推送",
204
200
  [PushType.DynamicAtAll]: "动态推送+At全体",
205
201
  [PushType.StartBroadcasting]: "开播推送",
206
- [PushType.LiveGuardBuy]: "上舰推送"
202
+ [PushType.LiveGuardBuy]: "上舰推送",
203
+ [PushType.WordCloud]: "弹幕词云推送"
207
204
  };
208
205
 
209
206
  //#endregion
@@ -340,16 +337,17 @@ const stopwords = new Set([
340
337
  "之前",
341
338
  "某天"
342
339
  ]);
340
+ var stop_words_default = stopwords;
343
341
 
344
342
  //#endregion
345
343
  //#region src/command_register.tsx
346
344
  var ComRegister = class {
347
345
  static inject = [
348
- "ba",
349
- "gi",
350
- "database",
351
- "bl",
352
- "sm"
346
+ "bilibili-notify",
347
+ "bilibili-notify-api",
348
+ "bilibili-notify-live",
349
+ "bilibili-notify-generate-img",
350
+ "database"
353
351
  ];
354
352
  qqRelatedBotList = [
355
353
  "qq",
@@ -375,6 +373,7 @@ var ComRegister = class {
375
373
  dynamicJob;
376
374
  liveJob;
377
375
  _jieba = __node_rs_jieba.Jieba.withDict(__node_rs_jieba_dict.dict);
376
+ stopwords;
378
377
  constructor(ctx, config) {
379
378
  this.ctx = ctx;
380
379
  this.init(config);
@@ -405,7 +404,7 @@ var ComRegister = class {
405
404
  this.logger.info("调用bili login指令");
406
405
  let content;
407
406
  try {
408
- content = await ctx.ba.getLoginQRCode();
407
+ content = await ctx["bilibili-notify-api"].getLoginQRCode();
409
408
  } catch (_) {
410
409
  return "bili login getLoginQRCode() 本次网络请求失败";
411
410
  }
@@ -430,7 +429,7 @@ var ComRegister = class {
430
429
  flag = false;
431
430
  let loginContent;
432
431
  try {
433
- loginContent = await ctx.ba.getLoginStatus(content.data.qrcode_key);
432
+ loginContent = await ctx["bilibili-notify-api"].getLoginStatus(content.data.qrcode_key);
434
433
  } catch (e) {
435
434
  this.logger.error(e);
436
435
  return;
@@ -444,24 +443,19 @@ var ComRegister = class {
444
443
  return await session.send("二维码已失效,请重新登录");
445
444
  }
446
445
  if (loginContent.data.code === 0) {
447
- const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
448
- const encryptedRefreshToken = ctx.ba.encrypt(loginContent.data.refresh_token);
446
+ const encryptedCookies = ctx["bilibili-notify-api"].encrypt(ctx["bilibili-notify-api"].getCookies());
447
+ const encryptedRefreshToken = ctx["bilibili-notify-api"].encrypt(loginContent.data.refresh_token);
449
448
  await ctx.database.upsert("loginBili", [{
450
449
  id: 1,
451
450
  bili_cookies: encryptedCookies,
452
451
  bili_refresh_token: encryptedRefreshToken
453
452
  }]);
454
453
  this.loginDBData = (await this.ctx.database.get("loginBili", 1))[0];
455
- await this.ctx.ba.loadCookiesFromDatabase();
454
+ await this.ctx["bilibili-notify-api"].loadCookiesFromDatabase();
456
455
  await this.checkIfLoginInfoIsLoaded();
457
456
  this.loginTimer();
458
- const subs = this.configSubsToSubscription(config.subs);
459
- const { code, msg } = await this.loadSubFromConfig(subs);
460
- if (code !== 0) this.logger.error(msg);
461
- ctx.ba.disposeNotifier();
462
- await session.send("登录成功");
463
- await session.execute("bili list");
464
- ctx.ba.enableRefreshCookiesDetect();
457
+ ctx["bilibili-notify-api"].disposeNotifier();
458
+ await session.send("登录成功,请重启插件");
465
459
  }
466
460
  } finally {
467
461
  flag = true;
@@ -477,7 +471,7 @@ var ComRegister = class {
477
471
  await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
478
472
  });
479
473
  biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
480
- const { data: { live_users } } = await ctx.ba.getTheUserWhoIsLiveStreaming();
474
+ const { data: { live_users } } = await ctx["bilibili-notify-api"].getTheUserWhoIsLiveStreaming();
481
475
  const subLiveUsers = [];
482
476
  for (const sub of this.subManager) {
483
477
  let onLive = false;
@@ -499,10 +493,10 @@ var ComRegister = class {
499
493
  });
500
494
  biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
501
495
  const i = index && index - 1 || 0;
502
- const content = await this.ctx.ba.getUserSpaceDynamic(uid);
496
+ const content = await this.ctx["bilibili-notify-api"].getUserSpaceDynamic(uid);
503
497
  const item = content.data.items[i];
504
498
  const buffer = await withRetry(async () => {
505
- return await this.ctx.gi.generateDynamicImg(item);
499
+ return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item);
506
500
  }, 1).catch(async (e) => {
507
501
  if (e.message === "直播开播动态,不做处理") {
508
502
  await session.send("直播开播动态,不做处理");
@@ -617,7 +611,7 @@ var ComRegister = class {
617
611
  ["初中", 4],
618
612
  ["毕业", 4]
619
613
  ];
620
- await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx.gi.generateWordCloudImg(words, "词云测试"), "image/jpg") }));
614
+ await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(words, "词云测试"), "image/jpg") }));
621
615
  const top5DanmakuMaker = [
622
616
  ["张三", 60],
623
617
  ["李四", 48],
@@ -625,46 +619,34 @@ var ComRegister = class {
625
619
  ["赵六", 27],
626
620
  ["田七", 25]
627
621
  ];
628
- const danmakerRankMsg = this.config.liveSummary.replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
622
+ const danmakerRankMsg = this.config.liveSummary.join("\n").replace("-dmc", "114").replace("-mdn", "特工").replace("-dca", "514").replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
629
623
  await session.send(danmakerRankMsg);
630
624
  });
631
625
  biliCom.subcommand(".cap").action(async ({ session }) => {
632
626
  const { code: userInfoCode, data: userInfoData } = await withRetry(async () => {
633
- const data$1 = await this.ctx.ba.getUserInfo("114514");
627
+ const data$1 = await this.ctx["bilibili-notify-api"].getUserInfo("114514");
634
628
  return {
635
629
  code: 0,
636
630
  data: data$1
637
631
  };
638
632
  }).then((content) => content.data);
639
633
  if (userInfoCode !== -352 || !userInfoData.v_voucher) return "不满足验证条件,不需要执行该命令,如果提示风控可以尝试重启插件";
640
- const { data } = await ctx.ba.v_voucherCaptcha(userInfoData.v_voucher);
634
+ const { data } = await ctx["bilibili-notify-api"].v_voucherCaptcha(userInfoData.v_voucher);
641
635
  if (!data.geetest) return "当前风控无法通过该验证解除,或许考虑人工申诉?";
642
636
  await session.send("请到该网站进行验证操作:https://kuresaru.github.io/geetest-validator/");
643
637
  await session.send("请手动填入 gt 和 challenge 后点击生成进行验证,验证完成后点击结果,根据提示输入对应validate");
644
638
  await session.send(`gt:${data.geetest.gt}`);
645
639
  await session.send(`challenge:${data.geetest.challenge}`);
646
- await session.send("请输入validate,格式为 val <validate>");
647
- const validate = await (async () => {
648
- while (true) {
649
- const validate$1 = await session.prompt();
650
- if (validate$1?.startsWith("val ")) return validate$1.slice(4);
651
- else await session.send("请输入正确的validate,格式为 val <validate>");
652
- }
653
- })();
640
+ await session.send("请直接输入validate");
641
+ const validate = await session.prompt();
654
642
  const seccode = `${validate}|jordan`;
655
- const { data: validateCaptchaData } = await ctx.ba.validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
643
+ const { data: validateCaptchaData } = await ctx["bilibili-notify-api"].validateCaptcha(data.geetest.challenge, data.token, validate, seccode);
656
644
  if (validateCaptchaData?.is_valid !== 1) return "验证不成功!";
657
- ctx.ba.addCookie(`x-bili-gaia-vtoken=${validateCaptchaData.grisk_id}`);
658
- const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
659
- await ctx.database.upsert("loginBili", [{
660
- id: 1,
661
- bili_cookies: encryptedCookies
662
- }]);
663
645
  return "验证成功!请重启插件";
664
646
  });
665
647
  }
666
648
  async init(config) {
667
- this.logger = this.ctx.logger("cr");
649
+ this.logger = this.ctx.logger("bilibili-notify-core");
668
650
  this.logger.info("初始化插件中...");
669
651
  this.config = config;
670
652
  this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
@@ -675,6 +657,7 @@ var ComRegister = class {
675
657
  this.logger.info("账号未登录,请登录");
676
658
  return;
677
659
  }
660
+ this.mergeStopWords(config.wordcloudStopWords);
678
661
  if (config.advancedSub) {
679
662
  this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
680
663
  await this.initAsyncPart(subs);
@@ -704,6 +687,14 @@ var ComRegister = class {
704
687
  this.updateSubNotifier();
705
688
  this.logger.info("插件初始化完毕!");
706
689
  }
690
+ mergeStopWords(stopWordsStr) {
691
+ if (!stopWordsStr || stopWordsStr.trim() === "") {
692
+ this.stopwords = new Set(stop_words_default);
693
+ return;
694
+ }
695
+ const additionalStopWords = stopWordsStr.split(",").map((word) => word.trim()).filter((word) => word !== "");
696
+ this.stopwords = new Set([...stop_words_default, ...additionalStopWords]);
697
+ }
707
698
  initManager() {
708
699
  for (const sub of this.subManager) {
709
700
  if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(luxon.DateTime.now().toSeconds()));
@@ -729,6 +720,7 @@ var ComRegister = class {
729
720
  live: s.live,
730
721
  liveAtAll: s.liveAtAll,
731
722
  liveGuardBuy: s.liveGuardBuy,
723
+ wordcloud: s.wordcloud,
732
724
  bot: null
733
725
  }));
734
726
  const target = [{
@@ -739,9 +731,11 @@ var ComRegister = class {
739
731
  uid: s.uid,
740
732
  dynamic: s.dynamic,
741
733
  live: s.live,
734
+ wordcloud: s.wordcloud,
742
735
  target,
743
736
  card: { enable: false },
744
- liveMsg: { enable: false }
737
+ liveMsg: { enable: false },
738
+ liveSummary: { enable: false }
745
739
  };
746
740
  });
747
741
  return subs;
@@ -758,23 +752,23 @@ var ComRegister = class {
758
752
  if (this.rebootCount >= 3) {
759
753
  this.logger.error("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
760
754
  await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 bn start 启动插件");
761
- await this.ctx.sm.disposePlugin();
755
+ await this.ctx["bilibili-notify"].disposePlugin();
762
756
  return;
763
757
  }
764
758
  this.rebootCount++;
765
759
  this.logger.info("插件出现未知错误,正在重启插件");
766
- const flag = await this.ctx.sm.restartPlugin();
760
+ const flag = await this.ctx["bilibili-notify"].restartPlugin();
767
761
  if (flag) this.logger.info("重启插件成功");
768
762
  else {
769
763
  this.logger.error("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
770
764
  await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 bn start 启动插件");
771
- await this.ctx.sm.disposePlugin();
765
+ await this.ctx["bilibili-notify"].disposePlugin();
772
766
  }
773
767
  }
774
768
  async sendPrivateMsgAndStopService() {
775
769
  await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
776
770
  this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 bn start 启动插件");
777
- await this.ctx.sm.disposePlugin();
771
+ await this.ctx["bilibili-notify"].disposePlugin();
778
772
  return;
779
773
  }
780
774
  async sendMessageWithRetry(bot, channelId, content) {
@@ -794,19 +788,22 @@ var ComRegister = class {
794
788
  const liveMsg = {
795
789
  customLiveStart: this.config.customLiveStart || "",
796
790
  customLive: this.config.customLive || "",
797
- customLiveEnd: this.config.customLiveEnd || ""
791
+ customLiveEnd: this.config.customLiveEnd || "",
792
+ liveSummary: this.config.liveSummary.join("\n") || ""
798
793
  };
799
794
  if (sub.liveMsg.enable) {
800
795
  liveMsg.customLiveStart = sub.liveMsg.customLiveStart || this.config.customLiveStart;
801
796
  liveMsg.customLive = sub.liveMsg.customLive || this.config.customLive;
802
797
  liveMsg.customLiveEnd = sub.liveMsg.customLiveEnd || this.config.customLiveEnd;
803
798
  }
799
+ if (sub.liveSummary.enable) liveMsg.liveSummary = sub.liveSummary.liveSummary || this.config.liveSummary.join("\n");
804
800
  this.liveMsgManager.set(sub.uid, liveMsg);
805
801
  const dynamicArr = [];
806
802
  const dynamicAtAllArr = [];
807
803
  const liveArr = [];
808
804
  const liveAtAllArr = [];
809
805
  const liveGuardBuyArr = [];
806
+ const wordcloudArr = [];
810
807
  for (const platform of sub.target) for (const channel of platform.channelArr) {
811
808
  const target = `${platform.platform}:${channel.channelId}`;
812
809
  if (channel.dynamic) dynamicArr.push(target);
@@ -814,13 +811,15 @@ var ComRegister = class {
814
811
  if (channel.live) liveArr.push(target);
815
812
  if (channel.liveAtAll) liveAtAllArr.push(target);
816
813
  if (channel.liveGuardBuy) liveGuardBuyArr.push(target);
814
+ if (channel.wordcloud) wordcloudArr.push(target);
817
815
  }
818
816
  this.pushArrMap.set(sub.uid, {
819
817
  dynamicArr,
820
818
  dynamicAtAllArr,
821
819
  liveArr,
822
820
  liveAtAllArr,
823
- liveGuardBuyArr
821
+ liveGuardBuyArr,
822
+ wordcloudArr
824
823
  });
825
824
  }
826
825
  this.logger.info("初始化推送群组/频道信息:");
@@ -880,13 +879,21 @@ var ComRegister = class {
880
879
  }, 1);
881
880
  this.logger.info(`成功推送上舰消息:${success.length}条`);
882
881
  }
882
+ if (type === PushType.WordCloud && record.wordcloudArr?.length >= 1) {
883
+ this.logger.info(record.wordcloudArr);
884
+ const wordcloudArr = structuredClone(record.wordcloudArr);
885
+ const success = await withRetry(async () => {
886
+ return await this.ctx.broadcast(wordcloudArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
887
+ }, 1);
888
+ this.logger.info(`成功推送词云消息:${success.length}条`);
889
+ }
883
890
  return;
884
891
  }
885
892
  dynamicDetect() {
886
893
  const handler = async () => {
887
894
  const currentPushDyn = {};
888
895
  const content = await withRetry(async () => {
889
- return await this.ctx.ba.getAllDynamic();
896
+ return await this.ctx["bilibili-notify-api"].getAllDynamic();
890
897
  }, 1).catch((e) => {
891
898
  this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
892
899
  });
@@ -895,13 +902,13 @@ var ComRegister = class {
895
902
  case -101: {
896
903
  this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
897
904
  await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
898
- await this.ctx.sm.disposePlugin();
905
+ await this.ctx["bilibili-notify"].disposePlugin();
899
906
  break;
900
907
  }
901
908
  case -352: {
902
909
  this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
903
910
  await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
904
- await this.ctx.sm.disposePlugin();
911
+ await this.ctx["bilibili-notify"].disposePlugin();
905
912
  break;
906
913
  }
907
914
  case 4101128:
@@ -926,7 +933,7 @@ var ComRegister = class {
926
933
  if (timeline < postTime) {
927
934
  const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
928
935
  const buffer = await withRetry(async () => {
929
- return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
936
+ return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
930
937
  }, 1).catch(async (e) => {
931
938
  if (e.message === "直播开播动态,不做处理") return;
932
939
  if (e.message === "出现关键词,屏蔽该动态") {
@@ -985,7 +992,7 @@ var ComRegister = class {
985
992
  const currentPushDyn = {};
986
993
  this.logger.info("开始获取动态信息...");
987
994
  const content = await withRetry(async () => {
988
- return await this.ctx.ba.getAllDynamic();
995
+ return await this.ctx["bilibili-notify-api"].getAllDynamic();
989
996
  }, 1).catch((e) => {
990
997
  this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
991
998
  });
@@ -994,13 +1001,13 @@ var ComRegister = class {
994
1001
  case -101: {
995
1002
  this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
996
1003
  await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 bn start 启动插件");
997
- await this.ctx.sm.disposePlugin();
1004
+ await this.ctx["bilibili-notify"].disposePlugin();
998
1005
  break;
999
1006
  }
1000
1007
  case -352: {
1001
1008
  this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
1002
1009
  await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 bn start 启动插件");
1003
- await this.ctx.sm.disposePlugin();
1010
+ await this.ctx["bilibili-notify"].disposePlugin();
1004
1011
  break;
1005
1012
  }
1006
1013
  case 4101128:
@@ -1031,7 +1038,7 @@ var ComRegister = class {
1031
1038
  const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1032
1039
  this.logger.info("开始渲染推送卡片...");
1033
1040
  const buffer = await withRetry(async () => {
1034
- return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
1041
+ return await this.ctx["bilibili-notify-generate-img"].generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
1035
1042
  }, 1).catch(async (e) => {
1036
1043
  if (e.message === "直播开播动态,不做处理") return;
1037
1044
  if (e.message === "出现关键词,屏蔽该动态") {
@@ -1096,7 +1103,7 @@ var ComRegister = class {
1096
1103
  return withLock(handler);
1097
1104
  }
1098
1105
  async useMasterInfo(uid, masterInfo, liveType) {
1099
- const { data } = await this.ctx.ba.getMasterInfo(uid);
1106
+ const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
1100
1107
  let liveOpenFollowerNum;
1101
1108
  let liveEndFollowerNum;
1102
1109
  let liveFollowerChange;
@@ -1121,7 +1128,7 @@ var ComRegister = class {
1121
1128
  };
1122
1129
  }
1123
1130
  async useLiveRoomInfo(roomId) {
1124
- const data = await withRetry(async () => await this.ctx.ba.getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
1131
+ const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
1125
1132
  this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1126
1133
  return false;
1127
1134
  });
@@ -1130,7 +1137,7 @@ var ComRegister = class {
1130
1137
  }
1131
1138
  async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, uid, liveNotifyMsg) {
1132
1139
  const buffer = await withRetry(async () => {
1133
- return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1140
+ return await this.ctx["bilibili-notify-generate-img"].generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
1134
1141
  }, 1).catch((e) => {
1135
1142
  this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
1136
1143
  });
@@ -1139,14 +1146,14 @@ var ComRegister = class {
1139
1146
  return await this.broadcastToTargets(uid, msg, liveType === LiveType.StartBroadcasting ? PushType.StartBroadcasting : PushType.Live);
1140
1147
  }
1141
1148
  async segmentDanmaku(danmaku, danmakuWeightRecord) {
1142
- this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !stopwords.has(word)).map((w) => {
1149
+ this._jieba.cut(danmaku, true).filter((word) => word.length >= 2 && !this.stopwords.has(word)).map((w) => {
1143
1150
  danmakuWeightRecord[w] = (danmakuWeightRecord[w] || 0) + 1;
1144
1151
  });
1145
1152
  }
1146
1153
  addUserToDanmakuMaker(username, danmakuMakerRecord) {
1147
1154
  danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
1148
1155
  }
1149
- async liveDetectWithListener(roomId, uid, cardStyle) {
1156
+ async liveDetectWithListener(roomId, sub) {
1150
1157
  let liveTime;
1151
1158
  let pushAtTimeTimer;
1152
1159
  const danmakuWeightRecord = {};
@@ -1155,24 +1162,24 @@ var ComRegister = class {
1155
1162
  let liveRoomInfo;
1156
1163
  let masterInfo;
1157
1164
  let watchedNum;
1158
- const liveMsgObj = this.liveMsgManager.get(uid);
1159
- const sendDanmakuWordCloud = async () => {
1165
+ const liveMsgObj = this.liveMsgManager.get(sub.uid);
1166
+ const sendDanmakuWordCloud = async (liveSummary) => {
1160
1167
  this.logger.info("开始制作弹幕词云");
1161
1168
  this.logger.info("正在获取前90热词");
1162
1169
  const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
1163
1170
  this.logger.info("弹幕词云前90词及权重:");
1164
1171
  this.logger.info(top90Words);
1165
1172
  this.logger.info("正在准备生成弹幕词云");
1166
- const buffer = await this.ctx.gi.generateWordCloudImg(top90Words, masterInfo.username);
1173
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1167
1174
  this.logger.info("弹幕词云生成完成,正在准备发送词云图片");
1168
- await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
1175
+ await this.broadcastToTargets(sub.uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
1169
1176
  this.logger.info("词云图片发送完毕!");
1170
1177
  this.logger.info("开始构建弹幕发送排行榜消息");
1171
1178
  const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1172
1179
  const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1173
1180
  const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1174
- const danmakuMakerMsg = this.config.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");
1175
- await this.broadcastToTargets(uid, danmakuMakerMsg, PushType.Live);
1181
+ const danmakuMakerMsg = liveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
1182
+ await this.broadcastToTargets(sub.uid, danmakuMakerMsg, PushType.WordCloud);
1176
1183
  Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
1177
1184
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
1178
1185
  };
@@ -1189,12 +1196,12 @@ var ComRegister = class {
1189
1196
  }
1190
1197
  liveTime = liveRoomInfo.live_time;
1191
1198
  const watched = watchedNum || "暂未获取到";
1192
- const liveMsg = liveMsgObj?.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-watched", watched).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
1199
+ const liveMsg = liveMsgObj.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-watched", watched).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
1193
1200
  await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
1194
1201
  liveRoomInfo,
1195
1202
  masterInfo,
1196
- cardStyle
1197
- }, uid, liveMsg);
1203
+ cardStyle: sub.card
1204
+ }, sub.uid, liveMsg);
1198
1205
  };
1199
1206
  const useMasterAndLiveRoomInfo = async (liveType) => {
1200
1207
  let flag = true;
@@ -1216,7 +1223,7 @@ var ComRegister = class {
1216
1223
  onError: async () => {
1217
1224
  liveStatus = false;
1218
1225
  pushAtTimeTimer?.();
1219
- this.ctx.bl.closeListener(roomId);
1226
+ this.ctx["bilibili-notify-live"].closeListener(roomId);
1220
1227
  await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
1221
1228
  this.logger.error(`[${roomId}]直播间连接发生错误!`);
1222
1229
  },
@@ -1241,7 +1248,7 @@ var ComRegister = class {
1241
1248
  body.gift_name,
1242
1249
  ")"
1243
1250
  ] });
1244
- this.broadcastToTargets(uid, content, PushType.LiveGuardBuy);
1251
+ this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
1245
1252
  },
1246
1253
  onLiveStart: async () => {
1247
1254
  if (liveStatus) return;
@@ -1253,12 +1260,12 @@ var ComRegister = class {
1253
1260
  }
1254
1261
  liveTime = liveRoomInfo.live_time;
1255
1262
  const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
1256
- const liveStartMsg = liveMsgObj?.customLiveStart.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
1263
+ const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
1257
1264
  await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
1258
1265
  liveRoomInfo,
1259
1266
  masterInfo,
1260
- cardStyle
1261
- }, uid, liveStartMsg);
1267
+ cardStyle: sub.card
1268
+ }, sub.uid, liveStartMsg);
1262
1269
  if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1263
1270
  },
1264
1271
  onLiveEnd: async () => {
@@ -1273,28 +1280,28 @@ var ComRegister = class {
1273
1280
  if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
1274
1281
  return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
1275
1282
  })();
1276
- const liveEndMsg = liveMsgObj?.customLiveEnd.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
1283
+ const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
1277
1284
  await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
1278
1285
  liveRoomInfo,
1279
1286
  masterInfo,
1280
- cardStyle
1281
- }, uid, liveEndMsg);
1287
+ cardStyle: sub.card
1288
+ }, sub.uid, liveEndMsg);
1282
1289
  pushAtTimeTimer();
1283
1290
  pushAtTimeTimer = null;
1284
- if (this.config.wordcloud) await sendDanmakuWordCloud();
1291
+ if (sub.wordcloud) await sendDanmakuWordCloud(liveMsgObj.liveSummary);
1285
1292
  }
1286
1293
  };
1287
- await this.ctx.bl.startLiveRoomListener(roomId, handler);
1294
+ await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
1288
1295
  if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1289
1296
  if (liveRoomInfo.live_status === 1) {
1290
1297
  liveTime = liveRoomInfo.live_time;
1291
1298
  const watched = watchedNum || "暂未获取到";
1292
- const liveMsg = liveMsgObj?.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-watched", watched).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
1299
+ const liveMsg = liveMsgObj.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime)).replace("-watched", watched).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`);
1293
1300
  if (this.config.restartPush) await this.sendLiveNotifyCard(LiveType.LiveBroadcast, watched, {
1294
1301
  liveRoomInfo,
1295
1302
  masterInfo,
1296
- cardStyle
1297
- }, uid, liveMsg);
1303
+ cardStyle: sub.card
1304
+ }, sub.uid, liveMsg);
1298
1305
  if (this.config.pushTime !== 0 && !pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1299
1306
  liveStatus = true;
1300
1307
  }
@@ -1319,7 +1326,7 @@ var ComRegister = class {
1319
1326
  const uids = [];
1320
1327
  for (const [uid] of this.liveStatusManager.entries()) uids.push(uid);
1321
1328
  const useLiveInfo = async () => {
1322
- const { data: data$1 } = await withRetry(async () => await this.ctx.ba.getLiveRoomInfoByUids(uids), 3).catch(async () => {
1329
+ const { data: data$1 } = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfoByUids(uids), 3).catch(async () => {
1323
1330
  return void 0;
1324
1331
  });
1325
1332
  if (!data$1) {
@@ -1341,7 +1348,7 @@ var ComRegister = class {
1341
1348
  liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1342
1349
  liveStatus.liveStartTimeInit = true;
1343
1350
  }
1344
- const liveMsg = liveMsgObj?.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.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}`);
1351
+ const liveMsg = liveMsgObj.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`);
1345
1352
  await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
1346
1353
  liveRoomInfo: liveStatus.liveRoomInfo,
1347
1354
  masterInfo: liveStatus.masterInfo,
@@ -1374,7 +1381,7 @@ var ComRegister = class {
1374
1381
  if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
1375
1382
  return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
1376
1383
  })();
1377
- const liveEndMsg = liveMsgObj?.customLiveEnd.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
1384
+ const liveEndMsg = liveMsgObj.customLiveEnd.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-follower_change", followerChange).replaceAll("\\n", "\n");
1378
1385
  await this.sendLiveNotifyCard(LiveType.StopBroadcast, followerChange, {
1379
1386
  liveRoomInfo: liveStatus.liveRoomInfo,
1380
1387
  masterInfo: liveStatus.masterInfo,
@@ -1393,7 +1400,7 @@ var ComRegister = class {
1393
1400
  liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1394
1401
  liveStatus.liveStartTimeInit = true;
1395
1402
  const follower = liveStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(liveStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : liveStatus.masterInfo.liveOpenFollowerNum.toString();
1396
- const liveStartMsg = liveMsgObj?.customLiveStart.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.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}`);
1403
+ const liveStartMsg = liveMsgObj.customLiveStart.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-follower", follower).replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`);
1397
1404
  await this.sendLiveNotifyCard(LiveType.StartBroadcasting, follower, {
1398
1405
  liveRoomInfo: liveStatus.liveRoomInfo,
1399
1406
  masterInfo: liveStatus.masterInfo,
@@ -1414,7 +1421,7 @@ var ComRegister = class {
1414
1421
  liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1415
1422
  liveStatus.liveStartTimeInit = true;
1416
1423
  }
1417
- const liveMsg = liveMsgObj?.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.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}`);
1424
+ const liveMsg = liveMsgObj.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveStatus.liveStartTime)).replace("-watched", "API模式无法获取").replaceAll("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`);
1418
1425
  await this.sendLiveNotifyCard(LiveType.LiveBroadcast, "API", {
1419
1426
  liveRoomInfo: liveStatus.liveRoomInfo,
1420
1427
  masterInfo: liveStatus.masterInfo,
@@ -1450,7 +1457,7 @@ var ComRegister = class {
1450
1457
  async checkIfLoginInfoIsLoaded() {
1451
1458
  return new Promise((resolve$1) => {
1452
1459
  const check = () => {
1453
- if (!this.ctx.ba.getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
1460
+ if (!this.ctx["bilibili-notify-api"].getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
1454
1461
  else resolve$1("success");
1455
1462
  };
1456
1463
  check();
@@ -1459,9 +1466,9 @@ var ComRegister = class {
1459
1466
  async subUserInBili(mid) {
1460
1467
  const checkGroupIsReady = async () => {
1461
1468
  if (!this.loginDBData?.dynamic_group_id) {
1462
- const createGroupData = await this.ctx.ba.createGroup("订阅");
1469
+ const createGroupData = await this.ctx["bilibili-notify-api"].createGroup("订阅");
1463
1470
  if (createGroupData.code === 22106) {
1464
- const allGroupData = await this.ctx.ba.getAllGroup();
1471
+ const allGroupData = await this.ctx["bilibili-notify-api"].getAllGroup();
1465
1472
  for (const group of allGroupData.data) if (group.name === "订阅") {
1466
1473
  this.loginDBData.dynamic_group_id = group.tagid.toString();
1467
1474
  this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
@@ -1488,7 +1495,7 @@ var ComRegister = class {
1488
1495
  const resp = await checkGroupIsReady();
1489
1496
  if (resp.code !== 0) return resp;
1490
1497
  const getGroupDetailData = async () => {
1491
- const relationGroupDetailData = await this.ctx.ba.getRelationGroupDetail(this.loginDBData.dynamic_group_id);
1498
+ const relationGroupDetailData = await this.ctx["bilibili-notify-api"].getRelationGroupDetail(this.loginDBData.dynamic_group_id);
1492
1499
  if (relationGroupDetailData.code !== 0) {
1493
1500
  if (relationGroupDetailData.code === 22104) {
1494
1501
  this.loginDBData.dynamic_group_id = null;
@@ -1517,7 +1524,7 @@ var ComRegister = class {
1517
1524
  code: 0,
1518
1525
  msg: "订阅对象已存在于分组中"
1519
1526
  };
1520
- const subUserData = await this.ctx.ba.follow(mid);
1527
+ const subUserData = await this.ctx["bilibili-notify-api"].follow(mid);
1521
1528
  const subUserMatchPattern = {
1522
1529
  [-101]: () => {
1523
1530
  return {
@@ -1562,7 +1569,7 @@ var ComRegister = class {
1562
1569
  };
1563
1570
  },
1564
1571
  22014: async () => {
1565
- const copyUserToGroupData = await this.ctx.ba.copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1572
+ const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1566
1573
  if (copyUserToGroupData.code !== 0) return {
1567
1574
  code: copyUserToGroupData.code,
1568
1575
  msg: "添加订阅对象到分组失败,请稍后重试"
@@ -1573,7 +1580,7 @@ var ComRegister = class {
1573
1580
  };
1574
1581
  },
1575
1582
  0: async () => {
1576
- const copyUserToGroupData = await this.ctx.ba.copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1583
+ const copyUserToGroupData = await this.ctx["bilibili-notify-api"].copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1577
1584
  if (copyUserToGroupData.code !== 0) return {
1578
1585
  code: copyUserToGroupData.code,
1579
1586
  msg: "添加订阅对象到分组失败,请稍后重试"
@@ -1591,7 +1598,7 @@ var ComRegister = class {
1591
1598
  for (const sub of Object.values(subs)) {
1592
1599
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1593
1600
  const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1594
- const data = await this.ctx.ba.getUserInfo(sub.uid);
1601
+ const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1595
1602
  return {
1596
1603
  code: 0,
1597
1604
  data
@@ -1620,7 +1627,7 @@ var ComRegister = class {
1620
1627
  sub.live = false;
1621
1628
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1622
1629
  }
1623
- if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.uid, sub.card);
1630
+ if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
1624
1631
  }
1625
1632
  const subInfo = await this.subUserInBili(sub.uid);
1626
1633
  if (subInfo.code !== 0) return subInfo;
@@ -1668,7 +1675,7 @@ var ComRegister = class {
1668
1675
  }
1669
1676
  async checkIfIsLogin() {
1670
1677
  if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
1671
- if (this.ctx.ba.getCookies() !== "[]") return true;
1678
+ if (this.ctx["bilibili-notify-api"].getCookies() !== "[]") return true;
1672
1679
  }
1673
1680
  return false;
1674
1681
  }
@@ -1684,6 +1691,7 @@ var ComRegister = class {
1684
1691
  live: koishi.Schema.boolean().default(true).description("直播"),
1685
1692
  liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
1686
1693
  liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
1694
+ wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
1687
1695
  platform: koishi.Schema.string().required().description("平台名"),
1688
1696
  target: koishi.Schema.string().required().description("群号/频道号")
1689
1697
  })).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
@@ -1694,8 +1702,8 @@ var ComRegister = class {
1694
1702
  masterAccountGuildId: koishi.Schema.string()
1695
1703
  }),
1696
1704
  liveDetectType: koishi.Schema.string(),
1697
- wordcloud: koishi.Schema.boolean(),
1698
- liveSummary: koishi.Schema.string(),
1705
+ wordcloudStopWords: koishi.Schema.string(),
1706
+ liveSummary: koishi.Schema.array(String),
1699
1707
  restartPush: koishi.Schema.boolean().required(),
1700
1708
  pushTime: koishi.Schema.number().required(),
1701
1709
  pushImgsInDynamic: koishi.Schema.boolean().required(),
@@ -1752,10 +1760,10 @@ const DYNAMIC_TYPE_LIVE_RCMD = "DYNAMIC_TYPE_LIVE_RCMD";
1752
1760
  const DYNAMIC_TYPE_UGC_SEASON = "DYNAMIC_TYPE_UGC_SEASON";
1753
1761
  const ADDITIONAL_TYPE_RESERVE = "ADDITIONAL_TYPE_RESERVE";
1754
1762
  var GenerateImg = class extends koishi.Service {
1755
- static inject = ["puppeteer", "ba"];
1763
+ static inject = ["puppeteer"];
1756
1764
  giConfig;
1757
1765
  constructor(ctx, config) {
1758
- super(ctx, "gi");
1766
+ super(ctx, "bilibili-notify-generate-img");
1759
1767
  this.giConfig = config;
1760
1768
  }
1761
1769
  async imgHandler(html) {
@@ -3332,11 +3340,15 @@ var BiliAPI = class extends koishi.Service {
3332
3340
  sub_key: ""
3333
3341
  };
3334
3342
  updateJob;
3343
+ pRetry;
3344
+ AbortError;
3335
3345
  constructor(ctx, config) {
3336
- super(ctx, "ba");
3346
+ super(ctx, "bilibili-notify-api");
3337
3347
  this.apiConfig = config;
3338
3348
  }
3339
3349
  async start() {
3350
+ this.pRetry = (await import("p-retry")).default;
3351
+ this.AbortError = (await import("p-retry")).AbortError;
3340
3352
  const CacheableLookup = (await import("cacheable-lookup")).default;
3341
3353
  this.cacheable = new CacheableLookup();
3342
3354
  this.cacheable.install(node_http.default.globalAgent);
@@ -3401,129 +3413,305 @@ var BiliAPI = class extends koishi.Service {
3401
3413
  return decrypted.toString();
3402
3414
  }
3403
3415
  async getTheUserWhoIsLiveStreaming() {
3404
- const { data } = await this.client.get(GET_LATEST_UPDATED_UPS);
3405
- return data;
3416
+ const run = async () => {
3417
+ const { data } = await this.client.get(GET_LATEST_UPDATED_UPS);
3418
+ return data;
3419
+ };
3420
+ return await this.pRetry(run, {
3421
+ onFailedAttempt: (error) => {
3422
+ this.logger.error(`getTheUserWhoIsLiveStreaming() 第${error.attemptNumber}次失败: ${error.message}`);
3423
+ },
3424
+ retries: 3
3425
+ });
3406
3426
  }
3407
3427
  async getLiveRoomInfoStreamKey(roomId) {
3408
- const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
3409
- return data;
3428
+ const run = async () => {
3429
+ const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
3430
+ return data;
3431
+ };
3432
+ return await this.pRetry(run, {
3433
+ onFailedAttempt: (error) => {
3434
+ this.logger.error(`getLiveRoomInfoStreamKey() 第${error.attemptNumber}次失败: ${error.message}`);
3435
+ },
3436
+ retries: 3
3437
+ });
3410
3438
  }
3411
3439
  async getLiveRoomInfoByUids(uids) {
3412
- const params = uids.map((uid) => `uids[]=${uid}`).join("&");
3413
- const { data } = await this.client.get(`${GET_LIVE_ROOMS_INFO}?${params}`);
3414
- return data;
3440
+ const run = async () => {
3441
+ const params = uids.map((uid) => `uids[]=${uid}`).join("&");
3442
+ const { data } = await this.client.get(`${GET_LIVE_ROOMS_INFO}?${params}`);
3443
+ return data;
3444
+ };
3445
+ return await this.pRetry(run, {
3446
+ onFailedAttempt: (error) => {
3447
+ this.logger.error(`getLiveRoomInfoByUids() 第${error.attemptNumber}次失败: ${error.message}`);
3448
+ },
3449
+ retries: 3
3450
+ });
3415
3451
  }
3416
3452
  async getServerUTCTime() {
3417
- const { data } = await this.client.get(GET_SERVER_UTC_TIME);
3418
- const regex = /Date\.UTC\((.*?)\)/;
3419
- const match = data.match(regex);
3420
- if (match) {
3421
- const timestamp = new Function(`return Date.UTC(${match[1]})`)();
3422
- return timestamp / 1e3;
3423
- }
3424
- throw new Error("解析服务器时间失败!");
3453
+ const run = async () => {
3454
+ const { data } = await this.client.get(GET_SERVER_UTC_TIME);
3455
+ const regex = /Date\.UTC\((.*?)\)/;
3456
+ const match = data.match(regex);
3457
+ if (match) {
3458
+ const timestamp = new Function(`return Date.UTC(${match[1]})`)();
3459
+ return timestamp / 1e3;
3460
+ }
3461
+ throw new this.AbortError("解析服务器时间失败!");
3462
+ };
3463
+ return await this.pRetry(run, {
3464
+ onFailedAttempt: (error) => {
3465
+ this.logger.error(`getServerUTCTime() 第${error.attemptNumber}次失败: ${error.message}`);
3466
+ },
3467
+ retries: 3
3468
+ });
3425
3469
  }
3426
3470
  async getTimeNow() {
3427
- const { data } = await this.client.get(GET_TIME_NOW);
3428
- return data;
3471
+ const run = async () => {
3472
+ const { data } = await this.client.get(GET_TIME_NOW);
3473
+ return data;
3474
+ };
3475
+ return await this.pRetry(run, {
3476
+ onFailedAttempt: (error) => {
3477
+ this.logger.error(`getTimeNow() 第${error.attemptNumber}次失败: ${error.message}`);
3478
+ },
3479
+ retries: 3
3480
+ });
3429
3481
  }
3430
3482
  async getAllGroup() {
3431
- const { data } = await this.client.get(GET_ALL_GROUP);
3432
- return data;
3483
+ const run = async () => {
3484
+ const { data } = await this.client.get(GET_ALL_GROUP);
3485
+ return data;
3486
+ };
3487
+ return await this.pRetry(run, {
3488
+ onFailedAttempt: (error) => {
3489
+ this.logger.error(`getAllGroup() 第${error.attemptNumber}次失败: ${error.message}`);
3490
+ },
3491
+ retries: 3
3492
+ });
3433
3493
  }
3434
3494
  async removeUserFromGroup(mid) {
3435
- const csrf = this.getCSRF();
3436
- const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
3437
- fids: mid,
3438
- tagids: 0,
3439
- csrf
3440
- }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3441
- return data;
3495
+ const run = async () => {
3496
+ const csrf = this.getCSRF();
3497
+ const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
3498
+ fids: mid,
3499
+ tagids: 0,
3500
+ csrf
3501
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3502
+ return data;
3503
+ };
3504
+ return await this.pRetry(run, {
3505
+ onFailedAttempt: (error) => {
3506
+ this.logger.error(`removeUserFromGroup() 第${error.attemptNumber}次失败: ${error.message}`);
3507
+ },
3508
+ retries: 3
3509
+ });
3442
3510
  }
3443
3511
  async copyUserToGroup(mid, groupId) {
3444
- const csrf = this.getCSRF();
3445
- const { data } = await this.client.post(COPY_USER_TO_GROUP, {
3446
- fids: mid,
3447
- tagids: groupId,
3448
- csrf
3449
- }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3450
- return data;
3512
+ const run = async () => {
3513
+ const csrf = this.getCSRF();
3514
+ const { data } = await this.client.post(COPY_USER_TO_GROUP, {
3515
+ fids: mid,
3516
+ tagids: groupId,
3517
+ csrf
3518
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3519
+ return data;
3520
+ };
3521
+ return await this.pRetry(run, {
3522
+ onFailedAttempt: (error) => {
3523
+ this.logger.error(`copyUserToGroup() 第${error.attemptNumber}次失败: ${error.message}`);
3524
+ },
3525
+ retries: 3
3526
+ });
3451
3527
  }
3452
3528
  async getUserSpaceDynamic(mid) {
3453
- const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}&host_mid=${mid}`);
3454
- return data;
3529
+ const run = async () => {
3530
+ const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}&host_mid=${mid}`);
3531
+ return data;
3532
+ };
3533
+ return await this.pRetry(run, {
3534
+ onFailedAttempt: (error) => {
3535
+ this.logger.error(`getUserSpaceDynamic() 第${error.attemptNumber}次失败: ${error.message}`);
3536
+ },
3537
+ retries: 3
3538
+ });
3455
3539
  }
3456
3540
  async createGroup(tag) {
3457
- const { data } = await this.client.post(CREATE_GROUP, {
3458
- tag,
3459
- csrf: this.getCSRF()
3460
- }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3461
- return data;
3541
+ const run = async () => {
3542
+ const { data } = await this.client.post(CREATE_GROUP, {
3543
+ tag,
3544
+ csrf: this.getCSRF()
3545
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3546
+ return data;
3547
+ };
3548
+ return await this.pRetry(run, {
3549
+ onFailedAttempt: (error) => {
3550
+ this.logger.error(`createGroup() 第${error.attemptNumber}次失败: ${error.message}`);
3551
+ },
3552
+ retries: 3
3553
+ });
3462
3554
  }
3463
3555
  async getAllDynamic() {
3464
- const { data } = await this.client.get(GET_ALL_DYNAMIC_LIST);
3465
- return data;
3556
+ const run = async () => {
3557
+ const { data } = await this.client.get(GET_ALL_DYNAMIC_LIST);
3558
+ return data;
3559
+ };
3560
+ return await this.pRetry(run, {
3561
+ onFailedAttempt: (error) => {
3562
+ this.logger.error(`getAllDynamic() 第${error.attemptNumber}次失败: ${error.message}`);
3563
+ },
3564
+ retries: 3
3565
+ });
3466
3566
  }
3467
3567
  async hasNewDynamic(updateBaseline) {
3468
- const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
3469
- return data;
3568
+ const run = async () => {
3569
+ const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
3570
+ return data;
3571
+ };
3572
+ return await this.pRetry(run, {
3573
+ onFailedAttempt: (error) => {
3574
+ this.logger.error(`hasNewDynamic() 第${error.attemptNumber}次失败: ${error.message}`);
3575
+ },
3576
+ retries: 3
3577
+ });
3470
3578
  }
3471
3579
  async follow(fid) {
3472
- const { data } = await this.client.post(MODIFY_RELATION, {
3473
- fid,
3474
- act: 1,
3475
- re_src: 11,
3476
- csrf: this.getCSRF()
3477
- }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3478
- return data;
3580
+ const run = async () => {
3581
+ const { data } = await this.client.post(MODIFY_RELATION, {
3582
+ fid,
3583
+ act: 1,
3584
+ re_src: 11,
3585
+ csrf: this.getCSRF()
3586
+ }, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3587
+ return data;
3588
+ };
3589
+ return await this.pRetry(run, {
3590
+ onFailedAttempt: (error) => {
3591
+ this.logger.error(`follow() 第${error.attemptNumber}次失败: ${error.message}`);
3592
+ },
3593
+ retries: 3
3594
+ });
3479
3595
  }
3480
3596
  async getRelationGroupDetail(tagid) {
3481
- const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
3482
- return data;
3597
+ const run = async () => {
3598
+ const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
3599
+ return data;
3600
+ };
3601
+ return await this.pRetry(run, {
3602
+ onFailedAttempt: (error) => {
3603
+ this.logger.error(`getRelationGroupDetail() 第${error.attemptNumber}次失败: ${error.message}`);
3604
+ },
3605
+ retries: 3
3606
+ });
3483
3607
  }
3484
3608
  async getCookieInfo(refreshToken) {
3485
- const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e) => {
3486
- this.logger.info(e.message);
3487
- return null;
3609
+ const run = async () => {
3610
+ const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e) => {
3611
+ this.logger.info(e.message);
3612
+ return null;
3613
+ });
3614
+ return data;
3615
+ };
3616
+ return await this.pRetry(run, {
3617
+ onFailedAttempt: (error) => {
3618
+ this.logger.error(`getCookieInfo() 第${error.attemptNumber}次失败: ${error.message}`);
3619
+ },
3620
+ retries: 3
3488
3621
  });
3489
- return data;
3490
3622
  }
3491
3623
  async getUserInfo(mid) {
3492
- if (mid === "11783021") {
3493
- console.log("检测到番剧出差UID,跳过远程用户接口访问");
3494
- return bangumiTripData;
3495
- }
3496
- const wbi = await this.getWbi({ mid });
3497
- const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
3498
- return data;
3624
+ const run = async () => {
3625
+ if (mid === "11783021") {
3626
+ console.log("检测到番剧出差UID,跳过远程用户接口访问");
3627
+ return bangumiTripData;
3628
+ }
3629
+ const wbi = await this.getWbi({ mid });
3630
+ const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
3631
+ return data;
3632
+ };
3633
+ return await this.pRetry(run, {
3634
+ onFailedAttempt: (error) => {
3635
+ this.logger.error(`getUserInfo() 第${error.attemptNumber}次失败: ${error.message}`);
3636
+ },
3637
+ retries: 3
3638
+ });
3499
3639
  }
3500
3640
  async getWbiKeys() {
3501
- const { data } = await this.client.get("https://api.bilibili.com/x/web-interface/nav");
3502
- const { data: { wbi_img: { img_url, sub_url } } } = data;
3503
- return {
3504
- img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
3505
- sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
3641
+ const run = async () => {
3642
+ const { data } = await this.client.get("https://api.bilibili.com/x/web-interface/nav");
3643
+ const { data: { wbi_img: { img_url, sub_url } } } = data;
3644
+ return {
3645
+ img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
3646
+ sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
3647
+ };
3506
3648
  };
3649
+ return await this.pRetry(run, {
3650
+ onFailedAttempt: (error) => {
3651
+ this.logger.error(`getWbiKeys() 第${error.attemptNumber}次失败: ${error.message}`);
3652
+ },
3653
+ retries: 3
3654
+ });
3507
3655
  }
3508
3656
  async getMyselfInfo() {
3509
- const { data } = await this.client.get(GET_MYSELF_INFO);
3510
- return data;
3657
+ const run = async () => {
3658
+ const { data } = await this.client.get(GET_MYSELF_INFO);
3659
+ return data;
3660
+ };
3661
+ return await this.pRetry(run, {
3662
+ onFailedAttempt: (error) => {
3663
+ this.logger.error(`getMyselfInfo() 第${error.attemptNumber}次失败: ${error.message}`);
3664
+ },
3665
+ retries: 3
3666
+ });
3511
3667
  }
3512
3668
  async getLoginQRCode() {
3513
- const { data } = await this.client.get(GET_LOGIN_QRCODE);
3514
- return data;
3669
+ const run = async () => {
3670
+ const { data } = await this.client.get(GET_LOGIN_QRCODE);
3671
+ return data;
3672
+ };
3673
+ return await this.pRetry(run, {
3674
+ onFailedAttempt: (error) => {
3675
+ this.logger.error(`getLoginQRCode() 第${error.attemptNumber}次失败: ${error.message}`);
3676
+ },
3677
+ retries: 3
3678
+ });
3515
3679
  }
3516
3680
  async getLoginStatus(qrcodeKey) {
3517
- const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
3518
- return data;
3681
+ const run = async () => {
3682
+ const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
3683
+ return data;
3684
+ };
3685
+ return await this.pRetry(run, {
3686
+ onFailedAttempt: (error) => {
3687
+ this.logger.error(`getLoginStatus() 第${error.attemptNumber}次失败: ${error.message}`);
3688
+ },
3689
+ retries: 3
3690
+ });
3519
3691
  }
3520
3692
  async getLiveRoomInfo(roomId) {
3521
- const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
3522
- return data;
3693
+ const run = async () => {
3694
+ const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
3695
+ return data;
3696
+ };
3697
+ return await this.pRetry(run, {
3698
+ onFailedAttempt: (error) => {
3699
+ this.logger.error(`getLiveRoomInfo() 第${error.attemptNumber}次失败: ${error.message}`);
3700
+ },
3701
+ retries: 3
3702
+ });
3523
3703
  }
3524
3704
  async getMasterInfo(mid) {
3525
- const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
3526
- return data;
3705
+ const run = async () => {
3706
+ const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
3707
+ return data;
3708
+ };
3709
+ return await this.pRetry(run, {
3710
+ onFailedAttempt: (error) => {
3711
+ this.logger.error(`getMasterInfo() 第${error.attemptNumber}次失败: ${error.message}`);
3712
+ },
3713
+ retries: 3
3714
+ });
3527
3715
  }
3528
3716
  disposeNotifier() {
3529
3717
  if (this.loginNotifier) this.loginNotifier.dispose();
@@ -3807,138 +3995,6 @@ var BiliAPI = class extends koishi.Service {
3807
3995
  return { data: data.data };
3808
3996
  }
3809
3997
  };
3810
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3811
- attempts: 3,
3812
- onFailure(error, attempts) {
3813
- this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
3814
- }
3815
- })], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
3816
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3817
- attempts: 3,
3818
- onFailure(error, attempts) {
3819
- this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
3820
- }
3821
- })], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
3822
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3823
- attempts: 3,
3824
- onFailure(error, attempts) {
3825
- this.logger.error(`getLiveRoomInfoByUids() 第${attempts}次失败: ${error.message}`);
3826
- }
3827
- })], BiliAPI.prototype, "getLiveRoomInfoByUids", null);
3828
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3829
- attempts: 3,
3830
- onFailure(error, attempts) {
3831
- this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
3832
- }
3833
- })], BiliAPI.prototype, "getServerUTCTime", null);
3834
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3835
- attempts: 3,
3836
- onFailure(error, attempts) {
3837
- this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
3838
- }
3839
- })], BiliAPI.prototype, "getTimeNow", null);
3840
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3841
- attempts: 3,
3842
- onFailure(error, attempts) {
3843
- this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
3844
- }
3845
- })], BiliAPI.prototype, "getAllGroup", null);
3846
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3847
- attempts: 3,
3848
- onFailure(error, attempts) {
3849
- this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
3850
- }
3851
- })], BiliAPI.prototype, "removeUserFromGroup", null);
3852
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3853
- attempts: 3,
3854
- onFailure(error, attempts) {
3855
- this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
3856
- }
3857
- })], BiliAPI.prototype, "copyUserToGroup", null);
3858
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3859
- attempts: 3,
3860
- onFailure(error, attempts) {
3861
- this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
3862
- }
3863
- })], BiliAPI.prototype, "getUserSpaceDynamic", null);
3864
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3865
- attempts: 3,
3866
- onFailure(error, attempts) {
3867
- this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
3868
- }
3869
- })], BiliAPI.prototype, "createGroup", null);
3870
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3871
- attempts: 3,
3872
- onFailure(error, attempts) {
3873
- this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
3874
- }
3875
- })], BiliAPI.prototype, "getAllDynamic", null);
3876
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3877
- attempts: 3,
3878
- onFailure(error, attempts) {
3879
- this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
3880
- }
3881
- })], BiliAPI.prototype, "hasNewDynamic", null);
3882
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3883
- attempts: 3,
3884
- onFailure(error, attempts) {
3885
- this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
3886
- }
3887
- })], BiliAPI.prototype, "follow", null);
3888
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3889
- attempts: 3,
3890
- onFailure(error, attempts) {
3891
- this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
3892
- }
3893
- })], BiliAPI.prototype, "getRelationGroupDetail", null);
3894
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3895
- attempts: 3,
3896
- onFailure(error, attempts) {
3897
- this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
3898
- }
3899
- })], BiliAPI.prototype, "getCookieInfo", null);
3900
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3901
- attempts: 3,
3902
- onFailure(error, attempts) {
3903
- this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
3904
- }
3905
- })], BiliAPI.prototype, "getUserInfo", null);
3906
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3907
- attempts: 3,
3908
- onFailure(error, attempts) {
3909
- this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
3910
- }
3911
- })], BiliAPI.prototype, "getWbiKeys", null);
3912
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3913
- attempts: 3,
3914
- onFailure(error, attempts) {
3915
- this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
3916
- }
3917
- })], BiliAPI.prototype, "getMyselfInfo", null);
3918
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3919
- attempts: 3,
3920
- onFailure(error, attempts) {
3921
- this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
3922
- }
3923
- })], BiliAPI.prototype, "getLoginQRCode", null);
3924
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3925
- attempts: 3,
3926
- onFailure(error, attempts) {
3927
- this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
3928
- }
3929
- })], BiliAPI.prototype, "getLoginStatus", null);
3930
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3931
- attempts: 3,
3932
- onFailure(error, attempts) {
3933
- this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
3934
- }
3935
- })], BiliAPI.prototype, "getLiveRoomInfo", null);
3936
- (0, __oxc_project_runtime_helpers_decorate.default)([Retry({
3937
- attempts: 3,
3938
- onFailure(error, attempts) {
3939
- this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
3940
- }
3941
- })], BiliAPI.prototype, "getMasterInfo", null);
3942
3998
  (function(_BiliAPI) {
3943
3999
  const Config$1 = _BiliAPI.Config = koishi.Schema.object({
3944
4000
  userAgent: koishi.Schema.string(),
@@ -3950,17 +4006,17 @@ var bili_api_default = BiliAPI;
3950
4006
  //#endregion
3951
4007
  //#region src/bili_live.ts
3952
4008
  var BLive = class extends koishi.Service {
3953
- static inject = ["ba"];
4009
+ static inject = ["bilibili-notify-api"];
3954
4010
  listenerRecord = {};
3955
4011
  constructor(ctx) {
3956
- super(ctx, "bl");
4012
+ super(ctx, "bilibili-notify-live");
3957
4013
  }
3958
4014
  stop() {
3959
4015
  for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
3960
4016
  }
3961
4017
  async startLiveRoomListener(roomId, handler) {
3962
- const cookiesStr = await this.ctx.ba.getCookiesForHeader();
3963
- const mySelfInfo = await this.ctx.ba.getMyselfInfo();
4018
+ const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
4019
+ const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
3964
4020
  this.listenerRecord[roomId] = (0, __akokko_blive_message_listener.startListen)(Number.parseInt(roomId), handler, { ws: {
3965
4021
  headers: { Cookie: cookiesStr },
3966
4022
  uid: mySelfInfo.data.mid
@@ -3996,8 +4052,8 @@ let globalConfig;
3996
4052
  var ServerManager = class extends koishi.Service {
3997
4053
  servers = [];
3998
4054
  constructor(ctx) {
3999
- super(ctx, "sm");
4000
- const sysCom = ctx.command("bn", "bili-notify插件运行相关指令", { permissions: ["authority:5"] });
4055
+ super(ctx, "bilibili-notify");
4056
+ const sysCom = ctx.command("bn", "bilibili-notify 插件运行相关指令", { permissions: ["authority:5"] });
4001
4057
  sysCom.subcommand(".restart", "重启插件").usage("重启插件").example("bn restart").action(async () => {
4002
4058
  this.logger.info("调用 bn restart 指令");
4003
4059
  if (await this.restartPlugin()) return "插件重启成功";
@@ -4040,7 +4096,7 @@ var ServerManager = class extends koishi.Service {
4040
4096
  advancedSub: globalConfig.advancedSub,
4041
4097
  subs: globalConfig.subs,
4042
4098
  master: globalConfig.master,
4043
- wordcloud: globalConfig.wordcloud,
4099
+ wordcloudStopWords: globalConfig.wordcloudStopWords,
4044
4100
  liveSummary: globalConfig.liveSummary,
4045
4101
  liveDetectType: globalConfig.liveDetectType,
4046
4102
  restartPush: globalConfig.restartPush,