koishi-plugin-node-async-bot-all 1.0.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 +2 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +138 -0
- package/package.json +32 -0
- package/readme.md +5 -0
package/lib/fun.d.ts
ADDED
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
apply: () => apply,
|
|
24
|
+
name: () => name
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/fun.ts
|
|
29
|
+
function getHongKongTime() {
|
|
30
|
+
const date = /* @__PURE__ */ new Date();
|
|
31
|
+
const formatter = new Intl.DateTimeFormat("en", {
|
|
32
|
+
timeZone: "Asia/Hong_Kong",
|
|
33
|
+
year: "numeric",
|
|
34
|
+
month: "2-digit",
|
|
35
|
+
day: "2-digit",
|
|
36
|
+
hour: "2-digit",
|
|
37
|
+
minute: "2-digit",
|
|
38
|
+
second: "2-digit",
|
|
39
|
+
hour12: false
|
|
40
|
+
});
|
|
41
|
+
const parts = formatter.formatToParts(date);
|
|
42
|
+
const partMap = {};
|
|
43
|
+
parts.forEach((part) => {
|
|
44
|
+
partMap[part.type] = part.value;
|
|
45
|
+
});
|
|
46
|
+
return `${partMap.year}-${partMap.month}-${partMap.day} ${partMap.hour}:${partMap.minute}:${partMap.second}`;
|
|
47
|
+
}
|
|
48
|
+
__name(getHongKongTime, "getHongKongTime");
|
|
49
|
+
async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
const timeoutId = setTimeout(() => {
|
|
52
|
+
controller.abort();
|
|
53
|
+
}, timeout);
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(url, {
|
|
56
|
+
...options,
|
|
57
|
+
signal: controller.signal
|
|
58
|
+
// 绑定终止信号
|
|
59
|
+
});
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
return response;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
clearTimeout(timeoutId);
|
|
64
|
+
if (error.name === "AbortError") {
|
|
65
|
+
throw new Error("请求超时");
|
|
66
|
+
} else {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__name(fetchWithTimeout, "fetchWithTimeout");
|
|
72
|
+
|
|
73
|
+
// src/index.ts
|
|
74
|
+
var name = "node-async-bot-all";
|
|
75
|
+
async function getServer(ctx, session) {
|
|
76
|
+
let msg = "";
|
|
77
|
+
let dataError = "";
|
|
78
|
+
let data = "";
|
|
79
|
+
let error = "";
|
|
80
|
+
ctx.logger.info("Got: " + session.text(".message", {
|
|
81
|
+
platform: session.platform,
|
|
82
|
+
messageId: session.quote.id,
|
|
83
|
+
guildId: session.guildId,
|
|
84
|
+
selfId: session.selfId,
|
|
85
|
+
userId: session.quote.user?.id,
|
|
86
|
+
channelId: session.quote.channel?.id
|
|
87
|
+
}));
|
|
88
|
+
const time = getHongKongTime();
|
|
89
|
+
try {
|
|
90
|
+
const response = await fetchWithTimeout("https://api.tasaed.top/get/minecraftServer/", {}, 8e3);
|
|
91
|
+
if (response.ok) {
|
|
92
|
+
data = await response.text();
|
|
93
|
+
ctx.logger.info("Server data: " + data);
|
|
94
|
+
data = JSON.parse(data);
|
|
95
|
+
msg = `${time}
|
|
96
|
+
【服务器当前人数】
|
|
97
|
+
➣ ${data["version"]}:${data["players"]}
|
|
98
|
+
进服指南请在群公告中查看。`;
|
|
99
|
+
ctx.logger.info("Sent: " + msg);
|
|
100
|
+
} else {
|
|
101
|
+
dataError = await response.text();
|
|
102
|
+
try {
|
|
103
|
+
const vError = JSON.parse(dataError);
|
|
104
|
+
error = vError["data"];
|
|
105
|
+
} catch (e) {
|
|
106
|
+
if (dataError.includes("CDN节点请求源服务器超时")) {
|
|
107
|
+
error = "请求超时";
|
|
108
|
+
} else {
|
|
109
|
+
error = "未知错误";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
ctx.logger.error(`Error fetching data: ${dataError}`);
|
|
113
|
+
msg = `${time}
|
|
114
|
+
查询失败:${error}
|
|
115
|
+
请稍后重试`;
|
|
116
|
+
ctx.logger.info("Sent: " + msg);
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
ctx.logger.error(`Request error: ${err.message}`);
|
|
120
|
+
msg = `${time}
|
|
121
|
+
查询失败:请求超时
|
|
122
|
+
请稍后重试`;
|
|
123
|
+
ctx.logger.info("Sent: " + msg);
|
|
124
|
+
}
|
|
125
|
+
return msg;
|
|
126
|
+
}
|
|
127
|
+
__name(getServer, "getServer");
|
|
128
|
+
function apply(ctx) {
|
|
129
|
+
ctx.command("cx").action(({ session }) => {
|
|
130
|
+
return getServer(ctx, session);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
__name(apply, "apply");
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
apply,
|
|
137
|
+
name
|
|
138
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-node-async-bot-all",
|
|
3
|
+
"description": "插件",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"chatbot",
|
|
14
|
+
"koishi",
|
|
15
|
+
"plugin"
|
|
16
|
+
],
|
|
17
|
+
"koishi": {
|
|
18
|
+
"preview":true,
|
|
19
|
+
"hidden":true
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ccd2s/node-async-bot-all"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@koishijs/client": "^5.30.4"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@koishijs/plugin-console": "^5.30.4",
|
|
30
|
+
"koishi": "^4.18.7"
|
|
31
|
+
}
|
|
32
|
+
}
|