koishi-plugin-bilibili-notify 3.3.10 → 3.3.11-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.mts CHANGED
@@ -17,6 +17,7 @@ interface BAConfig {
17
17
  live: boolean;
18
18
  liveAtAll: boolean;
19
19
  liveGuardBuy: boolean;
20
+ superchat: boolean;
20
21
  wordcloud: boolean;
21
22
  liveSummary: boolean;
22
23
  platform: string;
@@ -59,6 +60,7 @@ type Channel = {
59
60
  live: boolean;
60
61
  liveAtAll: boolean;
61
62
  liveGuardBuy: boolean;
63
+ superchat: boolean;
62
64
  wordcloud: boolean;
63
65
  liveSummary: boolean;
64
66
  };
package/lib/index.d.ts CHANGED
@@ -17,6 +17,7 @@ interface BAConfig {
17
17
  live: boolean;
18
18
  liveAtAll: boolean;
19
19
  liveGuardBuy: boolean;
20
+ superchat: boolean;
20
21
  wordcloud: boolean;
21
22
  liveSummary: boolean;
22
23
  platform: string;
@@ -59,6 +60,7 @@ type Channel = {
59
60
  live: boolean;
60
61
  liveAtAll: boolean;
61
62
  liveGuardBuy: boolean;
63
+ superchat: boolean;
62
64
  wordcloud: boolean;
63
65
  liveSummary: boolean;
64
66
  };
package/lib/index.js CHANGED
@@ -79,6 +79,7 @@ const BAConfigSchema = koishi.Schema.object({
79
79
  live: koishi.Schema.boolean().default(true).description("直播"),
80
80
  liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
81
81
  liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
82
+ superchat: koishi.Schema.boolean().default(false).description("SC消息"),
82
83
  wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
83
84
  liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
84
85
  platform: koishi.Schema.string().required().description("平台名"),
@@ -192,6 +193,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
192
193
  PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
193
194
  PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
194
195
  PushType$1[PushType$1["WordCloudAndLiveSummary"] = 5] = "WordCloudAndLiveSummary";
196
+ PushType$1[PushType$1["Superchat"] = 6] = "Superchat";
195
197
  return PushType$1;
196
198
  }({});
197
199
  const PushTypeMsg = {
@@ -200,7 +202,8 @@ const PushTypeMsg = {
200
202
  [PushType.DynamicAtAll]: "动态推送+At全体",
201
203
  [PushType.StartBroadcasting]: "开播推送",
202
204
  [PushType.LiveGuardBuy]: "上舰推送",
203
- [PushType.WordCloudAndLiveSummary]: "弹幕词云和直播总结推送"
205
+ [PushType.WordCloudAndLiveSummary]: "弹幕词云和直播总结推送",
206
+ [PushType.Superchat]: "SC推送"
204
207
  };
205
208
 
206
209
  //#endregion
@@ -684,16 +687,22 @@ var ComRegister$1 = class {
684
687
  if (timer) timer();
685
688
  }
686
689
  });
687
- this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
690
+ if (this.config.advancedSub) this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
688
691
  if (Object.keys(subs).length === 0) {
689
692
  this.logger.info("初始化完毕,未添加任何订阅!");
690
693
  return;
691
694
  }
692
695
  if (this.reciveSubTimes >= 1) await this.ctx["bilibili-notify"].restartPlugin();
693
- else await this.initAsyncPart(subs);
696
+ else {
697
+ this.processUname(subs);
698
+ await this.initAsyncPart(subs);
699
+ }
694
700
  this.reciveSubTimes++;
695
701
  });
696
702
  }
703
+ processUname(subs) {
704
+ for (const uname of Object.keys(subs)) subs[uname].uname = uname;
705
+ }
697
706
  async initAsyncPart(subs) {
698
707
  this.logger.info("获取到订阅信息,开始加载订阅...");
699
708
  const groupInfoResult = await this.getGroupInfo();
@@ -756,6 +765,7 @@ var ComRegister$1 = class {
756
765
  live: s.live,
757
766
  liveAtAll: s.liveAtAll,
758
767
  liveGuardBuy: s.liveGuardBuy,
768
+ superchat: s.superchat,
759
769
  wordcloud: s.wordcloud,
760
770
  liveSummary: s.liveSummary
761
771
  }));
