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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.mts 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,7 +687,7 @@ 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;
@@ -756,6 +759,7 @@ var ComRegister$1 = class {
756
759
  live: s.live,
757
760
  liveAtAll: s.liveAtAll,
758
761
  liveGuardBuy: s.liveGuardBuy,
762
+ superchat: s.superchat,
759
763
  wordcloud: s.wordcloud,
760
764
  liveSummary: s.liveSummary
761
765
  }));
@@ -846,6 +850,7 @@ var ComRegister$1 = class {
846
850
  const liveArr = [];
847
851
  const liveAtAllArr = [];
848
852
  const liveGuardBuyArr = [];
853
+ const superchatArr = [];
849
854
  const wordcloudArr = [];
850
855
  const liveSummaryArr = [];
851
856
  for (const platform of sub.target) for (const channel of platform.channelArr) {
@@ -856,6 +861,7 @@ var ComRegister$1 = class {
856
861
  ["live", liveArr],
857
862
  ["liveAtAll", liveAtAllArr],
858
863
  ["liveGuardBuy", liveGuardBuyArr],
864
+ ["superchat", superchatArr],
859
865
  ["wordcloud", wordcloudArr],
860
866
  ["liveSummary", liveSummaryArr]
861
867
  ];
@@ -868,6 +874,7 @@ var ComRegister$1 = class {
868
874
  liveAtAllArr,
869
875
  liveSummaryArr,
870
876
  liveGuardBuyArr,
877
+ superchatArr,
871
878
  wordcloudArr
872
879
  });
873
880
  }
@@ -917,7 +924,7 @@ var ComRegister$1 = class {
917
924
  async broadcastToTargets(uid, content, type) {
918
925
  const record = this.pushArrMap.get(uid);
919
926
  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);
927
+ 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
928
  if (!hasTargets) return;
922
929
  this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
923
930
  if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0) {
@@ -945,6 +952,11 @@ var ComRegister$1 = class {
945
952
  const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
946
953
  await withRetry(() => this.pushMessage(liveGuardBuyArr, (0, koishi.h)("message", content)), 1);
947
954
  }
955
+ if (type === PushType.Superchat && record.superchatArr?.length > 0) {
956
+ this.logger.info("推送SC:", record.superchatArr);
957
+ const superchatArr = structuredClone(record.superchatArr);
958
+ await withRetry(() => this.pushMessage(superchatArr, (0, koishi.h)("message", content)), 1);
959
+ }
948
960
  if (type === PushType.WordCloudAndLiveSummary) {
949
961
  const wordcloudArr = structuredClone(record.wordcloudArr);
950
962
  const liveSummaryArr = structuredClone(record.liveSummaryArr);
@@ -1152,7 +1164,7 @@ var ComRegister$1 = class {
1152
1164
  };
1153
1165
  return withLock(handler);
1154
1166
  }
1155
- async useMasterInfo(uid, masterInfo, liveType) {
1167
+ async getMasterInfo(uid, masterInfo, liveType) {
1156
1168
  const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
1157
1169
  let liveOpenFollowerNum;
1158
1170
  let liveEndFollowerNum;
@@ -1177,7 +1189,7 @@ var ComRegister$1 = class {
1177
1189
  medalName: data.medal_name
1178
1190
  };
1179
1191
  }
1180
- async useLiveRoomInfo(roomId) {
1192
+ async getLiveRoomInfo(roomId) {
1181
1193
  const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
1182
1194
  this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1183
1195
  });
@@ -1211,7 +1223,7 @@ var ComRegister$1 = class {
1211
1223
  const danmakuWeightRecord = {};
1212
1224
  const danmakuMakerRecord = {};
1213
1225
  let liveStatus = false;
1214
- let liveRoomInfo;
1226
+ const liveRoomInfo = {};
1215
1227
  let masterInfo;
1216
1228
  let watchedNum;
1217
1229
  const liveMsgObj = this.liveMsgManager.get(sub.uid);
@@ -1244,7 +1256,7 @@ var ComRegister$1 = class {
1244
1256
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
1245
1257
  };
1246
1258
  const pushAtTimeFunc = async () => {
1247
- if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1259
+ if (!await useLiveRoomInfo(LiveType.LiveBroadcast) && !await useMasterInfo(LiveType.LiveBroadcast)) {
1248
1260
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1249
1261
  return await this.sendPrivateMsgAndStopService();
1250
1262
  }
@@ -1263,21 +1275,34 @@ var ComRegister$1 = class {
1263
1275
  cardStyle: sub.customCardStyle
1264
1276
  }, sub.uid, liveMsg);
1265
1277
  };
1266
- const useMasterAndLiveRoomInfo = async (liveType) => {
1278
+ const useMasterInfo = async (liveType) => {
1267
1279
  let flag = true;
1268
- liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
1280
+ masterInfo = await this.getMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1269
1281
  flag = false;
1270
1282
  return null;
1271
1283
  });
1272
- if (!flag || !liveRoomInfo || !liveRoomInfo.uid) {
1273
- flag = false;
1274
- return flag;
1275
- }
1276
- masterInfo = await this.useMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1284
+ return flag;
1285
+ };
1286
+ const useLiveRoomInfo = async (liveType) => {
1287
+ let flag = true;
1288
+ const liveRoomInfoData = await this.getLiveRoomInfo(sub.roomid).catch(() => {
1277
1289
  flag = false;
1278
1290
  return null;
1279
1291
  });
1280
- return flag;
1292
+ if (!flag || !liveRoomInfoData || !liveRoomInfoData.uid) {
1293
+ flag = false;
1294
+ return flag;
1295
+ }
1296
+ if (liveType === LiveType.StartBroadcasting || liveType === LiveType.FirstLiveBroadcast) {
1297
+ liveRoomInfo.uid = liveRoomInfoData.uid;
1298
+ liveRoomInfo.live_time = liveRoomInfoData.live_time;
1299
+ liveRoomInfo.short_id = liveRoomInfoData.short_id;
1300
+ liveRoomInfo.room_id = liveRoomInfoData.room_id;
1301
+ liveRoomInfo.online_max = 0;
1302
+ }
1303
+ liveRoomInfo.live_status = liveRoomInfoData.live_status;
1304
+ liveRoomInfo.online = liveRoomInfoData.online;
1305
+ if (liveRoomInfo.online > liveRoomInfo.online_max) liveRoomInfo.online_max = liveRoomInfo.online;
1281
1306
  };
1282
1307
  const LIVE_EVENT_COOLDOWN = 10 * 1e3;
1283
1308
  let lastLiveStart = 0;
@@ -1298,6 +1323,8 @@ 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;
@@ -1318,11 +1345,12 @@ var ComRegister$1 = class {
1318
1345
  return;
1319
1346
  }
1320
1347
  liveStatus = true;
1321
- if (!await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting)) {
1348
+ if (!await useLiveRoomInfo(LiveType.StartBroadcasting) && !await useMasterInfo(LiveType.StartBroadcasting)) {
1322
1349
  liveStatus = false;
1323
1350
  await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1324
1351
  return await this.sendPrivateMsgAndStopService();
1325
1352
  }
1353
+ this.logger.info(`开播粉丝数:${masterInfo.liveOpenFollowerNum}`);
1326
1354
  liveTime = liveRoomInfo?.live_time || luxon.DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1327
1355
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1328
1356
  const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
@@ -1341,10 +1369,6 @@ var ComRegister$1 = class {
1341
1369
  const now = Date.now();
1342
1370
  if (now - lastLiveEnd < LIVE_EVENT_COOLDOWN) {
1343
1371
  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
1372
  return;
1349
1373
  }
1350
1374
  lastLiveEnd = now;
@@ -1352,7 +1376,13 @@ var ComRegister$1 = class {
1352
1376
  this.logger.warn(`[${sub.roomid}] 已是下播状态,忽略重复下播事件`);
1353
1377
  return;
1354
1378
  }
1379
+ if (!await useLiveRoomInfo(LiveType.StopBroadcast) && !await useMasterInfo(LiveType.StopBroadcast)) {
1380
+ liveStatus = false;
1381
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1382
+ return await this.sendPrivateMsgAndStopService();
1383
+ }
1355
1384
  liveStatus = false;
1385
+ this.logger.info(`开播时粉丝数:${masterInfo.liveOpenFollowerNum},下播时粉丝数:${masterInfo.liveEndFollowerNum},粉丝数变化:${masterInfo.liveFollowerChange}`);
1356
1386
  liveTime = liveRoomInfo?.live_time || luxon.DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1357
1387
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1358
1388
  const followerChange = (() => {
@@ -1375,7 +1405,8 @@ var ComRegister$1 = class {
1375
1405
  }
1376
1406
  };
1377
1407
  await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
1378
- if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1408
+ if (!await useLiveRoomInfo(LiveType.FirstLiveBroadcast) && !await useMasterInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1409
+ this.logger.info(`当前粉丝数:${masterInfo.liveOpenFollowerNum}`);
1379
1410
  if (liveRoomInfo.live_status === 1) {
1380
1411
  liveTime = liveRoomInfo.live_time;
1381
1412
  const watched = watchedNum || "暂未获取到";
@@ -1395,7 +1426,7 @@ var ComRegister$1 = class {
1395
1426
  async liveDetectWithAPI() {
1396
1427
  const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
1397
1428
  let flag = true;
1398
- LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1429
+ LiveAPIStatus.liveRoomInfo = await this.getLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1399
1430
  flag = false;
1400
1431
  return null;
1401
1432
  });
@@ -1403,7 +1434,7 @@ var ComRegister$1 = class {
1403
1434
  flag = false;
1404
1435
  return flag;
1405
1436
  }
1406
- LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1437
+ LiveAPIStatus.masterInfo = await this.getMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1407
1438
  flag = false;
1408
1439
  return null;
1409
1440
  });
@@ -1791,6 +1822,7 @@ var ComRegister$1 = class {
1791
1822
  live: koishi.Schema.boolean().default(true).description("直播"),
1792
1823
  liveAtAll: koishi.Schema.boolean().default(true).description("直播At全体"),
1793
1824
  liveGuardBuy: koishi.Schema.boolean().default(false).description("上舰消息"),
1825
+ superchat: koishi.Schema.boolean().default(false).description("SC"),
1794
1826
  wordcloud: koishi.Schema.boolean().default(true).description("弹幕词云"),
1795
1827
  liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
1796
1828
  platform: koishi.Schema.string().required().description("平台名"),
@@ -2017,7 +2049,7 @@ var GenerateImg$1 = class extends koishi.Service {
2017
2049
  </div>
2018
2050
  ${this.giConfig.hideDesc ? "" : `<p class="card-text">${data.description ? data.description : "这个主播很懒,什么简介都没写"}</p>`}
2019
2051
  <p class="card-link">
2020
- <span>人气:${data.online > 1e4 ? `${(data.online / 1e4).toFixed(1)}万` : data.online}</span>
2052
+ <span>${liveStatus === 3 ? "本场直播最高人气:" : "人气:"}${data.online > 1e4 ? `${(data.online / 1e4).toFixed(1)}万` : data.online}</span>
2021
2053
  <span>分区名称:${data.area_name}</span>
2022
2054
  </p>
2023
2055
  <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,7 +669,7 @@ 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;
@@ -738,6 +741,7 @@ var ComRegister$1 = class {
738
741
  live: s.live,
739
742
  liveAtAll: s.liveAtAll,
740
743
  liveGuardBuy: s.liveGuardBuy,
744
+ superchat: s.superchat,
741
745
  wordcloud: s.wordcloud,
742
746
  liveSummary: s.liveSummary
743
747
  }));
@@ -828,6 +832,7 @@ var ComRegister$1 = class {
828
832
  const liveArr = [];
829
833
  const liveAtAllArr = [];
830
834
  const liveGuardBuyArr = [];
835
+ const superchatArr = [];
831
836
  const wordcloudArr = [];
832
837
  const liveSummaryArr = [];
833
838
  for (const platform of sub.target) for (const channel of platform.channelArr) {
@@ -838,6 +843,7 @@ var ComRegister$1 = class {
838
843
  ["live", liveArr],
839
844
  ["liveAtAll", liveAtAllArr],
840
845
  ["liveGuardBuy", liveGuardBuyArr],
846
+ ["superchat", superchatArr],
841
847
  ["wordcloud", wordcloudArr],
842
848
  ["liveSummary", liveSummaryArr]
843
849
  ];
@@ -850,6 +856,7 @@ var ComRegister$1 = class {
850
856
  liveAtAllArr,
851
857
  liveSummaryArr,
852
858
  liveGuardBuyArr,
859
+ superchatArr,
853
860
  wordcloudArr
854
861
  });
855
862
  }
@@ -899,7 +906,7 @@ var ComRegister$1 = class {
899
906
  async broadcastToTargets(uid, content, type) {
900
907
  const record = this.pushArrMap.get(uid);
901
908
  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);
909
+ 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
910
  if (!hasTargets) return;
904
911
  this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
905
912
  if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length > 0) {
@@ -927,6 +934,11 @@ var ComRegister$1 = class {
927
934
  const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
928
935
  await withRetry(() => this.pushMessage(liveGuardBuyArr, h("message", content)), 1);
929
936
  }
937
+ if (type === PushType.Superchat && record.superchatArr?.length > 0) {
938
+ this.logger.info("推送SC:", record.superchatArr);
939
+ const superchatArr = structuredClone(record.superchatArr);
940
+ await withRetry(() => this.pushMessage(superchatArr, h("message", content)), 1);
941
+ }
930
942
  if (type === PushType.WordCloudAndLiveSummary) {
931
943
  const wordcloudArr = structuredClone(record.wordcloudArr);
932
944
  const liveSummaryArr = structuredClone(record.liveSummaryArr);
@@ -1134,7 +1146,7 @@ var ComRegister$1 = class {
1134
1146
  };
1135
1147
  return withLock(handler);
1136
1148
  }
1137
- async useMasterInfo(uid, masterInfo, liveType) {
1149
+ async getMasterInfo(uid, masterInfo, liveType) {
1138
1150
  const { data } = await this.ctx["bilibili-notify-api"].getMasterInfo(uid);
1139
1151
  let liveOpenFollowerNum;
1140
1152
  let liveEndFollowerNum;
@@ -1159,7 +1171,7 @@ var ComRegister$1 = class {
1159
1171
  medalName: data.medal_name
1160
1172
  };
1161
1173
  }
1162
- async useLiveRoomInfo(roomId) {
1174
+ async getLiveRoomInfo(roomId) {
1163
1175
  const data = await withRetry(async () => await this.ctx["bilibili-notify-api"].getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
1164
1176
  this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1165
1177
  });
@@ -1193,7 +1205,7 @@ var ComRegister$1 = class {
1193
1205
  const danmakuWeightRecord = {};
1194
1206
  const danmakuMakerRecord = {};
1195
1207
  let liveStatus = false;
1196
- let liveRoomInfo;
1208
+ const liveRoomInfo = {};
1197
1209
  let masterInfo;
1198
1210
  let watchedNum;
1199
1211
  const liveMsgObj = this.liveMsgManager.get(sub.uid);
@@ -1226,7 +1238,7 @@ var ComRegister$1 = class {
1226
1238
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
1227
1239
  };
1228
1240
  const pushAtTimeFunc = async () => {
1229
- if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1241
+ if (!await useLiveRoomInfo(LiveType.LiveBroadcast) && !await useMasterInfo(LiveType.LiveBroadcast)) {
1230
1242
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1231
1243
  return await this.sendPrivateMsgAndStopService();
1232
1244
  }
@@ -1245,21 +1257,34 @@ var ComRegister$1 = class {
1245
1257
  cardStyle: sub.customCardStyle
1246
1258
  }, sub.uid, liveMsg);
1247
1259
  };
1248
- const useMasterAndLiveRoomInfo = async (liveType) => {
1260
+ const useMasterInfo = async (liveType) => {
1249
1261
  let flag = true;
1250
- liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
1262
+ masterInfo = await this.getMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1251
1263
  flag = false;
1252
1264
  return null;
1253
1265
  });
1254
- if (!flag || !liveRoomInfo || !liveRoomInfo.uid) {
1255
- flag = false;
1256
- return flag;
1257
- }
1258
- masterInfo = await this.useMasterInfo(liveRoomInfo.uid.toString(), masterInfo, liveType).catch(() => {
1266
+ return flag;
1267
+ };
1268
+ const useLiveRoomInfo = async (liveType) => {
1269
+ let flag = true;
1270
+ const liveRoomInfoData = await this.getLiveRoomInfo(sub.roomid).catch(() => {
1259
1271
  flag = false;
1260
1272
  return null;
1261
1273
  });
1262
- return flag;
1274
+ if (!flag || !liveRoomInfoData || !liveRoomInfoData.uid) {
1275
+ flag = false;
1276
+ return flag;
1277
+ }
1278
+ if (liveType === LiveType.StartBroadcasting || liveType === LiveType.FirstLiveBroadcast) {
1279
+ liveRoomInfo.uid = liveRoomInfoData.uid;
1280
+ liveRoomInfo.live_time = liveRoomInfoData.live_time;
1281
+ liveRoomInfo.short_id = liveRoomInfoData.short_id;
1282
+ liveRoomInfo.room_id = liveRoomInfoData.room_id;
1283
+ liveRoomInfo.online_max = 0;
1284
+ }
1285
+ liveRoomInfo.live_status = liveRoomInfoData.live_status;
1286
+ liveRoomInfo.online = liveRoomInfoData.online;
1287
+ if (liveRoomInfo.online > liveRoomInfo.online_max) liveRoomInfo.online_max = liveRoomInfo.online;
1263
1288
  };
1264
1289
  const LIVE_EVENT_COOLDOWN = 10 * 1e3;
1265
1290
  let lastLiveStart = 0;
@@ -1280,6 +1305,8 @@ 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;
@@ -1300,11 +1327,12 @@ var ComRegister$1 = class {
1300
1327
  return;
1301
1328
  }
1302
1329
  liveStatus = true;
1303
- if (!await useMasterAndLiveRoomInfo(LiveType.StartBroadcasting)) {
1330
+ if (!await useLiveRoomInfo(LiveType.StartBroadcasting) && !await useMasterInfo(LiveType.StartBroadcasting)) {
1304
1331
  liveStatus = false;
1305
1332
  await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1306
1333
  return await this.sendPrivateMsgAndStopService();
1307
1334
  }
1335
+ this.logger.info(`开播粉丝数:${masterInfo.liveOpenFollowerNum}`);
1308
1336
  liveTime = liveRoomInfo?.live_time || DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1309
1337
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1310
1338
  const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
@@ -1323,10 +1351,6 @@ var ComRegister$1 = class {
1323
1351
  const now = Date.now();
1324
1352
  if (now - lastLiveEnd < LIVE_EVENT_COOLDOWN) {
1325
1353
  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
1354
  return;
1331
1355
  }
1332
1356
  lastLiveEnd = now;
@@ -1334,7 +1358,13 @@ var ComRegister$1 = class {
1334
1358
  this.logger.warn(`[${sub.roomid}] 已是下播状态,忽略重复下播事件`);
1335
1359
  return;
1336
1360
  }
1361
+ if (!await useLiveRoomInfo(LiveType.StopBroadcast) && !await useMasterInfo(LiveType.StopBroadcast)) {
1362
+ liveStatus = false;
1363
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1364
+ return await this.sendPrivateMsgAndStopService();
1365
+ }
1337
1366
  liveStatus = false;
1367
+ this.logger.info(`开播时粉丝数:${masterInfo.liveOpenFollowerNum},下播时粉丝数:${masterInfo.liveEndFollowerNum},粉丝数变化:${masterInfo.liveFollowerChange}`);
1338
1368
  liveTime = liveRoomInfo?.live_time || DateTime.now().toFormat("yyyy-MM-dd HH:mm:ss");
1339
1369
  const diffTime = await this.ctx["bilibili-notify-generate-img"].getTimeDifference(liveTime);
1340
1370
  const followerChange = (() => {
@@ -1357,7 +1387,8 @@ var ComRegister$1 = class {
1357
1387
  }
1358
1388
  };
1359
1389
  await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
1360
- if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1390
+ if (!await useLiveRoomInfo(LiveType.FirstLiveBroadcast) && !await useMasterInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1391
+ this.logger.info(`当前粉丝数:${masterInfo.liveOpenFollowerNum}`);
1361
1392
  if (liveRoomInfo.live_status === 1) {
1362
1393
  liveTime = liveRoomInfo.live_time;
1363
1394
  const watched = watchedNum || "暂未获取到";
@@ -1377,7 +1408,7 @@ var ComRegister$1 = class {
1377
1408
  async liveDetectWithAPI() {
1378
1409
  const useMasterAndLiveRoomInfo = async (liveType, LiveAPIStatus) => {
1379
1410
  let flag = true;
1380
- LiveAPIStatus.liveRoomInfo = await this.useLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1411
+ LiveAPIStatus.liveRoomInfo = await this.getLiveRoomInfo(LiveAPIStatus.roomId).catch(() => {
1381
1412
  flag = false;
1382
1413
  return null;
1383
1414
  });
@@ -1385,7 +1416,7 @@ var ComRegister$1 = class {
1385
1416
  flag = false;
1386
1417
  return flag;
1387
1418
  }
1388
- LiveAPIStatus.masterInfo = await this.useMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1419
+ LiveAPIStatus.masterInfo = await this.getMasterInfo(LiveAPIStatus.liveRoomInfo.uid, LiveAPIStatus.masterInfo, liveType).catch(() => {
1389
1420
  flag = false;
1390
1421
  return null;
1391
1422
  });
@@ -1773,6 +1804,7 @@ var ComRegister$1 = class {
1773
1804
  live: Schema.boolean().default(true).description("直播"),
1774
1805
  liveAtAll: Schema.boolean().default(true).description("直播At全体"),
1775
1806
  liveGuardBuy: Schema.boolean().default(false).description("上舰消息"),
1807
+ superchat: Schema.boolean().default(false).description("SC"),
1776
1808
  wordcloud: Schema.boolean().default(true).description("弹幕词云"),
1777
1809
  liveSummary: Schema.boolean().default(true).description("直播总结"),
1778
1810
  platform: Schema.string().required().description("平台名"),
@@ -1999,7 +2031,7 @@ var GenerateImg$1 = class extends Service {
1999
2031
  </div>
2000
2032
  ${this.giConfig.hideDesc ? "" : `<p class="card-text">${data.description ? data.description : "这个主播很懒,什么简介都没写"}</p>`}
2001
2033
  <p class="card-link">
2002
- <span>人气:${data.online > 1e4 ? `${(data.online / 1e4).toFixed(1)}万` : data.online}</span>
2034
+ <span>${liveStatus === 3 ? "本场直播最高人气:" : "人气:"}${data.online > 1e4 ? `${(data.online / 1e4).toFixed(1)}万` : data.online}</span>
2003
2035
  <span>分区名称:${data.area_name}</span>
2004
2036
  </p>
2005
2037
  <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.0",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [