koishi-plugin-bilibili-notify 3.2.0-alpha.0 → 3.2.0-alpha.2

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.
@@ -978,7 +978,9 @@ class ComRegister {
978
978
  // 判断是否信息是否获取成功
979
979
  if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.LiveBroadcast))) {
980
980
  // 未获取成功,直接返回
981
- return this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
981
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
982
+ // 停止服务
983
+ return await this.sendPrivateMsgAndStopService();
982
984
  }
983
985
  // 判断是否已经下播
984
986
  if (liveRoomInfo.live_status === 0) {
@@ -1069,7 +1071,9 @@ class ComRegister {
1069
1071
  // 设置开播状态为false
1070
1072
  liveStatus = false;
1071
1073
  // 未获取成功,直接返回
1072
- return await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1074
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1075
+ // 停止服务
1076
+ return await this.sendPrivateMsgAndStopService();
1073
1077
  }
1074
1078
  // 设置开播时间
1075
1079
  liveTime = liveRoomInfo.live_time;
@@ -1104,7 +1108,9 @@ class ComRegister {
1104
1108
  // 判断是否信息是否获取成功
1105
1109
  if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast))) {
1106
1110
  // 未获取成功,直接返回
1107
- return this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1111
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1112
+ // 停止服务
1113
+ return await this.sendPrivateMsgAndStopService();
1108
1114
  }
1109
1115
  // 更改直播时长
1110
1116
  liveRoomInfo.live_time = liveTime;
@@ -1216,9 +1222,23 @@ class ComRegister {
1216
1222
  for (const [uid] of this.liveStatusManager.entries()) {
1217
1223
  uids.push(uid);
1218
1224
  }
1225
+ const useLiveInfo = async () => {
1226
+ // 发送请求
1227
+ const { data } = await (0, utils_1.withRetry)(async () => (await this.ctx.ba.getLiveRoomInfoByUids(uids)), 3).catch(async () => {
1228
+ // 返回undefined
1229
+ return undefined;
1230
+ });
1231
+ if (!data) {
1232
+ // 停止服务
1233
+ await this.sendPrivateMsgAndStopService();
1234
+ // 返回
1235
+ return;
1236
+ }
1237
+ return data;
1238
+ };
1239
+ // 获取信息
1240
+ const data = await useLiveInfo();
1219
1241
  // 初始化
1220
- // 发送请求
1221
- const { data } = (await this.ctx.ba.getLiveRoomInfoByUids(uids));
1222
1242
  for (const item of Object.values(data)) {
1223
1243
  // 将用户uid转换为string
1224
1244
  const uid = item.uid.toString();
@@ -1232,30 +1252,34 @@ class ComRegister {
1232
1252
  liveStatus.live = true;
1233
1253
  // 初始化主播和直播间信息
1234
1254
  await useMasterAndLiveRoomInfo(type_1.LiveType.FirstLiveBroadcast, liveStatus);
1255
+ // 判断是否需要设置开播时间
1256
+ if (!liveStatus.liveStartTimeInit) {
1257
+ // 设置开播时间
1258
+ liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1259
+ // 设置开播时间初始化状态
1260
+ liveStatus.liveStartTimeInit = true;
1261
+ }
1235
1262
  // 设置直播中消息
1236
1263
  const liveMsg = this.config.customLive
1237
1264
  ? this.config.customLive
1238
1265
  .replace("-name", liveStatus.masterInfo.username)
1239
1266
  .replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime))
1240
- .replace("-watched", "暂未获取到")
1267
+ .replace("-watched", "")
1241
1268
  .replace("\\n", "\n")
1242
1269
  .replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
1243
1270
  : null;
1244
1271
  // 发送直播通知卡片
1245
- await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, "暂未获取到", {
1272
+ await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, "API", {
1246
1273
  liveRoomInfo: liveStatus.liveRoomInfo,
1247
1274
  masterInfo: liveStatus.masterInfo,
1248
1275
  cardStyle: sub.card,
1249
1276
  }, sub.target, liveMsg);
1250
1277
  }
1251
- else {
1252
- useMasterAndLiveRoomInfo(type_1.LiveType.NotLiveBroadcast, liveStatus);
1253
- }
1254
1278
  }
1255
1279
  // 定义函数
1256
1280
  const handler = async () => {
1257
1281
  // 发送请求
1258
- const { data } = (await this.ctx.ba.getLiveRoomInfoByUids(uids));
1282
+ const data = await useLiveInfo();
1259
1283
  // 进行处理
1260
1284
  for (const item of Object.values(data)) {
1261
1285
  // 将用户uid转换为string
@@ -1277,7 +1301,9 @@ class ComRegister {
1277
1301
  // 判断信息是否获取成功
1278
1302
  if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast, liveStatus))) {
1279
1303
  // 未获取成功,直接返回
1280
- return await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1304
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1305
+ // 停止服务
1306
+ return await this.sendPrivateMsgAndStopService();
1281
1307
  }