@@ -846,6 +856,7 @@ var ComRegister$1 = class {
846
856
  const liveArr = [];
847
857
  const liveAtAllArr = [];
848
858
  const liveGuardBuyArr = [];
859
+ const superchatArr = [];
849
860
  const wordcloudArr = [];
850
861
  const liveSummaryArr = [];
851
862
  for (const platform of sub.target) for (const channel of platform.channelArr) {
@@ -856,6 +867,7 @@ var ComRegister$1 = class {
856
867
  ["live", liveArr],
857
868
  ["liveAtAll", liveAtAllArr],
858
869
  ["liveGuardBuy", liveGuardBuyArr],
870
+ ["superchat", superchatArr],
859
871
  ["wordcloud", wordcloudArr],
860
872
  ["liveSummary", liveSummaryArr]
861
873
  ];
@@ -868,6 +880,7 @@ var ComRegister$1 = class {
868
880
  liveAtAllArr,
869
881
  liveSummaryArr,
870
882
  liveGuardBuyArr,
883
+ superchatArr,
871
884
  wordcloudArr
872
885
  });
873
886
  }
@@ -917,7 +930,7 @@ var ComRegister$1 = class {
917
930
  async broadcastToTargets(uid, content, type) {
918
931
  const record = this.pushArrMap.get(uid);
919
932
  if (!record) return;
920
- const hasTargets = type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0 || type === PushType.Dynamic && (record.dynamicArr?.length > 0 || record.dynamicAtAllArr?.length > 0) || (type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length > 0 || type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length > 0 || type === PushType.WordCloudAndLiveSummary && (record.wordcloudArr?.length > 0 || record.liveSummaryArr?.length > 0);
933
+ const hasTargets = type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0 || type === PushType.Dynamic && (record.dynamicArr?.length > 0 || record.dynamicAtAllArr?.length > 0) || (type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length > 0 || type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length > 0 || type === PushType.Superchat && record.superchatArr?.length > 0 || type === PushType.WordCloudAndLiveSummary && (record.wordcloudArr?.length > 0 || record.liveSummaryArr?.length > 0);
921
934
  if (!hasTargets) return;
922
935
  this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
923
936
  if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0) {
@@ -945,6 +958,11 @@ var ComRegister$1 = class {
945
958
  const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
946
959
  await withRetry(() => this.pushMessage(liveGuardBuyArr, (0, koishi.h)("message", content)), 1);
947
960
  }
961
+ if (type === PushType.Superchat && record.superchatArr?.length > 0) {
962
+ this.logger.info("推送SC:", record.superchatArr);
963
+ const superchatArr = structuredClone(record.superchatArr);
964
+ await withRetry(() => this.pushMessage(superchatArr, (0, koishi.h)("message", content)), 1);
965
+ }
948
966
  if (type === PushType.WordCloudAndLiveSummary) {
949
967
  const wordcloudArr = structuredClone(record.wordcloudArr);
950
968
  const liveSummaryArr = structuredClone(record.liveSummaryArr);
@@ -1152,7 +1170,7 @@ var ComRegister$1 = class {
1152
1170
  };
1153
1171
  return withLock(handler);
1154
1172
  }
1155
- async useMasterInfo(uid, masterInfo, liveType) {
1173
+ async getMasterInfo(uid, masterInfo, liveType) {
1156
1174
  const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
1157
1175
  let liveOpenFollowerNum;
1158
1176
  let liveEndFollowerNum;
@@ -1177,7 +1195,7 @@ var ComRegister$1 = class {
1177
1195
  medalName: data.medal_name
1178
1196
  };
1179
1197
  }
1180
- async useLiveRoomInfo(roomId) {
1198
+ async getLiveRoomInfo(roomId) {
1181
1199
  const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
1182
1200
  this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1183
1201
  });
@@ -1244,7 +1262,7 @@ var ComRegister$1 = class {
1244
1262
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
1245
1263
  };
1246
1264
  const pushAtTimeFunc = async () => {
1247
- if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1265
+ if (!await useLiveRoomInfo(LiveType.LiveBroadcast) && !await useMasterInfo(LiveType.LiveBroadcast)) {
1248
1266
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1249
1267
  return await this.sendPrivateMsgAndStopService();
1250
1268
  }
@@ -1263,21 +1281,28 @@ var ComRegister$1 = class {
1263
1281
  cardStyle: sub.customCardStyle
1264
1282
  }, sub.uid, liveMsg);
1265
1283
  };
1266
- const useMasterAndLiveRoomInfo = async (liveType) => {
1284
+ const useMasterInfo = async (liveType) => {
1267
1285
  let flag = true;
1268
- liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
1286
+ masterInfo = await this.getMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1269
1287
  flag = false;
1270
1288
  return null;
1271
1289
  });
1272
- if (!flag || !liveRoomInfo || !liveRoomInfo.uid) {
1290
+ return flag;
1291
+ };
1292
+ const useLiveRoomInfo = async (liveType) => {
1293
+ let flag = true;
1294
+ const data = await this.getLiveRoomInfo(sub.roomid).catch(() => {
1295
+ flag = false;
1296
+ });
1297
+ if (!flag || !data || !data.uid) {
1273
1298
  flag = false;
1274
1299
  return flag;
1275
1300
  }
1276
- masterInfo = await this.useMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1277
- flag = false;
1278
- return null;
1279
- });
1280
- return flag;
1301
+ liveRoomInfo = {
1302
+ ...liveRoomInfo,
1303
+ ...data
1304
+ };
1305
+ if (liveType === LiveType.StartBroadcasting || liveType === LiveType.FirstLiveBroadcast) liveRoomInfo.online_max = 0;
1281
1306
  };
1282
1307
  const LIVE_EVENT_COOLDOWN = 10 * 1e3;
1283
1308
  let lastLiveStart = 0;
@@ -1298,10 +1323,15 @@ var ComRegister$1 = class {
1298
1323
  onIncomeSuperChat: ({ body }) => {
1299
1324
  this.segmentDanmaku(body.content, danmakuWeightRecord);
1300
1325
  this.addUserToDanmakuMaker(body.user.uname, danmakuMakerRecord);
1326
+ const content = (0, koishi.h)("message", [koishi.h.text(`【${masterInfo.username}的直播间】${body.user.uname}的SC:${body.content}(${body.price}元)`)]);
1327
+ this.broadcastToTargets(sub.uid, content, PushType.Superchat);
1301
1328
  },
1302
1329
  onWatchedChange: ({ body }) => {
1303
1330
  watchedNum = body.text_small;
1304
1331
  },
1332
+ onAttentionChange: ({ body }) => {
1333
+ if (liveRoomInfo?.online_max && liveRoomInfo.online_max < body.attention) liveRoomInfo.online_max = body.attention;
1334
+ },
1305
1335
  onGuardBuy: ({ body }) => {
1306
1336
  const content = (0, koishi.h)("message", [koishi.h.text(`【${masterInfo.username}的直播间】${body.user.uname}加入了大航海(${body.gift_name})`)]);
1307
1337
  this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
@@ -1318,11 +1348,12 @@ var ComRegister$1 = class {
1318
1348
  return;
1319
1349
  }
1320
1350
  liveStatus = true;
1321
- if (!await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting)) {
1351
+ if (!await useLiveRoomInfo(LiveType.StartBroadcasting) && !await useMasterInfo(LiveType.StartBroadcasting)) {
1322
1352
  liveStatus = false;
1323
1353
  await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1324
1354
  return await this.sendPrivateMsgAndStopService();
1325
1355
  }
1356
+ this.logger.info(`开播粉丝数:${masterInfo.liveOpenFollowerNum}`);
1326
1357
  liveTime = liveRoomInfo?.live_time || luxon.DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1327
1358
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1328
1359
  const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
@@ -1341,10 +1372,6 @@ var ComRegister$1 = class {
1341
1372
  const now = Date.now();
1342
1373
  if (now - lastLiveEnd < LIVE_EVENT_COOLDOWN) {
1343
1374
  this.logger.warn(`[${sub.roomid}] 下播事件冷却期内被忽略`);
1344
- if (!liveTime) {
1345
- await useMasterAndLiveRoomInfo(LiveType.StopBroadcast);
1346
- liveTime = liveRoomInfo?.live_time || luxon.DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1347
- }
1348
1375
  return;
1349
1376
  }
1350
1377
  lastLiveEnd = now;
@@ -1352,7 +1379,13 @@ var ComRegister$1 = class {
1352
1379
  this.logger.warn(`[${sub.roomid}] 已是下播状态,忽略重复下播事件`);
1353
1380
  return;
1354
1381
  }
1382
+ if (!await useLiveRoomInfo(LiveType.StopBroadcast) && !await useMasterInfo(LiveType.StopBroadcast)) {
1383
+ liveStatus = false;
1384
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1385
+ return await this.sendPrivateMsgAndStopService();
1386
+ }
1355
1387
  liveStatus = false;
1388
+ this.logger.info(`开播时粉丝数:${masterInfo.liveOpenFollowerNum},下播时粉丝数:${masterInfo.liveEndFollowerNum},粉丝数变化:${masterInfo.liveFollowerChange}`);
1356
1389
  liveTime = liveRoomInfo?.live_time || luxon.DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1357
1390
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1358
1391
  const followerChange = (() => {
@@ -1375,7 +1408,8 @@ var ComRegister$1 = class {
1375
1408
  }
1376
1409
  };
1377
1410
  await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
1378
- if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1411
+ if (!await useLiveRoomInfo(LiveType.FirstLiveBroadcast) && !await useMasterInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1412
+ this.logger.info(`当前粉丝数:${masterInfo.liveOpenFollowerNum}`);
1379
1413
  if (liveRoomInfo.live_status === 1) {
1380
1414
  liveTime = liveRoomInfo.live_time;
1381
1415
  const watched = watchedNum || "暂未获取到";
@@ -1395,7 +1429,7 @@ var ComRegister$1 = class {
1395
1429
  async liveDetectWithAPI() {
1396
1430
  const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
1397
1431
  let flag = true;
1398
- LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1432
+ LiveAPIStatus.liveRoomInfo = await this.getLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1399
1433
  flag = false;
1400
1434
  return null;
1401
1435
  });
@@ -1403,7 +1437,7 @@ var ComRegister$1 = class {
1403
1437
  flag = false;
1404
1438
  return flag;
1405
1439
  }
1406
- LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1440
+ LiveAPIStatus.masterInfo = await this.getMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1407
1441
  flag = false;
1408
1442
  return null;
1409
1443
  });
@@ -1791,6 +1825,7 @@ var ComRegister$1 = class {
1791
1825
  live: koishi.Schema.boolean().default(true).description("直播"),
1792
1826
  liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
1793
1827
  liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
1828
+ superchat: koishi.Schema.boolean().default(false).description("SC"),
1794
1829
  wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
1795
1830
  liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
1796
1831
  platform: koishi.Schema.string().required().description("平台名"),
@@ -1867,6 +1902,9 @@ var GenerateImg$1 = class extends koishi.Service {
1867
1902
  super(ctx, "bilibili-notify-generate-img");
1868
1903
  this.giConfig = config;
1869
1904
  }
1905
+ numberToStr(num) {
1906
+ return num > 1e4 ? `${(num / 1e4).toFixed(1)}万` : num.toString();
1907
+ }
1870
1908
  async imgHandler(html) {
1871
1909
  const htmlPath = `file://${__dirname.replaceAll("\\", "/")}/page/0.html`;
1872
1910
  const page = await this.ctx.puppeteer.page();
@@ -2017,7 +2055,7 @@ var GenerateImg$1 = class extends koishi.Service {
2017
2055
  </div>
2018
2056
  ${this.giConfig.hideDesc ? "" : `<p class="card-text">${data.description ? data.description : "这个主播很懒,什么简介都没写"}</p>`}
2019
2057
  <p class="card-link">
2020
- <span>人气:${data.online > 1e4 ? `${(data.online / 1e4).toFixed(1)}万` : data.online}</span>
2058
+ <span>${liveStatus === 3 ? `本场直播最高人气:${this.numberToStr(data.online_max)}` : `人气:${this.numberToStr(data.online)}`}</span>
2021
2059
  <span>分区名称:${data.area_name}</span>
2022
2060
  </p>
2023
2061
  <p class="card-link">
package/lib/index.mjs CHANGED
@@ -61,6 +61,7 @@ const BAConfigSchema = Schema.object({
61
61
  live: Schema.boolean().default(true).description("直播"),
62
62
  liveAtAll: Schema.boolean().default(true).description("直播At全体"),
63
63
  liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
64
+ superchat: Schema.boolean().default(false).description("SC消息"),
64
65
  wordcloud: Schema.boolean().default(true).description("弹幕词云"),
65
66
  liveSummary: Schema.boolean().default(true).description("直播总结"),
66
67
  platform: Schema.string().required().description("平台名"),
@@ -174,6 +175,7 @@ let PushType = /* @__PURE__ */ function(PushType$1) {
174
175
  PushType$1[PushType$1["StartBroadcasting"] = 3] = "StartBroadcasting";
175
176
  PushType$1[PushType$1["LiveGuardBuy"] = 4] = "LiveGuardBuy";
176
177
  PushType$1[PushType$1["WordCloudAndLiveSummary"] = 5] = "WordCloudAndLiveSummary";
178
+ PushType$1[PushType$1["Superchat"] = 6] = "Superchat";
177
179
  return PushType$1;
178
180
  }({});
179
181
  const PushTypeMsg = {
@@ -182,7 +184,8 @@ const PushTypeMsg = {
182
184
  [PushType.DynamicAtAll]: "动态推送+At全体",
183
185
  [PushType.StartBroadcasting]: "开播推送",
184
186
  [PushType.LiveGuardBuy]: "上舰推送",
185
- [PushType.WordCloudAndLiveSummary]: "弹幕词云和直播总结推送"
187
+ [PushType.WordCloudAndLiveSummary]: "弹幕词云和直播总结推送",
188
+ [PushType.Superchat]: "SC推送"
186
189
  };
187
190
 
188
191
  //#endregion
@@ -666,16 +669,22 @@ var ComRegister$1 = class {
666
669
  if (timer) timer();
667
670
  }
668
671
  });
669
- this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
672
+ if (this.config.advancedSub) this.ctx.on("bilibili-notify/advanced-sub", async (subs) => {
670
673
  if (Object.keys(subs).length === 0) {
671
674
  this.logger.info("初始化完毕,未添加任何订阅!");
672
675
  return;
673
676
  }
674
677
  if (this.reciveSubTimes >= 1) await this.ctx["bilibili-notify"].restartPlugin();
675
- else await this.initAsyncPart(subs);
678
+ else {
679
+ this.processUname(subs);
680
+ await this.initAsyncPart(subs);
681
+ }
676
682
  this.reciveSubTimes++;
677
683
  });
678
684
  }
685
+ processUname(subs) {
686
+ for (const uname of Object.keys(subs)) subs[uname].uname = uname;
687
+ }
679
688
  async initAsyncPart(subs) {
680
689
  this.logger.info("获取到订阅信息,开始加载订阅...");
681
690
  const groupInfoResult = await this.getGroupInfo();
@@ -738,6 +747,7 @@ var ComRegister$1 = class {
738
747
  live: s.live,
739
748
  liveAtAll: s.liveAtAll,
740
749
  liveGuardBuy: s.liveGuardBuy,
750
+ superchat: s.superchat,
741
751
  wordcloud: s.wordcloud,
742
752
  liveSummary: s.liveSummary
743
753
  }));
@@ -828,6 +838,7 @@ var ComRegister$1 = class {
828
838
  const liveArr = [];
829
839
  const liveAtAllArr = [];
830
840
  const liveGuardBuyArr = [];
841
+ const superchatArr = [];
831
842
  const wordcloudArr = [];
832
843
  const liveSummaryArr = [];
833
844
  for (const platform of sub.target) for (const channel of platform.channelArr) {
@@ -838,6 +849,7 @@ var ComRegister$1 = class {
838
849
  ["live", liveArr],
839
850
  ["liveAtAll", liveAtAllArr],
840
851
  ["liveGuardBuy", liveGuardBuyArr],
852
+ ["superchat", superchatArr],
841
853
  ["wordcloud", wordcloudArr],
842
854
  ["liveSummary", liveSummaryArr]
843
855
  ];
@@ -850,6 +862,7 @@ var ComRegister$1 = class {
850
862
  liveAtAllArr,
851
863
  liveSummaryArr,
852
864
  liveGuardBuyArr,
865
+ superchatArr,
853
866
  wordcloudArr
854
867
  });
855
868
  }
@@ -899,7 +912,7 @@ var ComRegister$1 = class {
899
912
  async broadcastToTargets(uid, content, type) {
900
913
  const record = this.pushArrMap.get(uid);
901
914
  if (!record) return;
902
- const hasTargets = type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0 || type === PushType.Dynamic && (record.dynamicArr?.length > 0 || record.dynamicAtAllArr?.length > 0) || (type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length > 0 || type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length > 0 || type === PushType.WordCloudAndLiveSummary && (record.wordcloudArr?.length > 0 || record.liveSummaryArr?.length > 0);
915
+ const hasTargets = type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0 || type === PushType.Dynamic && (record.dynamicArr?.length > 0 || record.dynamicAtAllArr?.length > 0) || (type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length > 0 || type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length > 0 || type === PushType.Superchat && record.superchatArr?.length > 0 || type === PushType.WordCloudAndLiveSummary && (record.wordcloudArr?.length > 0 || record.liveSummaryArr?.length > 0);
903
916
  if (!hasTargets) return;
904
917
  this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
905
918
  if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0) {
@@ -927,6 +940,11 @@ var ComRegister$1 = class {
927
940
  const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
928
941
  await withRetry(() => this.pushMessage(liveGuardBuyArr, h("message", content)), 1);
929
942
  }
943
+ if (type === PushType.Superchat && record.superchatArr?.length > 0) {
944
+ this.logger.info("推送SC:", record.superchatArr);
945
+ const superchatArr = structuredClone(record.superchatArr);
946
+ await withRetry(() => this.pushMessage(superchatArr, h("message", content)), 1);
947
+ }
930
948
  if (type === PushType.WordCloudAndLiveSummary) {
931
949
  const wordcloudArr = structuredClone(record.wordcloudArr);
932
950
  const liveSummaryArr = structuredClone(record.liveSummaryArr);
@@ -1134,7 +1152,7 @@ var ComRegister$1 = class {
1134
1152
  };
1135
1153
  return withLock(handler);
1136
1154
  }
1137
- async useMasterInfo(uid, masterInfo, liveType) {
1155
+ async getMasterInfo(uid, masterInfo, liveType) {
1138
1156
  const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
1139
1157
  let liveOpenFollowerNum;
1140
1158
  let liveEndFollowerNum;
@@ -1159,7 +1177,7 @@ var ComRegister$1 = class {
1159
1177
  medalName: data.medal_name
1160
1178
  };
1161
1179
  }
1162
- async useLiveRoomInfo(roomId) {
1180
+ async getLiveRoomInfo(roomId) {
1163
1181
  const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
1164
1182
  this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1165
1183
  });
@@ -1226,7 +1244,7 @@ var ComRegister$1 = class {
1226
1244
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
1227
1245
  };
1228
1246
  const pushAtTimeFunc = async () => {
1229
- if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1247
+ if (!await useLiveRoomInfo(LiveType.LiveBroadcast) && !await useMasterInfo(LiveType.LiveBroadcast)) {
1230
1248
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1231
1249
  return await this.sendPrivateMsgAndStopService();
1232
1250
  }
@@ -1245,21 +1263,28 @@ var ComRegister$1 = class {
1245
1263
  cardStyle: sub.customCardStyle
1246
1264
  }, sub.uid, liveMsg);
1247
1265
  };
1248
- const useMasterAndLiveRoomInfo = async (liveType) => {
1266
+ const useMasterInfo = async (liveType) => {
1249
1267
  let flag = true;
1250
- liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
1268
+ masterInfo = await this.getMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1251
1269
  flag = false;
1252
1270
  return null;
1253
1271
  });
1254
- if (!flag || !liveRoomInfo || !liveRoomInfo.uid) {
1272
+ return flag;
1273
+ };
1274
+ const useLiveRoomInfo = async (liveType) => {
1275
+ let flag = true;
1276
+ const data = await this.getLiveRoomInfo(sub.roomid).catch(() => {
1277
+ flag = false;
1278
+ });
1279
+ if (!flag || !data || !data.uid) {
1255
1280
  flag = false;
1256
1281
  return flag;
1257
1282
  }
1258
- masterInfo = await this.useMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1259
- flag = false;
1260
- return null;
1261
- });
1262
- return flag;
1283
+ liveRoomInfo = {
1284
+ ...liveRoomInfo,
1285
+ ...data
1286
+ };
1287
+ if (liveType === LiveType.StartBroadcasting || liveType === LiveType.FirstLiveBroadcast) liveRoomInfo.online_max = 0;
1263
1288
  };
1264
1289
  const LIVE_EVENT_COOLDOWN = 10 * 1e3;
1265
1290
  let lastLiveStart = 0;
@@ -1280,10 +1305,15 @@ var ComRegister$1 = class {
1280
1305
  onIncomeSuperChat: ({ body }) => {
1281
1306
  this.segmentDanmaku(body.content, danmakuWeightRecord);
1282
1307
  this.addUserToDanmakuMaker(body.user.uname, danmakuMakerRecord);
1308
+ const content = h("message", [h.text(`【${masterInfo.username}的直播间】${body.user.uname}的SC:${body.content}(${body.price}元)`)]);
1309
+ this.broadcastToTargets(sub.uid, content, PushType.Superchat);
1283
1310
  },
1284
1311
  onWatchedChange: ({ body }) => {
1285
1312
  watchedNum = body.text_small;
1286
1313
  },
1314
+ onAttentionChange: ({ body }) => {
1315
+ if (liveRoomInfo?.online_max && liveRoomInfo.online_max < body.attention) liveRoomInfo.online_max = body.attention;
1316
+ },
1287
1317
  onGuardBuy: ({ body }) => {
1288
1318
  const content = h("message", [h.text(`【${masterInfo.username}的直播间】${body.user.uname}加入了大航海(${body.gift_name})`)]);
1289
1319
  this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
@@ -1300,11 +1330,12 @@ var ComRegister$1 = class {
1300
1330
  return;
1301
1331
  }
1302
1332
  liveStatus = true;
1303
- if (!await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting)) {
1333
+ if (!await useLiveRoomInfo(LiveType.StartBroadcasting) && !await useMasterInfo(LiveType.StartBroadcasting)) {
1304
1334
  liveStatus = false;
1305
1335
  await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1306
1336
  return await this.sendPrivateMsgAndStopService();
1307
1337
  }
1338
+ this.logger.info(`开播粉丝数:${masterInfo.liveOpenFollowerNum}`);
1308
1339
  liveTime = liveRoomInfo?.live_time || DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1309
1340
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1310
1341
  const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
@@ -1323,10 +1354,6 @@ var ComRegister$1 = class {
1323
1354
  const now = Date.now();
1324
1355
  if (now - lastLiveEnd < LIVE_EVENT_COOLDOWN) {
1325
1356
  this.logger.warn(`[${sub.roomid}] 下播事件冷却期内被忽略`);
1326
- if (!liveTime) {
1327
- await useMasterAndLiveRoomInfo(LiveType.StopBroadcast);
1328
- liveTime = liveRoomInfo?.live_time || DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1329
- }
1330
1357
  return;
1331
1358
  }
1332
1359
  lastLiveEnd = now;
@@ -1334,7 +1361,13 @@ var ComRegister$1 = class {
1334
1361
  this.logger.warn(`[${sub.roomid}] 已是下播状态,忽略重复下播事件`);
1335
1362
  return;
1336
1363
  }
1364
+ if (!await useLiveRoomInfo(LiveType.StopBroadcast) && !await useMasterInfo(LiveType.StopBroadcast)) {
1365
+ liveStatus = false;
1366
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1367
+ return await this.sendPrivateMsgAndStopService();
1368
+ }
1337
1369
  liveStatus = false;
1370
+ this.logger.info(`开播时粉丝数:${masterInfo.liveOpenFollowerNum},下播时粉丝数:${masterInfo.liveEndFollowerNum},粉丝数变化:${masterInfo.liveFollowerChange}`);
1338
1371
  liveTime = liveRoomInfo?.live_time || DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1339
1372
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1340
1373
  const followerChange = (() => {
@@ -1357,7 +1390,8 @@ var ComRegister$1 = class {
1357
1390
  }
1358
1391
  };
1359
1392
  await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
1360
- if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1393
+ if (!await useLiveRoomInfo(LiveType.FirstLiveBroadcast) && !await useMasterInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1394
+ this.logger.info(`当前粉丝数:${masterInfo.liveOpenFollowerNum}`);
1361
1395
  if (liveRoomInfo.live_status === 1) {
1362
1396
  liveTime = liveRoomInfo.live_time;
1363
1397
  const watched = watchedNum || "暂未获取到";
@@ -1377,7 +1411,7 @@ var ComRegister$1 = class {
1377
1411
  async liveDetectWithAPI() {
1378
1412
  const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
1379
1413
  let flag = true;
1380
- LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1414
+ LiveAPIStatus.liveRoomInfo = await this.getLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1381
1415
  flag = false;
1382
1416
  return null;
1383
1417
  });
@@ -1385,7 +1419,7 @@ var ComRegister$1 = class {
1385
1419
  flag = false;
1386
1420
  return flag;
1387
1421
  }
1388
- LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1422
+ LiveAPIStatus.masterInfo = await this.getMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1389
1423
  flag = false;
1390
1424
  return null;
1391
1425
  });
@@ -1773,6 +1807,7 @@ var ComRegister$1 = class {
1773
1807
  live: Schema.boolean().default(true).description("直播"),
1774
1808
  liveAtAll: Schema.boolean().default(true).description("直播At全体"),
1775
1809
  liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
1810
+ superchat: Schema.boolean().default(false).description("SC"),
1776
1811
  wordcloud: Schema.boolean().default(true).description("弹幕词云"),
1777
1812
  liveSummary: Schema.boolean().default(true).description("直播总结"),
1778
1813
  platform: Schema.string().required().description("平台名"),
@@ -1849,6 +1884,9 @@ var GenerateImg$1 = class extends Service {
1849
1884
  super(ctx, "bilibili-notify-generate-img");
1850
1885
  this.giConfig = config;
1851
1886
  }
1887
+ numberToStr(num) {
1888
+ return num > 1e4 ? `${(num / 1e4).toFixed(1)}万` : num.toString();
1889
+ }
1852
1890
  async imgHandler(html) {
1853
1891
  const htmlPath = `file://${__dirname.replaceAll("\\", "/")}/page/0.html`;
1854
1892
  const page = await this.ctx.puppeteer.page();
@@ -1999,7 +2037,7 @@ var GenerateImg$1 = class extends Service {
1999
2037
  </div>
2000
2038
  ${this.giConfig.hideDesc ? "" : `<p class="card-text">${data.description ? data.description : "这个主播很懒,什么简介都没写"}</p>`}
2001
2039
  <p class="card-link">
2002
- <span>人气:${data.online > 1e4 ? `${(data.online / 1e4).toFixed(1)}万` : data.online}</span>
2040
+ <span>${liveStatus === 3 ? `本场直播最高人气:${this.numberToStr(data.online_max)}` : `人气:${this.numberToStr(data.online)}`}</span>
2003
2041
  <span>分区名称:${data.area_name}</span>
2004
2042
  </p>
2005
2043
  <p class="card-link">
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "3.3.10",
4
+ "version": "3.3.11-alpha.1",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [