@sjtdev/koishi-plugin-dota2tracker 2.0.1 → 2.0.2

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.
Files changed (2) hide show
  1. package/lib/index.js +54 -3
  2. package/package.json +2 -6
package/lib/index.js CHANGED
@@ -2168,7 +2168,6 @@ var DatabaseService = class extends import_koishi7.Service {
2168
2168
  var import_fs = __toESM(require("fs"));
2169
2169
  var import_koishi8 = require("koishi");
2170
2170
  var import_path = __toESM(require("path"));
2171
- var import_p_queue = __toESM(require("p-queue"));
2172
2171
 
2173
2172
  // src/app/common/error.ts
2174
2173
  var import_util = require("util");
@@ -2218,13 +2217,16 @@ var StratzAPI = class extends import_koishi8.Service {
2218
2217
  super(ctx, "dota2tracker.stratz-api", true);
2219
2218
  this.pluginDir = pluginDir3;
2220
2219
  this.config = ctx.config;
2221
- this.queue = new import_p_queue.default({ concurrency: 1, interval: 200, intervalCap: 1 });
2220
+ this.queue = new MiniQueue(ctx, { interval: 200 });
2222
2221
  }
2223
2222
  static {
2224
2223
  __name(this, "StratzAPI");
2225
2224
  }
2226
2225
  BASE_URL = "https://api.stratz.com/graphql";
2227
2226
  queue;
2227
+ dispose() {
2228
+ this.queue.dispose();
2229
+ }
2228
2230
  async queryGetWeeklyMetaByPosition({ bracketIds }) {
2229
2231
  return this.query("GetWeeklyMetaByPosition", { bracketIds }, (data) => !!data.heroStats);
2230
2232
  }
@@ -2311,7 +2313,7 @@ var StratzAPI = class extends import_koishi8.Service {
2311
2313
  return result;
2312
2314
  }
2313
2315
  }
2314
- fetchData(query, isValid) {
2316
+ async fetchData(query, isValid) {
2315
2317
  return this.queue.add(async () => {
2316
2318
  try {
2317
2319
  const result = await this.ctx.http.post(this.BASE_URL, JSON.stringify(query), {
@@ -2352,6 +2354,55 @@ var StratzAPI = class extends import_koishi8.Service {
2352
2354
  return import_fs.default.readFileSync(import_path.default.join(this.pluginDir, "queries", `${queryName}.graphql`), { encoding: "utf-8" }).replace(/[\r\n]+/g, " ");
2353
2355
  }
2354
2356
  };
2357
+ var MiniQueue = class {
2358
+ // 新增一个停止标志
2359
+ // 1. 构造函数接收 ctx
2360
+ constructor(ctx, options) {
2361
+ this.ctx = ctx;
2362
+ this.interval = options.interval;
2363
+ }
2364
+ static {
2365
+ __name(this, "MiniQueue");
2366
+ }
2367
+ queue = [];
2368
+ isProcessing = false;
2369
+ interval;
2370
+ stopped = false;
2371
+ add(task) {
2372
+ if (this.stopped) {
2373
+ return Promise.reject(new Error("Queue has been disposed."));
2374
+ }
2375
+ return new Promise((resolve, reject) => {
2376
+ this.queue.push(async () => {
2377
+ try {
2378
+ const result = await task();
2379
+ resolve(result);
2380
+ } catch (error) {
2381
+ reject(error);
2382
+ }
2383
+ });
2384
+ this._process();
2385
+ });
2386
+ }
2387
+ // 4. 新增 dispose 方法
2388
+ dispose() {
2389
+ this.stopped = true;
2390
+ this.queue = [];
2391
+ }
2392
+ async _process() {
2393
+ if (this.isProcessing || this.queue.length === 0 || this.stopped) {
2394
+ return;
2395
+ }
2396
+ this.isProcessing = true;
2397
+ const task = this.queue.shift();
2398
+ if (task) {
2399
+ await task();
2400
+ await new Promise((resolve) => this.ctx.setTimeout(resolve, this.interval));
2401
+ }
2402
+ this.isProcessing = false;
2403
+ this._process();
2404
+ }
2405
+ };
2355
2406
 
2356
2407
  // src/app/data/valve.api.ts
2357
2408
  var import_koishi9 = require("koishi");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjtdev/koishi-plugin-dota2tracker",
3
3
  "description": "koishi插件-追踪群友的DOTA2对局",
4
- "version": "2.0.1",
4
+ "version": "2.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -29,8 +29,7 @@
29
29
  "dependencies": {
30
30
  "dotaconstants": "^9.5.0",
31
31
  "ejs": "^3.1.10",
32
- "luxon": "^3.8.0-alpha.1",
33
- "p-queue": "6"
32
+ "luxon": "^3.8.0-alpha.1"
34
33
  },
35
34
  "peerDependencies": {
36
35
  "koishi": "^4.18.9"
@@ -51,8 +50,5 @@
51
50
  "zh-CN",
52
51
  "en-US"
53
52
  ]
54
- },
55
- "devDependencies": {
56
- "@types/html-minifier-terser": "^7"
57
53
  }
58
54
  }