koishi-plugin-node-async-bot-all 1.0.4 → 1.2.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,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.0";
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);
@@ -187,13 +206,56 @@ async function getStatus(ctx, session) {
187
206
  return msg;
188
207
  }
189
208
  __name(getStatus, "getStatus");
209
+ async function getRandom(ctx, session, min, max) {
210
+ ctx.logger.info("Got: " + session.text(".message", {
211
+ platform: session.platform,
212
+ selfId: session.selfId
213
+ }));
214
+ const time = getHongKongTime();
215
+ let msg;
216
+ if (min == void 0 || max == void 0) {
217
+ min = 0;
218
+ max = 1e4;
219
+ }
220
+ min = Math.ceil(min);
221
+ max = Math.floor(max);
222
+ msg = `${time}
223
+ 生成的随机数:` + (Math.floor(Math.random() * (max - min + 1)) + min) + `(${min},${max})`;
224
+ ctx.logger.info("Sent: " + msg);
225
+ return msg;
226
+ }
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");
190
246
  function apply(ctx) {
191
- ctx.command("cx").action(({ session }) => {
247
+ ctx.command("cx", "查询服务器当前人数。").action(({ session }) => {
192
248
  return getServer(ctx, session);
193
249
  });
194
- ctx.command("status").action(({ session }) => {
250
+ ctx.command("status", "查询机器人状态。").action(({ session }) => {
195
251
  return getStatus(ctx, session);
196
252
  });
253
+ ctx.command("random [最小数:number] [最大数:number]", "随机数生成器,缺少参数时默认生成 0-10000 的随机数。").action(({ session }, min, max) => {
254
+ return getRandom(ctx, session, min, max);
255
+ });
256
+ ctx.command("info", "机器人信息").action(({ session }) => {
257
+ return getInfo(ctx, session);
258
+ });
197
259
  }
198
260
  __name(apply, "apply");
199
261
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-node-async-bot-all",
3
3
  "description": "插件",
4
- "version": "1.0.4",
4
+ "version": "1.2.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [