koishi-plugin-rina-currency 0.0.4 → 0.0.6

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");
@@ -162,7 +163,6 @@ function formatSnapshot(snapshot, defaultBank, rateType) {
162
163
  const sign = difference >= 0 ? "+" : "";
163
164
  lines.push(`工行较中行:${sign}${formatRate(difference)}(购汇 100,000 JPY 约${difference >= 0 ? "多" : "少"} ${formatMoney(Math.abs(difference) * 1e3)} CNY)`);
164
165
  }
165
- lines.push("数据来源:中国银行、工商银行;实际成交以银行渠道为准。");
166
166
  return lines.join("\n");
167
167
  }
168
168
  __name(formatSnapshot, "formatSnapshot");
@@ -172,8 +172,7 @@ function formatCost(amount, quote, type) {
172
172
  `按${BANK_LABELS[quote.bank]}${RATE_TYPE_LABELS[type]}计算:`,
173
173
  `${amount.toLocaleString("zh-CN")} JPY ≈ ${formatMoney(costForYen(amount, quote, type))} CNY`,
174
174
  `牌价:100 JPY = ${formatRate(quote[type])} CNY`,
175
- `牌价时间:${formatDateTime(quote.publishedAt)}`,
176
- "实际成交以银行渠道为准。"
175
+ `牌价时间:${formatDateTime(quote.publishedAt)}`
177
176
  ].join("\n");
178
177
  }
179
178
  __name(formatCost, "formatCost");
@@ -632,19 +631,12 @@ var Scheduler = class {
632
631
  } else if (this.config.collectOnStart) {
633
632
  await this.collectAndAlert();
634
633
  }
635
- this.scheduleAlignedCollections();
636
- this.ctx.setInterval(() => void this.runBroadcasts(), 3e4);
634
+ this.ctx.cron("* * * * *", () => {
635
+ void this.collectIfDue();
636
+ void this.runBroadcasts();
637
+ });
637
638
  });
638
639
  }
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
640
  getDueCollection(now = /* @__PURE__ */ new Date()) {
649
641
  const clock = chinaClock(now);
650
642
  const minutesSinceMidnight = clock.hour * 60 + clock.minute;
@@ -835,7 +827,7 @@ var RateService = class {
835
827
 
836
828
  // src/index.ts
837
829
  var name = "rina-currency";
838
- var inject = ["database"];
830
+ var inject = ["database", "cron"];
839
831
  var Config2 = Config;
840
832
  function apply(ctx, config) {
841
833
  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.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -9,6 +9,11 @@
9
9
  "dist"
10
10
  ],
11
11
  "license": "MIT",
12
+ "homepage": "https://github.com/738NGX/rinachanbot",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/738NGX/rinachanbot.git"
16
+ },
12
17
  "scripts": {
13
18
  "typecheck": "tsc --noEmit"
14
19
  },
@@ -21,6 +26,7 @@
21
26
  "koishi": "^4.18.7"
22
27
  },
23
28
  "dependencies": {
29
+ "koishi-plugin-cron": "^3.1.0",
24
30
  "sharp": "^0.34.2"
25
31
  },
26
32
  "devDependencies": {
@@ -34,7 +40,8 @@
34
40
  },
35
41
  "service": {
36
42
  "required": [
37
- "database"
43
+ "database",
44
+ "cron"
38
45
  ]
39
46
  }
40
47
  }
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