koishi-plugin-minecraft-search 0.0.1 → 0.0.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/LICENSE ADDED
@@ -0,0 +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.
package/lib/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export declare const name = "minecraft-search";
3
3
  export interface Config {
4
4
  server: string;
5
5
  picture: '1.jpg' | '2.jpg' | '3.jpg' | '4.jpg' | '5.jpg' | '6.jpg' | '7.jpg' | '8.jpg' | '9.jpg';
6
+ type: 'json' | 'image';
6
7
  }
7
8
  export declare const Config: Schema<Config>;
8
9
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -28,13 +28,57 @@ 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
- picture: import_koishi.Schema.union(["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg", "7.jpg", "8.jpg", "9.jpg"]).description("背景图").default("3.jpg")
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")
33
44
  });
45
+ function removeFormatting(str) {
46
+ return str.replace(/§[0-9a-fk-or]/g, "");
47
+ }
48
+ __name(removeFormatting, "removeFormatting");
34
49
  function apply(ctx, config) {
35
- ctx.command("mc/查服").action(async (agrv) => {
36
- const session = agrv.session;
37
- session.send(`<img src="https://api.imlazy.ink/mcapi/?name=Minecraft 服务器&host=${config.server}&type=image&getmotd=%0a%0a&getbg=${config.picture}"/>`);
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}`;
53
+ 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}]
62
+ `;
63
+ message += `🔗 地址: ${response.host}
64
+ `;
65
+ message += `📝 MOTD:
66
+ ${removeFormatting(response.motd.text)}
67
+ `;
68
+ message += `👥 玩家: ${response.players_online}/${response.players_max}
69
+ `;
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);
77
+ }
78
+ } catch (error) {
79
+ ctx.logger("minecraft-search").warn("查询服务器失败", error);
80
+ return `查询服务器失败: ${error.message}`;
81
+ }
38
82
  });
39
83
  }
40
84
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minecraft-search",
3
- "description": "使用雫 API查询基础的服务器信息",
4
- "version": "0.0.1",
3
+ "description": "使用雫 API查询基础的mc服务器信息",
4
+ "version": "0.0.2",
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
-
5
+ 使用雫 API查询基础的mc服务器信息