@sjtdev/koishi-plugin-dota2tracker 2.0.1 → 2.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.
- package/lib/index.js +64 -12
- package/package.json +2 -6
- package/template/match/match_1.ejs +2 -2
- package/template/match/match_2+.ejs +2 -2
- package/template/match/match_2.ejs +2 -2
- package/template/player/player_1.ejs +2 -2
- package/template/rank/rank_fun.ejs +2 -2
- package/template/report/daily.ejs +2 -2
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
|
|
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");
|
|
@@ -2430,7 +2481,7 @@ var ImageRenderer = class extends import_koishi10.Service {
|
|
|
2430
2481
|
$t: /* @__PURE__ */ __name((key, params) => this.ctx.dota2tracker.i18n.$t(languageTag, key, params), "$t"),
|
|
2431
2482
|
languageTag,
|
|
2432
2483
|
Random: import_koishi10.Random,
|
|
2433
|
-
fontFamily: this.config.templateFonts,
|
|
2484
|
+
fontFamily: this.config.templateFonts.map((f) => `${f}`).join(", "),
|
|
2434
2485
|
getImageUrl: this.getImageUrl.bind(this)
|
|
2435
2486
|
};
|
|
2436
2487
|
try {
|
|
@@ -2481,7 +2532,7 @@ var MessageBuilder = class extends import_koishi11.Service {
|
|
|
2481
2532
|
}
|
|
2482
2533
|
async buildHeroOfTheDayMessage(languageTag, heroRcmd, metaRcmd) {
|
|
2483
2534
|
const $t = /* @__PURE__ */ __name((key, params) => this.ctx.dota2tracker.i18n.$t(languageTag, `commands.dota2tracker.hero-of-the-day.messages.${key}`, params), "$t");
|
|
2484
|
-
let ejs2 = "<html><head><style>body{width:fit-content;height:fit-content;margin:0;padding:12px;}</style></head><body>";
|
|
2535
|
+
let ejs2 = "<html><head><style>body{width:fit-content;height:fit-content;margin:0;padding:12px;font-family:<%-fontFamily%>;}</style></head><body>";
|
|
2485
2536
|
if (heroRcmd.recommendationType !== "LIFETIME_NO_RECORD") {
|
|
2486
2537
|
ejs2 += `<h3>${$t("title_recommendation")}</h3>`;
|
|
2487
2538
|
ejs2 += `<p>${$t("recommendation_intro")}</p>`;
|
|
@@ -2493,13 +2544,13 @@ var MessageBuilder = class extends import_koishi11.Service {
|
|
|
2493
2544
|
ejs2 += `<p>${$t("details.table_intro")}</p>`;
|
|
2494
2545
|
ejs2 += `<div style="display: grid;grid-template-columns: repeat(6, auto);gap: 10px;text-align: center;align-items: center;">`;
|
|
2495
2546
|
ejs2 += `<div style="display: contents">
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2547
|
+
<div style="text-align:left">${$t("details.table_headers.hero")}</div>
|
|
2548
|
+
<div>${$t("details.table_headers.recent_wins")}</div>
|
|
2549
|
+
<div>${$t("details.table_headers.lifetime_wins")}</div>
|
|
2550
|
+
<div>${$t("details.table_headers.imp_bonus")}</div>
|
|
2551
|
+
<div>${$t("details.table_headers.is_hot_streak")}</div>
|
|
2552
|
+
<div>${$t("details.table_headers.total_score")}</div>
|
|
2553
|
+
</div>`;
|
|
2503
2554
|
ejs2 += heroRcmd.recommendationPool.map(
|
|
2504
2555
|
(hero) => `<div style="display: contents">
|
|
2505
2556
|
<div style="text-align:left">${this.ctx.dota2tracker.i18n.getDisplayNameForHero(hero.heroId, languageTag, { forceOfficialName: true }) + (heroRcmd.recommendedHeroes.includes(hero.heroId) ? "*" : "")}</div>
|
|
@@ -2583,6 +2634,7 @@ var MessageBuilder = class extends import_koishi11.Service {
|
|
|
2583
2634
|
padding: 16px;
|
|
2584
2635
|
width: fit-content;
|
|
2585
2636
|
background-color: #f7f7f7;
|
|
2637
|
+
font-family:<%-fontFamily%>;
|
|
2586
2638
|
}
|
|
2587
2639
|
table {
|
|
2588
2640
|
border-collapse: collapse;
|
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.
|
|
4
|
+
"version": "2.0.3",
|
|
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
|
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<title>Document</title>
|
|
7
7
|
<%- `<style>` %>
|
|
8
8
|
<%- include(`./match_1/style.css`) %>
|
|
9
|
-
<% if (fontFamily
|
|
10
|
-
<%- `body { font-family: ${fontFamily
|
|
9
|
+
<% if (fontFamily) { %>
|
|
10
|
+
<%- `body { font-family: ${fontFamily}; }` %>
|
|
11
11
|
<% } %>
|
|
12
12
|
<%- "</style>" %>
|
|
13
13
|
<style>
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<%- "<style>" %>
|
|
9
9
|
<%- include("./match_2/original.css") %>
|
|
10
10
|
<%- include("./match_2+/extra.css") %>
|
|
11
|
-
<% if (fontFamily
|
|
12
|
-
<%- `body { font-family: ${fontFamily
|
|
11
|
+
<% if (fontFamily) { %>
|
|
12
|
+
<%- `body { font-family: ${fontFamily}; }` %>
|
|
13
13
|
<% } %>
|
|
14
14
|
<%- "</style>" %>
|
|
15
15
|
</head>
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" />
|
|
8
8
|
<%- "<style>" %>
|
|
9
9
|
<%- include("./match_2/original.css") %>
|
|
10
|
-
<% if (fontFamily
|
|
11
|
-
<%- `body { font-family: ${fontFamily
|
|
10
|
+
<% if (fontFamily) { %>
|
|
11
|
+
<%- `body { font-family: ${fontFamily}; }` %>
|
|
12
12
|
<% } %>
|
|
13
13
|
<%- "</style>" %>
|
|
14
14
|
</head>
|
|
@@ -346,9 +346,9 @@
|
|
|
346
346
|
}
|
|
347
347
|
</style>
|
|
348
348
|
|
|
349
|
-
<% if (fontFamily
|
|
349
|
+
<% if (fontFamily) { %>
|
|
350
350
|
<%- "<style>" %>
|
|
351
|
-
<%- `body { font-family: ${fontFamily
|
|
351
|
+
<%- `body { font-family: ${fontFamily}; }` %>
|
|
352
352
|
<%- "</style>" %>
|
|
353
353
|
<% } %>
|
|
354
354
|
</head>
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
}
|
|
83
83
|
</style>
|
|
84
84
|
|
|
85
|
-
<% if (fontFamily
|
|
85
|
+
<% if (fontFamily) { %>
|
|
86
86
|
<%- "<style>" %>
|
|
87
|
-
<%- `body { font-family: ${fontFamily
|
|
87
|
+
<%- `body { font-family: ${fontFamily}; }` %>
|
|
88
88
|
<%- "</style>" %>
|
|
89
89
|
<% } %>
|
|
90
90
|
</head>
|
|
@@ -135,9 +135,9 @@
|
|
|
135
135
|
}
|
|
136
136
|
</style>
|
|
137
137
|
|
|
138
|
-
<% if (fontFamily
|
|
138
|
+
<% if (fontFamily) { %>
|
|
139
139
|
<%- "<style>" %>
|
|
140
|
-
<%- `body { font-family: ${fontFamily
|
|
140
|
+
<%- `body { font-family: ${fontFamily}; }` %>
|
|
141
141
|
<%- "</style>" %>
|
|
142
142
|
<% } %>
|
|
143
143
|
</head>
|