koishi-plugin-minecraft-search 2.0.2 → 2.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/lib/index.d.ts +2 -0
- package/lib/index.js +52 -2
- package/package.json +1 -1
- package/readme.md +14 -2
package/lib/index.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface ApiKeyConfig {
|
|
|
20
20
|
export interface Config {
|
|
21
21
|
minekuaiApiUrl: string;
|
|
22
22
|
showIpInDetail: boolean;
|
|
23
|
+
enablePermissionCheck: boolean;
|
|
24
|
+
allowMemberPowerCommands: boolean;
|
|
23
25
|
}
|
|
24
26
|
export declare const Config: Schema<Config>;
|
|
25
27
|
export declare const inject: {
|
package/lib/index.js
CHANGED
|
@@ -48,7 +48,11 @@ var Config = import_koishi.Schema.intersect([
|
|
|
48
48
|
}).description("麦块联机配置"),
|
|
49
49
|
import_koishi.Schema.object({
|
|
50
50
|
showIpInDetail: import_koishi.Schema.boolean().default(true).description("在查询详细状态时显示服务器IP地址")
|
|
51
|
-
}).description("显示配置")
|
|
51
|
+
}).description("显示配置"),
|
|
52
|
+
import_koishi.Schema.object({
|
|
53
|
+
enablePermissionCheck: import_koishi.Schema.boolean().default(true).description("启用管理员权限检查(仅限onebot机器人使用)"),
|
|
54
|
+
allowMemberPowerCommands: import_koishi.Schema.boolean().default(false).description("允许普通成员使用开服、重启、强制重启指令(仅限onebot机器人使用)")
|
|
55
|
+
}).description("权限配置")
|
|
52
56
|
]);
|
|
53
57
|
var inject = {
|
|
54
58
|
required: ["database"]
|
|
@@ -165,6 +169,20 @@ function apply(ctx, config) {
|
|
|
165
169
|
return server.name || "Minecraft 服务器";
|
|
166
170
|
}
|
|
167
171
|
__name(getServerName, "getServerName");
|
|
172
|
+
async function checkPermission(session, config2, isPowerCommand = false) {
|
|
173
|
+
if (!config2.enablePermissionCheck) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
if (isPowerCommand && config2.allowMemberPowerCommands) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const memberInfo = session.event?.member?.roles;
|
|
180
|
+
if (!memberInfo || !memberInfo.some((role) => role.name === "admin" || role.name === "owner" || role.id === "admin" || role.id === "owner")) {
|
|
181
|
+
return "❌ 仅限管理员和群主使用该指令。";
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
__name(checkPermission, "checkPermission");
|
|
168
186
|
function formatShortStatus(result, server) {
|
|
169
187
|
const displayName = getServerName(server);
|
|
170
188
|
if (!result.online) {
|
|
@@ -225,7 +243,7 @@ function apply(ctx, config) {
|
|
|
225
243
|
return message;
|
|
226
244
|
}
|
|
227
245
|
__name(formatDetailedStatus, "formatDetailedStatus");
|
|
228
|
-
ctx.command("mc/查服 [target:text]", "查询Minecraft服务器状态").action(async ({ session }, target) => {
|
|
246
|
+
ctx.guild().command("mc/查服 [target:text]", "查询Minecraft服务器状态").action(async ({ session }, target) => {
|
|
229
247
|
const servers = await ctx.database.get("minecraft_server", {});
|
|
230
248
|
if (target === void 0) {
|
|
231
249
|
if (servers.length === 0) {
|
|
@@ -285,6 +303,10 @@ function apply(ctx, config) {
|
|
|
285
303
|
return formatDetailedStatus(result.data, tempServer, config.showIpInDetail);
|
|
286
304
|
});
|
|
287
305
|
ctx.guild().command("mc/绑定 <host:string>", "绑定Minecraft服务器").option("name", "-n <name:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 5 }).option("instance", "-i <instance:string>", { fallback: "" }).action(async ({ session, options }, host) => {
|
|
306
|
+
const permissionError = await checkPermission(session, config);
|
|
307
|
+
if (permissionError) {
|
|
308
|
+
return permissionError;
|
|
309
|
+
}
|
|
288
310
|
if (!host) {
|
|
289
311
|
return "请提供服务器地址,例如:绑定+IP地址(不带端口时默认为25565)";
|
|
290
312
|
}
|
|
@@ -320,6 +342,10 @@ function apply(ctx, config) {
|
|
|
320
342
|
名称: ${newServer.name || "Minecraft 服务器"}`;
|
|
321
343
|
});
|
|
322
344
|
ctx.guild().command("mc/绑定密钥 <apiKey:string>", "绑定麦块API密钥").action(async ({ session }, apiKey) => {
|
|
345
|
+
const permissionError = await checkPermission(session, config);
|
|
346
|
+
if (permissionError) {
|
|
347
|
+
return permissionError;
|
|
348
|
+
}
|
|
323
349
|
if (!apiKey) {
|
|
324
350
|
return "请提供API密钥";
|
|
325
351
|
}
|
|
@@ -338,6 +364,10 @@ function apply(ctx, config) {
|
|
|
338
364
|
return "✅ API密钥绑定成功!";
|
|
339
365
|
});
|
|
340
366
|
ctx.guild().command("mc/解绑 <id:number>", "解绑Minecraft服务器").action(async ({ session }, id) => {
|
|
367
|
+
const permissionError = await checkPermission(session, config);
|
|
368
|
+
if (permissionError) {
|
|
369
|
+
return permissionError;
|
|
370
|
+
}
|
|
341
371
|
if (!id) {
|
|
342
372
|
return "请提供服务器ID,例如:解绑 1";
|
|
343
373
|
}
|
|
@@ -351,6 +381,10 @@ function apply(ctx, config) {
|
|
|
351
381
|
return `✅ 服务器已解绑`;
|
|
352
382
|
});
|
|
353
383
|
ctx.guild().command("mc/修改 <id:number>", "修改Minecraft服务器信息").option("name", "-n <name:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 0 }).option("instance", "-i <instance:string>", { fallback: "" }).action(async ({ session, options }, id) => {
|
|
384
|
+
const permissionError = await checkPermission(session, config);
|
|
385
|
+
if (permissionError) {
|
|
386
|
+
return permissionError;
|
|
387
|
+
}
|
|
354
388
|
if (!id) {
|
|
355
389
|
return "请提供服务器ID,例如:修改 1";
|
|
356
390
|
}
|
|
@@ -382,6 +416,10 @@ function apply(ctx, config) {
|
|
|
382
416
|
${parts.join("\n")}`;
|
|
383
417
|
});
|
|
384
418
|
ctx.guild().command("mc/开服 <id:number>", "启动麦块服务器").action(async ({ session }, id) => {
|
|
419
|
+
const permissionError = await checkPermission(session, config, true);
|
|
420
|
+
if (permissionError) {
|
|
421
|
+
return permissionError;
|
|
422
|
+
}
|
|
385
423
|
if (!id) return "请提供服务器ID,例如:开服 1";
|
|
386
424
|
const groupId = session.guildId;
|
|
387
425
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
@@ -396,6 +434,10 @@ ${parts.join("\n")}`;
|
|
|
396
434
|
}
|
|
397
435
|
});
|
|
398
436
|
ctx.guild().command("mc/重启 <id:number>", "重启麦块服务器").action(async ({ session }, id) => {
|
|
437
|
+
const permissionError = await checkPermission(session, config, true);
|
|
438
|
+
if (permissionError) {
|
|
439
|
+
return permissionError;
|
|
440
|
+
}
|
|
399
441
|
if (!id) return "请提供服务器ID,例如:重启 1";
|
|
400
442
|
const groupId = session.guildId;
|
|
401
443
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
@@ -410,6 +452,10 @@ ${parts.join("\n")}`;
|
|
|
410
452
|
}
|
|
411
453
|
});
|
|
412
454
|
ctx.guild().command("mc/强制重启 <id:number>", "强制重启麦块服务器").action(async ({ session }, id) => {
|
|
455
|
+
const permissionError = await checkPermission(session, config, true);
|
|
456
|
+
if (permissionError) {
|
|
457
|
+
return permissionError;
|
|
458
|
+
}
|
|
413
459
|
if (!id) return "请提供服务器ID,例如:强制重启 1";
|
|
414
460
|
const groupId = session.guildId;
|
|
415
461
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
@@ -513,6 +559,10 @@ ${parts.join("\n")}`;
|
|
|
513
559
|
return message.trim();
|
|
514
560
|
});
|
|
515
561
|
ctx.guild().command("mc/设置实例 <id:number> <instanceId:string>", "设置服务器的麦块实例ID").action(async ({ session }, id, instanceId) => {
|
|
562
|
+
const permissionError = await checkPermission(session, config);
|
|
563
|
+
if (permissionError) {
|
|
564
|
+
return permissionError;
|
|
565
|
+
}
|
|
516
566
|
if (!id || !instanceId) {
|
|
517
567
|
return "请提供服务器ID和实例ID,例如:设置实例 1 abc123";
|
|
518
568
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -53,7 +53,9 @@ npm install koishi-plugin-minecraft-search
|
|
|
53
53
|
```typescript
|
|
54
54
|
{
|
|
55
55
|
"minekuaiApiUrl": "https://minekuai.com/api/client", // 麦块API地址
|
|
56
|
-
"showIpInDetail": true // 是否在详细状态中显示IP地址
|
|
56
|
+
"showIpInDetail": true, // 是否在详细状态中显示IP地址
|
|
57
|
+
"enablePermissionCheck": true, // 启用管理员权限检查(仅限onebot机器人使用)
|
|
58
|
+
"allowMemberPowerCommands": false // 允许普通成员使用开服、重启、强制重启指令(仅限onebot机器人使用)
|
|
57
59
|
}
|
|
58
60
|
```
|
|
59
61
|
|
|
@@ -153,7 +155,7 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
|
|
|
153
155
|
- ⚡ **高性能查询**:支持并行查询多个服务器
|
|
154
156
|
- 🛡️ **错误处理**:完善的错误处理和用户提示
|
|
155
157
|
- 🗄️ **数据库存储**:使用数据库存储服务器配置,支持多群组管理
|
|
156
|
-
- 🔒
|
|
158
|
+
- 🔒 **权限控制**:支持全局权限管理,每个群组只能管理自己绑定的服务器,可控制普通成员使用电源指令的权限
|
|
157
159
|
- 🌐 **直接IP查询**:支持直接输入IP地址查询服务器状态
|
|
158
160
|
- 🔧 **实例ID管理**:支持在绑定和修改服务器时直接设置麦块实例ID
|
|
159
161
|
|
|
@@ -184,6 +186,16 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
|
|
|
184
186
|
<details>
|
|
185
187
|
<summary>点我查看更新日志详情</summary>
|
|
186
188
|
|
|
189
|
+
### v2.0.4
|
|
190
|
+
- 简化权限检查功能,移除群组级别的权限设置
|
|
191
|
+
- 优化权限检查功能配置项描述,明确仅限onebot机器人使用
|
|
192
|
+
|
|
193
|
+
### v2.0.3
|
|
194
|
+
- 新增权限检查功能,支持全局权限控制
|
|
195
|
+
- 新增配置项 `enablePermissionCheck` 控制是否启用权限检查
|
|
196
|
+
- 新增配置项 `allowMemberPowerCommands` 控制是否允许普通成员使用电源指令
|
|
197
|
+
- 优化权限检查逻辑
|
|
198
|
+
|
|
187
199
|
### v2.0.1
|
|
188
200
|
- 新增绑定服务器时支持 -i 选项直接设置麦块实例ID
|
|
189
201
|
- 新增修改服务器时支持 -i 选项修改麦块实例ID
|