koishi-plugin-bilibili-notify 3.2.9-alpha.0 → 3.2.9-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.
package/lib/index.js CHANGED
@@ -796,6 +796,61 @@ var ComRegister = class {
796
796
  });
797
797
  buffer && await session.send(koishi.h.image(buffer, "image/jpeg"));
798
798
  });
799
+ biliCom.subcommand(".wc").action(async ({ session }) => {
800
+ const words = [
801
+ ["kq8z1", 57],
802
+ ["v2n3a", 142],
803
+ ["b7x9p", 13],
804
+ ["w4m2s", 199],
805
+ ["t1j6u", 85],
806
+ ["z8c5l", 120],
807
+ ["h3r7y", 34],
808
+ ["n6d2q", 178],
809
+ ["p9s4e", 66],
810
+ ["f2g8b", 101],
811
+ ["m5v1k", 12],
812
+ ["x7a3w", 154],
813
+ ["c4t9z", 47],
814
+ ["u1b6n", 193],
815
+ ["e8y2h", 23],
816
+ ["j3l7p", 88],
817
+ ["s6q4d", 132],
818
+ ["g9m5x", 59],
819
+ ["a2w8c", 175],
820
+ ["l5h1v", 99],
821
+ ["y7k3t", 41],
822
+ ["d4z9u", 186],
823
+ ["q1e6j", 27],
824
+ ["r8p2s", 112],
825
+ ["b3n7f", 73],
826
+ ["v6x4m", 160],
827
+ ["t9c5w", 53],
828
+ ["z2u8h", 141],
829
+ ["h5y1j", 36],
830
+ ["n7l3s", 190],
831
+ ["p4d9g", 18],
832
+ ["f1b6a", 124],
833
+ ["m8v2x", 62],
834
+ ["x3a7c", 157],
835
+ ["c6t4u", 44],
836
+ ["u9b5e", 183],
837
+ ["e2y8k", 29],
838
+ ["j1l6q", 91],
839
+ ["s8g3m", 138],
840
+ ["g5w1t", 55],
841
+ ["a7z4h", 172],
842
+ ["l2h8p", 97],
843
+ ["y5k1n", 39],
844
+ ["d7u3f", 188],
845
+ ["q4e9v", 21],
846
+ ["r1p6x", 117],
847
+ ["b8n5c", 70],
848
+ ["v3x7w", 163],
849
+ ["t6c4a", 49],
850
+ ["z9u2j", 146]
851
+ ];
852
+ await session.send(/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: koishi.h.image(await this.ctx.gi.generateWordCloudImg(words, "图云测试"), "image/jpg") }));
853
+ });
799
854
  }
800
855
  async init(config) {
801
856
  this.logger = this.ctx.logger("cr");
@@ -1238,6 +1293,11 @@ var ComRegister = class {
1238
1293
  let masterInfo;
1239
1294
  let watchedNum;
1240
1295
  const liveMsgObj = this.liveMsgManager.get(uid);
1296
+ const sendDanmakuWordCloud = async () => {
1297
+ const top50Words = Object.entries(danmakuWeightRecord).sort((a$1, b$2) => b$2[1] - a$1[1]).slice(0, 50);
1298
+ const buffer = await this.ctx.gi.generateWordCloudImg(top50Words, masterInfo.username);
1299
+ await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
1300
+ };
1241
1301
  const pushAtTimeFunc = async () => {
1242
1302
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1243
1303
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1344,6 +1404,7 @@ var ComRegister = class {
1344
1404
  const words = Object.entries(danmakuWeightRecord);
1345
1405
  const buffer = await this.ctx.gi.generateWordCloudImg(words, masterInfo.username);
1346
1406
  await this.broadcastToTargets(uid, koishi.h.image(buffer, "image/jpeg"), PushType.Live);
1407
+ await sendDanmakuWordCloud();
1347
1408
  }
1348
1409
  };
1349
1410
  await this.ctx.bl.startLiveRoomListener(roomId, handler);
@@ -94324,6 +94385,8 @@ var GenerateImg = class extends koishi.Service {
94324
94385
  });
94325
94386
  }