1282
1308
  // 更改直播时长
1283
1309
  if (liveStatus.liveStartTimeInit) {
@@ -1329,7 +1355,9 @@ class ComRegister {
1329
1355
  // 判断信息是否获取成功
1330
1356
  if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.StopBroadcast, liveStatus))) {
1331
1357
  // 未获取成功,直接返回
1332
- return await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1358
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1359
+ // 停止服务
1360
+ return await this.sendPrivateMsgAndStopService();
1333
1361
  }
1334
1362
  // 设置开播时间
1335
1363
  liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
@@ -1368,7 +1396,9 @@ class ComRegister {
1368
1396
  // 判断是否信息是否获取成功
1369
1397
  if (!(await useMasterAndLiveRoomInfo(type_1.LiveType.LiveBroadcast, liveStatus))) {
1370
1398
  // 未获取成功,直接返回
1371
- return this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1399
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1400
+ // 停止服务
1401
+ return await this.sendPrivateMsgAndStopService();
1372
1402
  }
1373
1403
  // 判断是否需要设置开播时间
1374
1404
  if (!liveStatus.liveStartTimeInit) {
@@ -1377,19 +1407,17 @@ class ComRegister {
1377
1407
  // 设置开播时间初始化状态
1378
1408
  liveStatus.liveStartTimeInit = true;
1379
1409
  }
1380
- // 获取watched
1381
- const watched = "暂未获取到";
1382
1410
  // 设置直播中消息
1383
1411
  const liveMsg = this.config.customLive
1384
1412
  ? this.config.customLive
1385
1413
  .replace("-name", liveStatus.masterInfo.username)
1386
1414
  .replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime))
1387
- .replace("-watched", watched)
1415
+ .replace("-watched", "")
1388
1416
  .replace("\\n", "\n")
1389
1417
  .replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
1390
1418
  : null;
1391
1419
  // 发送直播通知卡片
1392
- await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, watched, {
1420
+ await this.sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, "API", {
1393
1421
  liveRoomInfo: liveStatus.liveRoomInfo,
1394
1422
  masterInfo: liveStatus.masterInfo,
1395
1423
  cardStyle: sub.card,
@@ -194,7 +194,7 @@ class GenerateImg extends koishi_1.Service {
194
194
  ${liveStatus === 1
195
195
  ? `当前粉丝数:${followerDisplay}`
196
196
  : liveStatus === 2
197
- ? `累计观看人数:${followerDisplay}`
197
+ ? `${followerDisplay !== "API" ? `粉丝数变化:${followerDisplay}` : ""}`
198
198
  : liveStatus === 3
199
199
  ? `粉丝数变化:${followerDisplay}`
200
200
  : ""}
package/lib/index.js CHANGED
@@ -324,7 +324,8 @@ exports.Config = koishi_1.Schema.object({
324
324
  liveDetectType: koishi_1.Schema.union(["WS", "API"])
325
325
  .role("radio")
326
326
  .default("WS")
327
- .description("直播检测方式,WS为连接到B站弹幕服务器,API为通过轮询发送请求监测,默认使用WS检测"),
327
+ .description("直播检测方式,WS为连接到B站弹幕服务器,API为通过轮询发送请求监测,默认使用WS检测")
328
+ .experimental(),
328
329
  restartPush: koishi_1.Schema.boolean()
329
330
  .default(true)
330
331
  .description("插件重启后,如果订阅的主播正在直播,是否进行一次推送,默认开启"),
@@ -396,6 +397,5 @@ exports.Config = koishi_1.Schema.object({
396
397
  debug: koishi_1.Schema.object({}).description("调试设置"),
397
398
  dynamicDebugMode: koishi_1.Schema.boolean()
398
399
  .default(false)
399
- .description("动态调试模式,开启后会在控制台输出动态推送的详细信息,用于调试")
400
- .experimental(),
400
+ .description("动态调试模式,开启后会在控制台输出动态推送的详细信息,用于调试"),
401
401
  });
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.2.0-alpha.0",
4
+ "version": "3.2.0-alpha.2",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -249,6 +249,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
249
249
  - ver 3.1.7-alpha.3 修复:推送视频类动态报错;
250
250
  - ver 3.1.7 修复:第一次使用插件报错 `TypeError: Cannot read properties of undefined (reading 'dynamic_group_id')`
251
251
  - ver 3.2.0-alpha.0 新增:直播检测 `API` 模式; 优化:提升直播检测 `WS` 模式使用体验;
252
+ - ver 3.2.0-alpha.1 修复:直播检测 `API` 模式,中途加入推送语无法正确显示直播时长;
253
+ - ver 3.2.0-alpha.2 修复:直播检测 `API` 模式,请求错误优化(防止不停向QQ发送消息);
252
254
 
253
255
  ## 交流群
254
256