koishi-plugin-warframe 1.4.5 → 1.4.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/README.md CHANGED
@@ -6,20 +6,24 @@ Toolkit for warframe. **(In development)**
6
6
 
7
7
  ## Commands
8
8
 
9
- | Command Name | Default Alias | Description |
10
- | ------------------------ | ---------------------- | ------------------------------------------------------------------------------------------- |
11
- | wmi [name:string] | | Warframe market orders. |
12
- | wmr [name:string] | | Warframe market orders. |
13
- | arbitration [day:number] | arbi, 仲裁, 仲裁表 | High-value arbitration schedule. The arg decide how long in days to display, defaults to 3. |
14
- | fissure | 裂缝, 裂隙 | Current fissures. |
15
- | spfissure | 钢铁裂缝, 钢铁裂隙 | Current steelpath fissures. |
16
- | rjfissure | 九重天裂缝, 九重天裂隙 | Current railjack fissures. |
17
- | circuit | 灵化, 灵化之源 | Weekly rewards of circuit, both warframe parts and incarnons. |
18
- | relic [name:string] | 遗物, 核桃 | Relic rewards with corresponding data, including wfm medium price and ducats value. |
19
- | weekly | 周常 | Weekly mission info (archon hunt, deep archimedea, temporal archimedea) |
20
- | environment | env, 地球, 福尔图娜 | Region environment (time) |
21
- | voidtrader | 虚空商人, 奸商 | Void trader info |
9
+ | Command Name | Default Alias | Description |
10
+ | -------------------------------------------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------- |
11
+ | wmi \<name:string\> | | Warframe market orders. |
12
+ | wmr \<name:string\> | | Warframe market orders. |
13
+ | arbitration [day:number] | arbi, 仲裁, 仲裁表 | High-value arbitration schedule. The arg decide how long in days to display, defaults to 3. |
14
+ | fissure | 裂缝, 裂隙 | Current fissures. |
15
+ | spfissure | 钢铁裂缝, 钢铁裂隙 | Current steelpath fissures. |
16
+ | rjfissure | 九重天裂缝, 九重天裂隙 | Current railjack fissures. |
17
+ | circuit | 灵化, 灵化之源 | Weekly rewards of circuit, both warframe parts and incarnons. |
18
+ | relic \<name:string\> | 遗物, 核桃 | Relic rewards with corresponding data, including wfm medium price and ducats value. |
19
+ | weekly | 周常 | Weekly mission info (archon hunt, deep archimedea, temporal archimedea) |
20
+ | environment | env, 地球, 福尔图娜 | Region environment (time) |
21
+ | voidtrader | 虚空商人, 奸商 | Void trader info |
22
+ | riven | | Analyze riven stats |
23
+ | rivenstat \<weaponType:string\> \<statType:string\> \<disposition:number\> | 紫卡数值 | Get riven stat range |
22
24
 
23
25
  ## Install
24
26
 
25
27
  Search `koishi-plugin-warframe` in koishi dependency manager, not in plugin market.
28
+
29
+ The npm source is suggested to be the `https://registry.npmjs.com` before installing, because the package `warframe-public-export-plus` is unavailable on some mirrors.
package/lib/index.d.ts CHANGED
@@ -27,6 +27,24 @@ export const msToHumanReadable: (ms: number) => string;
27
27
  * @returns
28
28
  */
29
29
  export function createAsyncCache<T>(factory: AsyncCacheFactory<T>, ttlMs?: number): AsyncCache<T>;
30
+ export class CacheStorage<T> {
31
+ private _limit;
32
+ private _storage;
33
+ /**
34
+ *
35
+ * @param limit defaults to 100.
36
+ */
37
+ constructor(limit?: number);
38
+ /**
39
+ * Get or set caches.
40
+ * @param hash The identity of data.
41
+ * @param fetchFn The function to get the data.
42
+ * @returns `Promise<T>` or `undefined`.
43
+ */
44
+ get(hash: string, fetchFn: () => Promise<T>): Promise<T>;
45
+ clear(): void;
46
+ get size(): number;
47
+ }
30
48
  export const normalizeName: (text: string) => string;
31
49
  export const fullWidthToHalfWidth: (text: string) => string;
32
50
  export const removeSpace: (text: string) => string;
package/lib/index.js CHANGED
@@ -92,6 +92,56 @@ function createAsyncCache(factory, ttlMs = 6e4) {
92
92
  return { get, update };
93
93
  }
94
94
  __name(createAsyncCache, "createAsyncCache");
