koishi-plugin-bilibili-notify 1.3.2 → 1.3.4

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/biliAPI.js CHANGED
@@ -3,6 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* eslint-disable @typescript-eslint/no-namespace */
7
+ /* eslint-disable @typescript-eslint/ban-types */
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
9
  const koishi_1 = require("koishi");
7
10
  const axios_1 = __importDefault(require("axios"));
8
11
  const tough_cookie_1 = require("tough-cookie");
@@ -180,8 +183,7 @@ class BiliAPI extends koishi_1.Service {
180
183
  return Math.floor(luxon_1.DateTime.now().setZone('UTC+8').toSeconds());
181
184
  }
182
185
  getCookies() {
183
- let cookies;
184
- cookies = JSON.stringify(this.jar.serializeSync().cookies);
186
+ const cookies = JSON.stringify(this.jar.serializeSync().cookies);
185
187
  return cookies;
186
188
  }
187
189
  getLoginInfoIsLoaded() {
@@ -359,6 +361,7 @@ class BiliAPI extends koishi_1.Service {
359
361
  case -111: {
360
362
  await this.ctx.database.remove('loginBili', [1]);
361
363
  notifyAndError('csrf 校验错误,请重新登录');
364
+ break;
362
365
  }
363
366
  case 86095: {
364
367
  await this.ctx.database.remove('loginBili', [1]);
@@ -374,7 +377,7 @@ class BiliAPI extends koishi_1.Service {
374
377
  bili_refresh_token: encryptedRefreshToken
375
378
  }]);
376
379
  // Get new csrf from cookies
377
- let newCsrf = this.jar.serializeSync().cookies.find(cookie => {
380
+ const newCsrf = this.jar.serializeSync().cookies.find(cookie => {
378
381
  if (cookie.key === 'bili_jct')
379
382
  return true;
380
383
  }).value;
@@ -392,6 +395,7 @@ class BiliAPI extends koishi_1.Service {
392
395
  case -111: {
393
396
  await this.ctx.database.remove('loginBili', [1]);
394
397
  notifyAndError('csrf 校验失败,请重新登录');
398
+ break;
395
399
  }
396
400
  case -400: throw new Error('请求错误');
397
401
  }
@@ -26,11 +26,12 @@ declare class ComRegister {
26
26
  satoriBot: Bot<Context>;
27
27
  chronocatBot: Bot<Context>;
28
28
  larkBot: Bot<Context>;
29
+ sendMsgFunc: (guild: string, bot: Bot<Context>, content: any) => Promise<void>;
29
30
  constructor(ctx: Context, config: ComRegister.Config);
30
31
  getTheCorrespondingBotBasedOnTheSession(session: Session): Bot<Context, any>;
31
32
  sendPrivateMsg(bot: Bot<Context>, content: string): Promise<void>;
32
33
  sendPrivateMsgAndRebootService(ctx: Context, bot: Bot<Context>, content: string): Promise<void>;
33
- sendMsg(ctx: Context, targets: Array<string>, bot: Bot<Context>, content: any): Promise<void>;
34
+ sendMsg(targets: Array<string>, bot: Bot<Context>, content: any): Promise<void>;
34
35
  dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
35
36
  debug_dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
36
37
  liveDetect(ctx: Context, bot: Bot<Context>, roomId: string, guildId: Array<string>): () => Promise<void>;
@@ -51,6 +52,7 @@ declare namespace ComRegister {
51
52
  masterAccountGuildId: string;
52
53
  };
53
54
  unlockSubLimits: boolean;
55
+ automaticResend: boolean;
54
56
  changeMasterInfoApi: boolean;
55
57
  liveStartAtAll: boolean;
56
58
  pushUrl: boolean;
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
7
+ /* eslint-disable @typescript-eslint/no-namespace */
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+ /* eslint-disable @typescript-eslint/ban-types */
7
10
  const koishi_1 = require("koishi");
8
11
  // 导入qrcode
9
12
  const qrcode_1 = __importDefault(require("qrcode"));
@@ -38,6 +41,8 @@ class ComRegister {
38
41
  chronocatBot;
39
42
  // Lark机器人
40
43
  larkBot;
44
+ // 发送消息方式
45
+ sendMsgFunc;
41
46
  constructor(ctx, config) {
42
47
  this.logger = ctx.logger('cr');
43
48
  /* ctx.on('ready', () => {
@@ -78,6 +83,41 @@ class ComRegister {
78
83
  });
79
84
  // 从数据库获取订阅
80
85
  this.getSubFromDatabase(ctx);
86
+ // 判断消息发送方式
87
+ if (config.automaticResend) {
88
+ this.sendMsgFunc = async (guild, bot, content) => {
89
+ // 多次尝试发送消息
90
+ const attempts = 3;
91
+ for (let i = 0; i < attempts; i++) {
92
+ try {
93
+ // 发送消息
94
+ await bot.sendMessage(guild, content);
95
+ // 防止消息发送速度过快被忽略
96
+ await ctx.sleep(500);
97
+ // 成功发送消息,跳出循环
98
+ break;
99
+ }
100
+ catch (e) {
101
+ if (i === attempts - 1) { // 已尝试三次
102
+ this.logger.error(`发送群组ID:${guild}消息失败!原因: ` + e.message);
103
+ this.sendPrivateMsg(bot, `发送群组ID:${guild}消息失败,请查看日志`);
104
+ }
105
+ }
106
+ }
107
+ };
108
+ }
109
+ else {
110
+ this.sendMsgFunc = async (guild, bot, content) => {
111
+ try {
112
+ // 发送消息
113
+ await bot.sendMessage(guild, content);
114
+ }
115
+ catch (e) {
116
+ this.logger.error(`发送群组ID:${guild}消息失败!原因: ` + e.message);
117
+ await this.sendPrivateMsg(bot, `发送群组ID:${guild}消息失败,请查看日志`);
118
+ }
119
+ };
120
+ }
81
121
  /* const testCom = ctx.command('test', { hidden: true, permissions: ['authority:5'] })
82
122
 
83
123
  testCom.subcommand('.cookies')
@@ -368,8 +408,6 @@ class ComRegister {
368
408
  if (this.subManager && this.subManager.some(sub => sub.uid === mid)) {
369
409
  return '已订阅该用户,请勿重复订阅';
370
410
  }
371
- // 定义是否需要直播通知,动态订阅,视频推送
372
- let liveMsg, dynamicMsg;
373
411
  // 获取用户信息
374
412
  let content;
375
413
  try {
@@ -411,7 +449,7 @@ class ComRegister {
411
449
  // 定义满足条件的群组数组
412
450
  const targetArr = [];
413
451
  // 判断群号是否符合条件
414
- for (let guild of guildId) {
452
+ for (const guild of guildId) {
415
453
  if (guildList.data.some(cv => cv.id === guild)) { // 机器人加入了该群
416
454
  // 保存到数组
417
455
  targetArr.push(guild);
@@ -480,15 +518,15 @@ class ComRegister {
480
518
  // 获取data
481
519
  const { data } = content;
482
520
  // 判断是否需要订阅直播
483
- liveMsg = await this.checkIfNeedSub(options.live, '直播', session, data);
521
+ const liveMsg = await this.checkIfNeedSub(options.live, '直播', session, data);
484
522
  // 判断是否需要订阅动态
485
- dynamicMsg = await this.checkIfNeedSub(options.dynamic, '动态', session);
523
+ const dynamicMsg = await this.checkIfNeedSub(options.dynamic, '动态', session);
486
524
  // 判断是否未订阅任何消息
487
525
  if (!liveMsg && !dynamicMsg) {
488
526
  return '您未订阅该UP的任何消息';
489
527
  }
490
528
  // 获取直播房间号
491
- let roomId = data.live_room?.roomid.toString();
529
+ const roomId = data.live_room?.roomid.toString();
492
530
  // 保存到数据库中
493
531
  const sub = await ctx.database.create('bilibili', {
494
532
  uid: mid,
@@ -759,13 +797,13 @@ class ComRegister {
759
797
  await ctx.sm.disposePlugin();
760
798
  }
761
799
  }
762
- async sendMsg(ctx, targets, bot, content) {
800
+ async sendMsg(targets, bot, content) {
763
801
  // 定义需要发送的数组
764
802
  let sendArr = [];
765
803
  // 判断是否需要推送所有机器人加入的群
766
804
  if (targets[0] === 'all') {
767
805
  // 获取所有guild
768
- for (let guild of (await bot.getGuildList()).data) {
806
+ for (const guild of (await bot.getGuildList()).data) {
769
807
  sendArr.push(guild.id);
770
808
  }
771
809
  }
@@ -773,25 +811,8 @@ class ComRegister {
773
811
  sendArr = targets;
774
812
  }
775
813
  // 循环给每个群组发送
776
- for (let guildId of sendArr) {
777
- // 多次尝试发送消息
778
- let attempts = 3;
779
- for (let i = 0; i < attempts; i++) {
780
- try {
781
- // 发送消息
782
- await bot.sendMessage(guildId, content);
783
- // 防止消息发送速度过快被忽略
784
- await ctx.sleep(500);
785
- // 成功发送消息,跳出循环
786
- break;
787
- }
788
- catch (e) {
789
- if (i === attempts - 1) { // 已尝试三次
790
- this.logger.error(`发送群组ID:${guildId}消息失败!原因: ` + e.message);
791
- this.sendPrivateMsg(bot, `发送群组ID:${guildId}消息失败,请检查机器人状态`);
792
- }
793
- }
794
- }
814
+ for (const guild of sendArr) {
815
+ await this.sendMsgFunc(guild, bot, content);
795
816
  }
796
817
  }
797
818
  dynamicDetect(ctx, bot, uid, guildId) {
@@ -837,7 +858,8 @@ class ComRegister {
837
858
  // 结束循环
838
859
  break;
839
860
  }
840
- case 4101128: { // 获取动态信息错误
861
+ case 4101128:
862
+ case 4101129: { // 获取动态信息错误
841
863
  // 输出日志
842
864
  this.logger.error('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message);
843
865
  // 发送私聊消息
@@ -883,7 +905,7 @@ class ComRegister {
883
905
  const upName = content.data.items[num].modules.module_author.name;
884
906
  const dynamicId = content.data.items[num].id_str;
885
907
  // 推送该条动态
886
- let attempts = 3;
908
+ const attempts = 3;
887
909
  for (let i = 0; i < attempts; i++) {
888
910
  // 获取动态推送图片
889
911
  try {
@@ -901,11 +923,11 @@ class ComRegister {
901
923
  return updatePoint(num);
902
924
  if (e.message === '出现关键词,屏蔽该动态') {
903
925
  // 如果需要发送才发送
904
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
926
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
905
927
  return updatePoint(num);
906
928
  }
907
929
  if (e.message === '已屏蔽转发动态') {
908
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
930
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
909
931
  return updatePoint(num);
910
932
  }
911
933
  // 未知错误
@@ -922,12 +944,12 @@ class ComRegister {
922
944
  if (pic) {
923
945
  this.logger.info('推送动态中,使用render模式');
924
946
  // pic存在,使用的是render模式
925
- await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
947
+ await this.sendMsg(guildId, bot, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
926
948
  }
927
949
  else if (buffer) {
928
950
  this.logger.info('推送动态中,使用page模式');
929
951
  // pic不存在,说明使用的是page模式
930
- await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
952
+ await this.sendMsg(guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
931
953
  }
932
954
  else {
933
955
  this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
@@ -984,7 +1006,8 @@ class ComRegister {
984
1006
  // 结束循环
985
1007
  break;
986
1008
  }
987
- case 4101128: { // 获取动态信息错误
1009
+ case 4101128:
1010
+ case 4101129: { // 获取动态信息错误
988
1011
  // 输出日志
989
1012
  this.logger.error('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message);
990
1013
  // 发送私聊消息
@@ -1032,7 +1055,7 @@ class ComRegister {
1032
1055
  const upName = content.data.items[num].modules.module_author.name;
1033
1056
  const dynamicId = content.data.items[num].id_str;
1034
1057
  // 推送该条动态
1035
- let attempts = 3;
1058
+ const attempts = 3;
1036
1059
  this.logger.info(`UID:${uid}-尝试渲染推送图片`);
1037
1060
  for (let i = 0; i < attempts; i++) {
1038
1061
  // 获取动态推送图片
@@ -1051,11 +1074,11 @@ class ComRegister {
1051
1074
  return updatePoint(num);
1052
1075
  if (e.message === '出现关键词,屏蔽该动态') {
1053
1076
  // 如果需要发送才发送
1054
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
1077
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
1055
1078
  return updatePoint(num);
1056
1079
  }
1057
1080
  if (e.message === '已屏蔽转发动态') {
1058
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
1081
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
1059
1082
  return updatePoint(num);
1060
1083
  }
1061
1084
  // 未知错误
@@ -1073,12 +1096,12 @@ class ComRegister {
1073
1096
  if (pic) {
1074
1097
  this.logger.info(`UID:${uid}-推送动态中,使用render模式`);
1075
1098
  // pic存在,使用的是render模式
1076
- await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
1099
+ await this.sendMsg(guildId, bot, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
1077
1100
  }
1078
1101
  else if (buffer) {
1079
1102
  this.logger.info(`UID:${uid}-推送动态中,使用page模式`);
1080
1103
  // pic不存在,说明使用的是page模式
1081
- await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
1104
+ await this.sendMsg(guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
1082
1105
  }
1083
1106
  else {
1084
1107
  this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
@@ -1108,7 +1131,7 @@ class ComRegister {
1108
1131
  let pic;
1109
1132
  let buffer;
1110
1133
  // 多次尝试生成图片
1111
- let attempts = 3;
1134
+ const attempts = 3;
1112
1135
  for (let i = 0; i < attempts; i++) {
1113
1136
  try {
1114
1137
  // 获取直播通知卡片
@@ -1129,12 +1152,12 @@ class ComRegister {
1129
1152
  // 推送直播信息
1130
1153
  // pic 存在,使用的是render模式
1131
1154
  if (pic) {
1132
- let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg, liveType !== LiveType.StartBroadcasting ? `https://live.bilibili.com/${roomId}` : ''] });
1133
- return await this.sendMsg(ctx, guildId, bot, pic + msg);
1155
+ const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg, liveType !== LiveType.StartBroadcasting ? `https://live.bilibili.com/${roomId}` : ''] });
1156
+ return await this.sendMsg(guildId, bot, pic + msg);
1134
1157
  }
1135
1158
  // pic不存在,说明使用的是page模式
1136
- let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg, liveType !== LiveType.StartBroadcasting ? `https://live.bilibili.com/${roomId}` : ''] });
1137
- await this.sendMsg(ctx, guildId, bot, msg);
1159
+ const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg, liveType !== LiveType.StartBroadcasting ? `https://live.bilibili.com/${roomId}` : ''] });
1160
+ await this.sendMsg(guildId, bot, msg);
1138
1161
  };
1139
1162
  }
1140
1163
  else {
@@ -1143,7 +1166,7 @@ class ComRegister {
1143
1166
  let pic;
1144
1167
  let buffer;
1145
1168
  // 多次尝试生成图片
1146
- let attempts = 3;
1169
+ const attempts = 3;
1147
1170
  for (let i = 0; i < attempts; i++) {
1148
1171
  try {
1149
1172
  // 获取直播通知卡片
@@ -1164,12 +1187,12 @@ class ComRegister {
1164
1187
  // 推送直播信息
1165
1188
  // pic 存在,使用的是render模式
1166
1189
  if (pic) {
1167
- let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1168
- return await this.sendMsg(ctx, guildId, bot, pic + msg);
1190
+ const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1191
+ return await this.sendMsg(guildId, bot, pic + msg);
1169
1192
  }
1170
1193
  // pic不存在,说明使用的是page模式
1171
- let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1172
- await this.sendMsg(ctx, guildId, bot, msg);
1194
+ const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1195
+ await this.sendMsg(guildId, bot, msg);
1173
1196
  };
1174
1197
  }
1175
1198
  // 定义获取主播信息方法
@@ -1196,7 +1219,7 @@ class ComRegister {
1196
1219
  flag = false;
1197
1220
  // 发送请求检测直播状态
1198
1221
  let content;
1199
- let attempts = 3;
1222
+ const attempts = 3;
1200
1223
  for (let i = 0; i < attempts; i++) {
1201
1224
  try {
1202
1225
  // 发送请求获取room信息
@@ -1216,7 +1239,7 @@ class ComRegister {
1216
1239
  if (firstSubscription) {
1217
1240
  firstSubscription = false;
1218
1241
  // 获取主播信息
1219
- let attempts = 3;
1242
+ const attempts = 3;
1220
1243
  for (let i = 0; i < attempts; i++) {
1221
1244
  try {
1222
1245
  // 发送请求获取主播信息
@@ -1252,7 +1275,7 @@ class ComRegister {
1252
1275
  // 下播了将定时器清零
1253
1276
  timer = 0;
1254
1277
  // 定义下播通知消息
1255
- let liveEndMsg = this.config.customLiveEnd
1278
+ const liveEndMsg = this.config.customLiveEnd
1256
1279
  .replace('-name', username)
1257
1280
  .replace('-time', await ctx.gi.getTimeDifference(liveTime));
1258
1281
  // 获取头像并缩放
@@ -1270,7 +1293,7 @@ class ComRegister {
1270
1293
  console.log(e);
1271
1294
  }
1272
1295
  // 发送下播通知
1273
- await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [resizedImage && koishi_1.h.image(resizedImage, 'image/png'), " ", liveEndMsg] }));
1296
+ await this.sendMsg(guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [resizedImage && koishi_1.h.image(resizedImage, 'image/png'), " ", liveEndMsg] }));
1274
1297
  }
1275
1298
  // 未进循环,还未开播,继续循环
1276
1299
  break;
@@ -1282,7 +1305,7 @@ class ComRegister {
1282
1305
  // 设置开播时间
1283
1306
  liveTime = data.live_time;
1284
1307
  // 获取主播信息
1285
- let attempts = 3;
1308
+ const attempts = 3;
1286
1309
  for (let i = 0; i < attempts; i++) {
1287
1310
  try {
1288
1311
  // 主播信息不会变,开播时刷新一次即可
@@ -1299,7 +1322,7 @@ class ComRegister {
1299
1322
  }
1300
1323
  }
1301
1324
  // 定义开播通知语
1302
- let liveStartMsg = this.config.customLiveStart
1325
+ const liveStartMsg = this.config.customLiveStart
1303
1326
  .replace('-name', username)
1304
1327
  .replace('-time', await ctx.gi.getTimeDifference(liveTime))
1305
1328
  .replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`);
@@ -1353,7 +1376,7 @@ class ComRegister {
1353
1376
  }
1354
1377
  let input; // 用户输入
1355
1378
  // 询问用户是否需要订阅直播
1356
- while (1) {
1379
+ while (true) {
1357
1380
  session.send(`是否需要订阅${subType}?需要输入 y 不需要输入 n `);
1358
1381
  input = await session.prompt();
1359
1382
  if (!input) {
@@ -1390,7 +1413,7 @@ class ComRegister {
1390
1413
  }
1391
1414
  else {
1392
1415
  // 获取subTable
1393
- let subTableArray = subInfo.split('\n');
1416
+ const subTableArray = subInfo.split('\n');
1394
1417
  subTableArray.splice(subTableArray.length - 1, 1);
1395
1418
  // 定义Table
1396
1419
  table = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: "\u5F53\u524D\u8BA2\u9605\u5BF9\u8C61\uFF1A" }), (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map(str => ((0, jsx_runtime_1.jsx)("li", { children: str }))) })] });
@@ -1491,7 +1514,7 @@ class ComRegister {
1491
1514
  // 判断数据库是否被篡改
1492
1515
  // 获取用户信息
1493
1516
  let content;
1494
- let attempts = 3;
1517
+ const attempts = 3;
1495
1518
  for (let i = 0; i < attempts; i++) {
1496
1519
  try {
1497
1520
  // 获取用户信息
@@ -1546,7 +1569,7 @@ class ComRegister {
1546
1569
  return;
1547
1570
  }
1548
1571
  // 构建订阅对象
1549
- let subManagerItem = {
1572
+ const subManagerItem = {
1550
1573
  id: sub.id,
1551
1574
  uid: sub.uid,
1552
1575
  roomId: sub.room_id,
@@ -1649,9 +1672,9 @@ class ComRegister {
1649
1672
  this.subManager.filter(sub => sub.uid === uid).map(async (sub, i) => {
1650
1673
  // 取消全部订阅 执行dispose方法,销毁定时器
1651
1674
  if (sub.dynamic)
1652
- this.subManager[i].dynamicDispose();
1675
+ await this.subManager[i].dynamicDispose();
1653
1676
  if (sub.live)
1654
- this.subManager[i].liveDispose();
1677
+ await this.subManager[i].liveDispose();
1655
1678
  // 从数据库中删除订阅
1656
1679
  await ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
1657
1680
  // 将该订阅对象从订阅管理对象中移除
@@ -1682,6 +1705,7 @@ class ComRegister {
1682
1705
  masterAccountGuildId: koishi_1.Schema.string()
1683
1706
  }),
1684
1707
  unlockSubLimits: koishi_1.Schema.boolean().required(),
1708
+ automaticResend: koishi_1.Schema.boolean().required(),
1685
1709
  changeMasterInfoApi: koishi_1.Schema.boolean().required(),
1686
1710
  liveStartAtAll: koishi_1.Schema.boolean().required(),
1687
1711
  pushUrl: koishi_1.Schema.boolean().required(),
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
4
  const koishi_1 = require("koishi");
4
5
  const path_1 = require("path");
5
6
  const url_1 = require("url");
@@ -182,9 +183,12 @@ class GenerateImg extends koishi_1.Service {
182
183
  </div>
183
184
  ${this.giConfig.hideDesc ? '' : `<p class="card-text">${data.description ? data.description : '这个主播很懒,什么都简介都没写'}</p>`}
184
185
  <p class="card-link">
185
- <span>${liveTime}</span>
186
+ <span>人气:${data.online}</span>
186
187
  <span>分区名称:${data.area_name}</span>
187
188
  </p>
189
+ <p class="card-link">
190
+ <span>${liveTime}</span>
191
+ </p>
188
192
  </div>
189
193
  </div>
190
194
  </div>
@@ -193,7 +197,7 @@ class GenerateImg extends koishi_1.Service {
193
197
  </html>
194
198
  `;
195
199
  // 多次尝试生成图片
196
- let attempts = 3;
200
+ const attempts = 3;
197
201
  for (let i = 0; i < attempts; i++) {
198
202
  try {
199
203
  // 判断渲染方式
@@ -297,7 +301,7 @@ class GenerateImg extends koishi_1.Service {
297
301
  const arrowImg = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'img/arrow.png'));
298
302
  if (module_dynamic.major && module_dynamic.major.draw) {
299
303
  if (module_dynamic.major.draw.items.length === 1) {
300
- let height = module_dynamic.major.draw.items[0].height;
304
+ const height = module_dynamic.major.draw.items[0].height;
301
305
  console.log(height);
302
306
  if (height > 3000) {
303
307
  major += `
@@ -353,6 +357,7 @@ class GenerateImg extends koishi_1.Service {
353
357
  const forwardUserAvatarUrl = forward_module_author.face;
354
358
  const forwardUserName = forward_module_author.name;
355
359
  // 获取转发的动态
360
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
356
361
  const [forwardMain, _, forwardInfo] = await getDynamicMajor(dynamicMajorData.orig, true);
357
362
  // 拼接main
358
363
  main += `
@@ -1374,7 +1379,7 @@ class GenerateImg extends koishi_1.Service {
1374
1379
  </html>
1375
1380
  `;
1376
1381
  // 多次尝试生成图片
1377
- let attempts = 3;
1382
+ const attempts = 3;
1378
1383
  for (let i = 0; i < attempts; i++) {
1379
1384
  try {
1380
1385
  // 判断渲染方式
@@ -1465,6 +1470,7 @@ class GenerateImg extends koishi_1.Service {
1465
1470
  return `${year}年${month}月${day}日 ${hours}:${minutes}:${seconds}`;
1466
1471
  }
1467
1472
  }
1473
+ // eslint-disable-next-line @typescript-eslint/no-namespace
1468
1474
  (function (GenerateImg) {
1469
1475
  GenerateImg.Config = koishi_1.Schema.object({
1470
1476
  renderType: koishi_1.Schema.number(),
package/lib/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface Config {
12
12
  master: {};
13
13
  basicSettings: {};
14
14
  unlockSubLimits: boolean;
15
+ automaticResend: boolean;
15
16
  renderType: 'render' | 'page';
16
17
  userAgent: string;
17
18
  dynamic: {};
package/lib/index.js CHANGED
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Config = exports.name = exports.inject = void 0;
30
30
  exports.apply = apply;
31
+ /* eslint-disable @typescript-eslint/ban-types */
31
32
  const koishi_1 = require("koishi");
32
33
  // import plugins
33
34
  // import Authority from './authority'
@@ -71,6 +72,9 @@ exports.Config = koishi_1.Schema.object({
71
72
  unlockSubLimits: koishi_1.Schema.boolean()
72
73
  .default(false)
73
74
  .description('解锁3个订阅限制,默认只允许订阅3位UP主。订阅过多用户可能有导致IP暂时被封禁的风险'),
75
+ automaticResend: koishi_1.Schema.boolean()
76
+ .default(true)
77
+ .description('是否开启自动重发功能,默认开启。开启后,如果推送失败,将会自动重发,尝试三次。关闭后,推送失败将不会再重发,直到下一次推送'),
74
78
  renderType: koishi_1.Schema.union(['render', 'page'])
75
79
  .role('')
76
80
  .default('render')
@@ -266,6 +270,7 @@ class ServerManager extends koishi_1.Service {
266
270
  const cr = this.ctx.plugin(comRegister_1.default, {
267
271
  master: globalConfig.master,
268
272
  unlockSubLimits: globalConfig.unlockSubLimits,
273
+ automaticResend: globalConfig.automaticResend,
269
274
  changeMasterInfoApi: globalConfig.changeMasterInfoApi,
270
275
  liveStartAtAll: globalConfig.liveStartAtAll,
271
276
  pushUrl: globalConfig.pushUrl,
package/lib/wbi.d.ts CHANGED
@@ -15,8 +15,8 @@ declare class Wbi extends Service {
15
15
  sub_key: any;
16
16
  }>;
17
17
  getWbi(params: any): Promise<string>;
18
- encrypt(text: string, secretKey?: string): string;
19
- decrypt(text: string, secretKey?: string): string;
18
+ encrypt(text: string): string;
19
+ decrypt(text: string): string;
20
20
  }
21
21
  declare namespace Wbi {
22
22
  interface Config {
package/lib/wbi.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* eslint-disable @typescript-eslint/no-namespace */
6
7
  const koishi_1 = require("koishi");
7
8
  const md5_1 = __importDefault(require("md5"));
8
9
  const crypto_1 = __importDefault(require("crypto"));
@@ -64,18 +65,18 @@ class Wbi extends koishi_1.Service {
64
65
  const query = this.encWbi(params, img_key, sub_key);
65
66
  return query;
66
67
  }
67
- encrypt(text, secretKey) {
68
+ encrypt(text) {
68
69
  const iv = crypto_1.default.randomBytes(16);
69
70
  const cipher = crypto_1.default.createCipheriv('aes-256-cbc', Buffer.from(this.wbiConfig.key), iv);
70
71
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
71
72
  return iv.toString('hex') + ':' + encrypted.toString('hex');
72
73
  }
73
- decrypt(text, secretKey) {
74
- let textParts = text.split(':');
75
- let iv = Buffer.from(textParts.shift(), 'hex');
76
- let encryptedText = Buffer.from(textParts.join(':'), 'hex');
77
- let decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(this.wbiConfig.key), iv);
78
- let decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
74
+ decrypt(text) {
75
+ const textParts = text.split(':');
76
+ const iv = Buffer.from(textParts.shift(), 'hex');
77
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex');
78
+ const decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(this.wbiConfig.key), iv);
79
+ const decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
79
80
  return decrypted.toString();
80
81
  }
81
82
  }
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.3.2",
4
+ "version": "1.3.4",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -37,11 +37,15 @@
37
37
  "tough-cookie": "^4.1.4"
38
38
  },
39
39
  "devDependencies": {
40
+ "@eslint/js": "^9.6.0",
40
41
  "@types/luxon": "^3",
41
42
  "@types/md5": "^2",
42
43
  "@types/qrcode": "^1",
43
44
  "@types/tough-cookie": "^4",
44
- "koishi-plugin-puppeteer": "^3.8.4"
45
+ "eslint": "9.x",
46
+ "globals": "^15.6.0",
47
+ "koishi-plugin-puppeteer": "^3.8.4",
48
+ "typescript-eslint": "^7.14.1"
45
49
  },
46
50
  "koishi": {
47
51
  "service": {
package/readme.md CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  - koishi-plugin-bilibili-notify [![npm](https://img.shields.io/npm/v/koishi-plugin-bilibili-notify?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-bilibili-notify)
8
8
  - [功能](#功能)
9
+ - [注意事项](#注意事项)
9
10
  - [安装](#安装)
10
11
  - [使用方法](#使用方法)
11
- - [注意事项](#注意事项)
12
12
  - [更新日志](#更新日志)
13
13
  - [交流群](#交流群)
14
14
  - [感谢](#感谢)
@@ -20,6 +20,21 @@
20
20
 
21
21
  订阅B站UP主直播
22
22
 
23
+ ## 注意事项
24
+
25
+ 0. 动态监测,当您订阅之后,会在您设置的dynamicLoopTime(默认为2分钟)之后才会开启监测。如果您需要测试则需要等待您设置的dynamicLoopTime的时间之后再发送测试动态
26
+
27
+ 1. 此插件依赖于 `database` 和 `puppeteer` 服务,同时受权限控制,需要具备 `authority:3` 及以上的权限才能使用本插件提供的指令,你可以参考下方配置登录插件中的方法得到一个超级管理员账号(具有 `authority:5` 的最高权限)
28
+
29
+ [配置登录插件](https://koishi.chat/zh-CN/manual/usage/platform.html#%E9%85%8D%E7%BD%AE%E7%99%BB%E5%BD%95%E6%8F%92%E4%BB%B6)
30
+
31
+ 2. 您还可以安装 `admin` 插件,给其他用户授予权限,操作方法请参考下方的权限管理
32
+
33
+ [权限管理](https://koishi.chat/zh-CN/manual/usage/customize.html)
34
+
35
+ 3. 指令使用方法请参考 `help bili`,子命令使用方法请加 `-h` ,例如 `bili login -h`
36
+ 4. 登录方式为二维码,输入命令 `bili login` 之后扫码登录,您的登录凭证将存储在您的本地数据库,并由您自己填写的密钥加密,所以请保管好你的密钥
37
+
23
38
  ## 安装
24
39
 
25
40
  1. 下载插件运行平台 [Koishi](https://koishi.chat/)
@@ -72,19 +87,6 @@
72
87
  - 使用指令 `sys`
73
88
  - 子命令:`start`、`stop`、`restart` 分别代表插件的启动,停止和重启
74
89
 
75
- ## 注意事项
76
-
77
- 1. 此插件依赖于 `database` 和 `puppeteer` 服务,同时受权限控制,需要具备 `authority:3` 及以上的权限才能使用本插件提供的指令,你可以参考下方配置登录插件中的方法得到一个超级管理员账号(具有 `authority:5` 的最高权限)
78
-
79
- [配置登录插件](https://koishi.chat/zh-CN/manual/usage/platform.html#%E9%85%8D%E7%BD%AE%E7%99%BB%E5%BD%95%E6%8F%92%E4%BB%B6)
80
-
81
- 2. 您还可以安装 `admin` 插件,给其他用户授予权限,操作方法请参考下方的权限管理
82
-
83
- [权限管理](https://koishi.chat/zh-CN/manual/usage/customize.html)
84
-
85
- 3. 指令使用方法请参考 `help bili`,子命令使用方法请加 `-h` ,例如 `bili login -h`
86
- 4. 登录方式为二维码,输入命令 `bili login` 之后扫码登录,您的登录凭证将存储在您的本地数据库,并由您自己填写的密钥加密,所以请保管好你的密钥
87
-
88
90
  ## 更新日志
89
91
 
90
92
  - ver 1.0.1 修复了一些bug,提供用户自己选择动态检测时间的选项
@@ -166,6 +168,8 @@
166
168
  - ver 1.3.0 修复bug:渲染动态时,过长的单图会导致渲染错误
167
169
  - ver 1.3.1 优化过长单图的显示样式
168
170
  - ver 1.3.2 增加对飞书平台的支持
171
+ - ver 1.3.3 新增直播推送人气信息展示
172
+ - ver 1.3.4 新增消息推送失败是否自动重发的选项,修复了一些潜在的bug
169
173
 
170
174
  ## 交流群
171
175