koishi-plugin-node-async-bot-all 1.1.0 → 1.2.1
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 +1 -0
- package/lib/index.js +44 -4
- package/package.json +3 -2
- package/res/info.txt +5 -0
package/lib/fun.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function getSystemUsage(): Promise<string>;
|
|
2
2
|
export declare function getHongKongTime(): string;
|
|
3
3
|
export declare function fetchWithTimeout(url: string, options?: {}, timeout?: number): Promise<Response>;
|
|
4
|
+
export declare function readInfoFile(): Promise<string>;
|
package/lib/index.js
CHANGED
|
@@ -37,6 +37,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
37
37
|
|
|
38
38
|
// src/fun.ts
|
|
39
39
|
var import_os = __toESM(require("os"));
|
|
40
|
+
|
|
41
|
+
// package.json
|
|
42
|
+
var version = "1.2.1";
|
|
43
|
+
|
|
44
|
+
// src/fun.ts
|
|
40
45
|
function getSystemName() {
|
|
41
46
|
return import_os.default.type() + " " + import_os.default.release();
|
|
42
47
|
}
|
|
@@ -115,18 +120,32 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
|
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
__name(fetchWithTimeout, "fetchWithTimeout");
|
|
123
|
+
async function readInfoFile() {
|
|
124
|
+
const fs = require("node:fs/promises");
|
|
125
|
+
const path = require("path");
|
|
126
|
+
let info;
|
|
127
|
+
try {
|
|
128
|
+
const aPath = path.resolve(__dirname, "..") + path.sep + "res" + path.sep + "info.txt";
|
|
129
|
+
info = await fs.readFile(aPath, "utf8");
|
|
130
|
+
info = info.toString().replace("&version;", version);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
info = e.message;
|
|
133
|
+
}
|
|
134
|
+
return info;
|
|
135
|
+
}
|
|
136
|
+
__name(readInfoFile, "readInfoFile");
|
|
118
137
|
|
|
119
138
|
// src/index.ts
|
|
120
139
|
var name = "node-async-bot-all";
|
|
121
140
|
async function getServer(ctx, session) {
|
|
122
|
-
let msg = "";
|
|
123
|
-
let dataError = "";
|
|
124
|
-
let data = "";
|
|
125
|
-
let error = "";
|
|
126
141
|
ctx.logger.info("Got: " + session.text(".message", {
|
|
127
142
|
platform: session.platform,
|
|
128
143
|
selfId: session.selfId
|
|
129
144
|
}));
|
|
145
|
+
let msg;
|
|
146
|
+
let dataError;
|
|
147
|
+
let data;
|
|
148
|
+
let error;
|
|
130
149
|
const time = getHongKongTime();
|
|
131
150
|
try {
|
|
132
151
|
const response = await fetchWithTimeout("https://api.tasaed.top/get/minecraftServer/", {}, 8e3);
|
|
@@ -206,6 +225,24 @@ async function getRandom(ctx, session, min, max) {
|
|
|
206
225
|
return msg;
|
|
207
226
|
}
|
|
208
227
|
__name(getRandom, "getRandom");
|
|
228
|
+
async function getInfo(ctx, session) {
|
|
229
|
+
ctx.logger.info("Got: " + session.text(".message", {
|
|
230
|
+
platform: session.platform,
|
|
231
|
+
selfId: session.selfId
|
|
232
|
+
}));
|
|
233
|
+
const time = getHongKongTime();
|
|
234
|
+
let msg = await readInfoFile();
|
|
235
|
+
if (!msg.includes("基沃托斯·工业革命")) {
|
|
236
|
+
ctx.logger.error("Error: " + msg);
|
|
237
|
+
msg = `${time}
|
|
238
|
+
读取信息失败`;
|
|
239
|
+
} else {
|
|
240
|
+
msg = msg.replace("&time;", time);
|
|
241
|
+
}
|
|
242
|
+
ctx.logger.info("Sent: " + msg);
|
|
243
|
+
return msg;
|
|
244
|
+
}
|
|
245
|
+
__name(getInfo, "getInfo");
|
|
209
246
|
function apply(ctx) {
|
|
210
247
|
ctx.command("cx", "查询服务器当前人数。").action(({ session }) => {
|
|
211
248
|
return getServer(ctx, session);
|
|
@@ -216,6 +253,9 @@ function apply(ctx) {
|
|
|
216
253
|
ctx.command("random [最小数:number] [最大数:number]", "随机数生成器,缺少参数时默认生成 0-10000 的随机数。").action(({ session }, min, max) => {
|
|
217
254
|
return getRandom(ctx, session, min, max);
|
|
218
255
|
});
|
|
256
|
+
ctx.command("info", "机器人信息").action(({ session }) => {
|
|
257
|
+
return getInfo(ctx, session);
|
|
258
|
+
});
|
|
219
259
|
}
|
|
220
260
|
__name(apply, "apply");
|
|
221
261
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-node-async-bot-all",
|
|
3
3
|
"description": "插件",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib",
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"res"
|
|
10
11
|
],
|
|
11
12
|
"license": "MIT",
|
|
12
13
|
"keywords": [
|