koishi-plugin-bilibili-notify 3.2.9-alpha.0 → 3.2.9-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.js CHANGED
@@ -1238,6 +1238,11 @@ var ComRegister = class {
1238
1238
  let masterInfo;
1239
1239
  let watchedNum;
1240
1240
  const liveMsgObj = this.liveMsgManager.get(uid);
1241
+ const sendDanmakuWordCloud = async () => {
1242
+ const top50Words = Object.entries(danmakuWeightRecord).sort((a$1, b$2) => b$2[1] - a$1[1]).slice(0, 50);
1243
+ const buffer = await this.ctx.gi.generateWordCloudImg(top50Words, masterInfo.username);
1244
+ await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
1245
+ };
1241
1246
  const pushAtTimeFunc = async () => {
1242
1247
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1243
1248
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1344,6 +1349,7 @@ var ComRegister = class {
1344
1349
  const words = Object.entries(danmakuWeightRecord);
1345
1350
  const buffer = await this.ctx.gi.generateWordCloudImg(words, masterInfo.username);
1346
1351
  await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
1352
+ await sendDanmakuWordCloud();
1347
1353
  }
1348
1354
  };
1349
1355
  await this.ctx.bl.startLiveRoomListener(roomId, handler);
@@ -94408,10 +94414,25 @@ var GenerateImg = class extends koishi.Service {
94408
94414
 
94409
94415
  const words = ${JSON.stringify(words)}
94410
94416
 
94417
+ // 词云大小缩放
94418
+ const maxWeight = Math.max(...words.map(w => w[1]));
94419
+ const minWeight = Math.min(...words.map(w => w[1]));
94420
+
94421
+ // 设置最大字体大小、最小字体大小(以像素为单位)
94422
+ const maxFontSize = 60;
94423
+ const minFontSize = 14;
94424
+
94425
+ // 用映射函数代替 weightFactor
94426
+ function getWeightFactor(size) {
94427
+ if (maxWeight === minWeight) return maxFontSize; // 防止除0
94428
+ const ratio = (size - minWeight) / (maxWeight - minWeight);
94429
+ return minFontSize + (maxFontSize - minFontSize) * ratio;
94430
+ }
94431
+
94411
94432
  WordCloud(canvas, {
94412
94433
  list: words,
94413
94434
  gridSize: Math.round(8 * (cssWidth / 1024)), // 自动适配大小
94414
- weightFactor: size => size * (cssWidth / 1024) * 1.2,
94435
+ weightFactor: getWeightFactor,
94415
94436
  fontFamily: 'Quicksand, sans-serif',
94416
94437
  color: () => {
94417
94438
  const colors = ['#007CF0', '#00DFD8', '#7928CA', '#FF0080', '#FF4D4D', '#F9CB28'];
@@ -94798,7 +94819,10 @@ var BiliAPI = class extends koishi.Service {
94798
94819
  return data$1;
94799
94820
  }
94800
94821
  async getCookieInfo(refreshToken) {
94801
- const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
94822
+ const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e$1) => {
94823
+ this.logger.info(e$1.message);
94824
+ return null;
94825
+ });
94802
94826
  return data$1;
94803
94827
  }
94804
94828
  async getUserInfo(mid) {
@@ -95021,7 +95045,7 @@ var BiliAPI = class extends koishi.Service {
95021
95045
  };
95022
95046
  try {
95023
95047
  const { data: data$1 } = await this.getCookieInfo(refreshToken);
95024
- if (!data$1.refresh) return;
95048
+ if (!data$1?.refresh) return;
95025
95049
  } catch (_$2) {
95026
95050
  if (times$1 >= 1) this.ctx.setTimeout(() => {
95027
95051
  this.checkIfTokenNeedRefresh(refreshToken, csrf, times$1 - 1);
package/lib/index.mjs CHANGED
@@ -1240,6 +1240,11 @@ var ComRegister = class {
1240
1240
  let masterInfo;
1241
1241
  let watchedNum;
1242
1242
  const liveMsgObj = this.liveMsgManager.get(uid);
1243
+ const sendDanmakuWordCloud = async () => {
1244
+ const top50Words = Object.entries(danmakuWeightRecord).sort((a$1, b$2) => b$2[1] - a$1[1]).slice(0, 50);
1245
+ const buffer = await this.ctx.gi.generateWordCloudImg(top50Words, masterInfo.username);
1246
+ await this.broadcastToTargets(uid, h.image(buffer, "image/jpeg"), PushType.Live);
1247
+ };
1243
1248
  const pushAtTimeFunc = async () => {
1244
1249
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1245
1250
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1346,6 +1351,7 @@ var ComRegister = class {
1346
1351
  const words = Object.entries(danmakuWeightRecord);
1347
1352
  const buffer = await this.ctx.gi.generateWordCloudImg(words, masterInfo.username);
1348
1353
  await this.broadcastToTargets(uid, h.image(buffer, "image/jpeg"), PushType.Live);
1354
+ await sendDanmakuWordCloud();
1349
1355
  }
1350
1356
  };
1351
1357
  await this.ctx.bl.startLiveRoomListener(roomId, handler);
@@ -94410,10 +94416,25 @@ var GenerateImg = class extends Service {
94410
94416
 
94411
94417
  const words = ${JSON.stringify(words)}
94412
94418
 
94419
+ // 词云大小缩放
94420
+ const maxWeight = Math.max(...words.map(w => w[1]));
94421
+ const minWeight = Math.min(...words.map(w => w[1]));
94422
+
94423
+ // 设置最大字体大小、最小字体大小(以像素为单位)
94424
+ const maxFontSize = 60;
94425
+ const minFontSize = 14;
94426
+
94427
+ // 用映射函数代替 weightFactor
94428
+ function getWeightFactor(size) {
94429
+ if (maxWeight === minWeight) return maxFontSize; // 防止除0
94430
+ const ratio = (size - minWeight) / (maxWeight - minWeight);
94431
+ return minFontSize + (maxFontSize - minFontSize) * ratio;
94432
+ }
94433
+
94413
94434
  WordCloud(canvas, {
94414
94435
  list: words,
94415
94436
  gridSize: Math.round(8 * (cssWidth / 1024)), // 自动适配大小
94416
- weightFactor: size => size * (cssWidth / 1024) * 1.2,
94437
+ weightFactor: getWeightFactor,
94417
94438
  fontFamily: 'Quicksand, sans-serif',
94418
94439
  color: () => {
94419
94440
  const colors = ['#007CF0', '#00DFD8', '#7928CA', '#FF0080', '#FF4D4D', '#F9CB28'];
@@ -94800,7 +94821,10 @@ var BiliAPI = class extends Service {
94800
94821
  return data$1;
94801
94822
  }
94802
94823
  async getCookieInfo(refreshToken) {
94803
- const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
94824
+ const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e$1) => {
94825
+ this.logger.info(e$1.message);
94826
+ return null;
94827
+ });
94804
94828
  return data$1;
94805
94829
  }
94806
94830
  async getUserInfo(mid) {
@@ -95023,7 +95047,7 @@ var BiliAPI = class extends Service {
95023
95047
  };
95024
95048
  try {
95025
95049
  const { data: data$1 } = await this.getCookieInfo(refreshToken);
95026
- if (!data$1.refresh) return;
95050
+ if (!data$1?.refresh) return;
95027
95051
  } catch (_$2) {
95028
95052
  if (times$1 >= 1) this.ctx.setTimeout(() => {
95029
95053
  this.checkIfTokenNeedRefresh(refreshToken, csrf, times$1 - 1);
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.9-alpha.0",
4
+ "version": "3.2.9-alpha.1",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -301,6 +301,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
301
301
 
302
302
  > [!CAUTION]
303
303
  > - ver 3.2.9-alpha.0 新增:弹幕词云; 不建议更新,目前仅做测试用!
304
+ > - ver 3.2.9-alpha.1 修复:弹幕词云显示问题,弹幕过多导致插件爆炸; 不建议更新,目前仅做测试用!
304
305
 
305
306
 
306
307
  ## 交流群