koishi-plugin-rina-currency 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Context } from 'koishi';
2
+ import 'koishi-plugin-cron';
2
3
  import { Config as ConfigSchema, Config as PluginConfig } from './config';
3
4
  export declare const name = "rina-currency";
4
5
  export declare const inject: string[];
package/lib/index.js CHANGED
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  name: () => name
37
37
  });
38
38
  module.exports = __toCommonJS(src_exports);
39
+ var import_koishi_plugin_cron = require("koishi-plugin-cron");
39
40
 
40
41
  // src/config.ts
41
42
  var import_koishi = require("koishi");
@@ -632,19 +633,12 @@ var Scheduler = class {
632
633
  } else if (this.config.collectOnStart) {
633
634
  await this.collectAndAlert();
634
635
  }
635
- this.scheduleAlignedCollections();
636
- this.ctx.setInterval(() => void this.runBroadcasts(), 3e4);
636
+ this.ctx.cron("* * * * *", () => {
637
+ void this.collectIfDue();
638
+ void this.runBroadcasts();
639
+ });
637
640
  });
638
641
  }
639
- /** Runs on China-time minute boundaries, with 17:00 as the daily anchor. */
640
- scheduleAlignedCollections() {
641
- const now = /* @__PURE__ */ new Date();
642
- const delay = 6e4 - now.getSeconds() * 1e3 - now.getMilliseconds();
643
- this.ctx.setTimeout(() => {
644
- void this.collectIfDue();
645
- this.ctx.setInterval(() => void this.collectIfDue(), 6e4);
646
- }, delay);
647
- }
648
642
  getDueCollection(now = /* @__PURE__ */ new Date()) {
649
643
  const clock = chinaClock(now);
650
644
  const minutesSinceMidnight = clock.hour * 60 + clock.minute;
@@ -835,7 +829,7 @@ var RateService = class {
835
829
 
836
830
  // src/index.ts
837
831
  var name = "rina-currency";
838
- var inject = ["database"];
832
+ var inject = ["database", "cron"];
839
833
  var Config2 = Config;
840
834
  function apply(ctx, config) {
841
835
  extendModel(ctx);
@@ -10,8 +10,6 @@ export declare class Scheduler {
10
10
  private lastCollectionSlot?;
11
11
  constructor(ctx: Context, logger: Logger, service: RateService, config: Config);
12
12
  start(): void;
13
- /** Runs on China-time minute boundaries, with 17:00 as the daily anchor. */
14
- private scheduleAlignedCollections;
15
13
  private getDueCollection;
16
14
  private collectIfDue;
17
15
  private getBot;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-rina-currency",
3
3
  "description": "面向购汇决策的日元汇率插件,基于中行和工行数据",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -21,6 +21,7 @@
21
21
  "koishi": "^4.18.7"
22
22
  },
23
23
  "dependencies": {
24
+ "koishi-plugin-cron": "^3.1.0",
24
25
  "sharp": "^0.34.2"
25
26
  },
26
27
  "devDependencies": {
@@ -34,7 +35,8 @@
34
35
  },
35
36
  "service": {
36
37
  "required": [
37
- "database"
38
+ "database",
39
+ "cron"
38
40
  ]
39
41
  }
40
42
  }
package/readme.md CHANGED
@@ -10,6 +10,7 @@
10
10
  plugins:
11
11
  database-sqlite:
12
12
  path: data/koishi.db
13
+ cron: {}
13
14
  rina-currency: {}
14
15
  ```
15
16
 
@@ -43,6 +44,7 @@ plugins:
43
44
 
44
45
  ```yaml
45
46
  plugins:
47
+ cron: {}
46
48
  rina-currency:
47
49
  defaultBank: boc
48
50
  defaultRateType: spotSell