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

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