koishi-plugin-bilibili-notify 3.3.11-alpha.4 → 3.3.12-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.
Files changed (3) hide show
  1. package/lib/index.js +35 -20
  2. package/lib/index.mjs +35 -20
  3. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -710,6 +710,7 @@ var ComRegister = class {
710
710
  for (const uname of Object.keys(subs)) subs[uname].uname = uname;
711
711
  }
712
712
  async initAsyncPart(subs) {
713
+ this.ctx["bilibili-notify-live"].clearListeners();
713
714
  this.logger.info("获取到订阅信息,开始加载订阅...");
714
715
  const groupInfoResult = await this.getGroupInfo();
715
716
  if (groupInfoResult.code !== 0) {
@@ -1244,25 +1245,29 @@ var ComRegister = class {
1244
1245
  this.logger.info("正在获取前90热词");
1245
1246
  const words = Object.entries(danmakuWeightRecord);
1246
1247
  const danmaker = Object.entries(danmakuMakerRecord);
1247
- if (words.length < 50) {
1248
- this.logger.info("热词不足50个,本次弹幕词云放弃");
1249
- return;
1250
- }
1251
- if (danmaker.length < 5) {
1252
- this.logger.info("发言人数不足5位,本次弹幕词云放弃");
1253
- return;
1254
- }
1255
- const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
1256
- this.logger.info("弹幕词云前90词及权重:");
1257
- this.logger.info(top90Words);
1258
- this.logger.info("正在准备生成弹幕词云");
1259
- const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1260
- const img = koishi.h.image(buffer, "image/jpeg");
1261
- this.logger.info("开始构建弹幕发送排行榜消息");
1262
- const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1263
- const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1264
- const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1265
- const summary = customLiveSummary.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");
1248
+ const img = (async () => {
1249
+ if (words.length < 50) {
1250
+ this.logger.info("热词不足50个,本次弹幕词云放弃");
1251
+ return;
1252
+ }
1253
+ const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
1254
+ this.logger.info("弹幕词云前90词及权重:");
1255
+ this.logger.info(top90Words);
1256
+ this.logger.info("正在准备生成弹幕词云");
1257
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1258
+ return koishi.h.image(buffer, "image/jpeg");
1259
+ })();
1260
+ const summary = (() => {
1261
+ if (danmaker.length < 5) {
1262
+ this.logger.info("发言人数不足5位,本次弹幕词云放弃");
1263
+ return;
1264
+ }
1265
+ this.logger.info("开始构建弹幕发送排行榜消息");
1266
+ const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1267
+ const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1268
+ const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1269
+ return customLiveSummary.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");
1270
+ })();
1266
1271
  await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
1267
1272
  Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
1268
1273
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
@@ -4164,9 +4169,13 @@ var BLive = class extends koishi.Service {
4164
4169
  super(ctx, "bilibili-notify-live");
4165
4170
  }
4166
4171
  stop() {
4167
- for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
4172
+ this.clearListeners();
4168
4173
  }
4169
4174
  async startLiveRoomListener(roomId, handler) {
4175
+ if (this.listenerRecord[roomId]) {
4176
+ this.logger.warn(`[${roomId}]直播间连接已存在,无法重复创建!`);
4177
+ return;
4178
+ }
4170
4179
  const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
4171
4180
  const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
4172
4181
  this.listenerRecord[roomId] = (0, blive_message_listener.startListen)(Number.parseInt(roomId), handler, { ws: {
@@ -4185,6 +4194,12 @@ var BLive = class extends koishi.Service {
4185
4194
  }
4186
4195
  this.logger.warn(`${roomId}直播间连接未成功关闭`);
4187
4196
  }
4197
+ clearListeners() {
4198
+ for (const key of Object.keys(this.listenerRecord)) {
4199
+ this.closeListener(key);
4200
+ delete this.listenerRecord[key];
4201
+ }
4202
+ }
4188
4203
  };
4189
4204
  var bili_live_default = BLive;
4190
4205
 
package/lib/index.mjs CHANGED
@@ -692,6 +692,7 @@ var ComRegister = class {
692
692
  for (const uname of Object.keys(subs)) subs[uname].uname = uname;
693
693
  }
694
694
  async initAsyncPart(subs) {
695
+ this.ctx["bilibili-notify-live"].clearListeners();
695
696
  this.logger.info("获取到订阅信息,开始加载订阅...");
696
697
  const groupInfoResult = await this.getGroupInfo();
697
698
  if (groupInfoResult.code !== 0) {
@@ -1226,25 +1227,29 @@ var ComRegister = class {
1226
1227
  this.logger.info("正在获取前90热词");
1227
1228
  const words = Object.entries(danmakuWeightRecord);
1228
1229
  const danmaker = Object.entries(danmakuMakerRecord);
1229
- if (words.length < 50) {
1230
- this.logger.info("热词不足50个,本次弹幕词云放弃");
1231
- return;
1232
- }
1233
- if (danmaker.length < 5) {
1234
- this.logger.info("发言人数不足5位,本次弹幕词云放弃");
1235
- return;
1236
- }
1237
- const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
1238
- this.logger.info("弹幕词云前90词及权重:");
1239
- this.logger.info(top90Words);
1240
- this.logger.info("正在准备生成弹幕词云");
1241
- const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1242
- const img = h.image(buffer, "image/jpeg");
1243
- this.logger.info("开始构建弹幕发送排行榜消息");
1244
- const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1245
- const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1246
- const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1247
- const summary = customLiveSummary.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");
1230
+ const img = (async () => {
1231
+ if (words.length < 50) {
1232
+ this.logger.info("热词不足50个,本次弹幕词云放弃");
1233
+ return;
1234
+ }
1235
+ const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
1236
+ this.logger.info("弹幕词云前90词及权重:");
1237
+ this.logger.info(top90Words);
1238
+ this.logger.info("正在准备生成弹幕词云");
1239
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
1240
+ return h.image(buffer, "image/jpeg");
1241
+ })();
1242
+ const summary = (() => {
1243
+ if (danmaker.length < 5) {
1244
+ this.logger.info("发言人数不足5位,本次弹幕词云放弃");
1245
+ return;
1246
+ }
1247
+ this.logger.info("开始构建弹幕发送排行榜消息");
1248
+ const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
1249
+ const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
1250
+ const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
1251
+ return customLiveSummary.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");
1252
+ })();
1248
1253
  await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
1249
1254
  Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
1250
1255
  Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
@@ -4146,9 +4151,13 @@ var BLive = class extends Service {
4146
4151
  super(ctx, "bilibili-notify-live");
4147
4152
  }
4148
4153
  stop() {
4149
- for (const key of Object.keys(this.listenerRecord)) this.closeListener(key);
4154
+ this.clearListeners();
4150
4155
  }
4151
4156
  async startLiveRoomListener(roomId, handler) {
4157
+ if (this.listenerRecord[roomId]) {
4158
+ this.logger.warn(`[${roomId}]直播间连接已存在,无法重复创建!`);
4159
+ return;
4160
+ }
4152
4161
  const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
4153
4162
  const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
4154
4163
  this.listenerRecord[roomId] = startListen(Number.parseInt(roomId), handler, { ws: {
@@ -4167,6 +4176,12 @@ var BLive = class extends Service {
4167
4176
  }
4168
4177
  this.logger.warn(`${roomId}直播间连接未成功关闭`);
4169
4178
  }
4179
+ clearListeners() {
4180
+ for (const key of Object.keys(this.listenerRecord)) {
4181
+ this.closeListener(key);
4182
+ delete this.listenerRecord[key];
4183
+ }
4184
+ }
4170
4185
  };
4171
4186
  var bili_live_default = BLive;
4172
4187
 
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.11-alpha.4",
4
+ "version": "3.3.12-alpha.0",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [