koishi-plugin-cs2-server-query 1.1.0 → 1.1.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.
- package/lib/index.js +57 -85
- package/package.json +1 -1
- package/readme.md +1 -1
package/lib/index.js
CHANGED
|
@@ -75,15 +75,6 @@ function apply(ctx, config) {
|
|
|
75
75
|
import_fs.default.writeFileSync(commandMappingFilePath, JSON.stringify(commandMappings, null, 2));
|
|
76
76
|
}
|
|
77
77
|
__name(saveCommandMappings, "saveCommandMappings");
|
|
78
|
-
const customIpFilePath = import_path.default.resolve(__dirname, "custom-ip.json");
|
|
79
|
-
let customIps = {};
|
|
80
|
-
if (import_fs.default.existsSync(customIpFilePath)) {
|
|
81
|
-
customIps = JSON.parse(import_fs.default.readFileSync(customIpFilePath, "utf-8"));
|
|
82
|
-
}
|
|
83
|
-
function saveCustomIps() {
|
|
84
|
-
import_fs.default.writeFileSync(customIpFilePath, JSON.stringify(customIps, null, 2));
|
|
85
|
-
}
|
|
86
|
-
__name(saveCustomIps, "saveCustomIps");
|
|
87
78
|
const difficultyColors = {
|
|
88
79
|
"简单": "#33cc00",
|
|
89
80
|
"普通": "#ffcc00",
|
|
@@ -259,6 +250,33 @@ function apply(ctx, config) {
|
|
|
259
250
|
}
|
|
260
251
|
}
|
|
261
252
|
});
|
|
253
|
+
ctx.setInterval(async () => {
|
|
254
|
+
for (const group of groups) {
|
|
255
|
+
for (const server of group.servers) {
|
|
256
|
+
try {
|
|
257
|
+
const info = await (0, import_steam_server_query.queryGameServerInfo)(server.ip);
|
|
258
|
+
server.name = info.name || server.name;
|
|
259
|
+
server.map = info.map;
|
|
260
|
+
server.players = info.players;
|
|
261
|
+
server.maxPlayers = info.maxPlayers;
|
|
262
|
+
server.status = "在线";
|
|
263
|
+
} catch (err) {
|
|
264
|
+
server.status = "离线";
|
|
265
|
+
try {
|
|
266
|
+
const newInfo = await (0, import_steam_server_query.queryGameServerInfo)(server.ip);
|
|
267
|
+
server.name = newInfo.name || server.name;
|
|
268
|
+
server.map = newInfo.map;
|
|
269
|
+
server.players = newInfo.players;
|
|
270
|
+
server.maxPlayers = newInfo.maxPlayers;
|
|
271
|
+
server.status = "在线";
|
|
272
|
+
} catch (err2) {
|
|
273
|
+
server.status = "离线";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
saveData();
|
|
279
|
+
}, 6e4);
|
|
262
280
|
ctx.command("cs2组创建 <name>", "添加一个新组").action((_, name2) => {
|
|
263
281
|
if (!name2) return "请提供组名。";
|
|
264
282
|
if (groups.some((group) => group.name === name2)) return "组已存在。";
|
|
@@ -304,6 +322,36 @@ function apply(ctx, config) {
|
|
|
304
322
|
return `服务器 "${serverName}" (${ip}) 已添加到组 "${groupName}" 中,但当前状态为离线。`;
|
|
305
323
|
}
|
|
306
324
|
});
|
|
325
|
+
ctx.command("cs2替换IP <groupName> <serverIndex> <newIP>", "替换指定组中指定编号的服务器的IP地址").action(async (_, groupName, serverIndex, newIP) => {
|
|
326
|
+
const group = groups.find((group2) => group2.name === groupName);
|
|
327
|
+
if (!group) return "未找到该组。";
|
|
328
|
+
const index = parseInt(serverIndex) - 1;
|
|
329
|
+
if (isNaN(index) || index < 0 || index >= group.servers.length) return "无效的服务器编号。";
|
|
330
|
+
const server = group.servers[index];
|
|
331
|
+
const oldIP = server.ip;
|
|
332
|
+
try {
|
|
333
|
+
const info = await (0, import_steam_server_query.queryGameServerInfo)(newIP);
|
|
334
|
+
server.name = info.name || `服务器 ${newIP}`;
|
|
335
|
+
server.ip = newIP;
|
|
336
|
+
server.map = info.map;
|
|
337
|
+
server.players = info.players;
|
|
338
|
+
server.maxPlayers = info.maxPlayers;
|
|
339
|
+
server.latency = 0;
|
|
340
|
+
server.status = "在线";
|
|
341
|
+
saveData();
|
|
342
|
+
return `服务器 ${serverIndex} 的IP地址已从 ${oldIP} 替换为 ${newIP},并成功更新服务器信息。`;
|
|
343
|
+
} catch (err) {
|
|
344
|
+
server.name = `服务器 ${newIP}`;
|
|
345
|
+
server.ip = newIP;
|
|
346
|
+
server.map = "未知";
|
|
347
|
+
server.players = 0;
|
|
348
|
+
server.maxPlayers = 0;
|
|
349
|
+
server.latency = 0;
|
|
350
|
+
server.status = "离线";
|
|
351
|
+
saveData();
|
|
352
|
+
return `服务器 ${serverIndex} 的IP地址已从 ${oldIP} 替换为 ${newIP},但当前状态为离线。`;
|
|
353
|
+
}
|
|
354
|
+
});
|
|
307
355
|
ctx.command("cs2组删除 <groupName>", "删除一个组").action((_, groupName) => {
|
|
308
356
|
const index = groups.findIndex((group) => group.name === groupName);
|
|
309
357
|
if (index === -1) return "未找到该组。";
|
|
@@ -354,82 +402,6 @@ function apply(ctx, config) {
|
|
|
354
402
|
if (Object.keys(commandMappings).length === 0) return "未找到任何指令映射。";
|
|
355
403
|
return `指令映射列表:${Object.entries(commandMappings).map(([command, groupName]) => `${command} -> ${groupName}`).join(", ")}`;
|
|
356
404
|
});
|
|
357
|
-
ctx.command("cs2更新IP <groupName> <oldIp> <newIp>", "手动更新服务器IP").action((_, groupName, oldIp, newIp) => {
|
|
358
|
-
const group = groups.find((group2) => group2.name === groupName);
|
|
359
|
-
if (!group) return "未找到该组。";
|
|
360
|
-
const server = group.servers.find((server2) => server2.ip === oldIp);
|
|
361
|
-
if (!server) return "未找到该服务器。";
|
|
362
|
-
server.ip = newIp;
|
|
363
|
-
saveData();
|
|
364
|
-
return `服务器IP已从 ${oldIp} 更新为 ${newIp}。`;
|
|
365
|
-
});
|
|
366
|
-
ctx.command("cs2添加自定义IP <groupName> <ip>", "手动添加自定义服务器IP").action((_, groupName, ip) => {
|
|
367
|
-
if (!customIps[groupName]) {
|
|
368
|
-
customIps[groupName] = [];
|
|
369
|
-
}
|
|
370
|
-
if (customIps[groupName].includes(ip)) {
|
|
371
|
-
return "该IP已存在于自定义IP列表中。";
|
|
372
|
-
}
|
|
373
|
-
customIps[groupName].push(ip);
|
|
374
|
-
saveCustomIps();
|
|
375
|
-
return `自定义IP ${ip} 已成功添加到组 ${groupName} 中。`;
|
|
376
|
-
});
|
|
377
|
-
ctx.command("cs2删除自定义IP <groupName> <ip>", "手动删除自定义服务器IP").action((_, groupName, ip) => {
|
|
378
|
-
if (!customIps[groupName]) {
|
|
379
|
-
return "该组没有自定义IP。";
|
|
380
|
-
}
|
|
381
|
-
const index = customIps[groupName].indexOf(ip);
|
|
382
|
-
if (index === -1) {
|
|
383
|
-
return "未找到该自定义IP。";
|
|
384
|
-
}
|
|
385
|
-
customIps[groupName].splice(index, 1);
|
|
386
|
-
saveCustomIps();
|
|
387
|
-
return `自定义IP ${ip} 已从组 ${groupName} 中删除。`;
|
|
388
|
-
});
|
|
389
|
-
ctx.setInterval(async () => {
|
|
390
|
-
for (const group of groups) {
|
|
391
|
-
for (const server of group.servers) {
|
|
392
|
-
try {
|
|
393
|
-
const info = await (0, import_steam_server_query.queryGameServerInfo)(server.ip);
|
|
394
|
-
server.status = "在线";
|
|
395
|
-
} catch (err) {
|
|
396
|
-
server.status = "离线";
|
|
397
|
-
const index = group.servers.indexOf(server);
|
|
398
|
-
if (index !== -1) {
|
|
399
|
-
group.servers.splice(index, 1);
|
|
400
|
-
}
|
|
401
|
-
if (customIps[group.name] && customIps[group.name].length > 0) {
|
|
402
|
-
const newIp = customIps[group.name].shift();
|
|
403
|
-
if (newIp) {
|
|
404
|
-
try {
|
|
405
|
-
const info = await (0, import_steam_server_query.queryGameServerInfo)(newIp);
|
|
406
|
-
group.servers.push({
|
|
407
|
-
name: info.name || `服务器 ${newIp}`,
|
|
408
|
-
ip: newIp,
|
|
409
|
-
map: info.map,
|
|
410
|
-
players: info.players,
|
|
411
|
-
maxPlayers: info.maxPlayers,
|
|
412
|
-
latency: 0,
|
|
413
|
-
status: "在线"
|
|
414
|
-
});
|
|
415
|
-
} catch (err2) {
|
|
416
|
-
group.servers.push({
|
|
417
|
-
name: `服务器 ${newIp}`,
|
|
418
|
-
ip: newIp,
|
|
419
|
-
map: "未知",
|
|
420
|
-
players: 0,
|
|
421
|
-
maxPlayers: 0,
|
|
422
|
-
latency: 0,
|
|
423
|
-
status: "离线"
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
saveData();
|
|
431
|
-
}
|
|
432
|
-
}, 10 * 60 * 1e3);
|
|
433
405
|
}
|
|
434
406
|
__name(apply, "apply");
|
|
435
407
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
package/readme.md
CHANGED