koishi-plugin-minecraft-search 0.0.2 → 0.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/LICENSE +21 -21
- package/lib/index.d.ts +6 -3
- package/lib/index.js +71 -37
- package/package.json +2 -2
- package/readme.md +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 forgetmelody
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 forgetmelody
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
2
|
export declare const name = "minecraft-search";
|
|
3
|
+
export interface ServerConfig {
|
|
4
|
+
name: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
}
|
|
3
8
|
export interface Config {
|
|
4
|
-
|
|
5
|
-
picture: '1.jpg' | '2.jpg' | '3.jpg' | '4.jpg' | '5.jpg' | '6.jpg' | '7.jpg' | '8.jpg' | '9.jpg';
|
|
6
|
-
type: 'json' | 'image';
|
|
9
|
+
servers: ServerConfig[];
|
|
7
10
|
}
|
|
8
11
|
export declare const Config: Schema<Config>;
|
|
9
12
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -28,57 +28,91 @@ module.exports = __toCommonJS(src_exports);
|
|
|
28
28
|
var import_koishi = require("koishi");
|
|
29
29
|
var name = "minecraft-search";
|
|
30
30
|
var Config = import_koishi.Schema.object({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"3.jpg",
|
|
37
|
-
"4.jpg",
|
|
38
|
-
"5.jpg",
|
|
39
|
-
"6.jpg",
|
|
40
|
-
"7.jpg",
|
|
41
|
-
"8.jpg",
|
|
42
|
-
"9.jpg"
|
|
43
|
-
]).description("背景图").default("3.jpg")
|
|
31
|
+
servers: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
32
|
+
name: import_koishi.Schema.string().description("服务器名称").required(),
|
|
33
|
+
host: import_koishi.Schema.string().description("服务器地址").required(),
|
|
34
|
+
port: import_koishi.Schema.number().description("服务器端口").default(25565)
|
|
35
|
+
})).description("Minecraft服务器列表").role("table").collapse().required()
|
|
44
36
|
});
|
|
45
37
|
function removeFormatting(str) {
|
|
46
38
|
return str.replace(/§[0-9a-fk-or]/g, "");
|
|
47
39
|
}
|
|
48
40
|
__name(removeFormatting, "removeFormatting");
|
|
49
41
|
function apply(ctx, config) {
|
|
50
|
-
ctx.command("mc/查服").action(async ({ session }) => {
|
|
51
|
-
const {
|
|
52
|
-
|
|
42
|
+
ctx.command("mc/查服 [serverName:string]").action(async ({ session }, serverName) => {
|
|
43
|
+
const { servers } = config;
|
|
44
|
+
if (!servers || servers.length === 0) {
|
|
45
|
+
return "未配置任何Minecraft服务器";
|
|
46
|
+
}
|
|
47
|
+
if (serverName) {
|
|
48
|
+
const targetServer = servers.find(
|
|
49
|
+
(server) => server.name.toLowerCase() === serverName.toLowerCase()
|
|
50
|
+
);
|
|
51
|
+
if (!targetServer) {
|
|
52
|
+
return `未找到名为"${serverName}"的服务器。可用服务器: ${servers.map((s) => s.name).join(", ")}`;
|
|
53
|
+
}
|
|
54
|
+
return await queryServer(targetServer);
|
|
55
|
+
}
|
|
56
|
+
const results = [];
|
|
57
|
+
for (const server of servers) {
|
|
58
|
+
try {
|
|
59
|
+
const result = await queryServer(server);
|
|
60
|
+
results.push(result);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
results.push(`❌ ${server.name} 查询失败: ${error.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return results.join("\n\n");
|
|
66
|
+
});
|
|
67
|
+
async function queryServer(server) {
|
|
68
|
+
const hostWithPort = `${server.host}:${server.port}`;
|
|
69
|
+
const apiUrl = `https://motd.minebbs.com/api/status?ip=${server.host}&port=${server.port}`;
|
|
53
70
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
const response = await ctx.http.get(apiUrl);
|
|
72
|
+
if (response.status !== "online") {
|
|
73
|
+
return `🔴 ${server.name}
|
|
74
|
+
🌐 ${hostWithPort}
|
|
75
|
+
状态: 离线`;
|
|
76
|
+
}
|
|
77
|
+
let message = `🟢 ${server.name}
|
|
78
|
+
`;
|
|
79
|
+
message += `🌐 IP: ${hostWithPort}
|
|
62
80
|
`;
|
|
63
|
-
|
|
81
|
+
message += `📝 MOTD: ${removeFormatting(response.pureMotd || response.motd?.text || "无")}
|
|
64
82
|
`;
|
|
65
|
-
|
|
66
|
-
${removeFormatting(response.motd.text)}
|
|
83
|
+
message += `🎮 版本: ${response.version} (协议 ${response.protocol})
|
|
67
84
|
`;
|
|
68
|
-
|
|
85
|
+
message += `👥 玩家: ${response.players.online}/${response.players.max}
|
|
69
86
|
`;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
message += `⏱️ 延迟: ${response.delay}ms
|
|
88
|
+
`;
|
|
89
|
+
if (response.players.online > 0 && response.players.sample) {
|
|
90
|
+
const playerNames = Array.isArray(response.players.sample) ? response.players.sample : response.players.sample.split(", ");
|
|
91
|
+
message += `🎯 在线玩家: ${playerNames.join(", ")}`;
|
|
92
|
+
} else if (response.players.online > 0) {
|
|
93
|
+
message += "🎯 在线玩家: 有玩家在线但未获取到列表";
|
|
94
|
+
} else {
|
|
95
|
+
message += "🎯 当前没有在线玩家";
|
|
77
96
|
}
|
|
97
|
+
return message;
|
|
78
98
|
} catch (error) {
|
|
79
|
-
ctx.logger("minecraft-search").warn(
|
|
80
|
-
|
|
99
|
+
ctx.logger("minecraft-search").warn(`查询服务器 ${server.name} 失败`, error);
|
|
100
|
+
throw new Error(`查询失败: ${error.message}`);
|
|
81
101
|
}
|
|
102
|
+
}
|
|
103
|
+
__name(queryServer, "queryServer");
|
|
104
|
+
ctx.command("mc/服务器列表").action(async ({ session }) => {
|
|
105
|
+
const { servers } = config;
|
|
106
|
+
if (!servers || servers.length === 0) {
|
|
107
|
+
return "未配置任何Minecraft服务器";
|
|
108
|
+
}
|
|
109
|
+
const serverList = servers.map(
|
|
110
|
+
(server) => `• ${server.name} - ${server.host}:${server.port}`
|
|
111
|
+
).join("\n");
|
|
112
|
+
return `📋 已配置的Minecraft服务器:
|
|
113
|
+
${serverList}
|
|
114
|
+
|
|
115
|
+
使用"mc/查服 服务器名称"查询特定服务器`;
|
|
82
116
|
});
|
|
83
117
|
}
|
|
84
118
|
__name(apply, "apply");
|
package/package.json
CHANGED
package/readme.md
CHANGED