koishi-plugin-node-async-bot-all 2.4.0 → 2.5.0
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 +5 -2
- package/lib/index.js +99 -85
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -11,9 +11,12 @@ interface botDataTables {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const name = "node-async-bot-all";
|
|
13
13
|
export declare const usage = "\u8FD9\u662F\u4E00\u4E2A\u79C1\u6709\u63D2\u4EF6\u3002";
|
|
14
|
+
export interface ConfigCxV2 {
|
|
15
|
+
id: string;
|
|
16
|
+
api: Array<string>;
|
|
17
|
+
}
|
|
14
18
|
export interface Config {
|
|
15
|
-
|
|
16
|
-
cxV2API: Array<string>;
|
|
19
|
+
cxV2: Array<ConfigCxV2>;
|
|
17
20
|
rwAPI: string;
|
|
18
21
|
timeout: number;
|
|
19
22
|
}
|
package/lib/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
33
33
|
// src/locales/zh-CN.yml
|
|
34
34
|
var require_zh_CN = __commonJS({
|
|
35
35
|
"src/locales/zh-CN.yml"(exports2, module2) {
|
|
36
|
-
module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【MC
|
|
36
|
+
module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 协议版本:{protocol}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\n运行时间:{online}", failed: "{time}\n状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成的随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{data}", failed: "{time}\n读取信息失败。" } }, rw: { description: "随机名言名句。", messages: { msg: "{time}\n{data}", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败(2)。" } } } };
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -128,6 +128,7 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3, log) {
|
|
|
128
128
|
return response;
|
|
129
129
|
} catch (error) {
|
|
130
130
|
clearTimeout(timeoutId);
|
|
131
|
+
log.error(error);
|
|
131
132
|
log.error(`${error.name}: ${error.message}`);
|
|
132
133
|
if (error.name === "AbortError") {
|
|
133
134
|
throw new Error("请求超时");
|
|
@@ -183,92 +184,103 @@ async function getServer(ctx, session) {
|
|
|
183
184
|
let data;
|
|
184
185
|
let error;
|
|
185
186
|
const time = getHongKongTime();
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
msg = {
|
|
191
|
-
"time": time,
|
|
192
|
-
"data": "未指定查询 API",
|
|
193
|
-
"success": 1
|
|
194
|
-
};
|
|
195
|
-
log.info("Sent:");
|
|
196
|
-
log.info(msg);
|
|
197
|
-
return msg;
|
|
198
|
-
}
|
|
199
|
-
const response = await fetchWithTimeout(api, {}, ctx.config.timeout, log);
|
|
200
|
-
if (response.ok) {
|
|
201
|
-
data = await response.text();
|
|
202
|
-
log.info("Server data: " + data);
|
|
203
|
-
data = JSON.parse(data);
|
|
204
|
-
if (data["list"] == null) {
|
|
205
|
-
msg = {
|
|
206
|
-
"time": time,
|
|
207
|
-
"players": data["players"],
|
|
208
|
-
"version": data["version"],
|
|
209
|
-
"protocol": data["protocol"],
|
|
210
|
-
"success": 3
|
|
211
|
-
};
|
|
212
|
-
log.info("Sent:");
|
|
213
|
-
log.info(msg);
|
|
214
|
-
} else {
|
|
215
|
-
msg = {
|
|
216
|
-
"time": time,
|
|
217
|
-
"players": data["players"],
|
|
218
|
-
"version": data["version"],
|
|
219
|
-
"list": data["list"].join(", "),
|
|
220
|
-
"protocol": data["protocol"],
|
|
221
|
-
"success": 0
|
|
222
|
-
};
|
|
223
|
-
log.info("Sent:");
|
|
224
|
-
log.info(msg);
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
dataError = await response.text();
|
|
228
|
-
try {
|
|
229
|
-
const vError = JSON.parse(dataError);
|
|
230
|
-
error = vError["data"];
|
|
231
|
-
if (error.includes("Connection refused")) {
|
|
232
|
-
error = session.text(".close");
|
|
233
|
-
} else if (error.includes("No route to host")) {
|
|
234
|
-
error = session.text(".host");
|
|
235
|
-
} else if (error.includes("Connection timed out")) {
|
|
236
|
-
error = session.text(".timeout");
|
|
237
|
-
} else if (error.includes("Server returned too few data")) {
|
|
238
|
-
error = session.text(".fewData");
|
|
239
|
-
} else if (error.includes("Server read timed out")) {
|
|
240
|
-
error = session.text(".timeout2");
|
|
241
|
-
}
|
|
242
|
-
} catch (e) {
|
|
243
|
-
if (dataError.includes("CDN节点请求源服务器超时")) {
|
|
244
|
-
error = session.text(".timeout");
|
|
245
|
-
} else {
|
|
246
|
-
error = session.text(".unknown");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
log.error(`Error fetching data: ${dataError}`);
|
|
250
|
-
msg = {
|
|
251
|
-
"time": time,
|
|
252
|
-
"data": error,
|
|
253
|
-
"success": 1
|
|
254
|
-
};
|
|
255
|
-
log.info("Sent:");
|
|
256
|
-
log.info(msg);
|
|
257
|
-
}
|
|
258
|
-
} catch (err) {
|
|
259
|
-
log.error(`Request error: ${err.message}`);
|
|
187
|
+
const index = ctx.config.cxV2.findIndex((item) => item.id === session.event.guild.id);
|
|
188
|
+
if (index !== -1) {
|
|
189
|
+
const api = ctx.config.cxV2[index]["api"];
|
|
190
|
+
if (api == void 0) {
|
|
260
191
|
msg = {
|
|
261
192
|
"time": time,
|
|
262
|
-
"data":
|
|
263
|
-
"success":
|
|
193
|
+
"data": "未指定查询 API",
|
|
194
|
+
"success": 2
|
|
264
195
|
};
|
|
265
196
|
log.info("Sent:");
|
|
266
197
|
log.info(msg);
|
|
198
|
+
return msg;
|
|
199
|
+
}
|
|
200
|
+
let count = 0;
|
|
201
|
+
let list = "";
|
|
202
|
+
for (const item of api) {
|
|
203
|
+
count++;
|
|
204
|
+
try {
|
|
205
|
+
const response = await fetchWithTimeout(item, {}, ctx.config.timeout, log);
|
|
206
|
+
if (response.ok) {
|
|
207
|
+
data = await response.text();
|
|
208
|
+
log.info("Server data: " + data);
|
|
209
|
+
data = JSON.parse(data);
|
|
210
|
+
if (data["list"] == null) {
|
|
211
|
+
const temp = {
|
|
212
|
+
"count": count,
|
|
213
|
+
"players": data["players"],
|
|
214
|
+
"version": data["version"],
|
|
215
|
+
"protocol": data["protocol"]
|
|
216
|
+
};
|
|
217
|
+
log.info(`Server ${count}:`);
|
|
218
|
+
log.info(temp);
|
|
219
|
+
list = list + "\n" + session.text(".listNoPlayer", temp);
|
|
220
|
+
} else {
|
|
221
|
+
const temp = {
|
|
222
|
+
"count": count,
|
|
223
|
+
"players": data["players"],
|
|
224
|
+
"version": data["version"],
|
|
225
|
+
"list": data["list"].join(", "),
|
|
226
|
+
"protocol": data["protocol"]
|
|
227
|
+
};
|
|
228
|
+
log.info(`Server ${count}:`);
|
|
229
|
+
log.info(temp);
|
|
230
|
+
list = list + "\n" + session.text(".list", temp);
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
dataError = await response.text();
|
|
234
|
+
try {
|
|
235
|
+
const vError = JSON.parse(dataError);
|
|
236
|
+
error = vError["data"];
|
|
237
|
+
if (error.includes("Connection refused")) {
|
|
238
|
+
error = session.text(".close");
|
|
239
|
+
} else if (error.includes("No route to host")) {
|
|
240
|
+
error = session.text(".host");
|
|
241
|
+
} else if (error.includes("Connection timed out")) {
|
|
242
|
+
error = session.text(".timeout");
|
|
243
|
+
} else if (error.includes("Server returned too few data")) {
|
|
244
|
+
error = session.text(".fewData");
|
|
245
|
+
} else if (error.includes("Server read timed out")) {
|
|
246
|
+
error = session.text(".timeout2");
|
|
247
|
+
}
|
|
248
|
+
} catch (e) {
|
|
249
|
+
if (dataError.includes("CDN节点请求源服务器超时")) {
|
|
250
|
+
error = session.text(".timeout");
|
|
251
|
+
} else {
|
|
252
|
+
error = session.text(".unknown");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
log.error(`Error fetching data: ${dataError}`);
|
|
256
|
+
const temp = {
|
|
257
|
+
"count": count,
|
|
258
|
+
"data": error
|
|
259
|
+
};
|
|
260
|
+
log.info(`Server ${count}:`);
|
|
261
|
+
log.info(temp);
|
|
262
|
+
list = list + "\n" + session.text(".listFailed", temp);
|
|
263
|
+
}
|
|
264
|
+
} catch (err) {
|
|
265
|
+
log.error(`Request error: ${err.message}`);
|
|
266
|
+
const temp = {
|
|
267
|
+
"count": count,
|
|
268
|
+
"data": session.text(".error")
|
|
269
|
+
};
|
|
270
|
+
log.info(`Server ${count}:`);
|
|
271
|
+
log.info(temp);
|
|
272
|
+
list = list + "\n" + session.text(".listFailed", temp);
|
|
273
|
+
}
|
|
267
274
|
}
|
|
275
|
+
msg = {
|
|
276
|
+
"time": time,
|
|
277
|
+
"list": list,
|
|
278
|
+
"success": 0
|
|
279
|
+
};
|
|
268
280
|
} else {
|
|
269
281
|
msg = {
|
|
270
282
|
"time": time,
|
|
271
|
-
"success":
|
|
283
|
+
"success": 1
|
|
272
284
|
};
|
|
273
285
|
log.info("Sent:");
|
|
274
286
|
log.info(msg);
|
|
@@ -401,7 +413,7 @@ async function getRW(ctx, session) {
|
|
|
401
413
|
__name(getRW, "getRW");
|
|
402
414
|
|
|
403
415
|
// package.json
|
|
404
|
-
var version = "2.
|
|
416
|
+
var version = "2.5.0";
|
|
405
417
|
|
|
406
418
|
// src/index.ts
|
|
407
419
|
var inject = ["database"];
|
|
@@ -412,8 +424,12 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
412
424
|
timeout: import_koishi2.Schema.number().default(8e3).description("超时时间(毫秒)")
|
|
413
425
|
}).description("基础"),
|
|
414
426
|
import_koishi2.Schema.object({
|
|
415
|
-
|
|
416
|
-
|
|
427
|
+
cxV2: import_koishi2.Schema.array(
|
|
428
|
+
import_koishi2.Schema.object({
|
|
429
|
+
id: import_koishi2.Schema.string().required().description("查询 群"),
|
|
430
|
+
api: import_koishi2.Schema.array(String).description("查询 API")
|
|
431
|
+
})
|
|
432
|
+
).default([]).description("查询的 API 和 群")
|
|
417
433
|
}).description("查询"),
|
|
418
434
|
import_koishi2.Schema.object({
|
|
419
435
|
rwAPI: import_koishi2.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
|
|
@@ -438,11 +454,9 @@ function apply(ctx) {
|
|
|
438
454
|
if (cx["success"] == 0) {
|
|
439
455
|
return session.text(".msg", cx);
|
|
440
456
|
} else if (cx["success"] == 1) {
|
|
441
|
-
return session.text(".failed", cx);
|
|
442
|
-
} else if (cx["success"] == 2) {
|
|
443
457
|
return session.text(".forbidden", cx);
|
|
444
|
-
} else if (cx["success"] ==
|
|
445
|
-
return session.text(".
|
|
458
|
+
} else if (cx["success"] == 2) {
|
|
459
|
+
return session.text(".failed", cx);
|
|
446
460
|
}
|
|
447
461
|
});
|
|
448
462
|
ctx.command("status").action(async ({ session }) => {
|