95
+ var CacheStorage = class {
96
+ static {
97
+ __name(this, "CacheStorage");
98
+ }
99
+ _limit;
100
+ _storage;
101
+ /**
102
+ *
103
+ * @param limit defaults to 100.
104
+ */
105
+ constructor(limit = 100) {
106
+ if (limit <= 0) {
107
+ throw new Error("Size of cache storage must be larger than 0!");
108
+ }
109
+ this._limit = limit;
110
+ this._storage = /* @__PURE__ */ new Map();
111
+ }
112
+ /**
113
+ * Get or set caches.
114
+ * @param hash The identity of data.
115
+ * @param fetchFn The function to get the data.
116
+ * @returns `Promise<T>` or `undefined`.
117
+ */
118
+ async get(hash, fetchFn) {
119
+ const existingPromise = this._storage.get(hash);
120
+ if (existingPromise) {
121
+ this._storage.delete(hash);
122
+ this._storage.set(hash, existingPromise);
123
+ return existingPromise;
124
+ }
125
+ const promise = fetchFn().catch((err) => {
126
+ this._storage.delete(hash);
127
+ throw err;
128
+ });
129
+ this._storage.set(hash, promise);
130
+ if (this._storage.size > this._limit) {
131
+ const oldestKey = this._storage.keys().next().value;
132
+ if (oldestKey) {
133
+ this._storage.delete(oldestKey);
134
+ }
135
+ }
136
+ return promise;
137
+ }
138
+ clear() {
139
+ this._storage.clear();
140
+ }
141
+ get size() {
142
+ return this._storage.size;
143
+ }
144
+ };
95
145
 
96
146
  // src/utils/text.ts
97
147
  var normalizeName = /* @__PURE__ */ __name((text) => fullWidthToHalfWidth(text).toLowerCase().replace(/[·'\-+()【】\[\]{},。!?;:_]/g, "").replace(/\s+/g, ""), "normalizeName");
@@ -294,11 +344,13 @@ var relicToFullNameZH = /* @__PURE__ */ __name((tier, category) => {
294
344
  }, "relicToFullNameZH");
295
345
 
296
346
  // src/utils/ocr.ts
297
- var extractTextFromImage = /* @__PURE__ */ __name(async (image, secret) => {
298
- if (image instanceof Blob) {
299
- const buffer = await image.arrayBuffer();
300
- image = Buffer.from(buffer).toString("base64");
301
- }
347
+ var import_node_crypto = __toESM(require("node:crypto"));
348
+ var ocrCache = new CacheStorage(100);
349
+ var getImageBase64Hash = /* @__PURE__ */ __name((base64) => {
350
+ const pureBase64 = base64.replace(/^data:image\/\w+;base64,/, "");
351
+ return import_node_crypto.default.createHash("sha256").update(pureBase64, "base64").digest("hex");
352
+ }, "getImageBase64Hash");
353
+ var getTextFromTencentOCR = /* @__PURE__ */ __name(async (image, secret) => {
302
354
  const tencentcloud = require("tencentcloud-sdk-nodejs-ocr");
303
355
  const ocrClient = tencentcloud.ocr.v20181119.Client;
304
356
  const clientConfig = {
@@ -314,15 +366,27 @@ var extractTextFromImage = /* @__PURE__ */ __name(async (image, secret) => {
314
366
  }
315
367
  };
316
368
  const client = new ocrClient(clientConfig);
369
+ const { TextDetections } = await client.GeneralAccurateOCR({
370
+ ImageBase64: image
371
+ });
372
+ const result = TextDetections?.map((t) => t.DetectedText).filter(
373
+ Boolean
374
+ );
375
+ return result;
376
+ }, "getTextFromTencentOCR");
377
+ var extractTextFromImage = /* @__PURE__ */ __name(async (image, secret) => {
378
+ if (image instanceof Blob) {
379
+ const buffer = await image.arrayBuffer();
380
+ image = Buffer.from(buffer).toString("base64");
381
+ }
382
+ const imageHash = getImageBase64Hash(image);
317
383
  try {
318
- const result = await client.GeneralAccurateOCR({
319
- ImageBase64: image
320
- });
321
- return result.TextDetections?.map((t) => t.DetectedText).filter(
322
- (v) => !!v
384
+ return await ocrCache.get(
385
+ imageHash,
386
+ () => getTextFromTencentOCR(image, secret)
323
387
  );
324
388
  } catch (err) {
325
- console.error("error", err);
389
+ console.error("Ocr request error!", err);
326
390
  return void 0;
327
391
  }
328
392
  }, "extractTextFromImage");
@@ -50550,6 +50614,9 @@ var parseOCRResult = /* @__PURE__ */ __name(async (ocrResult) => {
50550
50614
  if (input === "伤害") {
50551
50615
  return standard === "基础伤害" ? 1 : 0;
50552
50616
  }
50617
+ if (input === "弹药最大值") {
50618
+ return standard === "弹药上限" ? 1 : 0;
50619
+ }
50553
50620
  if (standard === "基础伤害" && input.match(/^伤害$|近战伤害/)) {
50554
50621
  return 1;
50555
50622
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-warframe",
3
3
  "description": "WF Toolkit",
4
- "version": "1.4.5",
4
+ "version": "1.4.6",
5
5
  "license": "GPL-3.0",
6
6
  "scripts": {
7
7
  "build": "yakumo build",