@karinjs/plugin-basic 1.0.9 → 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/LICENSE +21 -21
- package/README.md +31 -23
- package/config/config.json +6 -5
- package/dist/apps/login.d.ts +5 -0
- package/dist/apps/login.js +69 -0
- package/dist/apps/restart.js +1 -2
- package/dist/apps/status.js +15 -63
- package/dist/{chunk-473NAVE6.js → chunk-BJBUGOWQ.js} +50 -7
- package/dist/chunk-ODFXVVIE.js +90 -0
- package/dist/index.d.ts +54 -1
- package/dist/index.js +17 -6
- package/dist/web.config.d.ts +3 -18
- package/dist/web.config.js +13 -7
- package/package.json +65 -53
- package/dist/chunk-IN6XLNTH.js +0 -46
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 shijin
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 shijin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
## 安装插件
|
|
2
|
-
|
|
3
|
-
```bash
|
|
4
|
-
pnpm add @karinjs/plugin-basic -w
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
#
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
#
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
#
|
|
23
|
-
```
|
|
1
|
+
## 安装插件
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
pnpm add @karinjs/plugin-basic -w
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## 在 webui 安装
|
|
8
|
+
|
|
9
|
+
插件市场 -> `@karinjs/plugin-basic` -> 安装
|
|
10
|
+
|
|
11
|
+
## 基本指令
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
# 关机
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
# 重启
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
# 状态
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
# 插件列表
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
#web登录
|
|
31
|
+
```
|
package/config/config.json
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
config
|
|
3
|
+
} from "../chunk-BJBUGOWQ.js";
|
|
4
|
+
|
|
5
|
+
// src/apps/login.ts
|
|
6
|
+
import karin, { common, contactFriend, logger, segment } from "node-karin";
|
|
7
|
+
import axios from "node-karin/axios";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
var url = { IPv4: ["https://4.ipw.cn"], IPv6: ["https://6.ipw.cn"] };
|
|
10
|
+
var login = karin.command(/#?(面板|web)登录$/i, async (e) => {
|
|
11
|
+
const net = os.networkInterfaces();
|
|
12
|
+
const cfg = config();
|
|
13
|
+
const IP = { lan: { ipv4: null, ipv6: null }, net: { ipv4: null, ipv6: null } };
|
|
14
|
+
for (const i in net) {
|
|
15
|
+
for (const iface of net[i]) {
|
|
16
|
+
if (iface.internal) continue;
|
|
17
|
+
if (iface.family === "IPv4") {
|
|
18
|
+
const ip = iface.address;
|
|
19
|
+
if (ip.startsWith("192.168.") || ip.startsWith("10.") || ip.startsWith("172.") && parseInt(ip.split(".")[1]) >= 16 && parseInt(ip.split(".")[1]) <= 31) {
|
|
20
|
+
IP.lan.ipv4 = ip;
|
|
21
|
+
}
|
|
22
|
+
} else if (iface.family === "IPv6") {
|
|
23
|
+
const ip = iface.address;
|
|
24
|
+
if (ip.startsWith("fd") || ip.startsWith("fe80:") || ip.startsWith("fc")) {
|
|
25
|
+
IP.lan.ipv6 = ip;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
IP.net.ipv4 = await getnetIP("IPv4");
|
|
31
|
+
IP.net.ipv6 = await getnetIP("IPv6");
|
|
32
|
+
const port = process.env.HTTP_PORT;
|
|
33
|
+
const token = process.env.HTTP_AUTH_KEY;
|
|
34
|
+
const msg = [segment.text("\u9762\u677F\u767B\u5F55\u5730\u5740\uFF1A")];
|
|
35
|
+
if (cfg.domain) msg.push(segment.text(`- \u81EA\u5B9A\u4E49\u57DF\u540D: ${cfg.domain}/web/login?token=${token}`));
|
|
36
|
+
msg.push(segment.text(`- \u5185\u7F51\u5730\u5740: ${IP.lan.ipv4 ? `http://${IP.lan.ipv4}:${port}/web/login?token=${token}` : `http://${IP.lan.ipv4}:${port}/web/login?token=${token}`}`));
|
|
37
|
+
if (IP.net.ipv4) msg.push(segment.text(`- \u5916\u7F51IPv4\u5730\u5740: http://${IP.net.ipv4}:${port}/web/login?token=${token}`));
|
|
38
|
+
if (IP.net.ipv6) msg.push(segment.text(`- \u5916\u7F51IPv6\u5730\u5740: http://${IP.net.ipv6}:${port}/web/login?token=${token}`));
|
|
39
|
+
try {
|
|
40
|
+
const content = common.makeForward(msg, e.selfId, e.bot.account.name);
|
|
41
|
+
await e.bot.sendForwardMsg(contactFriend(e.userId), content);
|
|
42
|
+
if (e.isGroup) await e.reply("\u767B\u5F55\u5730\u5740\u5DF2\u7ECF\u79C1\u4FE1\u7ED9\u4E3B\u4EBA\u4E86\u54E6~");
|
|
43
|
+
} catch (err) {
|
|
44
|
+
msg.forEach((item) => {
|
|
45
|
+
item.text = item.text + "\n";
|
|
46
|
+
});
|
|
47
|
+
await e.bot.sendMsg(contactFriend(e.userId), msg);
|
|
48
|
+
if (e.isGroup) await e.reply("\u767B\u5F55\u5730\u5740\u5DF2\u7ECF\u79C1\u4FE1\u7ED9\u4E3B\u4EBA\u4E86\u54E6~");
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}, { name: "\u9762\u677F\u767B\u5F55", perm: "admin" });
|
|
53
|
+
async function getnetIP(type) {
|
|
54
|
+
for (const i of url[type] || []) {
|
|
55
|
+
try {
|
|
56
|
+
const res = await axios.get(i);
|
|
57
|
+
if (res.data) {
|
|
58
|
+
return res.data;
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
logger.error(`\u8BBF\u95EE${i}\u83B7\u53D6\u5916\u7F51${type}\u5730\u5740\u5931\u8D25: ${e}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
login
|
|
69
|
+
};
|
package/dist/apps/restart.js
CHANGED
package/dist/apps/status.js
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
MB,
|
|
3
|
+
getMonthStat,
|
|
4
|
+
getTodayStat,
|
|
5
|
+
initStat,
|
|
6
|
+
uptime
|
|
7
|
+
} from "../chunk-ODFXVVIE.js";
|
|
8
|
+
import {
|
|
9
|
+
config,
|
|
10
|
+
info
|
|
11
|
+
} from "../chunk-BJBUGOWQ.js";
|
|
5
12
|
|
|
6
13
|
// src/apps/status.ts
|
|
7
|
-
import
|
|
8
|
-
import { EVENT_COUNT, hooks, karin, RECV_MSG, redis, SEND_MSG } from "node-karin";
|
|
14
|
+
import { karin, logger } from "node-karin";
|
|
9
15
|
var status = karin.command(/^#状态$/, async (e) => {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const [
|
|
13
|
-
send,
|
|
14
|
-
recv,
|
|
15
|
-
event,
|
|
16
|
-
sendMonth,
|
|
17
|
-
recvMonth,
|
|
18
|
-
eventMonth
|
|
19
|
-
] = await Promise.all([
|
|
20
|
-
getStat(`${SEND_MSG}:${today}*`),
|
|
21
|
-
getStat(`${RECV_MSG}:${today}*`),
|
|
22
|
-
getStat(`${EVENT_COUNT}:${today}*`),
|
|
23
|
-
getStat(`${SEND_MSG}:${month}*`),
|
|
24
|
-
getStat(`${RECV_MSG}:${month}*`),
|
|
25
|
-
getStat(`${EVENT_COUNT}:${month}*`)
|
|
26
|
-
]);
|
|
16
|
+
const { send, recv, event } = await getTodayStat();
|
|
17
|
+
const { send: sendMonth, recv: recvMonth, event: eventMonth } = await getMonthStat();
|
|
27
18
|
await e.reply([
|
|
28
19
|
"------\u673A\u5668\u4EBA\u72B6\u6001------",
|
|
29
20
|
`\u5F53\u524D\u7248\u672C\uFF1Av${process.env.KARIN_VERSION}`,
|
|
@@ -40,47 +31,8 @@ var status = karin.command(/^#状态$/, async (e) => {
|
|
|
40
31
|
].join("\n"));
|
|
41
32
|
return true;
|
|
42
33
|
}, { name: "\u72B6\u6001\u7EDF\u8BA1" });
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return `${moment().format("YYYY-MM-DD")}:${scene}:${peer}${subPeer ? `:${subPeer}` : ""}`;
|
|
46
|
-
};
|
|
47
|
-
var getStat = async (pattern) => {
|
|
48
|
-
const keys = await redis.keys(pattern);
|
|
49
|
-
const values = await Promise.all(keys.map((key) => redis.get(key).then(Number)));
|
|
50
|
-
return values.reduce((total, value) => total + (value || 0), 0);
|
|
51
|
-
};
|
|
52
|
-
var MB = () => (process.memoryUsage().rss / 1024 / 1024).toFixed(2);
|
|
53
|
-
var uptime = () => {
|
|
54
|
-
const uptime2 = process.uptime();
|
|
55
|
-
const day = Math.floor(uptime2 / 86400);
|
|
56
|
-
const hour = Math.floor(uptime2 % 86400 / 3600);
|
|
57
|
-
const minute = Math.floor(uptime2 % 3600 / 60);
|
|
58
|
-
return `${day > 0 ? `${day}\u5929` : ""}${hour}\u5C0F\u65F6${minute}\u5206\u949F`;
|
|
59
|
-
};
|
|
60
|
-
(() => {
|
|
61
|
-
if (!config().status) return;
|
|
62
|
-
hooks.message((event, next) => {
|
|
63
|
-
try {
|
|
64
|
-
redis.incr(`${RECV_MSG}:${createKey(event.contact)}`);
|
|
65
|
-
} finally {
|
|
66
|
-
next();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
hooks.sendMsg.message((contact, _, __, next) => {
|
|
70
|
-
try {
|
|
71
|
-
redis.incr(`${SEND_MSG}:${createKey(contact)}`);
|
|
72
|
-
} finally {
|
|
73
|
-
next();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
hooks.eventCall((e, _, next) => {
|
|
77
|
-
try {
|
|
78
|
-
redis.incr(`${EVENT_COUNT}:${createKey(e.contact)}`);
|
|
79
|
-
} finally {
|
|
80
|
-
next();
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
})();
|
|
34
|
+
if (config().status) initStat();
|
|
35
|
+
logger.info(`${logger.violet(`[\u63D2\u4EF6:${info.version}]`)} ${logger.green(info.pkg.name)} \u521D\u59CB\u5316\u5B8C\u6210~`);
|
|
84
36
|
export {
|
|
85
37
|
status
|
|
86
38
|
};
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "@karinjs/plugin-basic",
|
|
7
|
-
version: "1.0
|
|
7
|
+
version: "1.1.0",
|
|
8
8
|
description: "karin plugin for basic functions",
|
|
9
9
|
homepage: "https://github.com/KarinJS/karin-plugin-basic",
|
|
10
10
|
bugs: {
|
|
@@ -34,12 +34,12 @@ var package_default = {
|
|
|
34
34
|
karin: "karin"
|
|
35
35
|
},
|
|
36
36
|
devDependencies: {
|
|
37
|
-
"@types/node": "^
|
|
38
|
-
eslint: "^9.
|
|
37
|
+
"@types/node": "^24.0.1",
|
|
38
|
+
eslint: "^9.29.0",
|
|
39
39
|
neostandard: "^0.12.1",
|
|
40
|
-
"node-karin": "^1.
|
|
41
|
-
tsup: "^8.
|
|
42
|
-
tsx: "^4.
|
|
40
|
+
"node-karin": "^1.10.7",
|
|
41
|
+
tsup: "^8.5.0",
|
|
42
|
+
tsx: "^4.20.3",
|
|
43
43
|
typescript: "^5.8.3"
|
|
44
44
|
},
|
|
45
45
|
publishConfig: {
|
|
@@ -62,6 +62,9 @@ var package_default = {
|
|
|
62
62
|
],
|
|
63
63
|
"ts-web": "src/web.config.ts",
|
|
64
64
|
web: "dist/web.config.js"
|
|
65
|
+
},
|
|
66
|
+
dependencies: {
|
|
67
|
+
"internal-ip": "^8.0.0"
|
|
65
68
|
}
|
|
66
69
|
};
|
|
67
70
|
|
|
@@ -81,6 +84,46 @@ var info = {
|
|
|
81
84
|
pkg: package_default
|
|
82
85
|
};
|
|
83
86
|
|
|
87
|
+
// src/utils/config.ts
|
|
88
|
+
import fs from "node:fs";
|
|
89
|
+
import path2 from "node:path";
|
|
90
|
+
import {
|
|
91
|
+
watch,
|
|
92
|
+
basePath,
|
|
93
|
+
filesByExt,
|
|
94
|
+
copyConfigSync,
|
|
95
|
+
requireFileSync
|
|
96
|
+
} from "node-karin";
|
|
97
|
+
var cache;
|
|
98
|
+
var dir = path2.join(basePath, info.name, "config");
|
|
99
|
+
var defConfig = path2.join(info.dir, "config");
|
|
100
|
+
var main = () => {
|
|
101
|
+
copyConfigSync(defConfig, dir, [".json"]);
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
const list = filesByExt(dir, ".json", "abs");
|
|
104
|
+
list.forEach((file) => watch(file, (old, now) => {
|
|
105
|
+
cache = void 0;
|
|
106
|
+
}));
|
|
107
|
+
}, 2e3);
|
|
108
|
+
};
|
|
109
|
+
var config = () => {
|
|
110
|
+
if (cache) return cache;
|
|
111
|
+
const user = requireFileSync(`${dir}/config.json`);
|
|
112
|
+
const def = requireFileSync(`${defConfig}/config.json`);
|
|
113
|
+
const result = { ...def, ...user };
|
|
114
|
+
cache = result;
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
var writeConfig = (config2) => {
|
|
118
|
+
const def = requireFileSync(`${defConfig}/config.json`);
|
|
119
|
+
const result = { ...def, ...config2 };
|
|
120
|
+
cache = result;
|
|
121
|
+
fs.writeFileSync(`${dir}/config.json`, JSON.stringify(result, null, 2));
|
|
122
|
+
};
|
|
123
|
+
main();
|
|
124
|
+
|
|
84
125
|
export {
|
|
85
|
-
info
|
|
126
|
+
info,
|
|
127
|
+
config,
|
|
128
|
+
writeConfig
|
|
86
129
|
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/core/redis.ts
|
|
2
|
+
import moment from "node-karin/moment";
|
|
3
|
+
import { EVENT_COUNT, hooks, RECV_MSG, redis, SEND_MSG } from "node-karin";
|
|
4
|
+
var isOn = false;
|
|
5
|
+
var createKey = (contact) => {
|
|
6
|
+
const { scene, peer, subPeer } = contact;
|
|
7
|
+
return `${moment().format("YYYY-MM-DD")}:${scene}:${peer}${subPeer ? `:${subPeer}` : ""}`;
|
|
8
|
+
};
|
|
9
|
+
var getStat = async (pattern) => {
|
|
10
|
+
const keys = await redis.keys(pattern);
|
|
11
|
+
const values = await Promise.all(keys.map((key) => redis.get(key).then(Number)));
|
|
12
|
+
return values.reduce((total, value) => total + (value || 0), 0);
|
|
13
|
+
};
|
|
14
|
+
var getTodayStat = async () => {
|
|
15
|
+
const today = moment().format("YYYY-MM-DD");
|
|
16
|
+
const [
|
|
17
|
+
send,
|
|
18
|
+
recv,
|
|
19
|
+
event
|
|
20
|
+
] = await Promise.all([
|
|
21
|
+
getStat(`${SEND_MSG}:${today}*`),
|
|
22
|
+
getStat(`${RECV_MSG}:${today}*`),
|
|
23
|
+
getStat(`${EVENT_COUNT}:${today}*`)
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
send,
|
|
27
|
+
recv,
|
|
28
|
+
event
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var getMonthStat = async () => {
|
|
32
|
+
const month = moment().format("YYYY-MM");
|
|
33
|
+
const [
|
|
34
|
+
send,
|
|
35
|
+
recv,
|
|
36
|
+
event
|
|
37
|
+
] = await Promise.all([
|
|
38
|
+
getStat(`${SEND_MSG}:${month}*`),
|
|
39
|
+
getStat(`${RECV_MSG}:${month}*`),
|
|
40
|
+
getStat(`${EVENT_COUNT}:${month}*`)
|
|
41
|
+
]);
|
|
42
|
+
return {
|
|
43
|
+
send,
|
|
44
|
+
recv,
|
|
45
|
+
event
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var MB = () => (process.memoryUsage().rss / 1024 / 1024).toFixed(2);
|
|
49
|
+
var uptime = () => {
|
|
50
|
+
const uptime2 = process.uptime();
|
|
51
|
+
const day = Math.floor(uptime2 / 86400);
|
|
52
|
+
const hour = Math.floor(uptime2 % 86400 / 3600);
|
|
53
|
+
const minute = Math.floor(uptime2 % 3600 / 60);
|
|
54
|
+
return `${day > 0 ? `${day}\u5929` : ""}${hour}\u5C0F\u65F6${minute}\u5206\u949F`;
|
|
55
|
+
};
|
|
56
|
+
var initStat = () => {
|
|
57
|
+
if (isOn) return;
|
|
58
|
+
isOn = true;
|
|
59
|
+
hooks.message((event, next) => {
|
|
60
|
+
try {
|
|
61
|
+
redis.incr(`${RECV_MSG}:${createKey(event.contact)}`);
|
|
62
|
+
} finally {
|
|
63
|
+
next();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
hooks.sendMsg.message((contact, _, __, next) => {
|
|
67
|
+
try {
|
|
68
|
+
redis.incr(`${SEND_MSG}:${createKey(contact)}`);
|
|
69
|
+
} finally {
|
|
70
|
+
next();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
hooks.eventCall((e, _, next) => {
|
|
74
|
+
try {
|
|
75
|
+
redis.incr(`${EVENT_COUNT}:${createKey(e.contact)}`);
|
|
76
|
+
} finally {
|
|
77
|
+
next();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
createKey,
|
|
84
|
+
getStat,
|
|
85
|
+
getTodayStat,
|
|
86
|
+
getMonthStat,
|
|
87
|
+
MB,
|
|
88
|
+
uptime,
|
|
89
|
+
initStat
|
|
90
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,55 @@
|
|
|
1
|
+
import { Contact } from 'node-karin';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 生成存储键
|
|
5
|
+
* @param contact 联系人
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* friend:<peer>
|
|
9
|
+
* group:<peer>
|
|
10
|
+
* guild:<peer>:<subPeer>
|
|
11
|
+
* direct:<peer>:<subPeer>
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare const createKey: (contact: Contact) => string;
|
|
15
|
+
/**
|
|
16
|
+
* 获取 Redis 键值统计
|
|
17
|
+
* @param pattern - 键值统计的 pattern
|
|
18
|
+
*/
|
|
19
|
+
declare const getStat: (pattern: string) => Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* 获取今日统计
|
|
22
|
+
*/
|
|
23
|
+
declare const getTodayStat: () => Promise<{
|
|
24
|
+
/** 今日发送消息 */
|
|
25
|
+
send: number;
|
|
26
|
+
/** 今日收到消息 */
|
|
27
|
+
recv: number;
|
|
28
|
+
/** 今日插件触发次数 */
|
|
29
|
+
event: number;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* 获取本月统计
|
|
33
|
+
*/
|
|
34
|
+
declare const getMonthStat: () => Promise<{
|
|
35
|
+
/** 本月发送消息 */
|
|
36
|
+
send: number;
|
|
37
|
+
/** 本月收到消息 */
|
|
38
|
+
recv: number;
|
|
39
|
+
/** 本月插件触发次数 */
|
|
40
|
+
event: number;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* 获取内存使用情况
|
|
44
|
+
*/
|
|
45
|
+
declare const MB: () => string;
|
|
46
|
+
/**
|
|
47
|
+
* 获取运行时间
|
|
48
|
+
*/
|
|
49
|
+
declare const uptime: () => string;
|
|
50
|
+
/**
|
|
51
|
+
* 初始化 Redis 键值统计
|
|
52
|
+
*/
|
|
53
|
+
declare const initStat: () => void;
|
|
54
|
+
|
|
55
|
+
export { MB, createKey, getMonthStat, getStat, getTodayStat, initStat, uptime };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
MB,
|
|
3
|
+
createKey,
|
|
4
|
+
getMonthStat,
|
|
5
|
+
getStat,
|
|
6
|
+
getTodayStat,
|
|
7
|
+
initStat,
|
|
8
|
+
uptime
|
|
9
|
+
} from "./chunk-ODFXVVIE.js";
|
|
10
|
+
export {
|
|
11
|
+
MB,
|
|
12
|
+
createKey,
|
|
13
|
+
getMonthStat,
|
|
14
|
+
getStat,
|
|
15
|
+
getTodayStat,
|
|
16
|
+
initStat,
|
|
17
|
+
uptime
|
|
18
|
+
};
|
package/dist/web.config.d.ts
CHANGED
|
@@ -10,25 +10,10 @@ interface Config {
|
|
|
10
10
|
restartMode: boolean;
|
|
11
11
|
/** 更新完成是否自动重启 */
|
|
12
12
|
restart: boolean;
|
|
13
|
+
/** 自定义登录域名 */
|
|
14
|
+
domain: string;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
declare const _default:
|
|
16
|
-
info: {
|
|
17
|
-
name: string;
|
|
18
|
-
version: string;
|
|
19
|
-
description: string;
|
|
20
|
-
author: {
|
|
21
|
-
name: string;
|
|
22
|
-
avatar: string;
|
|
23
|
-
}[];
|
|
24
|
-
};
|
|
25
|
-
/** 动态渲染的组件 */
|
|
26
|
-
components: () => node_karin.SwitchProps[];
|
|
27
|
-
/** 前端点击保存之后调用的方法 */
|
|
28
|
-
save: (config: Config) => {
|
|
29
|
-
success: boolean;
|
|
30
|
-
message: string;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
17
|
+
declare const _default: node_karin.DefineConfig<Config>;
|
|
33
18
|
|
|
34
19
|
export { _default as default };
|
package/dist/web.config.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
config,
|
|
3
|
+
info,
|
|
3
4
|
writeConfig
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
info
|
|
7
|
-
} from "./chunk-473NAVE6.js";
|
|
5
|
+
} from "./chunk-BJBUGOWQ.js";
|
|
8
6
|
|
|
9
7
|
// src/web.config.ts
|
|
10
|
-
import { components } from "node-karin";
|
|
11
|
-
var web_config_default = {
|
|
8
|
+
import { components, defineConfig } from "node-karin";
|
|
9
|
+
var web_config_default = defineConfig({
|
|
12
10
|
info: {
|
|
11
|
+
id: info.name,
|
|
13
12
|
name: "\u57FA\u7840\u63D2\u4EF6",
|
|
14
13
|
version: info.version,
|
|
15
14
|
description: info.pkg.description,
|
|
@@ -47,6 +46,13 @@ var web_config_default = {
|
|
|
47
46
|
label: "\u81EA\u52A8\u91CD\u542F",
|
|
48
47
|
description: "\u66F4\u65B0\u5B8C\u6210\u662F\u5426\u81EA\u52A8\u91CD\u542F",
|
|
49
48
|
defaultSelected: cfg.restart
|
|
49
|
+
}),
|
|
50
|
+
components.input.string("domain", {
|
|
51
|
+
color: "success",
|
|
52
|
+
label: "\u81EA\u5B9A\u4E49\u57DF\u540D",
|
|
53
|
+
description: "Web\u767B\u5F55\u53D1\u9001\u7684\u81EA\u5B9A\u4E49\u57DF\u540D",
|
|
54
|
+
defaultValue: cfg.domain,
|
|
55
|
+
isRequired: false
|
|
50
56
|
})
|
|
51
57
|
];
|
|
52
58
|
return list;
|
|
@@ -59,7 +65,7 @@ var web_config_default = {
|
|
|
59
65
|
message: "\u4FDD\u5B58\u6210\u529F"
|
|
60
66
|
};
|
|
61
67
|
}
|
|
62
|
-
};
|
|
68
|
+
});
|
|
63
69
|
export {
|
|
64
70
|
web_config_default as default
|
|
65
71
|
};
|
package/package.json
CHANGED
|
@@ -1,53 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@karinjs/plugin-basic",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "karin plugin for basic functions",
|
|
5
|
-
"homepage": "https://github.com/KarinJS/karin-plugin-basic",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/KarinJS/karin-plugin-basic/issues"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/KarinJS/karin-plugin-basic.git"
|
|
12
|
-
},
|
|
13
|
-
"author": "shijin",
|
|
14
|
-
"type": "module",
|
|
15
|
-
"main": "dist/index.js",
|
|
16
|
-
"files": [
|
|
17
|
-
"dist",
|
|
18
|
-
"config",
|
|
19
|
-
"resources",
|
|
20
|
-
"LICENSE",
|
|
21
|
-
"package.json",
|
|
22
|
-
"README.md"
|
|
23
|
-
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsc && tsup",
|
|
26
|
-
"pub": "npm publish --access public",
|
|
27
|
-
"sort": "npx sort-package-json",
|
|
28
|
-
"dev": "tsx src/app.ts",
|
|
29
|
-
"watch": "tsx watch src/index.ts",
|
|
30
|
-
"karin": "karin"
|
|
31
|
-
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
],
|
|
50
|
-
"ts-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@karinjs/plugin-basic",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "karin plugin for basic functions",
|
|
5
|
+
"homepage": "https://github.com/KarinJS/karin-plugin-basic",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/KarinJS/karin-plugin-basic/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/KarinJS/karin-plugin-basic.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "shijin",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"config",
|
|
19
|
+
"resources",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"package.json",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc && tsup",
|
|
26
|
+
"pub": "npm publish --access public",
|
|
27
|
+
"sort": "npx sort-package-json",
|
|
28
|
+
"dev": "tsx src/app.ts",
|
|
29
|
+
"watch": "tsx watch src/index.ts",
|
|
30
|
+
"karin": "karin"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.0.1",
|
|
34
|
+
"eslint": "^9.29.0",
|
|
35
|
+
"neostandard": "^0.12.1",
|
|
36
|
+
"node-karin": "^1.10.7",
|
|
37
|
+
"tsup": "^8.5.0",
|
|
38
|
+
"tsx": "^4.20.3",
|
|
39
|
+
"typescript": "^5.8.3"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://registry.npmjs.org"
|
|
44
|
+
},
|
|
45
|
+
"karin": {
|
|
46
|
+
"main": "src/index.ts",
|
|
47
|
+
"apps": [
|
|
48
|
+
"dist/apps"
|
|
49
|
+
],
|
|
50
|
+
"ts-apps": [
|
|
51
|
+
"src/apps"
|
|
52
|
+
],
|
|
53
|
+
"static": [
|
|
54
|
+
"resources"
|
|
55
|
+
],
|
|
56
|
+
"files": [
|
|
57
|
+
"config"
|
|
58
|
+
],
|
|
59
|
+
"ts-web": "src/web.config.ts",
|
|
60
|
+
"web": "dist/web.config.js"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"internal-ip": "^8.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/chunk-IN6XLNTH.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
info
|
|
3
|
-
} from "./chunk-473NAVE6.js";
|
|
4
|
-
|
|
5
|
-
// src/utils/config.ts
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import {
|
|
9
|
-
watch,
|
|
10
|
-
basePath,
|
|
11
|
-
filesByExt,
|
|
12
|
-
copyConfigSync,
|
|
13
|
-
requireFileSync
|
|
14
|
-
} from "node-karin";
|
|
15
|
-
var cache;
|
|
16
|
-
var dir = path.join(basePath, info.name, "config");
|
|
17
|
-
var defConfig = path.join(info.dir, "config");
|
|
18
|
-
var main = () => {
|
|
19
|
-
copyConfigSync(defConfig, dir, [".json"]);
|
|
20
|
-
setTimeout(() => {
|
|
21
|
-
const list = filesByExt(dir, ".json", "abs");
|
|
22
|
-
list.forEach((file) => watch(file, (old, now) => {
|
|
23
|
-
cache = void 0;
|
|
24
|
-
}));
|
|
25
|
-
}, 2e3);
|
|
26
|
-
};
|
|
27
|
-
var config = () => {
|
|
28
|
-
if (cache) return cache;
|
|
29
|
-
const user = requireFileSync(`${dir}/config.json`);
|
|
30
|
-
const def = requireFileSync(`${defConfig}/config.json`);
|
|
31
|
-
const result = { ...def, ...user };
|
|
32
|
-
cache = result;
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
var writeConfig = (config2) => {
|
|
36
|
-
const def = requireFileSync(`${defConfig}/config.json`);
|
|
37
|
-
const result = { ...def, ...config2 };
|
|
38
|
-
cache = result;
|
|
39
|
-
fs.writeFileSync(`${dir}/config.json`, JSON.stringify(result, null, 2));
|
|
40
|
-
};
|
|
41
|
-
main();
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
config,
|
|
45
|
-
writeConfig
|
|
46
|
-
};
|