koishi-plugin-node-async-bot-all 1.0.3 → 1.1.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 +1 -0
- package/lib/index.js +92 -1
- package/package.json +1 -1
package/lib/fun.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -26,6 +36,42 @@ __export(src_exports, {
|
|
|
26
36
|
module.exports = __toCommonJS(src_exports);
|
|
27
37
|
|
|
28
38
|
// src/fun.ts
|
|
39
|
+
var import_os = __toESM(require("os"));
|
|
40
|
+
function getSystemName() {
|
|
41
|
+
return import_os.default.type() + " " + import_os.default.release();
|
|
42
|
+
}
|
|
43
|
+
__name(getSystemName, "getSystemName");
|
|
44
|
+
function getMemoryUsage() {
|
|
45
|
+
const totalMemory = import_os.default.totalmem();
|
|
46
|
+
const freeMemory = import_os.default.freemem();
|
|
47
|
+
const usedMemory = totalMemory - freeMemory;
|
|
48
|
+
return Math.round(usedMemory / totalMemory * 100);
|
|
49
|
+
}
|
|
50
|
+
__name(getMemoryUsage, "getMemoryUsage");
|
|
51
|
+
async function getCpuUsage() {
|
|
52
|
+
const startUsage = process.cpuUsage();
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
const endUsage = process.cpuUsage(startUsage);
|
|
56
|
+
const totalUsage = endUsage.user + endUsage.system;
|
|
57
|
+
const percentage = totalUsage / (1e3 * 1e3);
|
|
58
|
+
resolve(Math.round(percentage * 100));
|
|
59
|
+
}, 1e3);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
__name(getCpuUsage, "getCpuUsage");
|
|
63
|
+
async function getSystemUsage() {
|
|
64
|
+
let info;
|
|
65
|
+
try {
|
|
66
|
+
info = `系统名称: ${getSystemName()}
|
|
67
|
+
CPU使用率: ${await getCpuUsage()}%
|
|
68
|
+
内存使用率: ${getMemoryUsage()}%`;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
info = error.message;
|
|
71
|
+
}
|
|
72
|
+
return info;
|
|
73
|
+
}
|
|
74
|
+
__name(getSystemUsage, "getSystemUsage");
|
|
29
75
|
function getHongKongTime() {
|
|
30
76
|
const date = /* @__PURE__ */ new Date();
|
|
31
77
|
const formatter = new Intl.DateTimeFormat("en", {
|
|
@@ -121,10 +167,55 @@ async function getServer(ctx, session) {
|
|
|
121
167
|
return msg;
|
|
122
168
|
}
|
|
123
169
|
__name(getServer, "getServer");
|
|
170
|
+
async function getStatus(ctx, session) {
|
|
171
|
+
ctx.logger.info("Got: " + session.text(".message", {
|
|
172
|
+
platform: session.platform,
|
|
173
|
+
selfId: session.selfId
|
|
174
|
+
}));
|
|
175
|
+
const time = getHongKongTime();
|
|
176
|
+
let msg;
|
|
177
|
+
const vMsg = await getSystemUsage();
|
|
178
|
+
if (!vMsg.includes("系统名称")) {
|
|
179
|
+
ctx.logger.error(vMsg);
|
|
180
|
+
msg = `${time}
|
|
181
|
+
状态获取失败。`;
|
|
182
|
+
} else {
|
|
183
|
+
msg = `${time}
|
|
184
|
+
` + vMsg;
|
|
185
|
+
}
|
|
186
|
+
ctx.logger.info("Sent: " + msg);
|
|
187
|
+
return msg;
|
|
188
|
+
}
|
|
189
|
+
__name(getStatus, "getStatus");
|
|
190
|
+
async function getRandom(ctx, session, min, max) {
|
|
191
|
+
ctx.logger.info("Got: " + session.text(".message", {
|
|
192
|
+
platform: session.platform,
|
|
193
|
+
selfId: session.selfId
|
|
194
|
+
}));
|
|
195
|
+
const time = getHongKongTime();
|
|
196
|
+
let msg;
|
|
197
|
+
if (min == void 0 || max == void 0) {
|
|
198
|
+
min = 0;
|
|
199
|
+
max = 1e4;
|
|
200
|
+
}
|
|
201
|
+
min = Math.ceil(min);
|
|
202
|
+
max = Math.floor(max);
|
|
203
|
+
msg = `${time}
|
|
204
|
+
生成的随机数:` + (Math.floor(Math.random() * (max - min + 1)) + min) + `(${min},${max})`;
|
|
205
|
+
ctx.logger.info("Sent: " + msg);
|
|
206
|
+
return msg;
|
|
207
|
+
}
|
|
208
|
+
__name(getRandom, "getRandom");
|
|
124
209
|
function apply(ctx) {
|
|
125
|
-
ctx.command("cx").action(({ session }) => {
|
|
210
|
+
ctx.command("cx", "查询服务器当前人数。").action(({ session }) => {
|
|
126
211
|
return getServer(ctx, session);
|
|
127
212
|
});
|
|
213
|
+
ctx.command("status", "查询机器人状态。").action(({ session }) => {
|
|
214
|
+
return getStatus(ctx, session);
|
|
215
|
+
});
|
|
216
|
+
ctx.command("random [最小数:number] [最大数:number]", "随机数生成器,缺少参数时默认生成 0-10000 的随机数。").action(({ session }, min, max) => {
|
|
217
|
+
return getRandom(ctx, session, min, max);
|
|
218
|
+
});
|
|
128
219
|
}
|
|
129
220
|
__name(apply, "apply");
|
|
130
221
|
// Annotate the CommonJS export names for ESM import in node:
|