94326
94387
  async generateWordCloudImg(words, masterName) {
94388
+ const fontURL = (0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "font/HYZhengYuan-75W.ttf"));
94389
+ const wordcloudJS = (0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "static/wordcloud2.min.js"));
94327
94390
  const html = `
94328
94391
  <!DOCTYPE html>
94329
94392
  <html lang="zh-CN">
@@ -94333,10 +94396,16 @@ var GenerateImg = class extends koishi.Service {
94333
94396
  <title>高清词云展示</title>
94334
94397
  <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&display=swap" rel="stylesheet">
94335
94398
  <style>
94399
+ @font-face {
94400
+ font-family: "Custom Font";
94401
+ src: url(${fontURL});
94402
+ }
94403
+
94336
94404
  * {
94337
94405
  margin: 0;
94338
94406
  padding: 0;
94339
94407
  box-sizing: border-box;
94408
+ font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
94340
94409
  }
94341
94410
 
94342
94411
  html {
@@ -94390,7 +94459,7 @@ var GenerateImg = class extends koishi.Service {
94390
94459
  </div>
94391
94460
  </div>
94392
94461
 
94393
- <script src="https://cdn.jsdelivr.net/npm/wordcloud@1.1.2/src/wordcloud2.min.js"></script>
94462
+ <script src="${wordcloudJS}"></script>
94394
94463
  <script>
94395
94464
  const canvas = document.getElementById('wordCloudCanvas');
94396
94465
  const ctx = canvas.getContext('2d');
@@ -94408,10 +94477,25 @@ var GenerateImg = class extends koishi.Service {
94408
94477
 
94409
94478
  const words = ${JSON.stringify(words)}
94410
94479
 
94480
+ // 词云大小缩放
94481
+ const maxWeight = Math.max(...words.map(w => w[1]));
94482
+ const minWeight = Math.min(...words.map(w => w[1]));
94483
+
94484
+ // 设置最大字体大小、最小字体大小(以像素为单位)
94485
+ const maxFontSize = 60;
94486
+ const minFontSize = 14;
94487
+
94488
+ // 用映射函数代替 weightFactor
94489
+ function getWeightFactor(size) {
94490
+ if (maxWeight === minWeight) return maxFontSize; // 防止除0
94491
+ const ratio = (size - minWeight) / (maxWeight - minWeight);
94492
+ return minFontSize + (maxFontSize - minFontSize) * ratio;
94493
+ }
94494
+
94411
94495
  WordCloud(canvas, {
94412
94496
  list: words,
94413
94497
  gridSize: Math.round(8 * (cssWidth / 1024)), // 自动适配大小
94414
- weightFactor: size => size * (cssWidth / 1024) * 1.2,
94498
+ weightFactor: getWeightFactor,
94415
94499
  fontFamily: 'Quicksand, sans-serif',
94416
94500
  color: () => {
94417
94501
  const colors = ['#007CF0', '#00DFD8', '#7928CA', '#FF0080', '#FF4D4D', '#F9CB28'];
@@ -94657,6 +94741,7 @@ var BiliAPI = class extends koishi.Service {
94657
94741
  this.cacheable = new CacheableLookup();
94658
94742
  this.cacheable.install(node_http.default.globalAgent);
94659
94743
  this.cacheable.install(node_https.default.globalAgent);
94744
+ this.jar = new tough_cookie.CookieJar();
94660
94745
  await this.createNewClient();
94661
94746
  await this.loadCookiesFromDatabase();
94662
94747
  this.updateJob = new cron.CronJob("0 0 * * *", async () => {
@@ -94798,7 +94883,10 @@ var BiliAPI = class extends koishi.Service {
94798
94883
  return data$1;
94799
94884
  }
94800
94885
  async getCookieInfo(refreshToken) {
94801
- const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
94886
+ const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e$1) => {
94887
+ this.logger.info(e$1.message);
94888
+ return null;
94889
+ });
94802
94890
  return data$1;
94803
94891
  }
94804
94892
  async getUserInfo(mid) {
@@ -94877,7 +94965,6 @@ var BiliAPI = class extends koishi.Service {
94877
94965
  }
94878
94966
  async createNewClient() {
94879
94967
  const wrapper = (await import("axios-cookiejar-support")).wrapper;
94880
- this.jar = new tough_cookie.CookieJar();
94881
94968
  this.client = wrapper(axios.default.create({
94882
94969
  jar: this.jar,
94883
94970
  headers: {
@@ -94891,7 +94978,6 @@ var BiliAPI = class extends koishi.Service {
94891
94978
  getCookies() {
94892
94979
  try {
94893
94980
  const cookies = this.jar.serializeSync().cookies.map((cookie) => {
94894
- if (!cookie.expires) cookie.expires = "Infinity";
94895
94981
  return cookie;
94896
94982
  });
94897
94983
  return JSON.stringify(cookies);
@@ -94971,10 +95057,15 @@ var BiliAPI = class extends koishi.Service {
94971
95057
  httpOnly = cookieData.httpOnly;
94972
95058
  sameSite = cookieData.sameSite;
94973
95059
  }
95060
+ const cdExpires = (() => {
95061
+ if (!cookieData.expires) return "Infinity";
95062
+ if (cookieData.expires !== "Infinity") return luxon.DateTime.fromISO(cookieData.expires).toJSDate();
95063
+ return cookieData.expires;
95064
+ })();
94974
95065
  const cookie = new tough_cookie.Cookie({
94975
95066
  key: cookieData.key,
94976
95067
  value: cookieData.value,
94977
- expires: cookieData.expires ? luxon.DateTime.fromISO(cookieData.expires).toJSDate() : "Infinity",
95068
+ expires: cdExpires,
94978
95069
  domain: cookieData.domain,
94979
95070
  path: cookieData.path,
94980
95071
  secure: cookieData.secure,
@@ -95021,7 +95112,7 @@ var BiliAPI = class extends koishi.Service {
95021
95112
  };
95022
95113
  try {
95023
95114
  const { data: data$1 } = await this.getCookieInfo(refreshToken);
95024
- if (!data$1.refresh) return;
95115
+ if (!data$1?.refresh) return;
95025
95116
  } catch (_$2) {
95026
95117
  if (times$1 >= 1) this.ctx.setTimeout(() => {
95027
95118
  this.checkIfTokenNeedRefresh(refreshToken, csrf, times$1 - 1);
@@ -95040,7 +95131,7 @@ var BiliAPI = class extends koishi.Service {
95040
95131
  const encrypted = new Uint8Array(await node_crypto.default.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data$1));
95041
95132
  return encrypted.reduce((str, c$1) => str + c$1.toString(16).padStart(2, "0"), "");
95042
95133
  }
95043
- const ts = luxon.DateTime.now().toSeconds();
95134
+ const ts = luxon.DateTime.now().toMillis();
95044
95135
  const correspondPath = await getCorrespondPath(ts);
95045
95136
  const { data: refreshCsrfHtml } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
95046
95137
  const { document: document$1 } = new jsdom.JSDOM(refreshCsrfHtml).window;
package/lib/index.mjs CHANGED
@@ -798,6 +798,61 @@ var ComRegister = class {
798
798
  });
799
799
  buffer && await session.send(h.image(buffer, "image/jpeg"));
800
800
  });
801
+ biliCom.subcommand(".wc").action(async ({ session }) => {
802
+ const words = [
803
+ ["kq8z1", 57],
804
+ ["v2n3a", 142],
805
+ ["b7x9p", 13],
806
+ ["w4m2s", 199],
807
+ ["t1j6u", 85],
808
+ ["z8c5l", 120],
809
+ ["h3r7y", 34],
810
+ ["n6d2q", 178],
811
+ ["p9s4e", 66],
812
+ ["f2g8b", 101],
813
+ ["m5v1k", 12],
814
+ ["x7a3w", 154],
815
+ ["c4t9z", 47],
816
+ ["u1b6n", 193],
817
+ ["e8y2h", 23],
818
+ ["j3l7p", 88],
819
+ ["s6q4d", 132],
820
+ ["g9m5x", 59],
821
+ ["a2w8c", 175],
822
+ ["l5h1v", 99],
823
+ ["y7k3t", 41],
824
+ ["d4z9u", 186],
825
+ ["q1e6j", 27],
826
+ ["r8p2s", 112],
827
+ ["b3n7f", 73],
828
+ ["v6x4m", 160],
829
+ ["t9c5w", 53],
830
+ ["z2u8h", 141],
831
+ ["h5y1j", 36],
832
+ ["n7l3s", 190],
833
+ ["p4d9g", 18],
834
+ ["f1b6a", 124],
835
+ ["m8v2x", 62],
836
+ ["x3a7c", 157],
837
+ ["c6t4u", 44],
838
+ ["u9b5e", 183],
839
+ ["e2y8k", 29],
840
+ ["j1l6q", 91],
841
+ ["s8g3m", 138],
842
+ ["g5w1t", 55],
843
+ ["a7z4h", 172],
844
+ ["l2h8p", 97],
845
+ ["y5k1n", 39],
846
+ ["d7u3f", 188],
847
+ ["q4e9v", 21],
848
+ ["r1p6x", 117],
849
+ ["b8n5c", 70],
850
+ ["v3x7w", 163],
851
+ ["t6c4a", 49],
852
+ ["z9u2j", 146]
853
+ ];
854
+ await session.send(/* @__PURE__ */ jsx("message", { children: h.image(await this.ctx.gi.generateWordCloudImg(words, "图云测试"), "image/jpg") }));
855
+ });
801
856
  }
802
857
  async init(config) {
803
858
  this.logger = this.ctx.logger("cr");
@@ -1240,6 +1295,11 @@ var ComRegister = class {
1240
1295
  let masterInfo;
1241
1296
  let watchedNum;
1242
1297
  const liveMsgObj = this.liveMsgManager.get(uid);
1298
+ const sendDanmakuWordCloud = async () => {
1299
+ const top50Words = Object.entries(danmakuWeightRecord).sort((a$1, b$2) => b$2[1] - a$1[1]).slice(0, 50);
1300
+ const buffer = await this.ctx.gi.generateWordCloudImg(top50Words, masterInfo.username);
1301
+ await this.broadcastToTargets(uid, h.image(buffer, "image/jpeg"), PushType.Live);
1302
+ };
1243
1303
  const pushAtTimeFunc = async () => {
1244
1304
  if (!await useMasterAndLiveRoomInfo(LiveType.LiveBroadcast)) {
1245
1305
  await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
@@ -1346,6 +1406,7 @@ var ComRegister = class {
1346
1406
  const words = Object.entries(danmakuWeightRecord);
1347
1407
  const buffer = await this.ctx.gi.generateWordCloudImg(words, masterInfo.username);
1348
1408
  await this.broadcastToTargets(uid, h.image(buffer, "image/jpeg"), PushType.Live);
1409
+ await sendDanmakuWordCloud();
1349
1410
  }
1350
1411
  };
1351
1412
  await this.ctx.bl.startLiveRoomListener(roomId, handler);
@@ -94326,6 +94387,8 @@ var GenerateImg = class extends Service {
94326
94387
  });
94327
94388
  }
94328
94389
  async generateWordCloudImg(words, masterName) {
94390
+ const fontURL = pathToFileURL(resolve$1(__dirname, "font/HYZhengYuan-75W.ttf"));
94391
+ const wordcloudJS = pathToFileURL(resolve$1(__dirname, "static/wordcloud2.min.js"));
94329
94392
  const html = `
