koishi-plugin-cs2-server-query 1.9.4 → 1.9.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.js +60 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -50,6 +50,15 @@ var Config = import_koishi.Schema.object({
|
|
|
50
50
|
statsBackgroundImage: import_koishi.Schema.string().description("统计背景图片URL (建议尺寸 1280x720)").default("image/stats-background.jpg")
|
|
51
51
|
// 默认路径
|
|
52
52
|
});
|
|
53
|
+
var mapStats = {};
|
|
54
|
+
var mapStatsFilePath = import_path.default.resolve(__dirname, "map-stats.json");
|
|
55
|
+
if (import_fs.default.existsSync(mapStatsFilePath)) {
|
|
56
|
+
mapStats = JSON.parse(import_fs.default.readFileSync(mapStatsFilePath, "utf-8"));
|
|
57
|
+
}
|
|
58
|
+
function saveMapStats() {
|
|
59
|
+
import_fs.default.writeFileSync(mapStatsFilePath, JSON.stringify(mapStats, null, 2));
|
|
60
|
+
}
|
|
61
|
+
__name(saveMapStats, "saveMapStats");
|
|
53
62
|
function apply(ctx, config) {
|
|
54
63
|
const dataFilePath = import_path.default.resolve(__dirname, config.dataFile);
|
|
55
64
|
const commandMappingFilePath = import_path.default.resolve(__dirname, config.commandMappingFile);
|
|
@@ -125,6 +134,27 @@ function apply(ctx, config) {
|
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
__name(checkAndAddMapTranslation, "checkAndAddMapTranslation");
|
|
137
|
+
function cleanupOldEntries() {
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
const sevenDaysAgo = now - 7 * 24 * 60 * 60 * 1e3;
|
|
140
|
+
for (const groupName in mapStats) {
|
|
141
|
+
const group = mapStats[groupName];
|
|
142
|
+
for (const mapName in group) {
|
|
143
|
+
group[mapName] = group[mapName].filter((ts) => ts >= sevenDaysAgo);
|
|
144
|
+
if (group[mapName].length === 0) {
|
|
145
|
+
delete group[mapName];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (Object.keys(group).length === 0) {
|
|
149
|
+
delete mapStats[groupName];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
saveMapStats();
|
|
153
|
+
}
|
|
154
|
+
__name(cleanupOldEntries, "cleanupOldEntries");
|
|
155
|
+
ctx.setInterval(() => {
|
|
156
|
+
cleanupOldEntries();
|
|
157
|
+
}, 24 * 60 * 60 * 1e3);
|
|
128
158
|
let autoSaveMapStatus = {};
|
|
129
159
|
const autoSaveMapStatusFilePath = import_path.default.resolve(__dirname, "auto-save-map-status.json");
|
|
130
160
|
if (import_fs.default.existsSync(autoSaveMapStatusFilePath)) {
|
|
@@ -235,6 +265,18 @@ function apply(ctx, config) {
|
|
|
235
265
|
border-radius: 4px;
|
|
236
266
|
color: white;
|
|
237
267
|
}
|
|
268
|
+
|
|
269
|
+
/* 新增热门标签样式 */
|
|
270
|
+
.hot-tag {
|
|
271
|
+
display: inline-block;
|
|
272
|
+
padding: 2px 6px;
|
|
273
|
+
border-radius: 4px;
|
|
274
|
+
background-color: #ff0000;
|
|
275
|
+
color: white;
|
|
276
|
+
font-size: 12px;
|
|
277
|
+
margin-left: 5px;
|
|
278
|
+
font-weight: bold;
|
|
279
|
+
}
|
|
238
280
|
</style>
|
|
239
281
|
</head>
|
|
240
282
|
<body>
|
|
@@ -256,7 +298,12 @@ function apply(ctx, config) {
|
|
|
256
298
|
const difficulty = translation?.difficulty;
|
|
257
299
|
const difficultyColor = difficulty ? difficultyColors[difficulty] : "#000000";
|
|
258
300
|
const mapDuration = server.status === "在线" ? Math.floor((Date.now() - server.mapChangeTime) / 6e4) : 0;
|
|
301
|
+
const recentCount = (mapStats[group.name]?.[server.map] || []).filter(
|
|
302
|
+
(ts) => Date.now() - ts <= 7 * 24 * 60 * 60 * 1e3
|
|
303
|
+
).length;
|
|
304
|
+
const isHot = recentCount >= 20;
|
|
259
305
|
return `
|
|
306
|
+
|
|
260
307
|
<tr>
|
|
261
308
|
<td><span class="server-index">${index + 1}</span></td>
|
|
262
309
|
<td>${server.name}</td>
|
|
@@ -264,6 +311,7 @@ function apply(ctx, config) {
|
|
|
264
311
|
<span class="map-name">${server.map}</span>
|
|
265
312
|
${translation ? `<br>(${translation.translation})` : ""}
|
|
266
313
|
${difficulty ? `<span class="difficulty" style="background-color: ${difficultyColor};">${difficulty}</span>` : ""}
|
|
314
|
+
${isHot ? `<span class="hot-tag">热门</span>` : ""}
|
|
267
315
|
</td>
|
|
268
316
|
<td style="color: ${(() => {
|
|
269
317
|
if (server.status !== "在线") return "#888";
|
|
@@ -831,6 +879,18 @@ ${subscriptionList}`;
|
|
|
831
879
|
const mapNameToCompare = sub.mapName;
|
|
832
880
|
const translatedMapName = mapTranslations[mapNameToCompare]?.translation;
|
|
833
881
|
let matchPercentage = 0;
|
|
882
|
+
if (server.map !== newMap) {
|
|
883
|
+
server.mapChangeTime = Date.now();
|
|
884
|
+
server.map = newMap;
|
|
885
|
+
if (!mapStats[group.name]) {
|
|
886
|
+
mapStats[group.name] = {};
|
|
887
|
+
}
|
|
888
|
+
if (!mapStats[group.name][newMap]) {
|
|
889
|
+
mapStats[group.name][newMap] = [];
|
|
890
|
+
}
|
|
891
|
+
mapStats[group.name][newMap].push(Date.now());
|
|
892
|
+
saveMapStats();
|
|
893
|
+
}
|
|
834
894
|
if (translatedMapName) {
|
|
835
895
|
matchPercentage = similarity(newMap, mapNameToCompare);
|
|
836
896
|
} else {
|