koishi-plugin-bilibili-notify 1.3.3 → 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) {
@@ -884,7 +905,7 @@ class ComRegister {
884
905
  const upName = content.data.items[num].modules.module_author.name;
885
906
  const dynamicId = content.data.items[num].id_str;
886
907
  // 推送该条动态
887
- let attempts = 3;
908
+ const attempts = 3;
888
909
  for (let i = 0; i < attempts; i++) {
889
910
  // 获取动态推送图片
890
911
  try {
@@ -902,11 +923,11 @@ class ComRegister {
902
923
  return updatePoint(num);
903
924
  if (e.message === '出现关键词,屏蔽该动态') {
904
925
  // 如果需要发送才发送
905
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
926
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
906
927
  return updatePoint(num);
907
928
  }
908
929
  if (e.message === '已屏蔽转发动态') {
909
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
930
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
910
931
  return updatePoint(num);
911
932
  }
912
933
  // 未知错误
@@ -923,12 +944,12 @@ class ComRegister {
923
944
  if (pic) {
924
945
  this.logger.info('推送动态中,使用render模式');
925
946
  // pic存在,使用的是render模式
926
- 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 }));
927
948
  }
928
949
  else if (buffer) {
929
950
  this.logger.info('推送动态中,使用page模式');
930
951
  // pic不存在,说明使用的是page模式
931
- 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] }));
932
953
  }
933
954
  else {
934
955
  this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
@@ -1034,7 +1055,7 @@ class ComRegister {
1034
1055
  const upName = content.data.items[num].modules.module_author.name;
1035
1056
  const dynamicId = content.data.items[num].id_str;
1036
1057
  // 推送该条动态
1037
- let attempts = 3;
1058
+ const attempts = 3;
1038
1059
  this.logger.info(`UID:${uid}-尝试渲染推送图片`);
1039
1060
  for (let i = 0; i < attempts; i++) {
1040
1061
  // 获取动态推送图片
@@ -1053,11 +1074,11 @@ class ComRegister {
1053
1074
  return updatePoint(num);
1054
1075
  if (e.message === '出现关键词,屏蔽该动态') {
1055
1076
  // 如果需要发送才发送
1056
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
1077
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
1057
1078
  return updatePoint(num);
1058
1079
  }
1059
1080
  if (e.message === '已屏蔽转发动态') {
1060
- this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
1081
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
1061
1082
  return updatePoint(num);
1062
1083
  }
1063
1084
  // 未知错误
@@ -1075,12 +1096,12 @@ class ComRegister {
1075
1096
  if (pic) {
1076
1097
  this.logger.info(`UID:${uid}-推送动态中,使用render模式`);
1077
1098
  // pic存在,使用的是render模式
1078
- 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 }));
1079
1100
  }
1080
1101
  else if (buffer) {
1081
1102
  this.logger.info(`UID:${uid}-推送动态中,使用page模式`);
1082
1103
  // pic不存在,说明使用的是page模式
1083
- 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] }));
1084
1105
  }
1085
1106
  else {
1086
1107
  this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
@@ -1110,7 +1131,7 @@ class ComRegister {
1110
1131
  let pic;
1111
1132
  let buffer;
1112
1133
  // 多次尝试生成图片
1113
- let attempts = 3;
1134
+ const attempts = 3;
1114
1135
  for (let i = 0; i < attempts; i++) {
1115
1136
  try {
1116
1137
  // 获取直播通知卡片
@@ -1131,12 +1152,12 @@ class ComRegister {
1131
1152
  // 推送直播信息
1132
1153
  // pic 存在,使用的是render模式
1133
1154
  if (pic) {
1134
- 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}` : ''] });
1135
- 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);
1136
1157
  }
1137
1158
  // pic不存在,说明使用的是page模式
1138
- 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}` : ''] });
1139
- 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);
1140
1161
  };
1141
1162
  }
