koishi-plugin-bilibili-notify 1.2.4 → 1.2.5

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.
@@ -7,8 +7,7 @@ const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
7
7
  const koishi_1 = require("koishi");
8
8
  // 导入qrcode
9
9
  const qrcode_1 = __importDefault(require("qrcode"));
10
- const axios_1 = __importDefault(require("axios"));
11
- const sharp_1 = __importDefault(require("sharp"));
10
+ const jimp_1 = __importDefault(require("jimp"));
12
11
  var LiveType;
13
12
  (function (LiveType) {
14
13
  LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
@@ -163,19 +162,9 @@ class ComRegister {
163
162
  this.logger.info('调用test gimg指令')
164
163
  // 获取主播信息
165
164
  const { data } = await ctx.biliAPI.getMasterInfo('194484313')
166
- // 获取图片二进制
167
- const resp = await axios({
168
- url: data.info.face,
169
- method: 'GET',
170
- responseType: 'arraybuffer'
165
+ const resizedImage = await Jimp.read(data.info.face).then(async image => {
166
+ return await image.resize(100, 100).getBufferAsync(Jimp.MIME_PNG)
171
167
  })
172
- // 使用sharp调整图片大小
173
- const resizedImage = await sharp(resp.data)
174
- .resize(100, 100, {
175
- kernel: sharp.kernel.lanczos3
176
- })
177
- .png({ compressionLevel: 9 })
178
- .toBuffer()
179
168
  // 发送下播提示语
180
169
  await session.send(
181
170
  <>{h.image(resizedImage, 'image/png')} 主播{data.info.uname}已下播</>
@@ -771,7 +760,8 @@ class ComRegister {
771
760
  }
772
761
  catch (e) {
773
762
  if (i === attempts - 1) { // 已尝试三次
774
- throw new Error(`发送群组ID:${guildId}消息失败!原因: ` + e.toString());
763
+ this.logger.error(`发送群组ID:${guildId}消息失败!原因: ` + e.toString());
764
+ this.sendPrivateMsg(bot, `发送群组ID:${guildId}消息失败,请检查机器人状态`);
775
765
  }
776
766
  }
777
767
  }
@@ -822,58 +812,54 @@ class ComRegister {
822
812
  continue;
823
813
  // 寻找发布时间比时间点更晚的动态
824
814
  if (items[num].modules.module_author.pub_ts > timePoint) {
815
+ // 定义变量
816
+ let pic;
817
+ let buffer;
818
+ // 从动态数据中取出UP主名称和动态ID
819
+ const upName = content.data.items[num].modules.module_author.name;
820
+ const dynamicId = content.data.items[num].id_str;
825
821
  // 推送该条动态
826
822
  let attempts = 3;
827
823
  for (let i = 0; i < attempts; i++) {
824
+ // 获取动态推送图片
828
825
  try {
829
- // 定义变量
830
- let pic;
831
- let buffer;
832
- // 从动态数据中取出UP主名称和动态ID
833
- const upName = content.data.items[num].modules.module_author.name;
834
- const dynamicId = content.data.items[num].id_str;
835
- // 判断是否需要发送URL
836
- const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
837
- // 获取动态推送图片
838
- try {
839
- // 渲染图片
840
- const { pic: gimgPic, buffer: gimgBuffer } = await ctx.gimg.generateDynamicImg(items[num]);
841
- pic = gimgPic;
842
- buffer = gimgBuffer;
843
- }
844
- catch (e) {
845
- // 直播开播动态,不做处理
846
- if (e.message === '直播开播动态,不做处理')
847
- break;
848
- if (e.message === '出现关键词,屏蔽该动态') {
849
- // 如果需要发送才发送
850
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
851
- break;
852
- }
853
- if (e.message === '已屏蔽转发动态') {
854
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
855
- break;
856
- }
857
- }
858
- // 如果pic存在,则直接返回pic
859
- if (pic) {
860
- // pic存在,使用的是render模式
861
- await this.sendMsg(ctx, guildId, bot, pic + dUrl);
862
- }
863
- else {
864
- // pic不存在,说明使用的是page模式
865
- await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
866
- }
867
- // 如果成功,那么跳出循环
868
- break;
826
+ // 渲染图片
827
+ const { pic: gimgPic, buffer: gimgBuffer } = await ctx.gimg.generateDynamicImg(items[num]);
828
+ pic = gimgPic;
829
+ buffer = gimgBuffer;
869
830
  }
870
831
  catch (e) {
871
- this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.toString());
872
- if (i === attempts - 1) { // 如果已经尝试了三次,那么抛出错误
832
+ // 直播开播动态,不做处理
833
+ if (e.message === '直播开播动态,不做处理')
834
+ break;
835
+ if (e.message === '出现关键词,屏蔽该动态') {
836
+ // 如果需要发送才发送
837
+ this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
838
+ break;
839
+ }
840
+ if (e.message === '已屏蔽转发动态') {
841
+ this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
842
+ break;
843
+ }
844
+ // 未知错误
845
+ if (i === attempts - 1) {
846
+ this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.toString());
847
+ // 发送私聊消息并重启服务
873
848
  return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
874
849
  }
875
850
  }
876
851
  }
852
+ // 判断是否需要发送URL
853
+ const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
854
+ // 如果pic存在,则直接返回pic
855
+ if (pic) {
856
+ // pic存在,使用的是render模式
857
+ await this.sendMsg(ctx, guildId, bot, pic + dUrl);
858
+ }
859
+ else {
860
+ // pic不存在,说明使用的是page模式
861
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
862
+ }
877
863
  // 更新时间点为最新发布动态的发布时间
878
864
  switch (num) {
879
865
  case 1: {
@@ -897,43 +883,50 @@ class ComRegister {
897
883
  // 相当于锁的作用,防止上一个循环没处理完
898
884
  let flag = true;
899
885
  const sendLiveNotifyCard = async (data, uData, liveType, liveStartMsg, atAll) => {
886
+ // 定义变量
887
+ let pic;
888
+ let buffer;
889
+ // 多次尝试生成图片
900
890
  let attempts = 3;
901
891
  for (let i = 0; i < attempts; i++) {
902
892
  try {
903
893
  // 获取直播通知卡片
904
- const { pic, buffer } = await ctx.gimg.generateLiveImg(data, uData, liveType);
905
- // 推送直播信息
906
- if (!liveStartMsg) {
907
- // pic 存在,使用的是render模式
908
- if (pic)
909
- return await this.sendMsg(ctx, guildId, bot, pic);
910
- // pic不存在,说明使用的是page模式
911
- await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png'));
912
- }
913
- else if (liveStartMsg && atAll) {
914
- // pic 存在,使用的是render模式
915
- if (pic)
916
- return await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
917
- // pic不存在,说明使用的是page模式
918
- await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
919
- }
920
- else {
921
- // pic 存在,使用的是render模式
922
- if (pic)
923
- return await this.sendMsg(ctx, guildId, bot, pic + liveStartMsg);
924
- // pic不存在,说明使用的是page模式
925
- await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
926
- }
894
+ const { pic: picv, buffer: bufferv } = await ctx.gimg.generateLiveImg(data, uData, liveType);
895
+ // 赋值
896
+ pic = picv;
897
+ buffer = bufferv;
927
898
  // 成功则跳出循环
928
899
  break;
929
900
  }
930
901
  catch (e) {
931
- this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
932
902
  if (i === attempts - 1) { // 已尝试三次
903
+ this.logger.error('liveDetect generateLiveImg() 推送卡片生成失败,原因:' + e.toString());
933
904
  return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
934
905
  }
935
906
  }
936
907
  }
908
+ // 推送直播信息
909
+ if (!liveStartMsg) {
910
+ // pic 存在,使用的是render模式
911
+ if (pic)
912
+ return await this.sendMsg(ctx, guildId, bot, pic);
913
+ // pic不存在,说明使用的是page模式
914
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png'));
915
+ }
916
+ else if (liveStartMsg && atAll) {
917
+ // pic 存在,使用的是render模式
918
+ if (pic)
919
+ return await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
920
+ // pic不存在,说明使用的是page模式
921
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
922
+ }
923
+ else {
924
+ // pic 存在,使用的是render模式
925
+ if (pic)
926
+ return await this.sendMsg(ctx, guildId, bot, pic + liveStartMsg);
927
+ // pic不存在,说明使用的是page模式
928
+ await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
929
+ }
937
930
  };
938
931
  return async () => {
939
932
  try {
@@ -1006,19 +999,10 @@ class ComRegister {
1006
999
  let liveEndMsg = this.config.customLiveEnd
1007
1000
  .replace('-name', uData.info.uname)
1008
1001
  .replace('-time', await ctx.gimg.getTimeDifference(liveTime));
1009
- // 获取图片二进制
1010
- const resp = await (0, axios_1.default)({
1011
- url: uData.info.face,
1012
- method: 'GET',
1013
- responseType: 'arraybuffer'
1002
+ // 获取头像并缩放
1003
+ const resizedImage = await jimp_1.default.read(uData.info.face).then(async (image) => {
1004
+ return await image.resize(100, 100).getBufferAsync(jimp_1.default.MIME_PNG);
1014
1005
  });
1015
- // 使用sharp调整图片大小
1016
- const resizedImage = await (0, sharp_1.default)(resp.data)
1017
- .resize(100, 100, {
1018
- kernel: sharp_1.default.kernel.lanczos3
1019
- })
1020
- .png({ compressionLevel: 9 })
1021
- .toBuffer();
1022
1006
  // 发送下播通知
1023
1007
  await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(resizedImage, 'image/png'), " ", liveEndMsg] }));
1024
1008
  }
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": "1.2.4",
4
+ "version": "1.2.5",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -29,11 +29,11 @@
29
29
  "dependencies": {
30
30
  "axios": "^1.6.7",
31
31
  "axios-cookiejar-support": "^5.0.0",
32
+ "jimp": "^0.22.12",
32
33
  "jsdom": "^24.0.0",
33
34
  "luxon": "^3.4.4",
34
35
  "md5": "^2.3.0",
35
36
  "qrcode": "^1.5.3",
36
- "sharp": "^0.33.3",
37
37
  "tough-cookie": "^4.1.3"
38
38
  },
39
39
  "devDependencies": {
package/readme.md CHANGED
@@ -138,6 +138,7 @@
138
138
  - ver 1.2.3-rc.11 测试版本,请跳过
139
139
  - ver 1.2.3 完善主播下播消息发送头像功能,优化控制台订阅信息显示
140
140
  - ver 1.2.4 优化了下播消息发送头像图片的质量和插件重启提示
141
+ - ver 1.2.5 修复了在多群订阅的情况下,其中一个群推送失败会导致其余的群全部重新推送的bug。更换图片处理依赖以解决在插件市场中被标记为不安全插件的问题
141
142
 
142
143
  ## 交流群
143
144