94330
94393
  <!DOCTYPE html>
94331
94394
  <html lang="zh-CN">
@@ -94335,10 +94398,16 @@ var GenerateImg = class extends Service {
94335
94398
  <title>高清词云展示</title>
94336
94399
  <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@500&display=swap" rel="stylesheet">
94337
94400
  <style>
94401
+ @font-face {
94402
+ font-family: "Custom Font";
94403
+ src: url(${fontURL});
94404
+ }
94405
+
94338
94406
  * {
94339
94407
  margin: 0;
94340
94408
  padding: 0;
94341
94409
  box-sizing: border-box;
94410
+ font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
94342
94411
  }
94343
94412
 
94344
94413
  html {
@@ -94392,7 +94461,7 @@ var GenerateImg = class extends Service {
94392
94461
  </div>
94393
94462
  </div>
94394
94463
 
94395
- <script src="https://cdn.jsdelivr.net/npm/wordcloud@1.1.2/src/wordcloud2.min.js"></script>
94464
+ <script src="${wordcloudJS}"></script>
94396
94465
  <script>
94397
94466
  const canvas = document.getElementById('wordCloudCanvas');
94398
94467
  const ctx = canvas.getContext('2d');
@@ -94410,10 +94479,25 @@ var GenerateImg = class extends Service {
94410
94479
 
94411
94480
  const words = ${JSON.stringify(words)}
94412
94481
 
94482
+ // 词云大小缩放
94483
+ const maxWeight = Math.max(...words.map(w => w[1]));
94484
+ const minWeight = Math.min(...words.map(w => w[1]));
94485
+
94486
+ // 设置最大字体大小、最小字体大小(以像素为单位)
94487
+ const maxFontSize = 60;
94488
+ const minFontSize = 14;
94489
+
94490
+ // 用映射函数代替 weightFactor
94491
+ function getWeightFactor(size) {
94492
+ if (maxWeight === minWeight) return maxFontSize; // 防止除0
94493
+ const ratio = (size - minWeight) / (maxWeight - minWeight);
94494
+ return minFontSize + (maxFontSize - minFontSize) * ratio;
94495
+ }
94496
+
94413
94497
  WordCloud(canvas, {
94414
94498
  list: words,
94415
94499
  gridSize: Math.round(8 * (cssWidth / 1024)), // 自动适配大小
94416
- weightFactor: size => size * (cssWidth / 1024) * 1.2,
94500
+ weightFactor: getWeightFactor,
94417
94501
  fontFamily: 'Quicksand, sans-serif',
94418
94502
  color: () => {
94419
94503
  const colors = ['#007CF0', '#00DFD8', '#7928CA', '#FF0080', '#FF4D4D', '#F9CB28'];
@@ -94659,6 +94743,7 @@ var BiliAPI = class extends Service {
94659
94743
  this.cacheable = new CacheableLookup();
94660
94744
  this.cacheable.install(http.globalAgent);
94661
94745
  this.cacheable.install(https.globalAgent);
94746
+ this.jar = new CookieJar();
94662
94747
  await this.createNewClient();
94663
94748
  await this.loadCookiesFromDatabase();
94664
94749
  this.updateJob = new CronJob("0 0 * * *", async () => {
@@ -94800,7 +94885,10 @@ var BiliAPI = class extends Service {
94800
94885
  return data$1;
94801
94886
  }
94802
94887
  async getCookieInfo(refreshToken) {
94803
- const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
94888
+ const { data: data$1 } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`).catch((e$1) => {
94889
+ this.logger.info(e$1.message);
94890
+ return null;
94891
+ });
94804
94892
  return data$1;
94805
94893
  }
94806
94894
  async getUserInfo(mid) {
@@ -94879,7 +94967,6 @@ var BiliAPI = class extends Service {
94879
94967
  }
94880
94968
  async createNewClient() {
94881
94969
  const wrapper = (await import("axios-cookiejar-support")).wrapper;
94882
- this.jar = new CookieJar();
94883
94970
  this.client = wrapper(axios.create({
94884
94971
  jar: this.jar,
94885
94972
  headers: {
@@ -94893,7 +94980,6 @@ var BiliAPI = class extends Service {
94893
94980
  getCookies() {
94894
94981
  try {
94895
94982
  const cookies = this.jar.serializeSync().cookies.map((cookie) => {
94896
- if (!cookie.expires) cookie.expires = "Infinity";
94897
94983
  return cookie;
94898
94984
  });
94899
94985
  return JSON.stringify(cookies);
@@ -94973,10 +95059,15 @@ var BiliAPI = class extends Service {
94973
95059
  httpOnly = cookieData.httpOnly;
94974
95060
  sameSite = cookieData.sameSite;
94975
95061
  }
95062
+ const cdExpires = (() => {
95063
+ if (!cookieData.expires) return "Infinity";
95064
+ if (cookieData.expires !== "Infinity") return DateTime.fromISO(cookieData.expires).toJSDate();
95065
+ return cookieData.expires;
95066
+ })();
94976
95067
  const cookie = new Cookie({
94977
95068
  key: cookieData.key,
94978
95069
  value: cookieData.value,
94979
- expires: cookieData.expires ? DateTime.fromISO(cookieData.expires).toJSDate() : "Infinity",
95070
+ expires: cdExpires,
94980
95071
  domain: cookieData.domain,
94981
95072
  path: cookieData.path,
94982
95073
  secure: cookieData.secure,
@@ -95023,7 +95114,7 @@ var BiliAPI = class extends Service {
95023
95114
  };
95024
95115
  try {
95025
95116
  const { data: data$1 } = await this.getCookieInfo(refreshToken);
95026
- if (!data$1.refresh) return;
95117
+ if (!data$1?.refresh) return;
95027
95118
  } catch (_$2) {
95028
95119
  if (times$1 >= 1) this.ctx.setTimeout(() => {
95029
95120
  this.checkIfTokenNeedRefresh(refreshToken, csrf, times$1 - 1);
@@ -95042,7 +95133,7 @@ var BiliAPI = class extends Service {
95042
95133
  const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data$1));
95043
95134
  return encrypted.reduce((str, c$1) => str + c$1.toString(16).padStart(2, "0"), "");
95044
95135
  }
95045
- const ts = DateTime.now().toSeconds();
95136
+ const ts = DateTime.now().toMillis();
95046
95137
  const correspondPath = await getCorrespondPath(ts);
95047
95138
  const { data: refreshCsrfHtml } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
95048
95139
  const { document: document$1 } = new JSDOM(refreshCsrfHtml).window;
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.2",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -301,6 +301,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
301
301
 
302
302
  > [!CAUTION]
303
303
  > - ver 3.2.9-alpha.0 新增:弹幕词云; 不建议更新,目前仅做测试用!
304
+ > - ver 3.2.9-alpha.1 修复:弹幕词云显示问题,弹幕过多导致插件爆炸; 不建议更新,目前仅做测试用!
305
+ > - ver 3.2.9-alpha.2 修复:`AxiosError: Request failed with status code 404 xxx at async BiliAPI.checkIfTokenNeedRefresh`、潜在cookie相关bug、弹幕词云bug `Error: 生成图片失败!错误: TimeoutError: Navigation timeout of 30000 ms exceeded`
304
306
 
305
307
 
306
308
  ## 交流群