koishi-plugin-node-async-bot-all 1.0.1 → 1.0.4
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 +70 -4
- 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", {
|
|
@@ -79,10 +125,7 @@ async function getServer(ctx, session) {
|
|
|
79
125
|
let error = "";
|
|
80
126
|
ctx.logger.info("Got: " + session.text(".message", {
|
|
81
127
|
platform: session.platform,
|
|
82
|
-
|
|
83
|
-
selfId: session.selfId,
|
|
84
|
-
userId: session.quote.user?.id,
|
|
85
|
-
channelId: session.quote.channel?.id
|
|
128
|
+
selfId: session.selfId
|
|
86
129
|
}));
|
|
87
130
|
const time = getHongKongTime();
|
|
88
131
|
try {
|
|
@@ -124,10 +167,33 @@ async function getServer(ctx, session) {
|
|
|
124
167
|
return msg;
|
|
125
168
|
}
|
|
126
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");
|
|
127
190
|
function apply(ctx) {
|
|
128
191
|
ctx.command("cx").action(({ session }) => {
|
|
129
192
|
return getServer(ctx, session);
|
|
130
193
|
});
|
|
194
|
+
ctx.command("status").action(({ session }) => {
|
|
195
|
+
return getStatus(ctx, session);
|
|
196
|
+
});
|
|
131
197
|
}
|
|
132
198
|
__name(apply, "apply");
|
|
133
199
|
// Annotate the CommonJS export names for ESM import in node:
|