koishi-plugin-bilibili-notify 3.3.1-rc.1 → 3.3.1-rc.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.
package/lib/index.d.mts CHANGED
@@ -87,7 +87,9 @@ type CustomLiveSummary = {
87
87
  liveSummary?: string;
88
88
  };
89
89
  type Subscription = {
90
+ uname: string;
90
91
  uid: string;
92
+ roomid: string;
91
93
  dynamic: boolean;
92
94
  live: boolean;
93
95
  target: Target;
package/lib/index.d.ts CHANGED
@@ -87,7 +87,9 @@ type CustomLiveSummary = {
87
87
  liveSummary?: string;
88
88
  };
89
89
  type Subscription = {
90
+ uname: string;
90
91
  uid: string;
92
+ roomid: string;
91
93
  dynamic: boolean;
92
94
  live: boolean;
93
95
  target: Target;
package/lib/index.js CHANGED
@@ -74,7 +74,7 @@ const BAConfigSchema = koishi.Schema.object({
74
74
  advancedSub: koishi.Schema.boolean().default(false).description("是否开启高级订阅,若开启高级订阅,请打开该选项并下载插件 bilibili-notify-advanced-subscription"),
75
75
  subs: koishi.Schema.array(koishi.Schema.object({
76
76
  name: koishi.Schema.string().required().description("备注"),
77
- uid: koishi.Schema.string().required().description("UID"),
77
+ uid: koishi.Schema.string().required().description("UID和roomid"),
78
78
  dynamic: koishi.Schema.boolean().default(true).description("动态"),
79
79
  dynamicAtAll: koishi.Schema.boolean().default(false).description("动态At全体"),
80
80
  live: koishi.Schema.boolean().default(true).description("直播"),
@@ -84,7 +84,7 @@ const BAConfigSchema = koishi.Schema.object({
84
84
  liveSummary: koishi.Schema.boolean().default(true).description("直播总结"),
85
85
  platform: koishi.Schema.string().required().description("平台名"),
86
86
  target: koishi.Schema.string().required().description("群号/频道号")
87
- })).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
87
+ })).role("table").description("输入订阅信息,自定义订阅内容; UID和roomid,如果经常在初始化插件遇到风控问题,请补充直播间房间号,使用英文逗号分隔例如,1234567,114514 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
88
88
  dynamic: koishi.Schema.object({}).description("动态推送设置"),
89
89
  dynamicUrl: koishi.Schema.boolean().default(false).description("发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!"),
90
90
  dynamicCron: koishi.Schema.string().default("*/2 * * * *").description("动态监测时间,请填入cron表达式,请勿填入过短时间"),
@@ -751,8 +751,11 @@ var ComRegister = class {
751
751
  channelArr,
752
752
  platform: s.platform
753
753
  }];
754
+ const [uid, roomid] = s.uid.split(",");
754
755
  subs[s.name] = {
755
- uid: s.uid,
756
+ uname: s.name,
757
+ uid,
758
+ roomid,
756
759
  dynamic: s.dynamic,
757
760
  live: s.live,
758
761
  target,
@@ -1193,7 +1196,7 @@ var ComRegister = class {
1193
1196
  addUserToDanmakuMaker(username, danmakuMakerRecord) {
1194
1197
  danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
1195
1198
  }
1196
- async liveDetectWithListener(roomId, sub) {
1199
+ async liveDetectWithListener(sub) {
1197
1200
  let liveTime;
1198
1201
  let pushAtTimeTimer;
1199
1202
  const danmakuWeightRecord = {};
@@ -1206,7 +1209,17 @@ var ComRegister = class {
1206
1209
  const sendDanmakuWordCloudAndLiveSummary = async (customLiveSummary) => {
1207
1210
  this.logger.info("开始制作弹幕词云");
1208
1211
  this.logger.info("正在获取前90热词");
1209
- const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
1212
+ const words = Object.entries(danmakuWeightRecord);
1213
+ const danmaker = Object.entries(danmakuMakerRecord);
1214
+ if (words.length < 50) {
1215
+ this.logger.info("热词不足50个,本次弹幕词云放弃");
1216
+ return;
1217
+ }
1218
+ if (danmaker.length < 5) {
1219
+ this.logger.info("发言人数不足5位,本次弹幕词云放弃");
1220
+ return;
1221
+ }
1222
+ const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
1210
1223
  this.logger.info("弹幕词云前90词及权重:");
1211
1224
  this.logger.info(top90Words);
1212
1225
  this.logger.info("正在准备生成弹幕词云");
@@ -1243,7 +1256,7 @@ var ComRegister = class {
1243
1256
  };
1244
1257
  const useMasterAndLiveRoomInfo = async (liveType) => {
1245
1258
  let flag = true;
1246
- liveRoomInfo = await this.useLiveRoomInfo(roomId).catch(() => {
1259
+ liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
1247
1260
  flag = false;
1248
1261
  return null;
1249
1262
  });
@@ -1261,9 +1274,9 @@ var ComRegister = class {
1261
1274
  onError: async () => {
1262
1275
  liveStatus = false;
1263
1276
  pushAtTimeTimer?.();
1264
- this.ctx["bilibili-notify-live"].closeListener(roomId);
1265
- await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
1266
- this.logger.error(`[${roomId}]直播间连接发生错误!`);
1277
+ this.ctx["bilibili-notify-live"].closeListener(sub.roomid);
1278
+ await this.sendPrivateMsg(`[${sub.roomid}]直播间连接发生错误!`);
1279
+ this.logger.error(`[${sub.roomid}]直播间连接发生错误!`);
1267
1280
  },
1268
1281
  onIncomeDanmu: ({ body }) => {
1269
1282
  this.segmentDanmaku(body.content, danmakuWeightRecord);
@@ -1306,7 +1319,7 @@ var ComRegister = class {
1306
1319
  }, sub.uid, liveStartMsg);
1307
1320
  if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
1308
1321
  pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1309
- this.liveWSManager.set(roomId, pushAtTimeTimer);
1322
+ this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
1310
1323
  }
1311
1324
  },
1312
1325
  onLiveEnd: async () => {
@@ -1332,7 +1345,7 @@ var ComRegister = class {
1332
1345
  await sendDanmakuWordCloudAndLiveSummary(liveMsgObj.liveSummary);
1333
1346
  }
1334
1347
  };
1335
- await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
1348
+ await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
1336
1349
  if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1337
1350
  if (liveRoomInfo.live_status === 1) {
1338
1351
  liveTime = liveRoomInfo.live_time;
@@ -1345,7 +1358,7 @@ var ComRegister = class {
1345
1358
  }, sub.uid, liveMsg);
1346
1359
  if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
1347
1360
  pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1348
- this.liveWSManager.set(roomId, pushAtTimeTimer);
1361
+ this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
1349
1362
  }
1350
1363
  liveStatus = true;
1351
1364
  }
@@ -1653,40 +1666,42 @@ var ComRegister = class {
1653
1666
  this.preInitConfig(subs);
1654
1667
  for (const sub of Object.values(subs)) {
1655
1668
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1656
- const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1657
- const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1658
- return data;
1659
- }).catch((e) => {
1660
- this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1661
- return {
1662
- code: -1,
1663
- message: `加载订阅UID:${sub.uid}失败!`
1664
- };
1665
- });
1666
- if (userInfoCode === -352 && userInfoData.v_voucher) {
1667
- this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
1668
- await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1669
- return {
1669
+ if (!sub.roomid) {
1670
+ this.logger.info(`UID:${sub.uid}请求了用户接口~`);
1671
+ const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1672
+ const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1673
+ return data;
1674
+ }).catch((e) => {
1675
+ this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1676
+ return {
1677
+ code: -1,
1678
+ message: `加载订阅UID:${sub.uid}失败!`
1679
+ };
1680
+ });
1681
+ if (userInfoCode === -352 && userInfoData.v_voucher) {
1682
+ this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
1683
+ await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1684
+ return {
1685
+ code: userInfoCode,
1686
+ message: userInfoMsg
1687
+ };
1688
+ }
1689
+ if (userInfoCode !== 0) return {
1670
1690
  code: userInfoCode,
1671
1691
  message: userInfoMsg
1672
1692
  };
1673
- }
1674
- if (userInfoCode !== 0) return {
1675
- code: userInfoCode,
1676
- message: userInfoMsg
1677
- };
1678
- if (this.config.liveDetectType === "WS" && sub.live) {
1679
- if (!userInfoData.live_room) {
1693
+ if (sub.live && !userInfoData.live_room) {
1680
1694
  sub.live = false;
1681
1695
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1682
1696
  }
1683
- if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
1697
+ sub.roomid = userInfoData.live_room.roomid;
1684
1698
  }
1699
+ if (sub.live && sub.roomid && this.config.liveDetectType === "WS") await this.liveDetectWithListener(sub);
1685
1700
  const subInfo = await this.subUserInBili(sub.uid);
1686
1701
  if (subInfo.code !== 0) return subInfo;
1687
1702
  this.subManager.set(sub.uid, {
1688
- uname: userInfoData.name,
1689
- roomId: sub.live ? userInfoData.live_room.roomid : "",
1703
+ uname: sub.uname,
1704
+ roomId: sub.roomid,
1690
1705
  target: sub.target,
1691
1706
  live: sub.live,
1692
1707
  dynamic: sub.dynamic,
package/lib/index.mjs CHANGED
@@ -55,7 +55,7 @@ const BAConfigSchema = Schema.object({
55
55
  advancedSub: Schema.boolean().default(false).description("是否开启高级订阅,若开启高级订阅,请打开该选项并下载插件 bilibili-notify-advanced-subscription"),
56
56
  subs: Schema.array(Schema.object({
57
57
  name: Schema.string().required().description("备注"),
58
- uid: Schema.string().required().description("UID"),
58
+ uid: Schema.string().required().description("UID和roomid"),
59
59
  dynamic: Schema.boolean().default(true).description("动态"),
60
60
  dynamicAtAll: Schema.boolean().default(false).description("动态At全体"),
61
61
  live: Schema.boolean().default(true).description("直播"),
@@ -65,7 +65,7 @@ const BAConfigSchema = Schema.object({
65
65
  liveSummary: Schema.boolean().default(true).description("直播总结"),
66
66
  platform: Schema.string().required().description("平台名"),
67
67
  target: Schema.string().required().description("群号/频道号")
68
- })).role("table").description("输入订阅信息,自定义订阅内容; 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
68
+ })).role("table").description("输入订阅信息,自定义订阅内容; UID和roomid,如果经常在初始化插件遇到风控问题,请补充直播间房间号,使用英文逗号分隔例如,1234567,114514 群号/频道号格式:频道号,频道号 使用英文逗号分隔,例如 1234567,2345678"),
69
69
  dynamic: Schema.object({}).description("动态推送设置"),
70
70
  dynamicUrl: Schema.boolean().default(false).description("发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!"),
71
71
  dynamicCron: Schema.string().default("*/2 * * * *").description("动态监测时间,请填入cron表达式,请勿填入过短时间"),
@@ -732,8 +732,11 @@ var ComRegister = class {
732
732
  channelArr,
733
733
  platform: s.platform
734
734
  }];
735
+ const [uid, roomid] = s.uid.split(",");
735
736
  subs[s.name] = {
736
- uid: s.uid,
737
+ uname: s.name,
738
+ uid,
739
+ roomid,
737
740
  dynamic: s.dynamic,
738
741
  live: s.live,
739
742
  target,
@@ -1174,7 +1177,7 @@ var ComRegister = class {
1174
1177
  addUserToDanmakuMaker(username, danmakuMakerRecord) {
1175
1178
  danmakuMakerRecord[username] = (danmakuMakerRecord[username] || 0) + 1;
1176
1179
  }
1177
- async liveDetectWithListener(roomId, sub) {
1180
+ async liveDetectWithListener(sub) {
1178
1181
  let liveTime;
1179
1182
  let pushAtTimeTimer;
1180
1183
  const danmakuWeightRecord = {};
@@ -1187,7 +1190,17 @@ var ComRegister = class {
1187
1190
  const sendDanmakuWordCloudAndLiveSummary = async (customLiveSummary) => {
1188
1191
  this.logger.info("开始制作弹幕词云");
1189
1192
  this.logger.info("正在获取前90热词");
1190
- const top90Words = Object.entries(danmakuWeightRecord).sort((a, b) => b[1] - a[1]).slice(0, 90);
1193
+ const words = Object.entries(danmakuWeightRecord);
1194
+ const danmaker = Object.entries(danmakuMakerRecord);
1195
+ if (words.length < 50) {
1196
+ this.logger.info("热词不足50个,本次弹幕词云放弃");
1197
+ return;
1198
+ }
1199
+ if (danmaker.length < 5) {
1200
+ this.logger.info("发言人数不足5位,本次弹幕词云放弃");
1201
+ return;
1202
+ }
1203
+ const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
1191
1204
  this.logger.info("弹幕词云前90词及权重:");
1192
1205
  this.logger.info(top90Words);
1193
1206
  this.logger.info("正在准备生成弹幕词云");
@@ -1224,7 +1237,7 @@ var ComRegister = class {
1224
1237
  };
1225
1238
  const useMasterAndLiveRoomInfo = async (liveType) => {
1226
1239
  let flag = true;
1227
- liveRoomInfo = await this.useLiveRoomInfo(roomId).catch(() => {
1240
+ liveRoomInfo = await this.useLiveRoomInfo(sub.roomid).catch(() => {
1228
1241
  flag = false;
1229
1242
  return null;
1230
1243
  });
@@ -1242,9 +1255,9 @@ var ComRegister = class {
1242
1255
  onError: async () => {
1243
1256
  liveStatus = false;
1244
1257
  pushAtTimeTimer?.();
1245
- this.ctx["bilibili-notify-live"].closeListener(roomId);
1246
- await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
1247
- this.logger.error(`[${roomId}]直播间连接发生错误!`);
1258
+ this.ctx["bilibili-notify-live"].closeListener(sub.roomid);
1259
+ await this.sendPrivateMsg(`[${sub.roomid}]直播间连接发生错误!`);
1260
+ this.logger.error(`[${sub.roomid}]直播间连接发生错误!`);
1248
1261
  },
1249
1262
  onIncomeDanmu: ({ body }) => {
1250
1263
  this.segmentDanmaku(body.content, danmakuWeightRecord);
@@ -1287,7 +1300,7 @@ var ComRegister = class {
1287
1300
  }, sub.uid, liveStartMsg);
1288
1301
  if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
1289
1302
  pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1290
- this.liveWSManager.set(roomId, pushAtTimeTimer);
1303
+ this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
1291
1304
  }
1292
1305
  },
1293
1306
  onLiveEnd: async () => {
@@ -1313,7 +1326,7 @@ var ComRegister = class {
1313
1326
  await sendDanmakuWordCloudAndLiveSummary(liveMsgObj.liveSummary);
1314
1327
  }
1315
1328
  };
1316
- await this.ctx["bilibili-notify-live"].startLiveRoomListener(roomId, handler);
1329
+ await this.ctx["bilibili-notify-live"].startLiveRoomListener(sub.roomid, handler);
1317
1330
  if (!await useMasterAndLiveRoomInfo(LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1318
1331
  if (liveRoomInfo.live_status === 1) {
1319
1332
  liveTime = liveRoomInfo.live_time;
@@ -1326,7 +1339,7 @@ var ComRegister = class {
1326
1339
  }, sub.uid, liveMsg);
1327
1340
  if (this.config.pushTime !== 0 && !pushAtTimeTimer) {
1328
1341
  pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1329
- this.liveWSManager.set(roomId, pushAtTimeTimer);
1342
+ this.liveWSManager.set(sub.roomid, pushAtTimeTimer);
1330
1343
  }
1331
1344
  liveStatus = true;
1332
1345
  }
@@ -1634,40 +1647,42 @@ var ComRegister = class {
1634
1647
  this.preInitConfig(subs);
1635
1648
  for (const sub of Object.values(subs)) {
1636
1649
  this.logger.info(`加载订阅UID:${sub.uid}中...`);
1637
- const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1638
- const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1639
- return data;
1640
- }).catch((e) => {
1641
- this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1642
- return {
1643
- code: -1,
1644
- message: `加载订阅UID:${sub.uid}失败!`
1645
- };
1646
- });
1647
- if (userInfoCode === -352 && userInfoData.v_voucher) {
1648
- this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
1649
- await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1650
- return {
1650
+ if (!sub.roomid) {
1651
+ this.logger.info(`UID:${sub.uid}请求了用户接口~`);
1652
+ const { code: userInfoCode, message: userInfoMsg, data: userInfoData } = await withRetry(async () => {
1653
+ const data = await this.ctx["bilibili-notify-api"].getUserInfo(sub.uid);
1654
+ return data;
1655
+ }).catch((e) => {
1656
+ this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1657
+ return {
1658
+ code: -1,
1659
+ message: `加载订阅UID:${sub.uid}失败!`
1660
+ };
1661
+ });
1662
+ if (userInfoCode === -352 && userInfoData.v_voucher) {
1663
+ this.logger.info("账号被风控,请使用指令 bili cap 进行风控验证");
1664
+ await this.sendPrivateMsg("账号被风控,请使用指令 bili cap 进行风控验证");
1665
+ return {
1666
+ code: userInfoCode,
1667
+ message: userInfoMsg
1668
+ };
1669
+ }
1670
+ if (userInfoCode !== 0) return {
1651
1671
  code: userInfoCode,
1652
1672
  message: userInfoMsg
1653
1673
  };
1654
- }
1655
- if (userInfoCode !== 0) return {
1656
- code: userInfoCode,
1657
- message: userInfoMsg
1658
- };
1659
- if (this.config.liveDetectType === "WS" && sub.live) {
1660
- if (!userInfoData.live_room) {
1674
+ if (sub.live && !userInfoData.live_room) {
1661
1675
  sub.live = false;
1662
1676
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1663
1677
  }
1664
- if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub);
1678
+ sub.roomid = userInfoData.live_room.roomid;
1665
1679
  }
1680
+ if (sub.live && sub.roomid && this.config.liveDetectType === "WS") await this.liveDetectWithListener(sub);
1666
1681
  const subInfo = await this.subUserInBili(sub.uid);
1667
1682
  if (subInfo.code !== 0) return subInfo;
1668
1683
  this.subManager.set(sub.uid, {
1669
- uname: userInfoData.name,
1670
- roomId: sub.live ? userInfoData.live_room.roomid : "",
1684
+ uname: sub.uname,
1685
+ roomId: sub.roomid,
1671
1686
  target: sub.target,
1672
1687
  live: sub.live,
1673
1688
  dynamic: sub.dynamic,
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.1-rc.1",
4
+ "version": "3.3.1-rc.2",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -329,6 +329,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
329
329
  > - ver 3.3.1-alpha.1 优化:拆分 `wordcloud` 和 `liveSummary`,优化指令 `bili cap` 风控验证;
330
330
  > - ver 3.3.1-rc.0 优化:代码结构,部分设置; 修复:启用高级订阅时,多次重载高级订阅插件会产生多个重复订阅;
331
331
  > - ver 3.3.1-rc.1 优化:动态错误处理
332
+ > - ver 3.3.1-rc.2 新增:订阅UID项可填写roomid,在目前版本可以极大降低风控概率;
332
333
 
333
334
  ## 交流群
334
335