koishi-plugin-node-async-bot-all 1.8.2 → 1.9.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/fun.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { Context } from "koishi";
1
2
  export declare function getSystemUsage(): Promise<object>;
2
3
  export declare function getHongKongTime(): string;
3
- export declare function fetchWithTimeout(url: string, options?: {}, timeout?: number): Promise<Response>;
4
+ export declare function fetchWithTimeout(url: string, options: {}, timeout: number, ctx: Context): Promise<Response>;
4
5
  export declare function readInfoFile(): Promise<string>;
5
6
  export declare function getAudioPath(name: string): Promise<string>;
6
7
  export declare function getAudioList(): Promise<string[]>;
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【服务器当前人数】\n➣ {version}:{players}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}", 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)。" } }, cassie: { description: "发送 C.A.S.S.I.E. 语音。", usage: "缺少参数时返回语音列表。\n使用示例:", examples: "cassie mtfSpawn 播放当机动特遣队重生并且SCP还活着时的语音。", messages: { msg: "{time}\n【播放列表】\n{data}", failed: "{time}\n发送失败,请稍后重试。", unknown: "{time}\n未知语音,发送 /cassie 查看播放列表。" } } } };
36
+ module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}", 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)。" } }, cassie: { description: "发送 C.A.S.S.I.E. 语音。", usage: "缺少参数时返回语音列表。\n使用示例:", examples: "cassie mtfSpawn 播放当机动特遣队重生并且SCP还活着时的语音。", messages: { msg: "{time}\n【播放列表】\n{data}", failed: "{time}\n发送失败,请稍后重试。", unknown: "{time}\n未知语音,发送 /cassie 查看播放列表。" } } } };
37
37
  }
38
38
  });
39
39
 
@@ -51,7 +51,7 @@ var import_koishi = require("koishi");
51
51
  var import_os = __toESM(require("os"));
52
52
 
53
53
  // package.json
54
- var version = "1.8.2";
54
+ var version = "1.9.0";
55
55
 
56
56
  // src/fun.ts
57
57
  var import_fs = __toESM(require("fs"));
@@ -112,7 +112,7 @@ function getHongKongTime() {
112
112
  ].join(":");
113
113
  }
114
114
  __name(getHongKongTime, "getHongKongTime");
115
- async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
115
+ async function fetchWithTimeout(url, options = {}, timeout = 5e3, ctx) {
116
116
  const controller = new AbortController();
117
117
  const timeoutId = setTimeout(() => {
118
118
  controller.abort();
@@ -124,9 +124,11 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
124
124
  // 绑定终止信号
125
125
  });
126
126
  clearTimeout(timeoutId);
127
+ ctx.logger.info(`Fetch code: ${response.status}`);
127
128
  return response;
128
129
  } catch (error) {
129
130
  clearTimeout(timeoutId);
131
+ ctx.logger.error(`${error.name}: ${error.message}`);
130
132
  if (error.name === "AbortError") {
131
133
  throw new Error("请求超时");
132
134
  } else {
@@ -171,7 +173,7 @@ async function getServer(ctx, session) {
171
173
  const time = getHongKongTime();
172
174
  if (session.event.guild.id == "757729218" || session.event.guild.id == "1047732162") {
173
175
  try {
174
- const response = await fetchWithTimeout("https://api.tasaed.top/get/minecraftServer/", {}, 8e3);
176
+ const response = await fetchWithTimeout("https://api.tasaed.top/get/minecraftServer/", {}, 8e3, ctx);
175
177
  if (response.ok) {
176
178
  data = await response.text();
177
179
  ctx.logger.info("Server data: " + data);
@@ -180,6 +182,8 @@ async function getServer(ctx, session) {
180
182
  "time": time,
181
183
  "players": data["players"],
182
184
  "version": data["version"],
185
+ "list": data["list"].join(", "),
186
+ "protocol": data["protocol"],
183
187
  "success": 0
184
188
  };
185
189
  ctx.logger.info("Sent:");
@@ -191,6 +195,10 @@ async function getServer(ctx, session) {
191
195
  error = vError["data"];
192
196
  if (error.includes("Connection refused")) {
193
197
  error = session.text(".close");
198
+ } else if (error.includes("No route to host")) {
199
+ error = session.text(".host");
200
+ } else if (error.includes("Connection timed out")) {
201
+ error = session.text(".timeout");
194
202
  }
195
203
  } catch (e) {
196
204
  if (dataError.includes("CDN节点请求源服务器超时")) {
@@ -308,7 +316,7 @@ async function getRW(ctx, session) {
308
316
  let data;
309
317
  const time = getHongKongTime();
310
318
  try {
311
- const response = await fetchWithTimeout("https://api.tasaed.top/rw/", {}, 8e3);
319
+ const response = await fetchWithTimeout("https://api.tasaed.top/rw/", {}, 8e3, ctx);
312
320
  if (response.ok) {
313
321
  data = await response.text();
314
322
  ctx.logger.info("Server data: " + data);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-node-async-bot-all",
3
3
  "description": "NodeAsync Bot插件(自用)",
4
- "version": "1.8.2",
4
+ "version": "1.9.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [