koishi-plugin-minecraft-search 0.0.2 → 0.0.4

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 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
- server: string;
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,92 @@ 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
- server: import_koishi.Schema.string().description("MC服务器地址").required(),
32
- type: import_koishi.Schema.union(["json", "image"]).description("返回格式类型").default("image"),
33
- picture: import_koishi.Schema.union([
34
- "1.jpg",
35
- "2.jpg",
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 { server, picture, type } = config;
52
- const apiUrl = `https://api.imlazy.ink/mcapi/?name=Minecraft%20服务器&host=${server}&type=${type}&getmotd=%0a%0a&getbg=${picture}`;
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
- if (type === "image") {
55
- await session.send(`<img src="${apiUrl}"/>`);
56
- } else {
57
- const response = await ctx.http.get(apiUrl);
58
- if (response.status !== "在线") {
59
- return `服务器 ${server} 当前离线`;
60
- }
61
- let message = `🟢 服务器信息 [${response.name}]
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
- message += `🔗 地址: ${response.host}
81
+ message += `📝 MOTD:
82
+ ${removeFormatting(response.pureMotd || response.motd?.text || "无")}
64
83
  `;
65
- message += `📝 MOTD:
66
- ${removeFormatting(response.motd.text)}
84
+ message += `🎮 版本: ${response.version} (协议 ${response.protocol})
67
85
  `;
68
- message += `👥 玩家: ${response.players_online}/${response.players_max}
86
+ message += `👥 玩家: ${response.players.online}/${response.players.max}
69
87
  `;
70
- if (response.players_online > 0) {
71
- const playerNames = response.players.map((p) => p.name);
72
- message += `🎮 在线玩家: ${playerNames.join(", ")}`;
73
- } else {
74
- message += "🎮 当前没有在线玩家";
75
- }
76
- await session.send(message);
88
+ message += `⏱️ 延迟: ${response.delay}ms
89
+ `;
90
+ if (response.players.online > 0 && response.players.sample) {
91
+ const playerNames = Array.isArray(response.players.sample) ? response.players.sample : response.players.sample.split(", ");
92
+ message += `🎯 在线玩家: ${playerNames.join(", ")}`;
93
+ } else if (response.players.online > 0) {
94
+ message += "🎯 在线玩家: 有玩家在线但未获取到列表";
95
+ } else {
96
+ message += "🎯 当前没有在线玩家";
77
97
  }
98
+ return message;
78
99
  } catch (error) {
79
- ctx.logger("minecraft-search").warn("查询服务器失败", error);
80
- return `查询服务器失败: ${error.message}`;
100
+ ctx.logger("minecraft-search").warn(`查询服务器 ${server.name} 失败`, error);
101
+ throw new Error(`查询失败: ${error.message}`);
81
102
  }
103
+ }
104
+ __name(queryServer, "queryServer");
105
+ ctx.command("mc/服务器列表").action(async ({ session }) => {
106
+ const { servers } = config;
107
+ if (!servers || servers.length === 0) {
108
+ return "未配置任何Minecraft服务器";
109
+ }
110
+ const serverList = servers.map(
111
+ (server) => `• ${server.name} - ${server.host}:${server.port}`
112
+ ).join("\n");
113
+ return `📋 已配置的Minecraft服务器:
114
+ ${serverList}
115
+
116
+ 使用"mc/查服 服务器名称"查询特定服务器`;
82
117
  });
83
118
  }
84
119
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minecraft-search",
3
- "description": "使用雫 API查询基础的mc服务器信息",
4
- "version": "0.0.2",
3
+ "description": "使用API查询基础的mc服务器信息",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/koishi-plugin-minecraft-search?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-minecraft-search)
4
4
 
5
- 使用雫 API查询基础的mc服务器信息
5
+ 使用API查询基础的mc服务器信息