@karinjs/plugin-basic 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/README.md CHANGED
@@ -4,6 +4,10 @@
4
4
  pnpm add @karinjs/plugin-basic -w
5
5
  ```
6
6
 
7
+ ## 在 webui 安装
8
+
9
+ 插件市场 -> `@karinjs/plugin-basic` -> 安装
10
+
7
11
  ## 基本指令
8
12
 
9
13
  ```
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  config
3
- } from "../chunk-DYA7JXHS.js";
4
- import "../chunk-CUYZ6VZG.js";
3
+ } from "../chunk-MNDJRJH2.js";
5
4
 
6
5
  // src/apps/login.ts
7
6
  import karin, { common, contactFriend, logger, segment } from "node-karin";
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  config
3
- } from "../chunk-DYA7JXHS.js";
4
- import "../chunk-CUYZ6VZG.js";
3
+ } from "../chunk-MNDJRJH2.js";
5
4
 
6
5
  // src/apps/restart.ts
7
6
  import { common, karin, logger, restart } from "node-karin";
@@ -1,29 +1,20 @@
1
1
  import {
2
- config
3
- } from "../chunk-DYA7JXHS.js";
4
- import "../chunk-CUYZ6VZG.js";
2
+ MB,
3
+ getMonthStat,
4
+ getTodayStat,
5
+ initStat,
6
+ uptime
7
+ } from "../chunk-ODFXVVIE.js";
8
+ import {
9
+ config,
10
+ info
11
+ } from "../chunk-MNDJRJH2.js";
5
12
 
6
13
  // src/apps/status.ts
7
- import moment from "node-karin/moment";
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 today = moment().format("YYYY-MM-DD");
11
- const month = moment().format("YYYY-MM");
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
- var createKey = (contact) => {
44
- const { scene, peer, subPeer } = contact;
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 "path";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@karinjs/plugin-basic",
7
- version: "1.1.0",
7
+ version: "1.2.1",
8
8
  description: "karin plugin for basic functions",
9
9
  homepage: "https://github.com/KarinJS/karin-plugin-basic",
10
10
  bugs: {
@@ -37,7 +37,7 @@ var package_default = {
37
37
  "@types/node": "^24.0.1",
38
38
  eslint: "^9.29.0",
39
39
  neostandard: "^0.12.1",
40
- "node-karin": "^1.10.7",
40
+ "node-karin": "^1.10.16",
41
41
  tsup: "^8.5.0",
42
42
  tsx: "^4.20.3",
43
43
  typescript: "^5.8.3"
@@ -84,6 +84,46 @@ var info = {
84
84
  pkg: package_default
85
85
  };
86
86
 
87
+ // src/utils/config.ts
88
+ import fs from "fs";
89
+ import path2 from "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
+
87
125
  export {
88
- info
126
+ info,
127
+ config,
128
+ writeConfig
89
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
- export { }
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
- info
3
- } from "./chunk-CUYZ6VZG.js";
4
-
5
- // src/index.ts
6
- import { logger } from "node-karin";
7
- logger.info(`${logger.violet(`[\u63D2\u4EF6:${info.version}]`)} ${logger.green(info.pkg.name)} \u521D\u59CB\u5316\u5B8C\u6210~`);
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
+ };
@@ -14,23 +14,6 @@ interface Config {
14
14
  domain: string;
15
15
  }
16
16
 
17
- declare const _default: {
18
- info: {
19
- name: string;
20
- version: string;
21
- description: string;
22
- author: {
23
- name: string;
24
- avatar: string;
25
- }[];
26
- };
27
- /** 动态渲染的组件 */
28
- components: () => (node_karin.SwitchProps | node_karin.InputProps)[];
29
- /** 前端点击保存之后调用的方法 */
30
- save: (config: Config) => {
31
- success: boolean;
32
- message: string;
33
- };
34
- };
17
+ declare const _default: node_karin.DefineConfig<Config>;
35
18
 
36
19
  export { _default as default };
@@ -1,15 +1,14 @@
1
1
  import {
2
2
  config,
3
+ info,
3
4
  writeConfig
4
- } from "./chunk-DYA7JXHS.js";
5
- import {
6
- info
7
- } from "./chunk-CUYZ6VZG.js";
5
+ } from "./chunk-MNDJRJH2.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,
@@ -66,7 +65,7 @@ var web_config_default = {
66
65
  message: "\u4FDD\u5B58\u6210\u529F"
67
66
  };
68
67
  }
69
- };
68
+ });
70
69
  export {
71
70
  web_config_default as default
72
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karinjs/plugin-basic",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "karin plugin for basic functions",
5
5
  "homepage": "https://github.com/KarinJS/karin-plugin-basic",
6
6
  "bugs": {
@@ -1,46 +0,0 @@
1
- import {
2
- info
3
- } from "./chunk-CUYZ6VZG.js";
4
-
5
- // src/utils/config.ts
6
- import fs from "fs";
7
- import path from "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
- };