1142
1163
  else {
@@ -1145,7 +1166,7 @@ class ComRegister {
1145
1166
  let pic;
1146
1167
  let buffer;
1147
1168
  // 多次尝试生成图片
1148
- let attempts = 3;
1169
+ const attempts = 3;
1149
1170
  for (let i = 0; i < attempts; i++) {
1150
1171
  try {
1151
1172
  // 获取直播通知卡片
@@ -1166,12 +1187,12 @@ class ComRegister {
1166
1187
  // 推送直播信息
1167
1188
  // pic 存在,使用的是render模式
1168
1189
  if (pic) {
1169
- let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1170
- 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);
1171
1192
  }
1172
1193
  // pic不存在,说明使用的是page模式
1173
- 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] });
1174
- 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);
1175
1196
  };
1176
1197
  }
1177
1198
  // 定义获取主播信息方法
@@ -1198,7 +1219,7 @@ class ComRegister {
1198
1219
  flag = false;
1199
1220
  // 发送请求检测直播状态
1200
1221
  let content;
1201
- let attempts = 3;
1222
+ const attempts = 3;
1202
1223
  for (let i = 0; i < attempts; i++) {
1203
1224
  try {
1204
1225
  // 发送请求获取room信息
@@ -1218,7 +1239,7 @@ class ComRegister {
1218
1239
  if (firstSubscription) {
1219
1240
  firstSubscription = false;
1220
1241
  // 获取主播信息
1221
- let attempts = 3;
1242
+ const attempts = 3;
1222
1243
  for (let i = 0; i < attempts; i++) {
1223
1244
  try {
1224
1245
  // 发送请求获取主播信息
@@ -1254,7 +1275,7 @@ class ComRegister {
1254
1275
  // 下播了将定时器清零
1255
1276
  timer = 0;
1256
1277
  // 定义下播通知消息
1257
- let liveEndMsg = this.config.customLiveEnd
1278
+ const liveEndMsg = this.config.customLiveEnd
1258
1279
  .replace('-name', username)
1259
1280
  .replace('-time', await ctx.gi.getTimeDifference(liveTime));
1260
1281
  // 获取头像并缩放
@@ -1272,7 +1293,7 @@ class ComRegister {
1272
1293
  console.log(e);
1273
1294
  }
1274
1295
  // 发送下播通知
1275
- 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] }));
1276
1297
  }
1277
1298
  // 未进循环,还未开播,继续循环
1278
1299
  break;
@@ -1284,7 +1305,7 @@ class ComRegister {
1284
1305
  // 设置开播时间
1285
1306
  liveTime = data.live_time;
1286
1307
  // 获取主播信息
1287
- let attempts = 3;
1308
+ const attempts = 3;
1288
1309
  for (let i = 0; i < attempts; i++) {
1289
1310
  try {
1290
1311
  // 主播信息不会变,开播时刷新一次即可
@@ -1301,7 +1322,7 @@ class ComRegister {
1301
1322
  }
1302
1323
  }
1303
1324
  // 定义开播通知语
1304
- let liveStartMsg = this.config.customLiveStart
1325
+ const liveStartMsg = this.config.customLiveStart
1305
1326
  .replace('-name', username)
1306
1327
  .replace('-time', await ctx.gi.getTimeDifference(liveTime))
1307
1328
  .replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`);
@@ -1355,7 +1376,7 @@ class ComRegister {
1355
1376
  }
1356
1377
  let input; // 用户输入
1357
1378
  // 询问用户是否需要订阅直播
1358
- while (1) {
1379
+ while (true) {
1359
1380
  session.send(`是否需要订阅${subType}?需要输入 y 不需要输入 n `);
1360
1381
  input = await session.prompt();
1361
1382
  if (!input) {
@@ -1392,7 +1413,7 @@ class ComRegister {
1392
1413
  }
1393
1414
  else {
1394
1415
  // 获取subTable
1395
- let subTableArray = subInfo.split('\n');
1416
+ const subTableArray = subInfo.split('\n');
1396
1417
  subTableArray.splice(subTableArray.length - 1, 1);
1397
1418
  // 定义Table
1398
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 }))) })] });
@@ -1493,7 +1514,7 @@ class ComRegister {
1493
1514
  // 判断数据库是否被篡改
1494
1515
  // 获取用户信息
1495
1516
  let content;
1496
- let attempts = 3;
1517
+ const attempts = 3;
1497
1518
  for (let i = 0; i < attempts; i++) {
1498
1519
  try {
1499
1520
  // 获取用户信息
@@ -1548,7 +1569,7 @@ class ComRegister {
1548
1569
  return;
1549
1570
  }
1550
1571
  // 构建订阅对象
1551
- let subManagerItem = {
1572
+ const subManagerItem = {
1552
1573
  id: sub.id,
1553
1574
  uid: sub.uid,
1554
1575
  roomId: sub.room_id,
@@ -1684,6 +1705,7 @@ class ComRegister {
1684
1705
  masterAccountGuildId: koishi_1.Schema.string()
1685
1706
  }),
1686
1707
  unlockSubLimits: koishi_1.Schema.boolean().required(),
1708
+ automaticResend: koishi_1.Schema.boolean().required(),
1687
1709
  changeMasterInfoApi: koishi_1.Schema.boolean().required(),
1688
1710
  liveStartAtAll: koishi_1.Schema.boolean().required(),
1689
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");
@@ -196,7 +197,7 @@ class GenerateImg extends koishi_1.Service {
196
197
  </html>
197
198
  `;
198
199
  // 多次尝试生成图片
199
- let attempts = 3;
200
+ const attempts = 3;
200
201
  for (let i = 0; i < attempts; i++) {
201
202
  try {
202
203
  // 判断渲染方式
@@ -300,7 +301,7 @@ class GenerateImg extends koishi_1.Service {
300
301
  const arrowImg = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'img/arrow.png'));
301
302
  if (module_dynamic.major && module_dynamic.major.draw) {
302
303
  if (module_dynamic.major.draw.items.length === 1) {
303
- let height = module_dynamic.major.draw.items[0].height;
304
+ const height = module_dynamic.major.draw.items[0].height;
304
305
  console.log(height);
305
306
  if (height > 3000) {
306
307
  major += `
@@ -356,6 +357,7 @@ class GenerateImg extends koishi_1.Service {
356
357
  const forwardUserAvatarUrl = forward_module_author.face;
357
358
  const forwardUserName = forward_module_author.name;
358
359
  // 获取转发的动态
360
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
359
361
  const [forwardMain, _, forwardInfo] = await getDynamicMajor(dynamicMajorData.orig, true);
360
362
  // 拼接main
361
363
  main += `
@@ -1377,7 +1379,7 @@ class GenerateImg extends koishi_1.Service {
1377
1379
  </html>
1378
1380
  `;
1379
1381
  // 多次尝试生成图片
1380
- let attempts = 3;
1382
+ const attempts = 3;
1381
1383
  for (let i = 0; i < attempts; i++) {
1382
1384
  try {
1383
1385
  // 判断渲染方式
@@ -1468,6 +1470,7 @@ class GenerateImg extends koishi_1.Service {
1468
1470
  return `${year}年${month}月${day}日 ${hours}:${minutes}:${seconds}`;
1469
1471
  }
1470
1472
  }
1473
+ // eslint-disable-next-line @typescript-eslint/no-namespace
1471
1474
  (function (GenerateImg) {
1472
1475
  GenerateImg.Config = koishi_1.Schema.object({
1473
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.3",
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,提供用户自己选择动态检测时间的选项
@@ -167,6 +169,7 @@
167
169
  - ver 1.3.1 优化过长单图的显示样式
168
170
  - ver 1.3.2 增加对飞书平台的支持
169
171
  - ver 1.3.3 新增直播推送人气信息展示
172
+ - ver 1.3.4 新增消息推送失败是否自动重发的选项,修复了一些潜在的bug
170
173
 
171
174
  ## 交流群
172
175