koishi-plugin-bilibili-notify 3.0.0-alpha.12 → 3.0.0-alpha.13

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.
@@ -4,15 +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/ban-types */
8
- /* eslint-disable @typescript-eslint/no-namespace */
9
- /* eslint-disable @typescript-eslint/no-explicit-any */
10
7
  const koishi_1 = require("koishi");
11
8
  // 导入qrcode
12
9
  const qrcode_1 = __importDefault(require("qrcode"));
13
- // 弹幕词云
14
- const segmentit_1 = require("segmentit");
15
- const d3_cloud_1 = __importDefault(require("d3-cloud"));
16
10
  var LiveType;
17
11
  (function (LiveType) {
18
12
  LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
@@ -22,9 +16,15 @@ var LiveType;
22
16
  })(LiveType || (LiveType = {}));
23
17
  class ComRegister {
24
18
  // 必须服务
25
- static inject = ['ba', 'gi', 'database', 'bl', 'sm'];
19
+ static inject = ["ba", "gi", "database", "canvas", "bl", "sm"];
26
20
  // 定义数组:QQ相关bot
27
- qqRelatedBotList = ['qq', 'onebot', 'red', 'satori', 'chronocat'];
21
+ qqRelatedBotList = [
22
+ "qq",
23
+ "onebot",
24
+ "red",
25
+ "satori",
26
+ "chronocat",
27
+ ];
28
28
  // logger
29
29
  logger;
30
30
  // config
@@ -58,76 +58,82 @@ class ComRegister {
58
58
  // 初始化
59
59
  this.init(config);
60
60
  // 注册指令
61
- const statusCom = ctx.command('status', '插件状态相关指令', { permissions: ['authority:5'] });
62
- statusCom.subcommand('.dyn', '查看动态监测运行状态')
63
- .usage('查看动态监测运行状态')
64
- .example('status dyn')
61
+ const statusCom = ctx.command("status", "插件状态相关指令", {
62
+ permissions: ["authority:5"],
63
+ });
64
+ statusCom
65
+ .subcommand(".dyn", "查看动态监测运行状态")
66
+ .usage("查看动态监测运行状态")
67
+ .example("status dyn")
65
68
  .action(() => {
66
69
  if (this.dynamicDispose) {
67
- return '动态监测正在运行';
68
- }
69
- else {
70
- return '动态监测未运行';
70
+ return "动态监测正在运行";
71
71
  }
72
+ return "动态监测未运行";
72
73
  });
73
- statusCom.subcommand('.sm', '查看订阅管理对象')
74
- .usage('查看订阅管理对象')
75
- .example('status sm')
74
+ statusCom
75
+ .subcommand(".sm", "查看订阅管理对象")
76
+ .usage("查看订阅管理对象")
77
+ .example("status sm")
76
78
  .action(async () => {
77
79
  this.logger.info(this.subManager);
78
- return '查看控制台';
80
+ return "查看控制台";
79
81
  });
80
82
  statusCom
81
- .subcommand('.bot', '查询当前拥有的机器人信息', { hidden: true })
82
- .usage('查询当前拥有的机器人信息')
83
- .example('status bot 查询当前拥有的机器人信息')
83
+ .subcommand(".bot", "查询当前拥有的机器人信息", { hidden: true })
84
+ .usage("查询当前拥有的机器人信息")
85
+ .example("status bot 查询当前拥有的机器人信息")
84
86
  .action(() => {
85
- this.logger.info('开始输出BOT信息');
86
- ctx.bots.forEach(bot => {
87
- this.logger.info('--------------------------------');
88
- this.logger.info('平台:' + bot.platform);
89
- this.logger.info('名称:' + bot.user.name);
90
- this.logger.info('--------------------------------');
91
- });
87
+ this.logger.info("开始输出BOT信息");
88
+ for (const bot of ctx.bots) {
89
+ this.logger.info("--------------------------------");
90
+ this.logger.info(`平台:${bot.platform}`);
91
+ this.logger.info(`名称:${bot.user.name}`);
92
+ this.logger.info("--------------------------------");
93
+ }
92
94
  });
93
95
  statusCom
94
- .subcommand('.env', '查询当前环境的信息', { hidden: true })
95
- .usage('查询当前环境的信息')
96
- .example('status env 查询当前环境的信息')
96
+ .subcommand(".env", "查询当前环境的信息", { hidden: true })
97
+ .usage("查询当前环境的信息")
98
+ .example("status env 查询当前环境的信息")
97
99
  .action(async ({ session }) => {
98
100
  await session.send(`Guild ID:${session.event.guild.id}`);
99
101
  await session.send(`Channel ID: ${session.event.channel.id}`);
100
102
  });
101
- const biliCom = ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] });
102
- biliCom.subcommand('.login', '登录B站之后才可以进行之后的操作')
103
- .usage('使用二维码登录,登录B站之后才可以进行之后的操作')
104
- .example('bili login')
103
+ const biliCom = ctx.command("bili", "bili-notify插件相关指令", {
104
+ permissions: ["authority:3"],
105
+ });
106
+ biliCom
107
+ .subcommand(".login", "登录B站之后才可以进行之后的操作")
108
+ .usage("使用二维码登录,登录B站之后才可以进行之后的操作")
109
+ .example("bili login")
105
110
  .action(async ({ session }) => {
106
- this.logger.info('调用bili login指令');
111
+ this.logger.info("调用bili login指令");
107
112
  // 获取二维码
113
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
108
114
  let content;
109
115
  try {
110
116
  content = await ctx.ba.getLoginQRCode();
111
117
  }
112
118
  catch (e) {
113
- return 'bili login getLoginQRCode() 本次网络请求失败';
119
+ return "bili login getLoginQRCode() 本次网络请求失败";
114
120
  }
115
121
  // 判断是否出问题
116
122
  if (content.code !== 0)
117
- return await session.send('出问题咯,请联系管理员解决');
123
+ return await session.send("出问题咯,请联系管理员解决");
118
124
  // 生成二维码
119
125
  qrcode_1.default.toBuffer(content.data.url, {
120
- errorCorrectionLevel: 'H', // 错误更正水平
121
- type: 'png', // 输出类型
126
+ errorCorrectionLevel: "H", // 错误更正水平
127
+ type: "png", // 输出类型
122
128
  margin: 1, // 边距大小
123
129
  color: {
124
- dark: '#000000', // 二维码颜色
125
- light: '#FFFFFF' // 背景颜色
126
- }
130
+ dark: "#000000", // 二维码颜色
131
+ light: "#FFFFFF", // 背景颜色
132
+ },
127
133
  }, async (err, buffer) => {
128
134
  if (err)
129
- return await session.send('二维码生成出错,请重新尝试');
130
- await session.send(koishi_1.h.image(buffer, 'image/png'));
135
+ return await session.send("二维码生成出错,请重新尝试");
136
+ await session.send(koishi_1.h.image(buffer, "image/png"));
131
137
  });
132
138
  // 检查之前是否存在登录定时器
133
139
  if (this.loginTimer)
@@ -142,6 +148,7 @@ class ComRegister {
142
148
  return;
143
149
  flag = false;
144
150
  // 获取登录信息
151
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
145
152
  let loginContent;
146
153
  try {
147
154
  loginContent = await ctx.ba.getLoginStatus(content.data.qrcode_key);
@@ -152,20 +159,23 @@ class ComRegister {
152
159
  }
153
160
  if (loginContent.code !== 0) {
154
161
  this.loginTimer();
155
- return await session.send('登录失败请重试');
162
+ return await session.send("登录失败请重试");
156
163
  }
157
164
  if (loginContent.data.code === 86038) {
158
165
  this.loginTimer();
159
- return await session.send('二维码已失效,请重新登录');
166
+ return await session.send("二维码已失效,请重新登录");
160
167
  }
161
- if (loginContent.data.code === 0) { // 登录成功
168
+ if (loginContent.data.code === 0) {
169
+ // 登录成功
162
170
  const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
163
171
  const encryptedRefreshToken = ctx.ba.encrypt(loginContent.data.refresh_token);
164
- await ctx.database.upsert('loginBili', [{
172
+ await ctx.database.upsert("loginBili", [
173
+ {
165
174
  id: 1,
166
175
  bili_cookies: encryptedCookies,
167
- bili_refresh_token: encryptedRefreshToken
168
- }]);
176
+ bili_refresh_token: encryptedRefreshToken,
177
+ },
178
+ ]);
169
179
  // 销毁定时器
170
180
  this.loginTimer();
171
181
  // 订阅手动订阅中的订阅
@@ -175,9 +185,9 @@ class ComRegister {
175
185
  // 清除控制台通知
176
186
  ctx.ba.disposeNotifier();
177
187
  // 发送成功登录推送
178
- await session.send('登录成功');
188
+ await session.send("登录成功");
179
189
  // bili show
180
- await session.execute('bili show');
190
+ await session.execute("bili show");
181
191
  // 开启cookies刷新检测
182
192
  ctx.ba.enableRefreshCookiesDetect();
183
193
  }
@@ -188,19 +198,19 @@ class ComRegister {
188
198
  }, 1000);
189
199
  });
190
200
  biliCom
191
- .subcommand('.unsub <uid:string>', '取消订阅UP主动态、直播或全部')
192
- .usage('取消订阅,加-l为取消直播订阅,加-d为取消动态订阅,什么都不加则为全部取消')
193
- .option('live', '-l')
194
- .option('dynamic', '-d')
195
- .example('bili unsub 用户UID -ld')
201
+ .subcommand(".unsub <uid:string>", "取消订阅UP主动态、直播或全部")
202
+ .usage("取消订阅,加-l为取消直播订阅,加-d为取消动态订阅,什么都不加则为全部取消")
203
+ .option("live", "-l")
204
+ .option("dynamic", "-d")
205
+ .example("bili unsub 用户UID -ld")
196
206
  .action(async ({ session, options }, uid) => {
197
- this.logger.info('调用bili.unsub指令');
207
+ this.logger.info("调用bili.unsub指令");
198
208
  // 若用户UID为空则直接返回
199
209
  if (!uid)
200
- return '用户UID不能为空';
210
+ return "用户UID不能为空";
201
211
  // -d -l两个选项不能同时存在
202
212
  if (options.dynamic && options.live)
203
- return '需要取消订阅该UP主请直接使用指令bili unsub 用户UID';
213
+ return "需要取消订阅该UP主请直接使用指令bili unsub 用户UID";
204
214
  // 定义是否存在
205
215
  let exist;
206
216
  await Promise.all(this.subManager.map(async (sub, i) => {
@@ -217,15 +227,18 @@ class ComRegister {
217
227
  return;
218
228
  }
219
229
  // 从数据库中删除订阅
220
- await ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
230
+ await ctx.database.remove("bilibili", {
231
+ uid: this.subManager[i].uid,
232
+ });
221
233
  // 将该订阅对象从订阅管理对象中移除
222
234
  this.subManager.splice(i, 1);
223
235
  // 将订阅对象移出订阅关注组
224
236
  const removeUserFromGroupData = await ctx.ba.removeUserFromGroup(sub.uid);
225
237
  // 判断是否移出成功 22105关注对象为自己
226
- if (removeUserFromGroupData.code !== 0 && removeUserFromGroupData.code !== 22105) {
238
+ if (removeUserFromGroupData.code !== 0 &&
239
+ removeUserFromGroupData.code !== 22105) {
227
240
  // 移出失败
228
- await session.send('取消订阅对象失败,请稍后重试');
241
+ await session.send("取消订阅对象失败,请稍后重试");
229
242
  // 将存在flag设置为true
230
243
  exist = true;
231
244
  // 结束循环
@@ -236,7 +249,7 @@ class ComRegister {
236
249
  // 判断是否还有动态订阅
237
250
  this.checkIfUserIsTheLastOneWhoSubDyn();
238
251
  // 发送成功通知
239
- await session.send('已取消订阅该用户');
252
+ await session.send("已取消订阅该用户");
240
253
  // 更新控制台提示
241
254
  this.updateSubNotifier();
242
255
  // 将存在flag设置为true
@@ -245,43 +258,47 @@ class ComRegister {
245
258
  }));
246
259
  // 未订阅该用户,无需取消订阅
247
260
  if (!exist)
248
- await session.send('未订阅该用户,无需取消订阅');
261
+ await session.send("未订阅该用户,无需取消订阅");
249
262
  });
250
263
  biliCom
251
- .subcommand('.show', '展示订阅对象')
252
- .usage('展示订阅对象')
253
- .example('bili show')
264
+ .subcommand(".show", "展示订阅对象")
265
+ .usage("展示订阅对象")
266
+ .example("bili show")
254
267
  .action(() => {
255
268
  const subTable = this.subShow();
256
269
  return subTable;
257
270
  });
258
271
  biliCom
259
- .subcommand('.sub <mid:string> [...groupId:string]', '订阅用户动态和直播通知')
260
- .option('multiplatform', '-m <value:string>', { type: /^(?:-?[A-Za-z0-9]+@?(?:,-?[A-Za-z0-9]+@?)*\.[A-Za-z0-9]+)(?:;(?:-?[A-Za-z0-9]+@?(?:,-?[A-Za-z0-9]+@?)*\.[A-Za-z0-9]+))*$/ })
261
- .option('live', '-l')
262
- .option('dynamic', '-d')
263
- .option('atAll', '-a')
264
- .usage('订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d')
265
- .example('bili sub 1194210119 目标群号或频道号 -l -d 订阅UID为1194210119的UP主的动态和直播')
272
+ .subcommand(".sub <mid:string> [...groupId:string]", "订阅用户动态和直播通知")
273
+ .option("multiplatform", "-m <value:string>", {
274
+ type: /^(?:-?[A-Za-z0-9]+@?(?:,-?[A-Za-z0-9]+@?)*\.[A-Za-z0-9]+)(?:;(?:-?[A-Za-z0-9]+@?(?:,-?[A-Za-z0-9]+@?)*\.[A-Za-z0-9]+))*$/,
275
+ })
276
+ .option("live", "-l")
277
+ .option("dynamic", "-d")
278
+ .option("atAll", "-a")
279
+ .usage("订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d")
280
+ .example("bili sub 1194210119 目标群号或频道号 -l -d 订阅UID为1194210119的UP主的动态和直播")
266
281
  .action(async ({ session, options }, mid, ...groupId) => {
267
- this.logger.info('调用bili.sub指令');
282
+ this.logger.info("调用bili.sub指令");
268
283
  // 先判断是否订阅直播,再判断是否解锁订阅限制,最后判断直播订阅是否已超三个
269
- if (options.live && !this.config.unlockSubLimits && (this.subManager.reduce((acc, cur) => acc + (cur.live ? 1 : 0), 0) >= 3)) {
270
- return '直播订阅已达上限,请取消部分直播订阅后再进行订阅';
284
+ if (options.live &&
285
+ !this.config.unlockSubLimits &&
286
+ this.subManager.reduce((acc, cur) => acc + (cur.live ? 1 : 0), 0) >= 3) {
287
+ return "直播订阅已达上限,请取消部分直播订阅后再进行订阅";
271
288
  }
272
289
  // 检查是否登录
273
290
  if (!(await this.checkIfIsLogin())) {
274
291
  // 未登录直接返回
275
- return '请使用指令bili login登录后再进行订阅操作';
292
+ return "请使用指令bili login登录后再进行订阅操作";
276
293
  }
277
294
  // 检查必选参数是否已填
278
295
  if (!mid)
279
- return '请输入用户uid';
296
+ return "请输入用户uid";
280
297
  // 订阅对象
281
298
  const subUserData = await this.subUserInBili(mid);
282
299
  // 判断是否订阅对象存在
283
300
  if (!subUserData.flag)
284
- return '订阅对象失败,请稍后重试!';
301
+ return "订阅对象失败,请稍后重试!";
285
302
  // 定义目标变量
286
303
  let target = [];
287
304
  // 判断是否使用了多群组推送
@@ -289,18 +306,18 @@ class ComRegister {
289
306
  // 定义channelIdArr
290
307
  const channelIdArr = [];
291
308
  // 遍历输入的群组
292
- groupId.forEach(group => {
309
+ for (const group of groupId) {
293
310
  channelIdArr.push({
294
311
  channelId: group,
295
312
  dynamic: true,
296
313
  live: true,
297
314
  liveGuardBuy: false,
298
- atAll: options.atAll
315
+ atAll: options.atAll,
299
316
  });
300
- });
317
+ }
301
318
  target.push({
302
319
  channelIdArr,
303
- platform: session.event.platform
320
+ platform: session.event.platform,
304
321
  });
305
322
  }
306
323
  else {
@@ -311,19 +328,20 @@ class ComRegister {
311
328
  }
312
329
  // 判断是否使用了多平台
313
330
  if (target.length > 0) {
314
- for (const [index, { channelIdArr, platform }] of target.entries()) {
315
- if (channelIdArr.length > 0) { // 输入了推送群号或频道号
331
+ for (const [index, { channelIdArr, platform },] of target.entries()) {
332
+ if (channelIdArr.length > 0) {
333
+ // 输入了推送群号或频道号
316
334
  // 拿到对应的bot
317
335
  const bot = this.getBot(platform);
318
336
  // 判断是否配置了对应平台的机器人
319
- if (!ctx.bots.some(bot => bot.platform === platform)) {
337
+ if (!ctx.bots.some((bot) => bot.platform === platform)) {
320
338
  // 发送提示消息
321
- await session.send('您未配置对应平台的机器人,不能在该平台进行订阅操作');
339
+ await session.send("您未配置对应平台的机器人,不能在该平台进行订阅操作");
322
340
  // 直接返回
323
341
  return;
324
342
  }
325
343
  // 判断是否需要加入的群全部推送
326
- if (channelIdArr[0].channelId !== 'all') {
344
+ if (channelIdArr[0].channelId !== "all") {
327
345
  // 定义满足条件的群组数组
328
346
  const targetArr = [];
329
347
  // 获取机器人加入的群组
@@ -337,7 +355,7 @@ class ComRegister {
337
355
  // 获取频道列表
338
356
  const channelList = await bot.getChannelList(guild.id);
339
357
  // 判断机器人是否加入群聊或频道
340
- if (channelList.data.some(channel => channel.id === channelId.channelId)) {
358
+ if (channelList.data.some((channel) => channel.id === channelId.channelId)) {
341
359
  // 加入群聊或频道
342
360
  targetArr.push(channelId);
343
361
  // 设置标志位为true
@@ -354,9 +372,22 @@ class ComRegister {
354
372
  // 判断targetArr是否为空
355
373
  if (target.length === 0) {
356
374
  // 为空则默认为当前环境
357
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, liveGuardBuy: false, atAll: options.atAll ? options.atAll : false }], platform: session.event.platform }];
375
+ target = [
376
+ {
377
+ channelIdArr: [
378
+ {
379
+ channelId: session.event.channel.id,
380
+ dynamic: true,
381
+ live: true,
382
+ liveGuardBuy: false,
383
+ atAll: options.atAll ? options.atAll : false,
384
+ },
385
+ ],
386
+ platform: session.event.platform,
387
+ },
388
+ ];
358
389
  // 没有满足条件的群组或频道
359
- await session.send('没有满足条件的群组或频道,默认订阅到当前聊天环境');
390
+ await session.send("没有满足条件的群组或频道,默认订阅到当前聊天环境");
360
391
  }
361
392
  // 将符合条件的群组添加到target中
362
393
  target[index].channelIdArr = targetArr;
@@ -365,18 +396,45 @@ class ComRegister {
365
396
  }
366
397
  else {
367
398
  // 未填写群号或频道号,默认为当前环境
368
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, liveGuardBuy: false, atAll: options.atAll ? options.atAll : false }], platform: session.event.platform }];
399
+ target = [
400
+ {
401
+ channelIdArr: [
402
+ {
403
+ channelId: session.event.channel.id,
404
+ dynamic: true,
405
+ live: true,
406
+ liveGuardBuy: false,
407
+ atAll: options.atAll ? options.atAll : false,
408
+ },
409
+ ],
410
+ platform: session.event.platform,
411
+ },
412
+ ];
369
413
  // 发送提示消息
370
- await session.send('没有填写群号或频道号,默认订阅到当前聊天环境');
414
+ await session.send("没有填写群号或频道号,默认订阅到当前聊天环境");
371
415
  }
372
416
  }
373
417
  }
374
418
  else {
375
419
  // 用户直接订阅,将当前环境赋值给target
376
- target = [{ channelIdArr: [{ channelId: session.event.channel.id, dynamic: true, live: true, liveGuardBuy: false, atAll: options.atAll ? options.atAll : false }], platform: session.event.platform }];
420
+ target = [
421
+ {
422
+ channelIdArr: [
423
+ {
424
+ channelId: session.event.channel.id,
425
+ dynamic: true,
426
+ live: true,
427
+ liveGuardBuy: false,
428
+ atAll: options.atAll ? options.atAll : false,
429
+ },
430
+ ],
431
+ platform: session.event.platform,
432
+ },
433
+ ];
377
434
  }
378
435
  }
379
- // 定义外围变量
436
+ // 定义外围变量
437
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
380
438
  let content;
381
439
  try {
382
440
  // 获取用户信息
@@ -384,7 +442,7 @@ class ComRegister {
384
442
  }
385
443
  catch (e) {
386
444
  // 返回错误信息
387
- return 'bili sub getUserInfo() 发生了错误,错误为:' + e.message;
445
+ return `bili sub getUserInfo() 发生了错误,错误为:${e.message}`;
388
446
  }
389
447
  // 判断是否成功获取用户信息
390
448
  if (content.code !== 0) {
@@ -393,19 +451,19 @@ class ComRegister {
393
451
  // 判断错误代码
394
452
  switch (content.code) {
395
453
  case -400:
396
- msg = '请求错误';
454
+ msg = "请求错误";
397
455
  break;
398
456
  case -403:
399
- msg = '访问权限不足,请尝试重新登录';
457
+ msg = "访问权限不足,请尝试重新登录";
400
458
  break;
401
459
  case -404:
402
- msg = '用户不存在';
460
+ msg = "用户不存在";
403
461
  break;
404
462
  case -352:
405
- msg = '风控校验失败,请尝试更换UA';
463
+ msg = "风控校验失败,请尝试更换UA";
406
464
  break;
407
465
  default:
408
- msg = '未知错误,错误信息:' + content.message;
466
+ msg = `未知错误,错误信息:${content.message}`;
409
467
  break;
410
468
  }
411
469
  // 返回错误信息
@@ -417,36 +475,38 @@ class ComRegister {
417
475
  const [liveMsg, dynamicMsg] = await this.checkIfNeedSub(options.live, options.dynamic, session, data.live_room);
418
476
  // 判断是否未订阅任何消息
419
477
  if (!liveMsg && !dynamicMsg)
420
- return '您未订阅该UP的任何消息';
478
+ return "您未订阅该UP的任何消息";
421
479
  // 获取到对应的订阅对象
422
- const subUser = this.subManager.find(sub => sub.uid === mid);
480
+ const subUser = this.subManager.find((sub) => sub.uid === mid);
423
481
  // 判断要订阅的用户是否已经存在于订阅管理对象中
424
482
  if (subUser) {
425
483
  // 已存在,判断是否重复订阅直播通知
426
484
  if (liveMsg && subUser.live) {
427
- return '已订阅该用户直播通知,请勿重复订阅';
485
+ return "已订阅该用户直播通知,请勿重复订阅";
428
486
  }
429
487
  // 已存在,判断是否重复订阅动态通知
430
488
  if (dynamicMsg && subUser.dynamic) {
431
- return '已订阅该用户动态通知,请勿重复订阅';
489
+ return "已订阅该用户动态通知,请勿重复订阅";
432
490
  }
433
491
  }
434
492
  // 获取直播房间号
435
493
  const roomId = data.live_room?.roomid.toString();
436
494
  // 获取用户信息
495
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
437
496
  let userData;
438
497
  try {
439
498
  const { data } = await ctx.ba.getMasterInfo(mid);
440
499
  userData = data;
441
500
  }
442
501
  catch (e) {
443
- this.logger.error('bili sub指令 getMasterInfo() 发生了错误,错误为:' + e.message);
444
- return '订阅出错啦,请重试';
502
+ this.logger.error(`bili sub指令 getMasterInfo() 发生了错误,错误为:${e.message}`);
503
+ return "订阅出错啦,请重试";
445
504
  }
446
505
  const liveDetectModeSelector = {
447
506
  API: async () => {
448
507
  // 判断是否已开启直播检测
449
- if (!this.liveDispose) { // 未开启直播检测
508
+ if (!this.liveDispose) {
509
+ // 未开启直播检测
450
510
  // 开启直播检测并保存销毁函数
451
511
  this.liveDispose = await this.liveDetectWithAPI();
452
512
  }
@@ -454,7 +514,7 @@ class ComRegister {
454
514
  WS: async () => {
455
515
  // 连接到服务器
456
516
  await this.liveDetectWithListener(roomId, target);
457
- }
517
+ },
458
518
  };
459
519
  // 订阅直播
460
520
  if (liveMsg) {
@@ -474,14 +534,14 @@ class ComRegister {
474
534
  await session.send(`订阅${userData.info.uname}动态通知`);
475
535
  }
476
536
  // 保存到数据库中
477
- const sub = await ctx.database.create('bilibili', {
537
+ const sub = await ctx.database.create("bilibili", {
478
538
  uid: mid,
479
539
  room_id: roomId,
480
540
  dynamic: dynamicMsg ? 1 : 0,
481
541
  live: liveMsg ? 1 : 0,
482
542
  target: JSON.stringify(target),
483
543
  platform: session.event.platform,
484
- time: new Date()
544
+ time: new Date(),
485
545
  });
486
546
  // 订阅数+1
487
547
  this.num++;
@@ -499,75 +559,83 @@ class ComRegister {
499
559
  this.updateSubNotifier();
500
560
  });
501
561
  biliCom
502
- .subcommand('.status <roomId:string>', '查询主播当前直播状态', { hidden: true })
503
- .usage('查询主播当前直播状态')
504
- .example('bili status 732')
562
+ .subcommand(".status <roomId:string>", "查询主播当前直播状态", {
563
+ hidden: true,
564
+ })
565
+ .usage("查询主播当前直播状态")
566
+ .example("bili status 732")
505
567
  .action(async ({ session }, roomId) => {
506
- this.logger.info('调用bili.status指令');
568
+ this.logger.info("调用bili.status指令");
507
569
  if (!roomId)
508
- return session.send('请输入房间号!');
570
+ return session.send("请输入房间号!");
571
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
509
572
  let content;
510
573
  try {
511
574
  content = await ctx.ba.getLiveRoomInfo(roomId);
512
575
  }
513
576
  catch (e) {
514
- return 'bili status指令 getLiveRoomInfo() 发生了错误,错误为:' + e.message;
577
+ return `bili status指令 getLiveRoomInfo() 发生了错误,错误为:${e.message}`;
515
578
  }
516
579
  const { data } = content;
580
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
517
581
  let userData;
518
582
  try {
519
583
  const { data: userInfo } = await ctx.ba.getMasterInfo(data.uid);
520
584
  userData = userInfo;
521
585
  }
522
586
  catch (e) {
523
- return 'bili status指令 getMasterInfo() 发生了错误,错误为:' + e.message;
587
+ return `bili status指令 getMasterInfo() 发生了错误,错误为:${e.message}`;
524
588
  }
525
589
  // B站出问题了
526
590
  if (content.code !== 0) {
527
- if (content.msg === '未找到该房间') {
528
- session.send('未找到该房间');
591
+ if (content.msg === "未找到该房间") {
592
+ session.send("未找到该房间");
529
593
  }
530
594
  else {
531
- session.send('未知错误,错误信息为:' + content.message);
595
+ session.send(`未知错误,错误信息为:${content.message}`);
532
596
  }
533
597
  return;
534
598
  }
535
- const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData.info.uname, userData.info.face, data.live_status !== 1 ?
536
- LiveType.NotLiveBroadcast :
537
- LiveType.LiveBroadcast);
599
+ const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData.info.uname, userData.info.face, data.live_status !== 1
600
+ ? LiveType.NotLiveBroadcast
601
+ : LiveType.LiveBroadcast);
538
602
  // pic 存在,使用的是render模式
539
603
  if (pic)
540
604
  return pic;
541
605
  // pic不存在,说明使用的是page模式
542
- await session.send(koishi_1.h.image(buffer, 'image/png'));
606
+ await session.send(koishi_1.h.image(buffer, "image/png"));
543
607
  });
544
608
  biliCom
545
- .subcommand('.private', '向主人账号发送一条测试消息', { hidden: true })
546
- .usage('向主人账号发送一条测试消息')
547
- .example('bili private 向主人账号发送一条测试消息')
609
+ .subcommand(".private", "向主人账号发送一条测试消息", { hidden: true })
610
+ .usage("向主人账号发送一条测试消息")
611
+ .example("bili private 向主人账号发送一条测试消息")
548
612
  .action(async ({ session }) => {
549
613
  // 发送消息
550
- await this.sendPrivateMsg('Hello World');
614
+ await this.sendPrivateMsg("Hello World");
551
615
  // 发送提示
552
- await session.send('已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误');
616
+ await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
553
617
  });
554
618
  }
555
619
  async init(config) {
556
620
  // 设置logger
557
- this.logger = this.ctx.logger('cr');
621
+ this.logger = this.ctx.logger("cr");
558
622
  // 将config设置给类属性
559
623
  this.config = config;
560
624
  // 拿到私人机器人实例
561
- this.privateBot = this.ctx.bots.find(bot => bot.platform === config.master.platform);
625
+ this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
562
626
  if (!this.privateBot) {
563
627
  this.ctx.notifier.create({
564
- content: '您未配置私人机器人,将无法向您推送机器人状态!'
628
+ content: "您未配置私人机器人,将无法向您推送机器人状态!",
565
629
  });
566
- this.logger.error('您未配置私人机器人,将无法向您推送机器人状态!');
630
+ this.logger.error("您未配置私人机器人,将无法向您推送机器人状态!");
567
631
  }
568
632
  // 判断消息发送方式
569
633
  if (config.automaticResend) {
570
- this.sendMsgFunc = async (bot, channelId, content) => {
634
+ this.sendMsgFunc = async (
635
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
636
+ bot, channelId,
637
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
638
+ content) => {
571
639
  // 多次尝试发送消息
572
640
  const attempts = 3;
573
641
  for (let i = 0; i < attempts; i++) {
@@ -580,8 +648,9 @@ class ComRegister {
580
648
  break;
581
649
  }
582
650
  catch (e) {
583
- if (i === attempts - 1) { // 已尝试三次
584
- this.logger.error(`发送群组ID:${channelId}消息失败!原因: ` + e.message);
651
+ if (i === attempts - 1) {
652
+ // 已尝试三次
653
+ this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
585
654
  console.log(e);
586
655
  this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
587
656
  }
@@ -590,48 +659,79 @@ class ComRegister {
590
659
  };
591
660
  }
592
661
  else {
593
- this.sendMsgFunc = async (bot, guild, content) => {
662
+ this.sendMsgFunc = async (
663
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
664
+ bot, guild,
665
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
666
+ content) => {
594
667
  try {
595
668
  // 发送消息
596
669
  await bot.sendMessage(guild, content);
597
670
  }
598
671
  catch (e) {
599
- this.logger.error(`发送群组ID:${guild}消息失败!原因: ` + e.message);
672
+ this.logger.error(`发送群组ID:${guild}消息失败!原因: ${e.message}`);
600
673
  await this.sendPrivateMsg(`发送群组ID:${guild}消息失败,请查看日志`);
601
674
  }
602
675
  };
603
676
  }
604
677
  // 检查登录数据库是否有数据
605
- this.loginDBData = (await this.ctx.database.get('loginBili', 1, ['dynamic_group_id']))[0];
678
+ this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
606
679
  // 判断登录信息是否已加载完毕
607
680
  await this.checkIfLoginInfoIsLoaded();
608
681
  // 如果未登录,则直接返回
609
682
  if (!(await this.checkIfIsLogin())) {
610
683
  // log
611
- this.logger.info(`账号未登录,请登录`);
684
+ this.logger.info("账号未登录,请登录");
612
685
  return;
613
686
  }
614
687
  // 从配置获取订阅
615
- config.sub && await this.loadSubFromConfig(config.sub);
688
+ config.sub && (await this.loadSubFromConfig(config.sub));
616
689
  // 从数据库获取订阅
617
690
  await this.loadSubFromDatabase();
618
691
  // 检查是否需要动态监测
619
692
  this.checkIfDynamicDetectIsNeeded();
620
693
  // 在控制台中显示订阅对象
621
694
  this.updateSubNotifier();
695
+ // Test
696
+ const testTarget = [
697
+ {
698
+ channelIdArr: [
699
+ {
700
+ channelId: "635762054",
701
+ dynamic: true,
702
+ live: false,
703
+ liveGuardBuy: false,
704
+ atAll: false,
705
+ },
706
+ ],
707
+ platform: "qqguild",
708
+ },
709
+ ];
710
+ const buffer = await this.ctx.gi.generateWordCloudImg();
711
+ this.sendMsg(testTarget, koishi_1.h.image(buffer, "image/png"));
622
712
  }
623
713
  splitMultiPlatformStr(str) {
624
- return str.split(';').map(cv => cv.split('.')).map(([idStr, platform]) => {
625
- const channelIdArr = idStr.split(',').map(id => {
714
+ return str
715
+ .split(";")
716
+ .map((cv) => cv.split("."))
717
+ .map(([idStr, platform]) => {
718
+ const channelIdArr = idStr.split(",").map((id) => {
626
719
  const atAll = /@$/.test(id); // 使用正则表达式检查 id 是否以 @ 结尾
627
720
  const channelId = atAll ? id.slice(0, -1) : id; // 去除末尾的 @
628
- return { channelId, dynamic: true, live: true, liveGuardBuy: false, atAll };
721
+ return {
722
+ channelId,
723
+ dynamic: true,
724
+ live: true,
725
+ liveGuardBuy: false,
726
+ atAll,
727
+ };
629
728
  });
630
729
  return { channelIdArr, platform };
631
730
  });
632
731
  }
732
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
633
733
  getBot(pf) {
634
- return this.ctx.bots.find(bot => bot.platform === pf);
734
+ return this.ctx.bots.find((bot) => bot.platform === pf);
635
735
  }
636
736
  async sendPrivateMsg(content) {
637
737
  if (this.config.master.enable) {
@@ -649,9 +749,9 @@ class ComRegister {
649
749
  // 判断重启次数是否超过三次
650
750
  if (this.rebootCount >= 3) {
651
751
  // logger
652
- this.logger.error('已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件');
752
+ this.logger.error("已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件");
653
753
  // 重启失败,发送消息
654
- await this.sendPrivateMsg('已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件');
754
+ await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件");
655
755
  // 关闭插件
656
756
  await this.ctx.sm.disposePlugin();
657
757
  // 结束
@@ -660,32 +760,33 @@ class ComRegister {
660
760
  // 重启次数+1
661
761
  this.rebootCount++;
662
762
  // logger
663
- this.logger.info('插件出现未知错误,正在重启插件');
763
+ this.logger.info("插件出现未知错误,正在重启插件");
664
764
  // 重启插件
665
765
  const flag = await this.ctx.sm.restartPlugin();
666
766
  // 判断是否重启成功
667
767
  if (flag) {
668
- this.logger.info('重启插件成功');
768
+ this.logger.info("重启插件成功");
669
769
  }
670
770
  else {
671
771
  // logger
672
- this.logger.error('重启插件失败,请检查机器人状态后使用指令 sys start 启动插件');
772
+ this.logger.error("重启插件失败,请检查机器人状态后使用指令 sys start 启动插件");
673
773
  // 重启失败,发送消息
674
- await this.sendPrivateMsg('重启插件失败,请检查机器人状态后使用指令 sys start 启动插件');
774
+ await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 sys start 启动插件");
675
775
  // 关闭插件
676
776
  await this.ctx.sm.disposePlugin();
677
777
  }
678
778
  }
679
779
  async sendPrivateMsgAndStopService() {
680
780
  // 发送消息
681
- await this.sendPrivateMsg('插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件');
781
+ await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件");
682
782
  // logger
683
- this.logger.error('插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件');
783
+ this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件");
684
784
  // 关闭插件
685
785
  await this.ctx.sm.disposePlugin();
686
786
  // 结束
687
787
  return;
688
788
  }
789
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
689
790
  async sendMsg(targets, content, live) {
690
791
  for (const target of targets) {
691
792
  // 获取机器人实例
@@ -693,7 +794,7 @@ class ComRegister {
693
794
  // 定义需要发送的数组
694
795
  let sendArr = [];
695
796
  // 判断是否需要推送所有机器人加入的群
696
- if (target.channelIdArr[0].channelId === 'all') {
797
+ if (target.channelIdArr[0].channelId === "all") {
697
798
  // 获取所有guild
698
799
  for (const guild of (await bot.getGuildList()).data) {
699
800
  sendArr.push({
@@ -701,7 +802,7 @@ class ComRegister {
701
802
  dynamic: target.channelIdArr[0].dynamic,
702
803
  live: target.channelIdArr[0].live,
703
804
  liveGuardBuy: target.channelIdArr[0].liveGuardBuy,
704
- atAll: target.channelIdArr[0].atAll
805
+ atAll: target.channelIdArr[0].atAll,
705
806
  });
706
807
  }
707
808
  }
@@ -752,7 +853,7 @@ class ComRegister {
752
853
  // 检测启动初始化
753
854
  if (detectSetup) {
754
855
  // 获取动态信息
755
- const data = await this.ctx.ba.getAllDynamic();
856
+ const data = (await this.ctx.ba.getAllDynamic());
756
857
  // 判断获取动态信息是否成功
757
858
  if (data.code !== 0)
758
859
  return;
@@ -765,6 +866,7 @@ class ComRegister {
765
866
  }
766
867
  // 获取用户所有动态数据
767
868
  let updateNum;
869
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
768
870
  let content;
769
871
  try {
770
872
  // 查询是否有新动态
@@ -774,46 +876,50 @@ class ComRegister {
774
876
  if (updateNum <= 0 || data.code !== 0)
775
877
  return;
776
878
  // 获取动态内容
777
- content = await this.ctx.ba.getAllDynamic(updateBaseline);
879
+ content = (await this.ctx.ba.getAllDynamic(updateBaseline));
778
880
  }
779
881
  catch (e) {
780
- return this.logger.error('dynamicDetect getUserSpaceDynamic() 发生了错误,错误为:' + e.message);
882
+ return this.logger.error(`dynamicDetect getUserSpaceDynamic() 发生了错误,错误为:${e.message}`);
781
883
  }
782
884
  // 判断获取动态内容是否成功
783
885
  if (content.code !== 0) {
784
886
  switch (content.code) {
785
- case -101: { // 账号未登录
887
+ case -101: {
888
+ // 账号未登录
786
889
  // 输出日志
787
- this.logger.error('账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件');
890
+ this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
788
891
  // 发送私聊消息
789
- await this.sendPrivateMsg('账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件');
892
+ await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
790
893
  // 停止服务
791
894
  await this.ctx.sm.disposePlugin();
792
895
  // 结束循环
793
896
  break;
794
897
  }
795
- case -352: { // 风控
898
+ case -352: {
899
+ // 风控
796
900
  // 输出日志
797
- this.logger.error('账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件');
901
+ this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
798
902
  // 发送私聊消息
799
- await this.sendPrivateMsg('账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件');
903
+ await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
800
904
  // 停止服务
801
905
  await this.ctx.sm.disposePlugin();
802
906
  // 结束循环
803
907
  break;
804
908
  }
805
909
  case 4101128:
806
- case 4101129: { // 获取动态信息错误
910
+ case 4101129: {
911
+ // 获取动态信息错误
807
912
  // 输出日志
808
- this.logger.error('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message);
913
+ this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
809
914
  // 发送私聊消息
810
- await this.sendPrivateMsg('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message); // 未知错误
915
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
811
916
  // 结束循环
812
917
  break;
813
918
  }
814
- default: { // 未知错误
919
+ default: {
920
+ // 未知错误
815
921
  // 发送私聊消息
816
- await this.sendPrivateMsg('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message); // 未知错误
922
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
817
923
  // 结束循环
818
924
  break;
819
925
  }
@@ -833,9 +939,11 @@ class ComRegister {
833
939
  // 从动态数据中取出UP主名称、UID和动态ID
834
940
  const upUID = items[num].modules.module_author.mid;
835
941
  // 寻找关注的UP主的动态
836
- this.subManager.forEach(async (sub) => {
942
+ for (const sub of this.subManager) {
837
943
  // 判断是否是订阅的UP主
838
- if (sub.dynamic && sub.uid == upUID) { // 订阅该UP主,推送该动态
944
+ // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
945
+ if (sub.dynamic && sub.uid == upUID) {
946
+ // 订阅该UP主,推送该动态
839
947
  // 判断更新动态是否为1条
840
948
  if (updateNum === 1) {
841
949
  // 判断dynamicIdStr是否有值,是否与当前动态ID一致
@@ -867,16 +975,16 @@ class ComRegister {
867
975
  }
868
976
  catch (e) {
869
977
  // 直播开播动态,不做处理
870
- if (e.message === '直播开播动态,不做处理')
978
+ if (e.message === "直播开播动态,不做处理")
871
979
  return;
872
- if (e.message === '出现关键词,屏蔽该动态') {
980
+ if (e.message === "出现关键词,屏蔽该动态") {
873
981
  // 如果需要发送才发送
874
982
  if (this.config.filter.notify) {
875
983
  await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
876
984
  }
877
985
  return;
878
986
  }
879
- if (e.message === '已屏蔽转发动态') {
987
+ if (e.message === "已屏蔽转发动态") {
880
988
  if (this.config.filter.notify) {
881
989
  await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
882
990
  }
@@ -884,30 +992,32 @@ class ComRegister {
884
992
  }
885
993
  // 未知错误
886
994
  if (i === attempts - 1) {
887
- this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.message);
995
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
888
996
  // 发送私聊消息并重启服务
889
997
  return await this.sendPrivateMsgAndStopService();
890
998
  }
891
999
  }
892
1000
  }
893
1001
  // 判断是否需要发送URL
894
- const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
1002
+ const dUrl = this.config.dynamicUrl
1003
+ ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
1004
+ : "";
895
1005
  // 如果pic存在,则直接返回pic
896
1006
  if (pic) {
897
- this.logger.info('推送动态中,使用render模式');
1007
+ this.logger.info("推送动态中,使用render模式");
898
1008
  // pic存在,使用的是render模式
899
- await this.sendMsg(sub.target, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
1009
+ await this.sendMsg(sub.target, pic + dUrl);
900
1010
  }
901
1011
  else if (buffer) {
902
- this.logger.info('推送动态中,使用page模式');
1012
+ this.logger.info("推送动态中,使用page模式");
903
1013
  // pic不存在,说明使用的是page模式
904
- await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
1014
+ await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), dUrl] }));
905
1015
  }
906
1016
  else {
907
- this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
1017
+ this.logger.info(`${items[num].modules.module_author.name}发布了一条动态,但是推送失败`);
908
1018
  }
909
1019
  }
910
- });
1020
+ }
911
1021
  }
912
1022
  }
913
1023
  finally {
@@ -936,7 +1046,7 @@ class ComRegister {
936
1046
  // 检测启动初始化
937
1047
  if (detectSetup) {
938
1048
  // 获取动态信息
939
- const data = await this.ctx.ba.getAllDynamic();
1049
+ const data = (await this.ctx.ba.getAllDynamic());
940
1050
  // 判断获取动态信息是否成功
941
1051
  if (data.code !== 0)
942
1052
  return;
@@ -950,59 +1060,65 @@ class ComRegister {
950
1060
  }
951
1061
  // 获取用户所有动态数据
952
1062
  let updateNum;
1063
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
953
1064
  let content;
954
1065
  try {
955
1066
  // 查询是否有新动态
956
1067
  const data = await this.ctx.ba.hasNewDynamic(updateBaseline);
957
1068
  updateNum = data.data.update_num;
1069
+ // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
958
1070
  console.log(`获取是否有新动态:`);
959
1071
  console.log(data);
960
1072
  // 没有新动态或获取动态信息失败直接返回
961
1073
  if (updateNum <= 0 || data.code !== 0)
962
1074
  return;
963
1075
  // 获取动态内容
964
- content = await this.ctx.ba.getAllDynamic(updateBaseline);
965
- console.log('获取动态内容:');
1076
+ content = (await this.ctx.ba.getAllDynamic(updateBaseline));
1077
+ console.log("获取动态内容:");
966
1078
  console.log(content.data.items[0]);
967
1079
  }
968
1080
  catch (e) {
969
- return this.logger.error('dynamicDetect getUserSpaceDynamic() 发生了错误,错误为:' + e.message);
1081
+ return this.logger.error(`dynamicDetect getUserSpaceDynamic() 发生了错误,错误为:${e.message}`);
970
1082
  }
971
1083
  // 判断获取动态内容是否成功
972
1084
  if (content.code !== 0) {
973
1085
  switch (content.code) {
974
- case -101: { // 账号未登录
1086
+ case -101: {
1087
+ // 账号未登录
975
1088
  // 输出日志
976
- this.logger.error('账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件');
1089
+ this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
977
1090
  // 发送私聊消息
978
- await this.sendPrivateMsg('账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件');
1091
+ await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
979
1092
  // 停止服务
980
1093
  await this.ctx.sm.disposePlugin();
981
1094
  // 结束循环
982
1095
  break;
983
1096
  }
984
- case -352: { // 风控
1097
+ case -352: {
1098
+ // 风控
985
1099
  // 输出日志
986
- this.logger.error('账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件');
1100
+ this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
987
1101
  // 发送私聊消息
988
- await this.sendPrivateMsg('账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件');
1102
+ await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
989
1103
  // 停止服务
990
1104
  await this.ctx.sm.disposePlugin();
991
1105
  // 结束循环
992
1106
  break;
993
1107
  }
994
1108
  case 4101128:
995
- case 4101129: { // 获取动态信息错误
1109
+ case 4101129: {
1110
+ // 获取动态信息错误
996
1111
  // 输出日志
997
- this.logger.error('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message);
1112
+ this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
998
1113
  // 发送私聊消息
999
- await this.sendPrivateMsg('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message); // 未知错误
1114
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
1000
1115
  // 结束循环
1001
1116
  break;
1002
1117
  }
1003
- default: { // 未知错误
1118
+ default: {
1119
+ // 未知错误
1004
1120
  // 发送私聊消息
1005
- await this.sendPrivateMsg('获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message); // 未知错误
1121
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
1006
1122
  // 结束循环
1007
1123
  break;
1008
1124
  }
@@ -1018,7 +1134,7 @@ class ComRegister {
1018
1134
  // 检查更新的动态
1019
1135
  for (let num = updateNum - 1; num >= 0; num--) {
1020
1136
  // 有更新动态
1021
- console.log('有更新动态');
1137
+ console.log("有更新动态");
1022
1138
  // 没有动态内容则直接跳过
1023
1139
  if (!items[num])
1024
1140
  continue;
@@ -1028,10 +1144,12 @@ class ComRegister {
1028
1144
  const dynamicId = content.data.items[num].id_str;
1029
1145
  console.log(`寻找关注的UP主,当前动态UP主:${upName},UID:${upUID},动态ID:${dynamicId}`);
1030
1146
  // 寻找关注的UP主的动态
1031
- this.subManager.forEach(async (sub) => {
1147
+ for (const sub of this.subManager) {
1032
1148
  console.log(`当前订阅UP主:${sub.uid}`);
1033
1149
  // 判断是否是订阅的UP主
1034
- if (sub.dynamic && sub.uid == upUID) { // 订阅该UP主,推送该动态
1150
+ // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
1151
+ if (sub.dynamic && sub.uid == upUID) {
1152
+ // 订阅该UP主,推送该动态
1035
1153
  // 判断更新动态是否为1条
1036
1154
  if (updateNum === 1) {
1037
1155
  // 判断dynamicIdStr是否有值,是否与当前动态ID一致
@@ -1064,16 +1182,16 @@ class ComRegister {
1064
1182
  }
1065
1183
  catch (e) {
1066
1184
  // 直播开播动态,不做处理
1067
- if (e.message === '直播开播动态,不做处理')
1185
+ if (e.message === "直播开播动态,不做处理")
1068
1186
  return;
1069
- if (e.message === '出现关键词,屏蔽该动态') {
1187
+ if (e.message === "出现关键词,屏蔽该动态") {
1070
1188
  // 如果需要发送才发送
1071
1189
  if (this.config.filter.notify) {
1072
1190
  await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
1073
1191
  }
1074
1192
  return;
1075
1193
  }
1076
- if (e.message === '已屏蔽转发动态') {
1194
+ if (e.message === "已屏蔽转发动态") {
1077
1195
  if (this.config.filter.notify) {
1078
1196
  await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
1079
1197
  }
@@ -1081,30 +1199,32 @@ class ComRegister {
1081
1199
  }
1082
1200
  // 未知错误
1083
1201
  if (i === attempts - 1) {
1084
- this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.message);
1202
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
1085
1203
  // 发送私聊消息并重启服务
1086
1204
  return await this.sendPrivateMsgAndStopService();
1087
1205
  }
1088
1206
  }
1089
1207
  }
1090
1208
  // 判断是否需要发送URL
1091
- const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
1209
+ const dUrl = this.config.dynamicUrl
1210
+ ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
1211
+ : "";
1092
1212
  // 如果pic存在,则直接返回pic
1093
1213
  if (pic) {
1094
- this.logger.info('推送动态中,使用render模式');
1214
+ this.logger.info("推送动态中,使用render模式");
1095
1215
  // pic存在,使用的是render模式
1096
- await this.sendMsg(sub.target, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
1216
+ await this.sendMsg(sub.target, pic + dUrl);
1097
1217
  }
1098
1218
  else if (buffer) {
1099
- this.logger.info('推送动态中,使用page模式');
1219
+ this.logger.info("推送动态中,使用page模式");
1100
1220
  // pic不存在,说明使用的是page模式
1101
- await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), dUrl] }));
1221
+ await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), dUrl] }));
1102
1222
  }
1103
1223
  else {
1104
- this.logger.info(items[num].modules.module_author.name + '发布了一条动态,但是推送失败');
1224
+ this.logger.info(`${items[num].modules.module_author.name}发布了一条动态,但是推送失败`);
1105
1225
  }
1106
1226
  }
1107
- });
1227
+ }
1108
1228
  }
1109
1229
  }
1110
1230
  finally {
@@ -1130,8 +1250,9 @@ class ComRegister {
1130
1250
  break;
1131
1251
  }
1132
1252
  catch (e) {
1133
- if (i === attempts - 1) { // 已尝试三次
1134
- this.logger.error('liveDetect generateLiveImg() 推送卡片生成失败,原因:' + e.message);
1253
+ if (i === attempts - 1) {
1254
+ // 已尝试三次
1255
+ this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
1135
1256
  // 发送私聊消息并重启服务
1136
1257
  return await this.sendPrivateMsgAndStopService();
1137
1258
  }
@@ -1142,13 +1263,13 @@ class ComRegister {
1142
1263
  if (pic) {
1143
1264
  // 只有在开播时才艾特全体成员
1144
1265
  if (liveType === LiveType.StartBroadcasting) {
1145
- return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ''), true);
1266
+ return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ""), true);
1146
1267
  }
1147
1268
  // 正常不需要艾特全体成员
1148
- return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ''));
1269
+ return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ""));
1149
1270
  }
1150
1271
  // pic不存在,说明使用的是page模式
1151
- const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), liveNotifyMsg || ''] });
1272
+ const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), liveNotifyMsg || ""] }));
1152
1273
  // 只有在开播时才艾特全体成员
1153
1274
  if (liveType === LiveType.StartBroadcasting) {
1154
1275
  return await this.sendMsg(info.target, msg, true);
@@ -1159,10 +1280,15 @@ class ComRegister {
1159
1280
  // 定义获取主播信息方法
1160
1281
  async useMasterInfo(uid) {
1161
1282
  const { data } = await this.ctx.ba.getMasterInfo(uid);
1162
- return { username: data.info.uname, userface: data.info.face, roomId: data.room_id };
1283
+ return {
1284
+ username: data.info.uname,
1285
+ userface: data.info.face,
1286
+ roomId: data.room_id,
1287
+ };
1163
1288
  }
1164
1289
  async useLiveRoomInfo(roomId) {
1165
1290
  // 发送请求获取直播间信息
1291
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1166
1292
  let content;
1167
1293
  const attempts = 3;
1168
1294
  for (let i = 0; i < attempts; i++) {
@@ -1173,8 +1299,9 @@ class ComRegister {
1173
1299
  break;
1174
1300
  }
1175
1301
  catch (e) {
1176
- this.logger.error('liveDetect getLiveRoomInfo 发生了错误,错误为:' + e.message);
1177
- if (i === attempts - 1) { // 已尝试三次
1302
+ this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1303
+ if (i === attempts - 1) {
1304
+ // 已尝试三次
1178
1305
  // 发送私聊消息并重启服务
1179
1306
  return await this.sendPrivateMsgAndStopService();
1180
1307
  }
@@ -1193,6 +1320,7 @@ class ComRegister {
1193
1320
  const liveRecord = {};
1194
1321
  // 定义函数: 发送请求获取直播状态
1195
1322
  const useLiveStatus = async (roomId) => {
1323
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1196
1324
  let content;
1197
1325
  const attempts = 3;
1198
1326
  for (let i = 0; i < attempts; i++) {
@@ -1203,8 +1331,9 @@ class ComRegister {
1203
1331
  break;
1204
1332
  }
1205
1333
  catch (e) {
1206
- this.logger.error('liveDetect getLiveRoomInfo 发生了错误,错误为:' + e.message);
1207
- if (i === attempts - 1) { // 已尝试三次
1334
+ this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
1335
+ if (i === attempts - 1) {
1336
+ // 已尝试三次
1208
1337
  // 发送私聊消息并重启服务
1209
1338
  return await this.sendPrivateMsgAndStopService();
1210
1339
  }
@@ -1227,17 +1356,21 @@ class ComRegister {
1227
1356
  // 将第一次订阅置为false
1228
1357
  liveDetectSetup = false;
1229
1358
  // 初始化subRecord
1230
- this.subManager.forEach(sub => {
1359
+ for (const sub of this.subManager) {
1231
1360
  // 判断是否订阅直播
1232
1361
  if (sub.live) {
1233
1362
  // 将该订阅添加到subRecord中
1234
- liveRecord[sub.uid] = { liveStatus: 0, liveTime: '', target: sub.target };
1363
+ liveRecord[sub.uid] = {
1364
+ liveStatus: 0,
1365
+ liveTime: "",
1366
+ target: sub.target,
1367
+ };
1235
1368
  }
1236
- });
1369
+ }
1237
1370
  // 先判断是否有UP主正在直播
1238
1371
  if (liveUsers.count > 0) {
1239
1372
  // 遍历liveUsers
1240
- liveUsers.items.forEach(async (item) => {
1373
+ for (const item of liveUsers.items) {
1241
1374
  // 判断是否有订阅对象正在直播
1242
1375
  if (liveRecord[item.mid]) {
1243
1376
  // 获取当前用户直播间信息
@@ -1247,26 +1380,28 @@ class ComRegister {
1247
1380
  // 改变开播状态
1248
1381
  liveRecord[item.mid].liveStatus = 1;
1249
1382
  // 设置直播中消息
1250
- const liveMsg = this.config.customLive ? this.config.customLive
1251
- .replace('-name', item.uname)
1252
- .replace('-time', await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
1253
- .replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`) : null;
1383
+ const liveMsg = this.config.customLive
1384
+ ? this.config.customLive
1385
+ .replace("-name", item.uname)
1386
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
1387
+ .replace("-link", `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`)
1388
+ : null;
1254
1389
  // 发送直播通知卡片
1255
1390
  if (this.config.restartPush)
1256
1391
  this.sendLiveNotifyCard({
1257
1392
  username: item.uname,
1258
1393
  userface: item.face,
1259
1394
  target: liveRecord[item.mid].target,
1260
- data
1395
+ data,
1261
1396
  }, LiveType.LiveBroadcast, liveMsg);
1262
1397
  }
1263
- });
1398
+ }
1264
1399
  }
1265
1400
  // 没有正在直播的订阅对象,直接返回
1266
1401
  return;
1267
1402
  }
1268
1403
  // 获取当前订阅直播的数量
1269
- const currentLiveSubs = this.subManager.filter(sub => sub.live);
1404
+ const currentLiveSubs = this.subManager.filter((sub) => sub.live);
1270
1405
  // 获取当前liveRecord里的订阅数量
1271
1406
  const currentLiveRecordKeys = Object.keys(liveRecord);
1272
1407
  // 判断是否能匹配双方数量
@@ -1279,15 +1414,25 @@ class ComRegister {
1279
1414
  const data = await useLiveStatus(sub.roomId.toString());
1280
1415
  switch (data.live_status) {
1281
1416
  case 0:
1282
- case 2: { // 未开播
1417
+ case 2: {
1418
+ // 未开播
1283
1419
  // 添加到liveRecord中
1284
- liveRecord[sub.uid] = { liveStatus: 0, liveTime: '', target: sub.target };
1420
+ liveRecord[sub.uid] = {
1421
+ liveStatus: 0,
1422
+ liveTime: "",
1423
+ target: sub.target,
1424
+ };
1285
1425
  // break
1286
1426
  break;
1287
1427
  }
1288
- case 1: { //正在直播
1428
+ case 1: {
1429
+ //正在直播
1289
1430
  // 添加到liveRecord中
1290
- liveRecord[sub.uid] = { liveStatus: 1, liveTime: data.live_time, target: sub.target };
1431
+ liveRecord[sub.uid] = {
1432
+ liveStatus: 1,
1433
+ liveTime: data.live_time,
1434
+ target: sub.target,
1435
+ };
1291
1436
  }
1292
1437
  }
1293
1438
  }
@@ -1295,10 +1440,10 @@ class ComRegister {
1295
1440
  }
1296
1441
  if (currentLiveRecordKeys.length > currentLiveSubs.length) {
1297
1442
  // 创建Set
1298
- const setCurrentLiveSubs = new Set(currentLiveSubs.map(sub => sub.uid));
1443
+ const setCurrentLiveSubs = new Set(currentLiveSubs.map((sub) => sub.uid));
1299
1444
  // 找出 currentLiveRecordKeys中比currentLiveSubs 多的元素
1300
- const extraInCurrentLiveSubs = currentLiveRecordKeys.filter(key => !setCurrentLiveSubs.has(key));
1301
- // 遍历 extraInCurrentLiveSubs
1445
+ const extraInCurrentLiveSubs = currentLiveRecordKeys.filter((key) => !setCurrentLiveSubs.has(key));
1446
+ // 遍历 extraInCurrentLiveSubs
1302
1447
  for (const subUID of extraInCurrentLiveSubs) {
1303
1448
  // 删除记录
1304
1449
  delete liveRecord[subUID];
@@ -1306,79 +1451,90 @@ class ComRegister {
1306
1451
  }
1307
1452
  // 数量没有差异,则不进行其他操作
1308
1453
  // 遍历liveUsers
1309
- liveUsers.items.forEach(async (item) => {
1454
+ for (const item of liveUsers.items) {
1310
1455
  // 判断是否有正在直播的订阅对象
1311
- if (liveRecord[item.mid]) { // 有正在直播的订阅对象
1456
+ if (liveRecord[item.mid]) {
1457
+ // 有正在直播的订阅对象
1312
1458
  // 获取当前用户直播间信息
1313
1459
  const data = await useLiveStatus(item.room_id.toString());
1314
1460
  // 判断开播状态
1315
1461
  switch (liveRecord[item.mid].liveStatus) {
1316
- case 0: { // 之前未开播,现在开播了
1462
+ case 0: {
1463
+ // 之前未开播,现在开播了
1317
1464
  // 设置开播时间
1318
1465
  liveRecord[item.mid].liveTime = data.live_time;
1319
- // 定义开播通知语
1320
- const liveStartMsg = this.config.customLiveStart ? this.config.customLiveStart
1321
- .replace('-name', item.uname)
1322
- .replace('-time', await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
1323
- .replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`) : null;
1466
+ // 定义开播通知语
1467
+ const liveStartMsg = this.config.customLiveStart
1468
+ ? this.config.customLiveStart
1469
+ .replace("-name", item.uname)
1470
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
1471
+ .replace("-link", `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`)
1472
+ : null;
1324
1473
  // 发送直播通知卡片
1325
1474
  await this.sendLiveNotifyCard({
1326
1475
  username: item.uname,
1327
1476
  userface: item.face,
1328
1477
  target: liveRecord[item.mid].target,
1329
- data
1478
+ data,
1330
1479
  }, LiveType.LiveBroadcast, liveStartMsg);
1331
1480
  // 改变开播状态
1332
1481
  liveRecord[item.mid].liveStatus = 1;
1333
1482
  // 结束
1334
1483
  break;
1335
1484
  }
1336
- case 1: { // 仍在直播
1485
+ case 1: {
1486
+ // 仍在直播
1337
1487
  if (this.config.pushTime > 0) {
1338
1488
  timer++;
1339
1489
  // 开始记录时间
1340
- if (timer >= (6 * 60 * this.config.pushTime)) { // 到时间推送直播消息
1490
+ if (timer >= 6 * 60 * this.config.pushTime) {
1491
+ // 到时间推送直播消息
1341
1492
  // 到时间重新计时
1342
1493
  timer = 0;
1343
1494
  // 定义直播中通知消息
1344
- const liveMsg = this.config.customLive ? this.config.customLive
1345
- .replace('-name', item.uname)
1346
- .replace('-time', await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
1347
- .replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`) : null;
1495
+ const liveMsg = this.config.customLive
1496
+ ? this.config.customLive
1497
+ .replace("-name", item.uname)
1498
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
1499
+ .replace("-link", `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`)
1500
+ : null;
1348
1501
  // 发送直播通知卡片
1349
1502
  this.sendLiveNotifyCard({
1350
1503
  username: item.uname,
1351
1504
  userface: item.face,
1352
1505
  target: liveRecord[item.mid].target,
1353
- data
1506
+ data,
1354
1507
  }, LiveType.LiveBroadcast, liveMsg);
1355
1508
  }
1356
1509
  }
1357
1510
  }
1358
1511
  }
1359
1512
  }
1360
- });
1513
+ }
1361
1514
  // 找出liveRecord中liveStatus为1但liveUsers中没有的元素
1362
- const extraInLiveRecord = currentLiveRecordKeys.filter(key => !liveUsers.items.some(item => item.mid === Number(key)));
1515
+ const extraInLiveRecord = currentLiveRecordKeys.filter((key) => !liveUsers.items.some((item) => item.mid === Number(key)));
1363
1516
  // 遍历 extraInLiveRecord
1364
- for (const subUID of extraInLiveRecord) { // 下播的主播
1517
+ for (const subUID of extraInLiveRecord) {
1518
+ // 下播的主播
1365
1519
  // 获取主播信息
1366
1520
  const masterInfo = await this.useMasterInfo(subUID);
1367
1521
  // 获取直播间消息
1368
1522
  const liveRoomInfo = await this.useLiveRoomInfo(masterInfo.roomId.toString());
1369
1523
  // 设置开播时间
1370
1524
  liveRoomInfo.live_time = liveRecord[subUID].liveTime;
1371
- // 定义下播播通知语
1372
- const liveEndMsg = this.config.customLiveEnd ? this.config.customLiveEnd
1373
- .replace('-name', masterInfo.username)
1374
- .replace('-time', await this.ctx.gi.getTimeDifference(liveRecord[subUID].liveTime))
1375
- .replace('-link', `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
1525
+ // 定义下播播通知语
1526
+ const liveEndMsg = this.config.customLiveEnd
1527
+ ? this.config.customLiveEnd
1528
+ .replace("-name", masterInfo.username)
1529
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[subUID].liveTime))
1530
+ .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1531
+ : null;
1376
1532
  // 发送下播通知
1377
1533
  this.sendLiveNotifyCard({
1378
1534
  username: masterInfo.username,
1379
1535
  userface: masterInfo.userface,
1380
1536
  target: liveRecord[subUID].target,
1381
- data: liveRoomInfo
1537
+ data: liveRoomInfo,
1382
1538
  }, LiveType.StopBroadcast, liveEndMsg);
1383
1539
  }
1384
1540
  }
@@ -1401,18 +1557,19 @@ class ComRegister {
1401
1557
  // 定义channelIdArr总长度
1402
1558
  let channelIdArrLen = 0;
1403
1559
  // 定义数据
1560
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1404
1561
  let liveRoomInfo;
1405
1562
  let masterInfo;
1406
1563
  // 找到频道/群组对应的
1407
- const liveGuardBuyPushTargetArr = target.map(channel => {
1564
+ const liveGuardBuyPushTargetArr = target.map((channel) => {
1408
1565
  // 获取符合条件的target
1409
- const liveGuardBuyArr = channel.channelIdArr.filter(channelId => channelId.liveGuardBuy);
1566
+ const liveGuardBuyArr = channel.channelIdArr.filter((channelId) => channelId.liveGuardBuy);
1410
1567
  // 将当前liveDanmakuArr的长度+到channelIdArrLen中
1411
1568
  channelIdArrLen += liveGuardBuyArr.length;
1412
1569
  // 返回符合的target
1413
1570
  return {
1414
1571
  channelIdArr: liveGuardBuyArr,
1415
- platform: channel.platform
1572
+ platform: channel.platform,
1416
1573
  };
1417
1574
  });
1418
1575
  // 定义定时推送函数
@@ -1420,75 +1577,43 @@ class ComRegister {
1420
1577
  // 判断是否信息是否获取成功
1421
1578
  if (!(await useMasterAndLiveRoomInfo())) {
1422
1579
  // 未获取成功,直接返回
1423
- return this.sendPrivateMsg('获取直播间信息失败,推送直播卡片失败!');
1580
+ return this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1424
1581
  }
1425
1582
  // 设置开播时间
1426
1583
  liveTime = liveRoomInfo.live_time;
1427
1584
  // 设置直播中消息
1428
- const liveMsg = this.config.customLive ? this.config.customLive
1429
- .replace('-name', masterInfo.username)
1430
- .replace('-time', await this.ctx.gi.getTimeDifference(liveTime))
1431
- .replace('-link', `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
1585
+ const liveMsg = this.config.customLive
1586
+ ? this.config.customLive
1587
+ .replace("-name", masterInfo.username)
1588
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
1589
+ .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1590
+ : null;
1432
1591
  // 发送直播通知卡片
1433
1592
  await this.sendLiveNotifyCard({
1434
1593
  username: masterInfo.username,
1435
1594
  userface: masterInfo.userface,
1436
1595
  target,
1437
- data: liveRoomInfo
1596
+ data: liveRoomInfo,
1438
1597
  }, LiveType.LiveBroadcast, liveMsg);
1439
1598
  };
1440
- // 定义获取弹幕权重Record函数
1441
- const getDanmakuWeightRecord = () => {
1599
+ // TODO:WordCloud
1600
+ /* // 定义获取弹幕权重Record函数
1601
+ const getDanmakuWeightRecord = (): Record<string, number> => {
1442
1602
  // 创建segmentit
1443
- const segmentit = (0, segmentit_1.useDefault)(new segmentit_1.Segment());
1603
+ const segmentit = useDefault(new Segment());
1444
1604
  // 创建Record
1445
- const danmakuWeightRecord = {};
1605
+ const danmakuWeightRecord: Record<string, number> = {};
1446
1606
  // 循环遍历currentLiveDanmakuArr
1447
1607
  for (const danmaku of currentLiveDanmakuArr) {
1448
1608
  // 遍历结果
1449
- segmentit.doSegment(danmaku).map((word) => {
1609
+ segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
1450
1610
  // 定义权重
1451
1611
  danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
1452
1612
  });
1453
1613
  }
1454
1614
  // 返回Record
1455
1615
  return danmakuWeightRecord;
1456
- };
1457
- // 定义获取弹幕词云函数
1458
- const sendDanmakuWordCloud = (danmakuWeightRecord) => {
1459
- // 准备词云数据
1460
- const wordList = Object.keys(danmakuWeightRecord).map(word => ({ text: word, value: danmakuWeightRecord[word] }));
1461
- // 创建画布
1462
- const width = 800;
1463
- const height = 600;
1464
- // 定义绘制函数
1465
- const generateSVG = async (words) => {
1466
- // 定义svg头部
1467
- const svgHeader = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">`;
1468
- // 定义svg尾部
1469
- const svgFooter = '</svg>';
1470
- // 定义svg身体
1471
- const svgBody = words.map(d => {
1472
- return `<text x="${d.x}" y="${d.y}" font-family="Arial" font-size="${d.size}" fill="black">${d.text}</text>`;
1473
- }).join('\n');
1474
- // 拼接svg
1475
- const svgContent = svgHeader + svgBody + svgFooter;
1476
- // 渲染svg
1477
- const pic = await this.ctx.gi.generateWordCloudImg(svgContent);
1478
- // 发送消息
1479
- this.sendMsg(target, pic);
1480
- };
1481
- // 配置词云
1482
- const layout = (0, d3_cloud_1.default)()
1483
- .size([width, height])
1484
- .words(wordList.map(d => ({ text: d.text, size: d.value })))
1485
- .padding(5)
1486
- .font('Arial')
1487
- .fontSize(d => d.size)
1488
- .on('end', generateSVG);
1489
- // 生成词云
1490
- layout.start();
1491
- };
1616
+ }; */
1492
1617
  // 定义直播间信息获取函数
1493
1618
  const useMasterAndLiveRoomInfo = async () => {
1494
1619
  // 定义函数是否执行成功flag
@@ -1520,15 +1645,15 @@ class ComRegister {
1520
1645
  // 判断是否信息是否获取成功
1521
1646
  if (!(await useMasterAndLiveRoomInfo())) {
1522
1647
  // 未获取成功,直接返回
1523
- return this.sendPrivateMsg('获取直播间信息失败,启动直播间弹幕检测失败!');
1648
+ return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
1524
1649
  }
1525
1650
  // 构建消息处理函数
1526
1651
  const handler = {
1527
1652
  onOpen: () => {
1528
- this.logger.info('直播间连接成功');
1653
+ this.logger.info("直播间连接成功");
1529
1654
  },
1530
1655
  onClose: () => {
1531
- this.logger.info('直播间连接已断开');
1656
+ this.logger.info("直播间连接已断开");
1532
1657
  },
1533
1658
  onIncomeDanmu: ({ body }) => {
1534
1659
  // 保存消息到数组
@@ -1555,21 +1680,23 @@ class ComRegister {
1555
1680
  // 设置开播状态为false
1556
1681
  liveStatus = false;
1557
1682
  // 未获取成功,直接返回
1558
- return await this.sendPrivateMsg('获取直播间信息失败,推送直播开播卡片失败!');
1683
+ return await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1559
1684
  }
1560
1685
  // 设置开播时间
1561
1686
  liveTime = liveRoomInfo.live_time;
1562
- // 定义开播通知语
1563
- const liveStartMsg = this.config.customLiveStart ? this.config.customLiveStart
1564
- .replace('-name', masterInfo.username)
1565
- .replace('-time', await this.ctx.gi.getTimeDifference(liveTime))
1566
- .replace('-link', `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
1687
+ // 定义开播通知语
1688
+ const liveStartMsg = this.config.customLiveStart
1689
+ ? this.config.customLiveStart
1690
+ .replace("-name", masterInfo.username)
1691
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
1692
+ .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1693
+ : null;
1567
1694
  // 推送开播通知
1568
1695
  await this.sendLiveNotifyCard({
1569
1696
  username: masterInfo.username,
1570
1697
  userface: masterInfo.userface,
1571
1698
  target,
1572
- data: liveRoomInfo
1699
+ data: liveRoomInfo,
1573
1700
  }, LiveType.StartBroadcasting, liveStartMsg);
1574
1701
  // 判断定时器是否已开启
1575
1702
  if (!pushAtTimeTimer) {
@@ -1578,33 +1705,33 @@ class ComRegister {
1578
1705
  }
1579
1706
  },
1580
1707
  onLiveEnd: async () => {
1708
+ // 将直播状态设置为false
1709
+ liveStatus = false;
1581
1710
  // 判断是否信息是否获取成功
1582
1711
  if (!(await useMasterAndLiveRoomInfo())) {
1583
1712
  // 未获取成功,直接返回
1584
- return this.sendPrivateMsg('获取直播间信息失败,推送直播下播卡片失败!');
1713
+ return this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1585
1714
  }
1586
1715
  // 更改直播时长
1587
1716
  liveRoomInfo.live_time = liveTime;
1588
- // 定义下播播通知语
1589
- const liveEndMsg = this.config.customLiveEnd ? this.config.customLiveEnd
1590
- .replace('-name', masterInfo.username)
1591
- .replace('-time', await this.ctx.gi.getTimeDifference(liveTime)) : null;
1717
+ // 定义下播播通知语
1718
+ const liveEndMsg = this.config.customLiveEnd
1719
+ ? this.config.customLiveEnd
1720
+ .replace("-name", masterInfo.username)
1721
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
1722
+ : null;
1592
1723
  // 推送通知卡片
1593
1724
  await this.sendLiveNotifyCard({
1594
1725
  username: masterInfo.username,
1595
1726
  userface: masterInfo.userface,
1596
1727
  target,
1597
- data: liveRoomInfo
1728
+ data: liveRoomInfo,
1598
1729
  }, LiveType.StopBroadcast, liveEndMsg);
1599
1730
  // 关闭定时推送定时器
1600
1731
  pushAtTimeTimer();
1601
1732
  // 将推送定时器变量置空
1602
1733
  pushAtTimeTimer = null;
1603
- // 发送弹幕词云
1604
- sendDanmakuWordCloud(getDanmakuWeightRecord());
1605
- // 将直播状态设置为false
1606
- liveStatus = false;
1607
- }
1734
+ },
1608
1735
  };
1609
1736
  // 启动直播间弹幕监测
1610
1737
  await this.ctx.bl.startLiveRoomListener(roomId, handler);
@@ -1613,17 +1740,19 @@ class ComRegister {
1613
1740
  // 设置开播时间
1614
1741
  liveTime = liveRoomInfo.live_time;
1615
1742
  // 定义直播中通知消息
1616
- const liveMsg = this.config.customLive ? this.config.customLive
1617
- .replace('-name', masterInfo.username)
1618
- .replace('-time', await this.ctx.gi.getTimeDifference(liveTime))
1619
- .replace('-link', `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
1743
+ const liveMsg = this.config.customLive
1744
+ ? this.config.customLive
1745
+ .replace("-name", masterInfo.username)
1746
+ .replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
1747
+ .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1748
+ : null;
1620
1749
  // 发送直播通知卡片
1621
1750
  if (this.config.restartPush) {
1622
1751
  await this.sendLiveNotifyCard({
1623
1752
  username: masterInfo.username,
1624
1753
  userface: masterInfo.userface,
1625
1754
  target,
1626
- data: liveRoomInfo
1755
+ data: liveRoomInfo,
1627
1756
  }, LiveType.LiveBroadcast, liveMsg);
1628
1757
  }
1629
1758
  // 正在直播,开启定时器
@@ -1638,18 +1767,20 @@ class ComRegister {
1638
1767
  }
1639
1768
  subShow() {
1640
1769
  // 在控制台中显示订阅对象
1641
- let table = ``;
1642
- this.subManager.forEach(sub => {
1643
- table += `UID:${sub.uid} ${sub.dynamic ? '已订阅动态' : ''} ${sub.live ? '已订阅直播' : ''}` + '\n';
1644
- });
1645
- return table ? table : '没有订阅任何UP';
1770
+ let table = "";
1771
+ for (const sub of this.subManager) {
1772
+ table += `UID:${sub.uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
1773
+ }
1774
+ return table ? table : "没有订阅任何UP";
1646
1775
  }
1647
- async checkIfNeedSub(liveSub, dynamicSub, session, liveRoomData) {
1776
+ async checkIfNeedSub(liveSub, dynamicSub, session,
1777
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1778
+ liveRoomData) {
1648
1779
  // 定义方法:用户直播间是否存在
1649
1780
  const liveRoom = async () => {
1650
1781
  if (!liveRoomData) {
1651
1782
  // 未开通直播间
1652
- await session.send('该用户未开通直播间,无法订阅直播');
1783
+ await session.send("该用户未开通直播间,无法订阅直播");
1653
1784
  // 返回false
1654
1785
  return true;
1655
1786
  }
@@ -1681,28 +1812,30 @@ class ComRegister {
1681
1812
  // 获取订阅信息
1682
1813
  const subInfo = this.subShow();
1683
1814
  // 定义table
1684
- let table = '';
1685
- if (subInfo === '没有订阅任何UP') {
1815
+ let table = "";
1816
+ if (subInfo === "没有订阅任何UP") {
1686
1817
  table = subInfo;
1687
1818
  }
1688
1819
  else {
1689
1820
  // 获取subTable
1690
- const subTableArray = subInfo.split('\n');
1821
+ const subTableArray = subInfo.split("\n");
1691
1822
  subTableArray.splice(subTableArray.length - 1, 1);
1692
1823
  // 定义Table
1693
- 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 }))) })] });
1824
+ 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) => (
1825
+ // biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
1826
+ (0, jsx_runtime_1.jsx)("li", { children: str }))) })] }));
1694
1827
  }
1695
1828
  // 设置更新后的提示
1696
1829
  this.subNotifier = this.ctx.notifier.create(table);
1697
1830
  }
1698
1831
  async checkIfLoginInfoIsLoaded() {
1699
- return new Promise(resolve => {
1832
+ return new Promise((resolve) => {
1700
1833
  const check = () => {
1701
1834
  if (!this.ctx.ba.getLoginInfoIsLoaded()) {
1702
1835
  this.ctx.setTimeout(check, 500);
1703
1836
  }
1704
1837
  else {
1705
- resolve('success');
1838
+ resolve("success");
1706
1839
  }
1707
1840
  };
1708
1841
  check();
@@ -1712,7 +1845,8 @@ class ComRegister {
1712
1845
  // 获取关注分组信息
1713
1846
  const checkGroupIsReady = async () => {
1714
1847
  // 判断是否有数据
1715
- if (this.loginDBData.dynamic_group_id === '' || this.loginDBData.dynamic_group_id === null) {
1848
+ if (this.loginDBData.dynamic_group_id === "" ||
1849
+ this.loginDBData.dynamic_group_id === null) {
1716
1850
  // 没有数据,没有创建分组,尝试创建分组
1717
1851
  const createGroupData = await this.ctx.ba.createGroup("订阅");
1718
1852
  // 如果分组已创建,则获取分组id
@@ -1722,7 +1856,7 @@ class ComRegister {
1722
1856
  // 遍历所有分组
1723
1857
  for (const group of allGroupData.data) {
1724
1858
  // 找到订阅分组
1725
- if (group.name === '订阅') {
1859
+ if (group.name === "订阅") {
1726
1860
  // 拿到分组id
1727
1861
  this.loginDBData.dynamic_group_id = group.tagid;
1728
1862
  // 结束循环
@@ -1736,7 +1870,9 @@ class ComRegister {
1736
1870
  return false;
1737
1871
  }
1738
1872
  // 创建成功,保存到数据库
1739
- this.ctx.database.set('loginBili', 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
1873
+ this.ctx.database.set("loginBili", 1, {
1874
+ dynamic_group_id: this.loginDBData.dynamic_group_id,
1875
+ });
1740
1876
  // 创建成功
1741
1877
  return true;
1742
1878
  }
@@ -1747,7 +1883,7 @@ class ComRegister {
1747
1883
  // 判断是否创建成功
1748
1884
  if (!flag) {
1749
1885
  // 创建分组失败
1750
- return { flag: false, msg: '创建分组失败,请尝试重启插件' };
1886
+ return { flag: false, msg: "创建分组失败,请尝试重启插件" };
1751
1887
  }
1752
1888
  // 获取分组明细
1753
1889
  const relationGroupDetailData = await this.ctx.ba.getRelationGroupDetail(this.loginDBData.dynamic_group_id);
@@ -1761,51 +1897,67 @@ class ComRegister {
1761
1897
  // 判断是否创建成功
1762
1898
  if (!flag) {
1763
1899
  // 创建分组失败
1764
- return { flag: false, msg: '创建分组失败,请尝试重启插件' };
1900
+ return { flag: false, msg: "创建分组失败,请尝试重启插件" };
1765
1901
  }
1766
- return { flag: true, msg: '分组不存在,已重新创建分组' };
1902
+ return { flag: true, msg: "分组不存在,已重新创建分组" };
1767
1903
  }
1768
1904
  // 获取分组明细失败
1769
- return { flag: false, msg: '获取分组明细失败' };
1905
+ return { flag: false, msg: "获取分组明细失败" };
1770
1906
  }
1771
- relationGroupDetailData.data.forEach(user => {
1907
+ for (const user of relationGroupDetailData.data) {
1772
1908
  if (user.mid === mid) {
1773
1909
  // 已关注订阅对象
1774
- return { flag: true, msg: '订阅对象已存在于分组中' };
1910
+ return { flag: true, msg: "订阅对象已存在于分组中" };
1775
1911
  }
1776
- });
1912
+ }
1777
1913
  // 订阅对象
1778
1914
  const subUserData = await this.ctx.ba.follow(mid);
1779
1915
  // 判断是否订阅成功
1780
1916
  switch (subUserData.code) {
1781
- case -101: return { flag: false, msg: '账号未登录,请使用指令bili login登录后再进行订阅操作' };
1782
- case -102: return { flag: false, msg: '账号被封停,无法进行订阅操作' };
1783
- case 22002: return { flag: false, msg: '因对方隐私设置,无法进行订阅操作' };
1784
- case 22003: return { flag: false, msg: '你已将对方拉黑,无法进行订阅操作' };
1785
- case 22013: return { flag: false, msg: '账号已注销,无法进行订阅操作' };
1786
- case 40061: return { flag: false, msg: '账号不存在,请检查uid输入是否正确或用户是否存在' };
1787
- case 22001: break; // 订阅对象为自己 无需添加到分组
1917
+ case -101:
1918
+ return {
1919
+ flag: false,
1920
+ msg: "账号未登录,请使用指令bili login登录后再进行订阅操作",
1921
+ };
1922
+ case -102:
1923
+ return { flag: false, msg: "账号被封停,无法进行订阅操作" };
1924
+ case 22002:
1925
+ return { flag: false, msg: "因对方隐私设置,无法进行订阅操作" };
1926
+ case 22003:
1927
+ return { flag: false, msg: "你已将对方拉黑,无法进行订阅操作" };
1928
+ case 22013:
1929
+ return { flag: false, msg: "账号已注销,无法进行订阅操作" };
1930
+ case 40061:
1931
+ return {
1932
+ flag: false,
1933
+ msg: "账号不存在,请检查uid输入是否正确或用户是否存在",
1934
+ };
1935
+ case 22001:
1936
+ break; // 订阅对象为自己 无需添加到分组
1788
1937
  case 22014: // 已关注订阅对象 无需再次关注
1789
- case 0: { // 执行订阅成功
1938
+ case 0: {
1939
+ // 执行订阅成功
1790
1940
  // 把订阅对象添加到分组中
1791
1941
  const copyUserToGroupData = await this.ctx.ba.copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1792
1942
  // 判断是否添加成功
1793
1943
  if (copyUserToGroupData.code !== 0) {
1794
1944
  // 添加失败
1795
- return { flag: false, msg: '添加订阅对象到分组失败,请稍后重试' };
1945
+ return { flag: false, msg: "添加订阅对象到分组失败,请稍后重试" };
1796
1946
  }
1797
1947
  }
1798
1948
  }
1799
1949
  // 订阅成功
1800
- return { flag: true, msg: '用户订阅成功' };
1950
+ return { flag: true, msg: "用户订阅成功" };
1801
1951
  }
1802
1952
  async loadSubFromConfig(subs) {
1803
1953
  for (const sub of subs) {
1804
1954
  // 定义Data
1955
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1805
1956
  let data;
1806
1957
  // 判断是否需要订阅直播
1807
1958
  if (sub.live) {
1808
1959
  // 获取用户信息
1960
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1809
1961
  let content;
1810
1962
  // 设置重试次数
1811
1963
  const attempts = 3;
@@ -1817,8 +1969,9 @@ class ComRegister {
1817
1969
  break;
1818
1970
  }
1819
1971
  catch (e) {
1820
- this.logger.error('loadSubFromConfig() getUserInfo() 发生了错误,错误为:' + e.message);
1821
- if (i === attempts - 1) { // 已尝试三次
1972
+ this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1973
+ if (i === attempts - 1) {
1974
+ // 已尝试三次
1822
1975
  // 发送私聊消息并重启服务
1823
1976
  return await this.sendPrivateMsgAndStopService();
1824
1977
  }
@@ -1833,11 +1986,12 @@ class ComRegister {
1833
1986
  // 发送提示
1834
1987
  this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1835
1988
  }
1836
- //
1989
+ //
1837
1990
  const liveDetectModeSelector = {
1838
1991
  API: async () => {
1839
1992
  // 判断是否已开启直播检测
1840
- if (!this.liveDispose) { // 未开启直播检测
1993
+ if (!this.liveDispose) {
1994
+ // 未开启直播检测
1841
1995
  // 开启直播检测并保存销毁函数
1842
1996
  this.liveDispose = await this.liveDetectWithAPI();
1843
1997
  }
@@ -1845,7 +1999,7 @@ class ComRegister {
1845
1999
  WS: async () => {
1846
2000
  // 连接到服务器
1847
2001
  await this.liveDetectWithListener(data.live_room.roomid, sub.target);
1848
- }
2002
+ },
1849
2003
  };
1850
2004
  // 判断是否订阅直播
1851
2005
  if (sub.live) {
@@ -1862,25 +2016,26 @@ class ComRegister {
1862
2016
  this.subManager.push({
1863
2017
  id: +sub.uid,
1864
2018
  uid: sub.uid,
1865
- roomId: sub.live ? data.live_room.roomid : '',
2019
+ roomId: sub.live ? data.live_room.roomid : "",
1866
2020
  target: sub.target,
1867
- platform: '',
2021
+ platform: "",
1868
2022
  live: sub.live,
1869
- dynamic: sub.dynamic
2023
+ dynamic: sub.dynamic,
1870
2024
  });
1871
2025
  }
1872
2026
  }
1873
2027
  async loadSubFromDatabase() {
1874
2028
  // 从数据库中获取数据
1875
- const subData = await this.ctx.database.get('bilibili', { id: { $gt: 0 } });
2029
+ const subData = await this.ctx.database.get("bilibili", { id: { $gt: 0 } });
1876
2030
  // 定义变量:订阅直播数
1877
2031
  let liveSubNum = 0;
1878
2032
  // 循环遍历
1879
2033
  for (const sub of subData) {
1880
2034
  // 判断是否存在没有任何订阅的数据
1881
- if (!sub.dynamic && !sub.live) { // 存在未订阅任何项目的数据
2035
+ if (!sub.dynamic && !sub.live) {
2036
+ // 存在未订阅任何项目的数据
1882
2037
  // 删除该条数据
1883
- this.ctx.database.remove('bilibili', { id: sub.id });
2038
+ this.ctx.database.remove("bilibili", { id: sub.id });
1884
2039
  // log
1885
2040
  this.logger.warn(`UID:${sub.uid} 该条数据没有任何订阅数据,自动取消订阅`);
1886
2041
  // 跳过下面的步骤
@@ -1895,7 +2050,7 @@ class ComRegister {
1895
2050
  // 发送私聊消息
1896
2051
  await this.sendPrivateMsg(`UID:${sub.uid} ${subUserData.msg},自动取消订阅`);
1897
2052
  // 删除该条数据
1898
- await this.ctx.database.remove('bilibili', { id: sub.id });
2053
+ await this.ctx.database.remove("bilibili", { id: sub.id });
1899
2054
  // 跳过下面的步骤
1900
2055
  continue;
1901
2056
  }
@@ -1903,6 +2058,7 @@ class ComRegister {
1903
2058
  const target = JSON.parse(sub.target);
1904
2059
  /* 判断数据库是否被篡改 */
1905
2060
  // 获取用户信息
2061
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1906
2062
  let content;
1907
2063
  const attempts = 3;
1908
2064
  for (let i = 0; i < attempts; i++) {
@@ -1913,8 +2069,9 @@ class ComRegister {
1913
2069
  break;
1914
2070
  }
1915
2071
  catch (e) {
1916
- this.logger.error('getSubFromDatabase() getUserInfo() 发生了错误,错误为:' + e.message);
1917
- if (i === attempts - 1) { // 已尝试三次
2072
+ this.logger.error(`getSubFromDatabase() getUserInfo() 发生了错误,错误为:${e.message}`);
2073
+ if (i === attempts - 1) {
2074
+ // 已尝试三次
1918
2075
  // 发送私聊消息并重启服务
1919
2076
  return await this.sendPrivateMsgAndStopService();
1920
2077
  }
@@ -1925,7 +2082,7 @@ class ComRegister {
1925
2082
  // 定义函数删除数据和发送提示
1926
2083
  const deleteSub = async () => {
1927
2084
  // 从数据库删除该条数据
1928
- await this.ctx.database.remove('bilibili', { id: sub.id });
2085
+ await this.ctx.database.remove("bilibili", { id: sub.id });
1929
2086
  // 给用户发送提示
1930
2087
  await this.sendPrivateMsg(`UID:${sub.uid} 数据库内容被篡改,已取消对该UP主的订阅`);
1931
2088
  };
@@ -1934,11 +2091,9 @@ class ComRegister {
1934
2091
  switch (content.code) {
1935
2092
  case -352:
1936
2093
  case -403: {
1937
- await this.sendPrivateMsg('你的登录信息已过期,请重新登录Bilibili');
2094
+ await this.sendPrivateMsg("你的登录信息已过期,请重新登录Bilibili");
1938
2095
  return;
1939
2096
  }
1940
- case -400:
1941
- case -404:
1942
2097
  default: {
1943
2098
  await deleteSub();
1944
2099
  // PrivateMsg
@@ -1950,7 +2105,9 @@ class ComRegister {
1950
2105
  }
1951
2106
  }
1952
2107
  // 检测房间号是否被篡改
1953
- if (sub.live && (!data.live_room || data.live_room.roomid != sub.room_id)) {
2108
+ if (sub.live &&
2109
+ // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
2110
+ (!data.live_room || data.live_room.roomid != sub.room_id)) {
1954
2111
  // 房间号被篡改,删除该订阅
1955
2112
  await deleteSub();
1956
2113
  // log
@@ -1967,15 +2124,16 @@ class ComRegister {
1967
2124
  roomId: sub.room_id,
1968
2125
  target,
1969
2126
  platform: sub.platform,
1970
- live: sub.live === 1 ? true : false,
1971
- dynamic: sub.dynamic === 1 ? true : false,
1972
- liveDispose: null
2127
+ live: sub.live === 1,
2128
+ dynamic: sub.dynamic === 1,
2129
+ liveDispose: null,
1973
2130
  };
1974
2131
  // 定义直播模式监测器
1975
2132
  const liveDetectModeSelector = {
1976
2133
  API: async () => {
1977
2134
  // 判断是否已开启直播检测
1978
- if (!this.liveDispose) { // 未开启直播检测
2135
+ if (!this.liveDispose) {
2136
+ // 未开启直播检测
1979
2137
  // 开启直播检测并保存销毁函数
1980
2138
  this.liveDispose = await this.liveDetectWithAPI();
1981
2139
  }
@@ -1996,7 +2154,7 @@ class ComRegister {
1996
2154
  // 订阅直播,开始循环检测
1997
2155
  await this.liveDetectWithListener(sub.room_id, target);
1998
2156
  }
1999
- }
2157
+ },
2000
2158
  };
2001
2159
  // 判断是否订阅直播
2002
2160
  if (sub.live) {
@@ -2009,7 +2167,7 @@ class ComRegister {
2009
2167
  }
2010
2168
  checkIfDynamicDetectIsNeeded() {
2011
2169
  // 检查是否有订阅对象需要动态监测
2012
- if (this.subManager.some(sub => sub.dynamic))
2170
+ if (this.subManager.some((sub) => sub.dynamic))
2013
2171
  this.enableDynamicDetect();
2014
2172
  }
2015
2173
  enableDynamicDetect() {
@@ -2031,7 +2189,7 @@ class ComRegister {
2031
2189
  // 从管理对象中移除
2032
2190
  this.subManager.splice(index, 1);
2033
2191
  // 从数据库中删除
2034
- this.ctx.database.remove('bilibili', [this.subManager[index].id]);
2192
+ this.ctx.database.remove("bilibili", [this.subManager[index].id]);
2035
2193
  // num--
2036
2194
  this.num--;
2037
2195
  // 判断是否还存在订阅了动态的对象,不存在则停止动态监测
@@ -2039,25 +2197,26 @@ class ComRegister {
2039
2197
  };
2040
2198
  try {
2041
2199
  switch (type) {
2042
- case 0: { // 取消Live订阅
2200
+ case 0: {
2201
+ // 取消Live订阅
2043
2202
  // 获取订阅对象所在的索引
2044
- const index = this.subManager.findIndex(sub => sub.roomId === id);
2203
+ const index = this.subManager.findIndex((sub) => sub.roomId === id);
2045
2204
  // 获取订阅对象
2046
- const sub = this.subManager.find(sub => sub.roomId === id);
2205
+ const sub = this.subManager.find((sub) => sub.roomId === id);
2047
2206
  // 判断是否存在订阅对象
2048
2207
  if (!sub) {
2049
- msg = '未订阅该用户,无需取消订阅';
2208
+ msg = "未订阅该用户,无需取消订阅";
2050
2209
  return msg;
2051
2210
  }
2052
2211
  // 取消订阅
2053
2212
  sub.live = false;
2054
2213
  // 判断直播检测方式
2055
2214
  switch (this.config.liveDetectMode) {
2056
- case 'API': {
2057
- msg = '请手动删除订阅,并重启插件';
2215
+ case "API": {
2216
+ msg = "请手动删除订阅,并重启插件";
2058
2217
  break;
2059
2218
  }
2060
- case 'WS': {
2219
+ case "WS": {
2061
2220
  // 取消直播监听
2062
2221
  this.ctx.bl.closeListener(sub.roomId);
2063
2222
  }
@@ -2066,23 +2225,26 @@ class ComRegister {
2066
2225
  if (checkIfNoSubExist(sub)) {
2067
2226
  // 从管理对象中移除
2068
2227
  removeSub(index);
2069
- return '已取消订阅该用户';
2228
+ return "已取消订阅该用户";
2070
2229
  }
2071
2230
  // 更新数据库
2072
- this.ctx.database.upsert('bilibili', [{
2231
+ this.ctx.database.upsert("bilibili", [
2232
+ {
2073
2233
  id: +`${sub.id}`,
2074
- live: 0
2075
- }]);
2076
- return '已取消订阅Live';
2234
+ live: 0,
2235
+ },
2236
+ ]);
2237
+ return "已取消订阅Live";
2077
2238
  }
2078
- case 1: { // 取消Dynamic订阅
2239
+ case 1: {
2240
+ // 取消Dynamic订阅
2079
2241
  // 获取订阅对象所在的索引
2080
- const index = this.subManager.findIndex(sub => sub.uid === id);
2242
+ const index = this.subManager.findIndex((sub) => sub.uid === id);
2081
2243
  // 获取订阅对象
2082
- const sub = this.subManager.find(sub => sub.uid === id);
2244
+ const sub = this.subManager.find((sub) => sub.uid === id);
2083
2245
  // 判断是否存在订阅对象
2084
2246
  if (!sub) {
2085
- msg = '未订阅该用户,无需取消订阅';
2247
+ msg = "未订阅该用户,无需取消订阅";
2086
2248
  return msg;
2087
2249
  }
2088
2250
  // 取消订阅
@@ -2093,14 +2255,16 @@ class ComRegister {
2093
2255
  if (checkIfNoSubExist(sub)) {
2094
2256
  // 从管理对象中移除
2095
2257
  removeSub(index);
2096
- return '已取消订阅该用户';
2258
+ return "已取消订阅该用户";
2097
2259
  }
2098
2260
  // 更新数据库
2099
- this.ctx.database.upsert('bilibili', [{
2261
+ this.ctx.database.upsert("bilibili", [
2262
+ {
2100
2263
  id: sub.id,
2101
- dynamic: 0
2102
- }]);
2103
- return '已取消订阅Dynamic';
2264
+ dynamic: 0,
2265
+ },
2266
+ ]);
2267
+ return "已取消订阅Dynamic";
2104
2268
  }
2105
2269
  }
2106
2270
  }
@@ -2110,14 +2274,16 @@ class ComRegister {
2110
2274
  }
2111
2275
  }
2112
2276
  checkIfUserIsTheLastOneWhoSubDyn() {
2113
- if (this.dynamicDispose && !this.subManager.some(sub => sub.dynamic)) {
2277
+ if (this.dynamicDispose && !this.subManager.some((sub) => sub.dynamic)) {
2114
2278
  // 停止动态监测
2115
2279
  this.dynamicDispose();
2116
2280
  this.dynamicDispose = null;
2117
2281
  }
2118
2282
  }
2119
2283
  unsubAll(uid) {
2120
- this.subManager.filter(sub => sub.uid === uid).map(async (sub, i) => {
2284
+ this.subManager
2285
+ .filter((sub) => sub.uid === uid)
2286
+ .map(async (sub, i) => {
2121
2287
  // 判断是否还存在订阅了动态的对象,不存在则停止动态监测
2122
2288
  this.checkIfUserIsTheLastOneWhoSubDyn();
2123
2289
  switch (this.config.liveDetectMode) {
@@ -2130,7 +2296,9 @@ class ComRegister {
2130
2296
  }
2131
2297
  }
2132
2298
  // 从数据库中删除订阅
2133
- await this.ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
2299
+ await this.ctx.database.remove("bilibili", {
2300
+ uid: this.subManager[i].uid,
2301
+ });
2134
2302
  // 将该订阅对象从订阅管理对象中移除
2135
2303
  this.subManager.splice(i, 1);
2136
2304
  // id--
@@ -2142,9 +2310,11 @@ class ComRegister {
2142
2310
  });
2143
2311
  }
2144
2312
  async checkIfIsLogin() {
2145
- if ((await this.ctx.database.get('loginBili', 1)).length !== 0) { // 数据库中有数据
2313
+ if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
2314
+ // 数据库中有数据
2146
2315
  // 检查cookie中是否有值
2147
- if (this.ctx.ba.getCookies() !== '[]') { // 有值说明已登录
2316
+ if (this.ctx.ba.getCookies() !== "[]") {
2317
+ // 有值说明已登录
2148
2318
  return true;
2149
2319
  }
2150
2320
  }
@@ -2154,31 +2324,33 @@ class ComRegister {
2154
2324
  (function (ComRegister) {
2155
2325
  ComRegister.Config = koishi_1.Schema.object({
2156
2326
  sub: koishi_1.Schema.array(koishi_1.Schema.object({
2157
- uid: koishi_1.Schema.string().description('订阅用户UID'),
2158
- dynamic: koishi_1.Schema.boolean().description('是否订阅用户动态'),
2159
- live: koishi_1.Schema.boolean().description('是否订阅用户直播'),
2327
+ uid: koishi_1.Schema.string().description("订阅用户UID"),
2328
+ dynamic: koishi_1.Schema.boolean().description("是否订阅用户动态"),
2329
+ live: koishi_1.Schema.boolean().description("是否订阅用户直播"),
2160
2330
  target: koishi_1.Schema.array(koishi_1.Schema.object({
2161
2331
  channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
2162
- channelId: koishi_1.Schema.string().description('频道/群组号'),
2163
- dynamic: koishi_1.Schema.boolean().description('该频道/群组是否推送动态信息'),
2164
- live: koishi_1.Schema.boolean().description('该频道/群组是否推送直播通知'),
2165
- liveGuardBuy: koishi_1.Schema.boolean().description('该频道/群组是否推送弹幕消息'),
2166
- atAll: koishi_1.Schema.boolean().description('推送开播通知时是否艾特全体成员')
2167
- })).description('频道/群组信息'),
2168
- platform: koishi_1.Schema.string().description('推送平台')
2169
- })).description('订阅用户需要发送的频道/群组信息')
2170
- })).role('table').description('手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播'),
2332
+ channelId: koishi_1.Schema.string().description("频道/群组号"),
2333
+ dynamic: koishi_1.Schema.boolean().description("该频道/群组是否推送动态信息"),
2334
+ live: koishi_1.Schema.boolean().description("该频道/群组是否推送直播通知"),
2335
+ liveGuardBuy: koishi_1.Schema.boolean().description("该频道/群组是否推送弹幕消息"),
2336
+ atAll: koishi_1.Schema.boolean().description("推送开播通知时是否艾特全体成员"),
2337
+ })).description("频道/群组信息"),
2338
+ platform: koishi_1.Schema.string().description("推送平台"),
2339
+ })).description("订阅用户需要发送的频道/群组信息"),
2340
+ }))
2341
+ .role("table")
2342
+ .description("手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播"),
2171
2343
  master: koishi_1.Schema.object({
2172
2344
  enable: koishi_1.Schema.boolean(),
2173
2345
  platform: koishi_1.Schema.string(),
2174
2346
  masterAccount: koishi_1.Schema.string(),
2175
- masterAccountGuildId: koishi_1.Schema.string()
2347
+ masterAccountGuildId: koishi_1.Schema.string(),
2176
2348
  }),
2177
2349
  unlockSubLimits: koishi_1.Schema.boolean().required(),
2178
2350
  automaticResend: koishi_1.Schema.boolean().required(),
2179
2351
  liveDetectMode: koishi_1.Schema.union([
2180
- koishi_1.Schema.const('API'),
2181
- koishi_1.Schema.const('WS')
2352
+ koishi_1.Schema.const("API"),
2353
+ koishi_1.Schema.const("WS"),
2182
2354
  ]).required(),
2183
2355
  restartPush: koishi_1.Schema.boolean().required(),
2184
2356
  pushTime: koishi_1.Schema.number().required(),
@@ -2194,7 +2366,7 @@ class ComRegister {
2194
2366
  regex: koishi_1.Schema.string(),
2195
2367
  keywords: koishi_1.Schema.array(String),
2196
2368
  }),
2197
- dynamicDebugMode: koishi_1.Schema.boolean().required()
2369
+ dynamicDebugMode: koishi_1.Schema.boolean().required(),
2198
2370
  });
2199
2371
  })(ComRegister || (ComRegister = {}));
2200
2372
  exports.default = ComRegister;