koishi-plugin-bilibili-notify 3.0.1 → 3.0.3

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.
@@ -16,7 +16,6 @@ declare class ComRegister {
16
16
  loginDBData: FlatPick<LoginBili, "dynamic_group_id">;
17
17
  privateBot: Bot<Context>;
18
18
  dynamicDispose: () => void;
19
- liveDispose: () => void;
20
19
  sendMsgFunc: (bot: Bot<Context, any>, channelId: string, content: any) => Promise<void>;
21
20
  constructor(ctx: Context, config: ComRegister.Config);
22
21
  init(config: ComRegister.Config): Promise<void>;
@@ -84,7 +83,6 @@ declare namespace ComRegister {
84
83
  customLive: string;
85
84
  customLiveEnd: string;
86
85
  dynamicUrl: boolean;
87
- dynamicLoopTime: number;
88
86
  filter: {
89
87
  enable: boolean;
90
88
  notify: boolean;
@@ -16,7 +16,7 @@ const type_1 = require("./type");
16
16
  // import { Segment, useDefault } from "segmentit";
17
17
  class ComRegister {
18
18
  // 必须服务
19
- static inject = ["ba", "gi", "database", "bl", "sm"];
19
+ static inject = ["ba", "gi", "database", "bl", "sm", "cron"];
20
20
  // 定义数组:QQ相关bot
21
21
  qqRelatedBotList = [
22
22
  "qq",
@@ -47,8 +47,6 @@ class ComRegister {
47
47
  privateBot;
48
48
  // 动态检测销毁函数
49
49
  dynamicDispose;
50
- // 直播检测销毁函数
51
- liveDispose;
52
50
  // 发送消息方式
53
51
  sendMsgFunc;
54
52
  // 构造函数
@@ -328,6 +326,15 @@ class ComRegister {
328
326
  this.checkIfDynamicDetectIsNeeded();
329
327
  // 在控制台中显示订阅对象
330
328
  this.updateSubNotifier();
329
+ // 注册插件销毁函数
330
+ this.ctx.on("dispose", () => {
331
+ // 销毁登录定时器
332
+ if (this.loginTimer)
333
+ this.loginTimer();
334
+ // 销毁动态监测
335
+ if (this.dynamicDispose)
336
+ this.dynamicDispose();
337
+ });
331
338
  // logger
332
339
  this.logger.info("插件初始化完毕!");
333
340
  }
@@ -765,7 +772,8 @@ class ComRegister {
765
772
  // 检查更新的动态
766
773
  for (const item of items) {
767
774
  // 动态ID如果一致则结束循环
768
- if (item.id_str === dynamicIdStr1st || item.id_str === dynamicIdStr2nd) {
775
+ if (item.id_str === dynamicIdStr1st ||
776
+ item.id_str === dynamicIdStr2nd) {
769
777
  // logger
770
778
  this.logger.info("动态ID与上次检测第一条一致,结束循环");
771
779
  this.logger.info("动态检测结束");
@@ -1435,12 +1443,9 @@ class ComRegister {
1435
1443
  }
1436
1444
  enableDynamicDetect() {
1437
1445
  // 开始动态监测
1438
- if (this.config.dynamicDebugMode) {
1439
- this.dynamicDispose = this.ctx.setInterval(this.debug_dynamicDetect(), this.config.dynamicLoopTime * 1000);
1440
- }
1441
- else {
1442
- this.dynamicDispose = this.ctx.setInterval(this.dynamicDetect(), this.config.dynamicLoopTime * 1000);
1443
- }
1446
+ this.dynamicDispose = this.ctx.cron("*/2 * * * *", this.config.dynamicDebugMode
1447
+ ? this.debug_dynamicDetect()
1448
+ : this.dynamicDetect());
1444
1449
  }
1445
1450
  async checkIfIsLogin() {
1446
1451
  if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
@@ -1500,7 +1505,6 @@ class ComRegister {
1500
1505
  customLive: koishi_1.Schema.string(),
1501
1506
  customLiveEnd: koishi_1.Schema.string().required(),
1502
1507
  dynamicUrl: koishi_1.Schema.boolean().required(),
1503
- dynamicLoopTime: koishi_1.Schema.number().default(60),
1504
1508
  filter: koishi_1.Schema.object({
1505
1509
  enable: koishi_1.Schema.boolean(),
1506
1510
  notify: koishi_1.Schema.boolean(),
package/lib/index.d.ts CHANGED
@@ -8,15 +8,6 @@ declare module "koishi" {
8
8
  }
9
9
  declare class ServerManager extends Service {
10
10
  servers: ForkScope[];
11
- dynamicLoopTime: number;
12
- dynamicLoopTimePatternMatching: {
13
- "1\u5206\u949F": number;
14
- "2\u5206\u949F": number;
15
- "3\u5206\u949F": number;
16
- "5\u5206\u949F": number;
17
- "10\u5206\u949F": number;
18
- "20\u5206\u949F": number;
19
- };
20
11
  constructor(ctx: Context);
21
12
  protected start(): void | Promise<void>;
22
13
  registerPlugin: () => boolean;
@@ -52,7 +43,6 @@ export interface Config {
52
43
  }>;
53
44
  dynamic: {};
54
45
  dynamicUrl: boolean;
55
- dynamicLoopTime: "1分钟" | "2分钟" | "3分钟" | "5分钟" | "10分钟" | "20分钟";
56
46
  pushImgsInDynamic: boolean;
57
47
  live: {};
58
48
  liveDetectMode: "API" | "WS";
package/lib/index.js CHANGED
@@ -46,23 +46,12 @@ const Database = __importStar(require("./database"));
46
46
  const generateImg_1 = __importDefault(require("./generateImg"));
47
47
  const biliAPI_1 = __importDefault(require("./biliAPI"));
48
48
  const blive_1 = __importDefault(require("./blive"));
49
- exports.inject = ["puppeteer", "database", "notifier"];
49
+ exports.inject = ["puppeteer", "database", "notifier", "cron"];
50
50
  exports.name = "bilibili-notify";
51
51
  let globalConfig;
52
52
  class ServerManager extends koishi_1.Service {
53
53
  // 服务
54
54
  servers = [];
55
- // 动态循环时间
56
- dynamicLoopTime;
57
- // 定义具体时间模式匹配
58
- dynamicLoopTimePatternMatching = {
59
- "1分钟": 60,
60
- "2分钟": 120,
61
- "3分钟": 180,
62
- "5分钟": 300,
63
- "10分钟": 600,
64
- "20分钟": 1200,
65
- };
66
55
  constructor(ctx) {
67
56
  super(ctx, "sm");
68
57
  // 插件运行相关指令
@@ -104,10 +93,6 @@ class ServerManager extends koishi_1.Service {
104
93
  });
105
94
  }
106
95
  start() {
107
- // 加载配置
108
- // 转换为具体时间
109
- this.dynamicLoopTime =
110
- this.dynamicLoopTimePatternMatching[globalConfig.dynamicLoopTime];
111
96
  // 注册插件
112
97
  if (!this.registerPlugin()) {
113
98
  this.logger.error("插件启动失败");
@@ -150,7 +135,6 @@ class ServerManager extends koishi_1.Service {
150
135
  customLiveStart: globalConfig.customLiveStart,
151
136
  customLive: globalConfig.customLive,
152
137
  customLiveEnd: globalConfig.customLiveEnd,
153
- dynamicLoopTime: this.dynamicLoopTime,
154
138
  dynamicUrl: globalConfig.dynamicUrl,
155
139
  filter: globalConfig.filter,
156
140
  dynamicDebugMode: globalConfig.dynamicDebugMode,
@@ -340,17 +324,6 @@ exports.Config = koishi_1.Schema.object({
340
324
  dynamicUrl: koishi_1.Schema.boolean()
341
325
  .default(false)
342
326
  .description("发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!"),
343
- dynamicLoopTime: koishi_1.Schema.union([
344
- "1分钟",
345
- "2分钟",
346
- "3分钟",
347
- "5分钟",
348
- "10分钟",
349
- "20分钟",
350
- ])
351
- .role("")
352
- .default("2分钟")
353
- .description("设定多久检测一次动态。若需动态的时效性,可以设置为1分钟。若订阅的UP主经常在短时间内连着发多条动态应该将该值提高,否则会出现动态漏推送和晚推送的问题,默认值为2分钟"),
354
327
  pushImgsInDynamic: koishi_1.Schema.boolean()
355
328
  .default(false)
356
329
  .description("是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片"),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "3.0.1",
4
+ "version": "3.0.3",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -44,6 +44,7 @@
44
44
  "@types/qrcode": "^1.5.5",
45
45
  "@types/tough-cookie": "^4.0.5",
46
46
  "globals": "^15.14.0",
47
+ "koishi-plugin-cron": "^3.1.0",
47
48
  "koishi-plugin-puppeteer": "^3.9.0"
48
49
  },
49
50
  "koishi": {
@@ -51,14 +52,12 @@
51
52
  "required": [
52
53
  "database",
53
54
  "puppeteer",
54
- "notifier"
55
+ "notifier",
56
+ "cron"
55
57
  ]
56
58
  },
57
59
  "description": {
58
60
  "zh": "Bilibili动态推送,直播通知插件。具体使用方法请参考readme.md"
59
- },
60
- "locales": [
61
- "zh"
62
- ]
61
+ }
63
62
  }
64
63
  }
package/readme.md CHANGED
@@ -217,6 +217,8 @@
217
217
  - ver 3.0.1-alpha.1 新增:直播提示语换行符,配置项 `sub.name` 为可选项; 修复:debug模式下动态监测5S一次; 优化:加载订阅
218
218
  - ver 3.0.1-alpha.2 优化:改进错误提示,改进订阅加载方式
219
219
  - ver 3.0.1 修复:动态推送过程中,如果上一次请求的第一条动态被删除,可能导致动态重复推送(本次修复并不能完全保障不重复推送,如果第一条和第二条都被删除则可能会出现重复推送); 新增:配置项 `subTimeout` 设置订阅超时时间
220
+ - ver 3.0.2 优化:动态监测,新增依赖服务 `cron`
221
+ - ver 3.0.3 移除:配置项 `dynamicLoopTime` ,动态循环时间将不再可选,默认为两分钟
220
222
 
221
223
  ## 交流群
222
224