node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2
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/CHANGELOG.md +1029 -0
- package/default/comment/config.json +34 -0
- package/default/comment/friendDirect.json +10 -0
- package/default/comment/groupGuild.json +11 -0
- package/default/comment/server.json +17 -0
- package/default/config/adapter.json +28 -0
- package/default/config/config.json +47 -0
- package/default/config/groups.json +47 -0
- package/default/config/groups.yaml +70 -0
- package/default/config/pm2.json +16 -0
- package/default/config/privates.json +23 -0
- package/default/config/privates.yaml +31 -0
- package/default/config/redis.json +10 -0
- package/default/config/render.json +19 -0
- package/default/view/group.yaml +73 -0
- package/dist/index.d.ts +9869 -0
- package/dist/index.js +12643 -0
- package/dist/module/art-template.cjs +11 -0
- package/dist/module/art-template.d.ts +1 -0
- package/dist/module/axios.cjs +22 -0
- package/dist/module/axios.d.ts +2 -0
- package/dist/module/chalk.cjs +22 -0
- package/dist/module/chalk.d.ts +2 -0
- package/dist/module/chokidar.cjs +22 -0
- package/dist/module/chokidar.d.ts +2 -0
- package/dist/module/commander.cjs +35 -0
- package/dist/module/commander.d.ts +3 -0
- package/dist/module/commander.js +3 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/module/express.cjs +112 -0
- package/dist/module/express.d.ts +1 -0
- package/dist/module/express.js +1 -0
- package/dist/module/level.cjs +22 -0
- package/dist/module/level.d.ts +2 -0
- package/dist/module/lodash.cjs +11 -0
- package/dist/module/lodash.d.ts +1 -0
- package/dist/module/log4js.cjs +22 -0
- package/dist/module/log4js.d.ts +2 -0
- package/dist/module/moment.cjs +11 -0
- package/dist/module/moment.d.ts +1 -0
- package/dist/module/node-schedule.cjs +22 -0
- package/dist/module/node-schedule.d.ts +2 -0
- package/dist/module/redis.cjs +22 -0
- package/dist/module/redis.d.ts +2 -0
- package/dist/module/ws.cjs +28 -0
- package/dist/module/ws.d.ts +1 -0
- package/dist/module/ws.js +1 -0
- package/dist/module/yaml.cjs +22 -0
- package/dist/module/yaml.d.ts +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +142 -128
- package/LICENSE +0 -674
- package/README.md +0 -56
- package/config/defSet/App.yaml +0 -42
- package/config/defSet/config.yaml +0 -65
- package/config/defSet/group.yaml +0 -56
- package/config/defSet/pm2.yaml +0 -21
- package/config/defSet/redis.yaml +0 -18
- package/config/defSet/server.yaml +0 -42
- package/config/view/group.yaml +0 -92
- package/lib/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.d.ts +0 -78
- package/lib/adapter/input/index.js +0 -205
- package/lib/adapter/onebot/11/convert.d.ts +0 -12
- package/lib/adapter/onebot/11/convert.js +0 -167
- package/lib/adapter/onebot/11/event.d.ts +0 -25
- package/lib/adapter/onebot/11/event.js +0 -442
- package/lib/adapter/onebot/11/index.d.ts +0 -508
- package/lib/adapter/onebot/11/index.js +0 -1047
- package/lib/cli/index.d.ts +0 -92
- package/lib/cli/index.js +0 -307
- package/lib/cli/init.d.ts +0 -2
- package/lib/cli/init.js +0 -22
- package/lib/cli/karin.d.ts +0 -2
- package/lib/cli/karin.js +0 -16
- package/lib/cli/pkg.d.ts +0 -4
- package/lib/cli/pkg.js +0 -14
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +0 -8
- package/lib/core/index.d.ts +0 -10
- package/lib/core/index.js +0 -10
- package/lib/core/init/config.d.ts +0 -43
- package/lib/core/init/config.js +0 -201
- package/lib/core/init/dir.d.ts +0 -4
- package/lib/core/init/dir.js +0 -7
- package/lib/core/init/init.d.ts +0 -1
- package/lib/core/init/init.js +0 -47
- package/lib/core/karin/karin.d.ts +0 -198
- package/lib/core/karin/karin.js +0 -226
- package/lib/core/listener/listener.d.ts +0 -145
- package/lib/core/listener/listener.js +0 -235
- package/lib/core/plugin/base.d.ts +0 -156
- package/lib/core/plugin/base.js +0 -131
- package/lib/core/plugin/loader.d.ts +0 -141
- package/lib/core/plugin/loader.js +0 -618
- package/lib/core/process/process.d.ts +0 -18
- package/lib/core/process/process.js +0 -96
- package/lib/core/server/server.d.ts +0 -25
- package/lib/core/server/server.js +0 -295
- package/lib/db/index.d.ts +0 -2
- package/lib/db/index.js +0 -2
- package/lib/db/level/level.d.ts +0 -19
- package/lib/db/level/level.js +0 -36
- package/lib/db/redis/redis.d.ts +0 -2
- package/lib/db/redis/redis.js +0 -135
- package/lib/db/redis/redis_level.d.ts +0 -112
- package/lib/db/redis/redis_level.js +0 -281
- package/lib/event/handler/base.d.ts +0 -42
- package/lib/event/handler/base.js +0 -200
- package/lib/event/handler/message.d.ts +0 -29
- package/lib/event/handler/message.js +0 -307
- package/lib/event/handler/notice.d.ts +0 -18
- package/lib/event/handler/notice.js +0 -214
- package/lib/event/handler/request.d.ts +0 -18
- package/lib/event/handler/request.js +0 -115
- package/lib/event/handler/review.d.ts +0 -55
- package/lib/event/handler/review.js +0 -386
- package/lib/event/index.d.ts +0 -5
- package/lib/event/index.js +0 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -8
- package/lib/modules/art-template.d.ts +0 -1
- package/lib/modules/axios.d.ts +0 -2
- package/lib/modules/chalk.d.ts +0 -2
- package/lib/modules/chokidar.d.ts +0 -2
- package/lib/modules/commander.d.ts +0 -2
- package/lib/modules/commander.js +0 -2
- package/lib/modules/express.d.ts +0 -3
- package/lib/modules/express.js +0 -3
- package/lib/modules/level.d.ts +0 -2
- package/lib/modules/lodash.d.ts +0 -1
- package/lib/modules/log4js.d.ts +0 -2
- package/lib/modules/moment.d.ts +0 -1
- package/lib/modules/node-schedule.d.ts +0 -2
- package/lib/modules/redis.d.ts +0 -2
- package/lib/modules/ws.d.ts +0 -3
- package/lib/modules/ws.js +0 -3
- package/lib/modules/yaml.d.ts +0 -2
- package/lib/modules.d.ts +0 -15
- package/lib/modules.js +0 -15
- package/lib/render/app.d.ts +0 -56
- package/lib/render/app.js +0 -120
- package/lib/render/base.d.ts +0 -30
- package/lib/render/base.js +0 -69
- package/lib/render/client.d.ts +0 -41
- package/lib/render/client.js +0 -238
- package/lib/render/http.d.ts +0 -19
- package/lib/render/http.js +0 -50
- package/lib/render/index.d.ts +0 -6
- package/lib/render/index.js +0 -6
- package/lib/render/server.d.ts +0 -25
- package/lib/render/server.js +0 -101
- package/lib/render/wormhole.d.ts +0 -1
- package/lib/render/wormhole.js +0 -156
- package/lib/types/adapter/api.d.ts +0 -399
- package/lib/types/adapter/api.js +0 -1
- package/lib/types/adapter/base.d.ts +0 -560
- package/lib/types/adapter/base.js +0 -1
- package/lib/types/config/config.d.ts +0 -379
- package/lib/types/config/config.js +0 -1
- package/lib/types/element/element.d.ts +0 -565
- package/lib/types/element/element.js +0 -1
- package/lib/types/element/qqbot.d.ts +0 -123
- package/lib/types/element/qqbot.js +0 -1
- package/lib/types/event/contact.d.ts +0 -28
- package/lib/types/event/contact.js +0 -1
- package/lib/types/event/event.d.ts +0 -305
- package/lib/types/event/event.js +0 -1
- package/lib/types/event/index.d.ts +0 -12
- package/lib/types/event/index.js +0 -7
- package/lib/types/event/message.d.ts +0 -109
- package/lib/types/event/message.js +0 -74
- package/lib/types/event/notice.d.ts +0 -513
- package/lib/types/event/notice.js +0 -52
- package/lib/types/event/reply.d.ts +0 -50
- package/lib/types/event/reply.js +0 -1
- package/lib/types/event/request.d.ts +0 -126
- package/lib/types/event/request.js +0 -52
- package/lib/types/event/sender.d.ts +0 -44
- package/lib/types/event/sender.js +0 -1
- package/lib/types/index.d.ts +0 -13
- package/lib/types/index.js +0 -13
- package/lib/types/logger/logger.d.ts +0 -110
- package/lib/types/logger/logger.js +0 -1
- package/lib/types/onebot11/api.d.ts +0 -53
- package/lib/types/onebot11/api.js +0 -1
- package/lib/types/onebot11/event.d.ts +0 -619
- package/lib/types/onebot11/event.js +0 -2
- package/lib/types/onebot11/index.d.ts +0 -6
- package/lib/types/onebot11/index.js +0 -6
- package/lib/types/onebot11/params.d.ts +0 -609
- package/lib/types/onebot11/params.js +0 -1
- package/lib/types/onebot11/response.d.ts +0 -516
- package/lib/types/onebot11/response.js +0 -1
- package/lib/types/onebot11/segment.d.ts +0 -269
- package/lib/types/onebot11/segment.js +0 -1
- package/lib/types/onebot11/sender.d.ts +0 -59
- package/lib/types/onebot11/sender.js +0 -1
- package/lib/types/plugin/app.d.ts +0 -71
- package/lib/types/plugin/app.js +0 -1
- package/lib/types/plugin/plugin.d.ts +0 -473
- package/lib/types/plugin/plugin.js +0 -1
- package/lib/types/render/render.d.ts +0 -118
- package/lib/types/render/render.js +0 -1
- package/lib/types/type/global.d.ts +0 -25
- package/lib/types/type/global.js +0 -1
- package/lib/utils/common/common.d.ts +0 -236
- package/lib/utils/common/common.js +0 -708
- package/lib/utils/config/config.d.ts +0 -193
- package/lib/utils/config/config.js +0 -328
- package/lib/utils/config/updateVersion.d.ts +0 -33
- package/lib/utils/config/updateVersion.js +0 -145
- package/lib/utils/config/yamlEditor.d.ts +0 -101
- package/lib/utils/config/yamlEditor.js +0 -330
- package/lib/utils/core/handler.d.ts +0 -18
- package/lib/utils/core/handler.js +0 -46
- package/lib/utils/core/logger.d.ts +0 -3
- package/lib/utils/core/logger.js +0 -105
- package/lib/utils/core/segment.d.ts +0 -279
- package/lib/utils/core/segment.js +0 -451
- package/lib/utils/index.d.ts +0 -13
- package/lib/utils/index.js +0 -13
- package/lib/utils/tools/button.d.ts +0 -2
- package/lib/utils/tools/button.js +0 -27
- package/lib/utils/tools/exec.d.ts +0 -20
- package/lib/utils/tools/exec.js +0 -54
- package/lib/utils/tools/ffmpeg.d.ts +0 -12
- package/lib/utils/tools/ffmpeg.js +0 -25
- package/lib/utils/tools/restart.d.ts +0 -15
- package/lib/utils/tools/restart.js +0 -39
- package/lib/utils/tools/stop.d.ts +0 -7
- package/lib/utils/tools/stop.js +0 -13
- package/lib/utils/tools/update.d.ts +0 -67
- package/lib/utils/tools/update.js +0 -151
- /package/{config → default}/view/App.yaml +0 -0
- /package/{config → default}/view/config.yaml +0 -0
- /package/{config → default}/view/pm2.yaml +0 -0
- /package/{config → default}/view/redis.yaml +0 -0
- /package/{config → default}/view/server.yaml +0 -0
- /package/{lib/modules → dist/module}/art-template.js +0 -0
- /package/{lib/modules → dist/module}/axios.js +0 -0
- /package/{lib/modules → dist/module}/chalk.js +0 -0
- /package/{lib/modules → dist/module}/chokidar.js +0 -0
- /package/{lib/modules → dist/module}/level.js +0 -0
- /package/{lib/modules → dist/module}/lodash.js +0 -0
- /package/{lib/modules → dist/module}/log4js.js +0 -0
- /package/{lib/modules → dist/module}/moment.js +0 -0
- /package/{lib/modules → dist/module}/node-schedule.js +0 -0
- /package/{lib/modules → dist/module}/redis.js +0 -0
- /package/{lib/modules → dist/module}/yaml.js +0 -0
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'log4js';
|
|
2
|
-
import { Redis, App, Config, Server, Package, GroupCfg, KarinEventTypes } from '../../types/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* 配置文件
|
|
5
|
-
*/
|
|
6
|
-
export declare const config: {
|
|
7
|
-
/**
|
|
8
|
-
* 运行目录绝对路径
|
|
9
|
-
*/
|
|
10
|
-
dir: string;
|
|
11
|
-
/**
|
|
12
|
-
* 运行目录配置文件夹路径
|
|
13
|
-
*/
|
|
14
|
-
cfgDir: string;
|
|
15
|
-
/**
|
|
16
|
-
* node-karin npm包路径
|
|
17
|
-
*/
|
|
18
|
-
pkgDir: string;
|
|
19
|
-
/**
|
|
20
|
-
* node-karin 包配置文件夹路径
|
|
21
|
-
*/
|
|
22
|
-
pkgCfgDir: string;
|
|
23
|
-
change: Map<string, any>;
|
|
24
|
-
watcher: Map<string, any>;
|
|
25
|
-
review: boolean;
|
|
26
|
-
logger: Logger;
|
|
27
|
-
/**
|
|
28
|
-
* 初始化配置
|
|
29
|
-
*/
|
|
30
|
-
initCfg(): Promise<void>;
|
|
31
|
-
getPlugins(): Promise<string[]>;
|
|
32
|
-
/**
|
|
33
|
-
* 递归创建目录
|
|
34
|
-
* @param dirname - 要创建的文件夹路径
|
|
35
|
-
*/
|
|
36
|
-
mkdir(dirname: string): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* 为每一个插件建立对应的文件夹
|
|
39
|
-
*/
|
|
40
|
-
dirPath(_path: string, plugins: string[]): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* 超时时间
|
|
43
|
-
*/
|
|
44
|
-
timeout(type?: "ws" | "grpc"): number;
|
|
45
|
-
/**
|
|
46
|
-
* Redis 配置
|
|
47
|
-
* 采用实时读取优化性能
|
|
48
|
-
*/
|
|
49
|
-
readonly redis: Redis;
|
|
50
|
-
/**
|
|
51
|
-
* 主人列表
|
|
52
|
-
*/
|
|
53
|
-
readonly master: string[];
|
|
54
|
-
/**
|
|
55
|
-
* 管理员列表
|
|
56
|
-
*/
|
|
57
|
-
readonly admin: string[];
|
|
58
|
-
/**
|
|
59
|
-
* App管理
|
|
60
|
-
*/
|
|
61
|
-
readonly App: App;
|
|
62
|
-
/**
|
|
63
|
-
* 基本配置
|
|
64
|
-
*/
|
|
65
|
-
readonly Config: Config;
|
|
66
|
-
/**
|
|
67
|
-
* Server 配置文档
|
|
68
|
-
*/
|
|
69
|
-
readonly Server: Server;
|
|
70
|
-
/**
|
|
71
|
-
* packageon
|
|
72
|
-
* 实时获取packageon文件
|
|
73
|
-
*/
|
|
74
|
-
readonly package: Package;
|
|
75
|
-
/**
|
|
76
|
-
* 获取群配置
|
|
77
|
-
* @param group_id - 群号
|
|
78
|
-
* @param e - 事件
|
|
79
|
-
*/
|
|
80
|
-
group(group_id: string, e: KarinEventTypes): GroupCfg;
|
|
81
|
-
/**
|
|
82
|
-
* 获取配置yaml
|
|
83
|
-
* @param type 类型
|
|
84
|
-
* @param name 文件名称
|
|
85
|
-
* @param isWatch 是否监听文件
|
|
86
|
-
*/
|
|
87
|
-
getYaml(type: "defSet" | "config", name: string, isWatch?: boolean): any;
|
|
88
|
-
/**
|
|
89
|
-
* 监听配置文件
|
|
90
|
-
* @param type 类型
|
|
91
|
-
* @param name 文件名称 不带后缀
|
|
92
|
-
* @param file 文件路径
|
|
93
|
-
*/
|
|
94
|
-
watch(type: "defSet" | "config", name: string, file: string): Promise<true | undefined>;
|
|
95
|
-
changeApp(): Promise<void>;
|
|
96
|
-
changeCfg(): Promise<void>;
|
|
97
|
-
changeGroup(): Promise<void>;
|
|
98
|
-
"__#2@#review"(): Promise<void>;
|
|
99
|
-
};
|
|
100
|
-
export declare const Cfg: {
|
|
101
|
-
/**
|
|
102
|
-
* 运行目录绝对路径
|
|
103
|
-
*/
|
|
104
|
-
dir: string;
|
|
105
|
-
/**
|
|
106
|
-
* 运行目录配置文件夹路径
|
|
107
|
-
*/
|
|
108
|
-
cfgDir: string;
|
|
109
|
-
/**
|
|
110
|
-
* node-karin npm包路径
|
|
111
|
-
*/
|
|
112
|
-
pkgDir: string;
|
|
113
|
-
/**
|
|
114
|
-
* node-karin 包配置文件夹路径
|
|
115
|
-
*/
|
|
116
|
-
pkgCfgDir: string;
|
|
117
|
-
change: Map<string, any>;
|
|
118
|
-
watcher: Map<string, any>;
|
|
119
|
-
review: boolean;
|
|
120
|
-
logger: Logger;
|
|
121
|
-
/**
|
|
122
|
-
* 初始化配置
|
|
123
|
-
*/
|
|
124
|
-
initCfg(): Promise<void>;
|
|
125
|
-
getPlugins(): Promise<string[]>;
|
|
126
|
-
/**
|
|
127
|
-
* 递归创建目录
|
|
128
|
-
* @param dirname - 要创建的文件夹路径
|
|
129
|
-
*/
|
|
130
|
-
mkdir(dirname: string): boolean;
|
|
131
|
-
/**
|
|
132
|
-
* 为每一个插件建立对应的文件夹
|
|
133
|
-
*/
|
|
134
|
-
dirPath(_path: string, plugins: string[]): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* 超时时间
|
|
137
|
-
*/
|
|
138
|
-
timeout(type?: "ws" | "grpc"): number;
|
|
139
|
-
/**
|
|
140
|
-
* Redis 配置
|
|
141
|
-
* 采用实时读取优化性能
|
|
142
|
-
*/
|
|
143
|
-
readonly redis: Redis;
|
|
144
|
-
/**
|
|
145
|
-
* 主人列表
|
|
146
|
-
*/
|
|
147
|
-
readonly master: string[];
|
|
148
|
-
/**
|
|
149
|
-
* 管理员列表
|
|
150
|
-
*/
|
|
151
|
-
readonly admin: string[];
|
|
152
|
-
/**
|
|
153
|
-
* App管理
|
|
154
|
-
*/
|
|
155
|
-
readonly App: App;
|
|
156
|
-
/**
|
|
157
|
-
* 基本配置
|
|
158
|
-
*/
|
|
159
|
-
readonly Config: Config;
|
|
160
|
-
/**
|
|
161
|
-
* Server 配置文档
|
|
162
|
-
*/
|
|
163
|
-
readonly Server: Server;
|
|
164
|
-
/**
|
|
165
|
-
* packageon
|
|
166
|
-
* 实时获取packageon文件
|
|
167
|
-
*/
|
|
168
|
-
readonly package: Package;
|
|
169
|
-
/**
|
|
170
|
-
* 获取群配置
|
|
171
|
-
* @param group_id - 群号
|
|
172
|
-
* @param e - 事件
|
|
173
|
-
*/
|
|
174
|
-
group(group_id: string, e: KarinEventTypes): GroupCfg;
|
|
175
|
-
/**
|
|
176
|
-
* 获取配置yaml
|
|
177
|
-
* @param type 类型
|
|
178
|
-
* @param name 文件名称
|
|
179
|
-
* @param isWatch 是否监听文件
|
|
180
|
-
*/
|
|
181
|
-
getYaml(type: "defSet" | "config", name: string, isWatch?: boolean): any;
|
|
182
|
-
/**
|
|
183
|
-
* 监听配置文件
|
|
184
|
-
* @param type 类型
|
|
185
|
-
* @param name 文件名称 不带后缀
|
|
186
|
-
* @param file 文件路径
|
|
187
|
-
*/
|
|
188
|
-
watch(type: "defSet" | "config", name: string, file: string): Promise<true | undefined>;
|
|
189
|
-
changeApp(): Promise<void>;
|
|
190
|
-
changeCfg(): Promise<void>;
|
|
191
|
-
changeGroup(): Promise<void>;
|
|
192
|
-
"__#2@#review"(): Promise<void>;
|
|
193
|
-
};
|
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import Yaml from 'yaml';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import chokidar from 'chokidar';
|
|
5
|
-
import { karinDir } from '../../core/init/dir.js';
|
|
6
|
-
import { common } from '../../utils/common/common.js';
|
|
7
|
-
/**
|
|
8
|
-
* 配置文件
|
|
9
|
-
*/
|
|
10
|
-
export const config = new (class Cfg {
|
|
11
|
-
/**
|
|
12
|
-
* 运行目录绝对路径
|
|
13
|
-
*/
|
|
14
|
-
dir;
|
|
15
|
-
/**
|
|
16
|
-
* 运行目录配置文件夹路径
|
|
17
|
-
*/
|
|
18
|
-
cfgDir;
|
|
19
|
-
/**
|
|
20
|
-
* node-karin npm包路径
|
|
21
|
-
*/
|
|
22
|
-
pkgDir;
|
|
23
|
-
/**
|
|
24
|
-
* node-karin 包配置文件夹路径
|
|
25
|
-
*/
|
|
26
|
-
pkgCfgDir;
|
|
27
|
-
change;
|
|
28
|
-
watcher;
|
|
29
|
-
review;
|
|
30
|
-
logger;
|
|
31
|
-
constructor() {
|
|
32
|
-
this.dir = process.cwd();
|
|
33
|
-
this.pkgDir = karinDir;
|
|
34
|
-
this.cfgDir = this.dir + '/config';
|
|
35
|
-
this.pkgCfgDir = this.pkgDir + '/config/defSet';
|
|
36
|
-
/** 缓存 */
|
|
37
|
-
this.change = new Map();
|
|
38
|
-
/** 监听文件 */
|
|
39
|
-
this.watcher = new Map();
|
|
40
|
-
/** 拦截器状态 */
|
|
41
|
-
this.review = false;
|
|
42
|
-
this.initCfg();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 初始化配置
|
|
46
|
-
*/
|
|
47
|
-
async initCfg() {
|
|
48
|
-
const list = [
|
|
49
|
-
this.dir + '/temp/input',
|
|
50
|
-
this.dir + '/plugins/karin-plugin-example',
|
|
51
|
-
this.cfgDir + '/config',
|
|
52
|
-
this.cfgDir + '/plugin',
|
|
53
|
-
];
|
|
54
|
-
list.forEach(path => this.mkdir(path));
|
|
55
|
-
if (this.pkgCfgDir !== (this.cfgDir + '/defSet').replace(/\\/g, '/')) {
|
|
56
|
-
const files = fs.readdirSync(this.pkgCfgDir).filter(file => file.endsWith('.yaml'));
|
|
57
|
-
files.forEach(file => {
|
|
58
|
-
const path = `${this.cfgDir}/config/${file}`;
|
|
59
|
-
const pathDef = `${this.pkgCfgDir}/${file}`;
|
|
60
|
-
if (!fs.existsSync(path))
|
|
61
|
-
fs.copyFileSync(pathDef, path);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/** 为每个插件包创建统一存储的文件夹 */
|
|
65
|
-
const plugins = await this.getPlugins();
|
|
66
|
-
const DataList = [
|
|
67
|
-
'data',
|
|
68
|
-
'temp',
|
|
69
|
-
'resources',
|
|
70
|
-
'temp/html',
|
|
71
|
-
this.cfgDir + '/plugin',
|
|
72
|
-
];
|
|
73
|
-
DataList.forEach(path => this.dirPath(path, plugins));
|
|
74
|
-
this.logger = (await import('../core/logger.js')).default;
|
|
75
|
-
}
|
|
76
|
-
async getPlugins() {
|
|
77
|
-
const list = [];
|
|
78
|
-
const files = fs.readdirSync('./plugins', { withFileTypes: true });
|
|
79
|
-
// 过滤掉非karin-plugin-开头的文件夹
|
|
80
|
-
list.push(...files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-'))).map(dir => dir.name));
|
|
81
|
-
// 获取npm插件
|
|
82
|
-
list.push(...(await common.getNpmPlugins(false)));
|
|
83
|
-
return list;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 递归创建目录
|
|
87
|
-
* @param dirname - 要创建的文件夹路径
|
|
88
|
-
*/
|
|
89
|
-
mkdir(dirname) {
|
|
90
|
-
if (fs.existsSync(dirname))
|
|
91
|
-
return true;
|
|
92
|
-
/** 递归自调用 */
|
|
93
|
-
if (this.mkdir(path.dirname(dirname)))
|
|
94
|
-
fs.mkdirSync(dirname);
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 为每一个插件建立对应的文件夹
|
|
99
|
-
*/
|
|
100
|
-
async dirPath(_path, plugins) {
|
|
101
|
-
this.mkdir(_path);
|
|
102
|
-
for (const plugin of plugins) {
|
|
103
|
-
const path = `${_path}/${plugin}`;
|
|
104
|
-
this.mkdir(path);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 超时时间
|
|
109
|
-
*/
|
|
110
|
-
timeout(type = 'ws') {
|
|
111
|
-
let timeout = 60;
|
|
112
|
-
if (type === 'ws') {
|
|
113
|
-
timeout = this.Server.websocket.timeout;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
timeout = this.Server.grpc.timeout;
|
|
117
|
-
}
|
|
118
|
-
return timeout || 60;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Redis 配置
|
|
122
|
-
* 采用实时读取优化性能
|
|
123
|
-
*/
|
|
124
|
-
get redis() {
|
|
125
|
-
const config = this.getYaml('config', 'redis', false);
|
|
126
|
-
const defSet = this.getYaml('defSet', 'redis', false);
|
|
127
|
-
const data = { ...defSet, ...config };
|
|
128
|
-
return data;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* 主人列表
|
|
132
|
-
*/
|
|
133
|
-
get master() {
|
|
134
|
-
return this.Config.master || [];
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 管理员列表
|
|
138
|
-
*/
|
|
139
|
-
get admin() {
|
|
140
|
-
return this.Config.admin || [];
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* App管理
|
|
144
|
-
*/
|
|
145
|
-
get App() {
|
|
146
|
-
const key = 'change.App';
|
|
147
|
-
const res = this.change.get(key);
|
|
148
|
-
/** 取缓存 */
|
|
149
|
-
if (res)
|
|
150
|
-
return res;
|
|
151
|
-
/** 取配置 */
|
|
152
|
-
const config = this.getYaml('config', 'App', true);
|
|
153
|
-
const defSet = this.getYaml('defSet', 'App', true);
|
|
154
|
-
const data = { ...defSet, ...config };
|
|
155
|
-
/** 缓存 */
|
|
156
|
-
this.change.set(key, data);
|
|
157
|
-
return data;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 基本配置
|
|
161
|
-
*/
|
|
162
|
-
get Config() {
|
|
163
|
-
const key = 'change.config';
|
|
164
|
-
const res = this.change.get(key);
|
|
165
|
-
/** 取缓存 */
|
|
166
|
-
if (res)
|
|
167
|
-
return res;
|
|
168
|
-
/** 取配置 */
|
|
169
|
-
const config = this.getYaml('config', 'config', true);
|
|
170
|
-
const defSet = this.getYaml('defSet', 'config', false);
|
|
171
|
-
const data = { ...defSet, ...config };
|
|
172
|
-
const Config = {
|
|
173
|
-
...data,
|
|
174
|
-
WhiteList: {
|
|
175
|
-
users: data.WhiteList.users.map((i) => String(i)),
|
|
176
|
-
groups: data.WhiteList.groups.map((i) => String(i)),
|
|
177
|
-
GroupMsgLog: data.WhiteList.GroupMsgLog.map((i) => String(i)),
|
|
178
|
-
},
|
|
179
|
-
BlackList: {
|
|
180
|
-
users: data.BlackList.users.map((i) => String(i)),
|
|
181
|
-
groups: data.BlackList.groups.map((i) => String(i)),
|
|
182
|
-
GroupMsgLog: data.BlackList.GroupMsgLog.map((i) => String(i)),
|
|
183
|
-
},
|
|
184
|
-
master: data.master.map((i) => String(i)),
|
|
185
|
-
admin: data.admin.map((i) => String(i)),
|
|
186
|
-
private: {
|
|
187
|
-
white_list: data.private.white_list.map((i) => String(i)),
|
|
188
|
-
tips: data.private.tips,
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
|
-
/** 缓存 */
|
|
192
|
-
this.change.set(key, Config);
|
|
193
|
-
return Config;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Server 配置文档
|
|
197
|
-
*/
|
|
198
|
-
get Server() {
|
|
199
|
-
const key = 'change.server';
|
|
200
|
-
/** 取缓存 */
|
|
201
|
-
const res = this.change.get(key);
|
|
202
|
-
if (res)
|
|
203
|
-
return res;
|
|
204
|
-
/** 取配置 */
|
|
205
|
-
const config = this.getYaml('config', 'server', true);
|
|
206
|
-
const defSet = this.getYaml('defSet', 'server', false);
|
|
207
|
-
const data = { ...defSet, ...config };
|
|
208
|
-
/** 缓存 */
|
|
209
|
-
this.change.set(key, data);
|
|
210
|
-
return data;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* packageon
|
|
214
|
-
* 实时获取packageon文件
|
|
215
|
-
*/
|
|
216
|
-
get package() {
|
|
217
|
-
const data = fs.readFileSync(this.pkgDir + '/package.json', 'utf8');
|
|
218
|
-
const pack = JSON.parse(data);
|
|
219
|
-
return pack;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* 获取群配置
|
|
223
|
-
* @param group_id - 群号
|
|
224
|
-
* @param e - 事件
|
|
225
|
-
*/
|
|
226
|
-
group(group_id, e) {
|
|
227
|
-
const key = 'change.group';
|
|
228
|
-
/** 取缓存 */
|
|
229
|
-
const res = this.change.get(key);
|
|
230
|
-
const keys = e?.self_id ? [`Bot.${e.self_id}.${group_id}`, `Bot.${e.self_id}`, group_id] : [group_id];
|
|
231
|
-
if (res) {
|
|
232
|
-
const cfg = { ...res.defCfg.default, ...res.Config.default };
|
|
233
|
-
for (const k of keys) {
|
|
234
|
-
if (res.Config?.[k])
|
|
235
|
-
return { ...cfg, ...res.Config?.[k] };
|
|
236
|
-
}
|
|
237
|
-
return cfg;
|
|
238
|
-
}
|
|
239
|
-
/** 取配置 */
|
|
240
|
-
const Config = this.getYaml('config', 'group', true);
|
|
241
|
-
const defCfg = this.getYaml('defSet', 'group', false);
|
|
242
|
-
const data = { Config, defCfg };
|
|
243
|
-
/** 缓存 */
|
|
244
|
-
this.change.set(key, data);
|
|
245
|
-
const cfg = { ...defCfg.default, ...Config.default };
|
|
246
|
-
for (const k of keys) {
|
|
247
|
-
if (Config[k])
|
|
248
|
-
return { ...cfg, ...Config[k] };
|
|
249
|
-
}
|
|
250
|
-
return cfg;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* 获取配置yaml
|
|
254
|
-
* @param type 类型
|
|
255
|
-
* @param name 文件名称
|
|
256
|
-
* @param isWatch 是否监听文件
|
|
257
|
-
*/
|
|
258
|
-
getYaml(type, name, isWatch = false) {
|
|
259
|
-
/** 文件路径 */
|
|
260
|
-
const file = type === 'defSet' ? `${this.pkgCfgDir}/${name}.yaml` : `${this.cfgDir}/config/${name}.yaml`;
|
|
261
|
-
/** 读取文件 */
|
|
262
|
-
const data = Yaml.parse(fs.readFileSync(file, 'utf8'));
|
|
263
|
-
/** 监听文件 */
|
|
264
|
-
if (isWatch)
|
|
265
|
-
this.watch(type, name, file);
|
|
266
|
-
return data;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* 监听配置文件
|
|
270
|
-
* @param type 类型
|
|
271
|
-
* @param name 文件名称 不带后缀
|
|
272
|
-
* @param file 文件路径
|
|
273
|
-
*/
|
|
274
|
-
async watch(type, name, file) {
|
|
275
|
-
const key = `change.${name}`;
|
|
276
|
-
/** 已经监听过了 */
|
|
277
|
-
const res = this.watcher.get(key);
|
|
278
|
-
if (res)
|
|
279
|
-
return true;
|
|
280
|
-
/** 监听文件 */
|
|
281
|
-
const watcher = chokidar.watch(file);
|
|
282
|
-
/** 监听文件变化 */
|
|
283
|
-
watcher.on('change', () => {
|
|
284
|
-
this.change.delete(key);
|
|
285
|
-
this.logger.mark(`[修改配置文件][${type}][${name}]`);
|
|
286
|
-
/** 文件修改后调用对应的方法 */
|
|
287
|
-
switch (`change_${name}`) {
|
|
288
|
-
case 'change_App':
|
|
289
|
-
this.changeApp();
|
|
290
|
-
break;
|
|
291
|
-
case 'change_config':
|
|
292
|
-
this.changeCfg();
|
|
293
|
-
break;
|
|
294
|
-
case 'change_group':
|
|
295
|
-
this.changeGroup();
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
/** 缓存 防止重复监听 */
|
|
300
|
-
this.watcher.set(key, watcher);
|
|
301
|
-
}
|
|
302
|
-
async changeApp() {
|
|
303
|
-
await this.#review();
|
|
304
|
-
}
|
|
305
|
-
async changeCfg() {
|
|
306
|
-
/** 修改日志等级 */
|
|
307
|
-
this.logger.level = this.Config.log4jsCfg.level;
|
|
308
|
-
await this.#review();
|
|
309
|
-
if (this.Server.HotUpdate) {
|
|
310
|
-
const { Bot } = await import('../../index.js');
|
|
311
|
-
Bot.emit('restart_http', {});
|
|
312
|
-
Bot.emit('restart_grpc', {});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async changeGroup() {
|
|
316
|
-
await this.#review();
|
|
317
|
-
}
|
|
318
|
-
async #review() {
|
|
319
|
-
// 应该改成事件监听
|
|
320
|
-
if (this.review)
|
|
321
|
-
return;
|
|
322
|
-
this.review = true;
|
|
323
|
-
const { review } = await import('../../event/index.js');
|
|
324
|
-
review.main();
|
|
325
|
-
this.review = false;
|
|
326
|
-
}
|
|
327
|
-
})();
|
|
328
|
-
export const Cfg = config;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export default class Version {
|
|
2
|
-
path: string;
|
|
3
|
-
packageDir: string;
|
|
4
|
-
CHANGELOGDir: string;
|
|
5
|
-
packageJson: any;
|
|
6
|
-
version: string;
|
|
7
|
-
commitsMap: {
|
|
8
|
-
[key: string]: string[];
|
|
9
|
-
};
|
|
10
|
-
HEAD: string;
|
|
11
|
-
cmd: string;
|
|
12
|
-
stdout: string | string[];
|
|
13
|
-
url: string;
|
|
14
|
-
constructor(path: string);
|
|
15
|
-
init(): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* 获取当前仓库最新的一个标签的HEAD
|
|
18
|
-
*/
|
|
19
|
-
gitTag(): Promise<false | undefined>;
|
|
20
|
-
/**
|
|
21
|
-
* 获取当前仓库的远程地址
|
|
22
|
-
*/
|
|
23
|
-
gitUrl(): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* 更新版本号 tag
|
|
26
|
-
*/
|
|
27
|
-
updateVersion(): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* 封装exce方法
|
|
30
|
-
* @param {string} cmd 执行的命令
|
|
31
|
-
*/
|
|
32
|
-
exce(cmd: string): Promise<string>;
|
|
33
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { exec } from 'child_process';
|
|
3
|
-
export default class Version {
|
|
4
|
-
path;
|
|
5
|
-
packageDir;
|
|
6
|
-
CHANGELOGDir;
|
|
7
|
-
packageJson;
|
|
8
|
-
version;
|
|
9
|
-
commitsMap;
|
|
10
|
-
HEAD;
|
|
11
|
-
cmd;
|
|
12
|
-
stdout;
|
|
13
|
-
url;
|
|
14
|
-
constructor(path) {
|
|
15
|
-
this.cmd = '';
|
|
16
|
-
this.stdout = '';
|
|
17
|
-
this.url = '';
|
|
18
|
-
this.HEAD = '';
|
|
19
|
-
this.path = path;
|
|
20
|
-
this.packageDir = this.path + '/packageon';
|
|
21
|
-
this.CHANGELOGDir = this.path + '/CHANGELOG.md';
|
|
22
|
-
this.packageJson = JSON.parse(fs.readFileSync(this.packageDir, 'utf-8'));
|
|
23
|
-
this.version = this.packageJson.version;
|
|
24
|
-
this.commitsMap = {
|
|
25
|
-
release: ['### Releases'],
|
|
26
|
-
feat: ['### 新增功能'],
|
|
27
|
-
fix: ['### Bug修复'],
|
|
28
|
-
docs: ['### 文档更新'],
|
|
29
|
-
style: ['### 代码样式修改'],
|
|
30
|
-
refactor: ['### 代码重构'],
|
|
31
|
-
perf: ['### 性能优化'],
|
|
32
|
-
chore: ['### 构建工具相关'],
|
|
33
|
-
revert: ['### 回滚'],
|
|
34
|
-
others: ['### 其他提交'],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async init() {
|
|
38
|
-
/** 获取仓库地址 */
|
|
39
|
-
await this.gitUrl();
|
|
40
|
-
/** 取tag对应的head */
|
|
41
|
-
await this.gitTag();
|
|
42
|
-
const HEAD = this.HEAD ? `${this.HEAD}..HEAD ` : '';
|
|
43
|
-
this.cmd = `git log ${HEAD}--pretty=format:"HEAD: %H=分割=sha: %h=分割=log: %s"`;
|
|
44
|
-
this.stdout = (await this.exce(this.cmd));
|
|
45
|
-
if (!this.stdout)
|
|
46
|
-
throw new Error('commit为空...');
|
|
47
|
-
this.stdout = this.stdout.trim().split('\n');
|
|
48
|
-
const reg = /(fix|feat|docs|style|refactor|perf|release|chore|revert)(:|:)/i;
|
|
49
|
-
for (const commit of this.stdout) {
|
|
50
|
-
/** 拆分 */
|
|
51
|
-
const [HEAD, sha, log] = commit.split('=分割=').map(item => item.trim().replace(/^(HEAD|sha|log): /, ''));
|
|
52
|
-
/** 排除此项 */
|
|
53
|
-
if (log.startsWith('Merge branch'))
|
|
54
|
-
continue;
|
|
55
|
-
const match = log.match(reg);
|
|
56
|
-
const type = match ? match[1].toLowerCase() : 'others';
|
|
57
|
-
/** 拼接commit */
|
|
58
|
-
const info = `- ${log} ([${sha}](${this.url}/commit/${HEAD}))`;
|
|
59
|
-
this.commitsMap[type].push(info);
|
|
60
|
-
}
|
|
61
|
-
/** 更新版本号 */
|
|
62
|
-
await this.updateVersion();
|
|
63
|
-
/** YYYY-MM-DD */
|
|
64
|
-
const date = new Date().toLocaleDateString().replace(/\//g, '-');
|
|
65
|
-
const text = [`## ${this.version} (${date})`];
|
|
66
|
-
for (const key in this.commitsMap) {
|
|
67
|
-
/** 排除空 */
|
|
68
|
-
if (this.commitsMap[key].length === 1) {
|
|
69
|
-
delete this.commitsMap[key];
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
text.push(this.commitsMap[key].join('\n'));
|
|
73
|
-
}
|
|
74
|
-
/** 判断是否有CHANGELOG.md文件 */
|
|
75
|
-
if (fs.existsSync(this.CHANGELOGDir)) {
|
|
76
|
-
const oldText = fs.readFileSync(this.CHANGELOGDir, 'utf-8');
|
|
77
|
-
text.push(oldText);
|
|
78
|
-
}
|
|
79
|
-
fs.writeFileSync(this.CHANGELOGDir, text.join('\n\n'));
|
|
80
|
-
console.log('更新成功~');
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* 获取当前仓库最新的一个标签的HEAD
|
|
84
|
-
*/
|
|
85
|
-
async gitTag() {
|
|
86
|
-
const cmd = 'git tag';
|
|
87
|
-
const stdout = await this.exce(cmd);
|
|
88
|
-
if (!stdout)
|
|
89
|
-
return false;
|
|
90
|
-
const tags = stdout.trim().split('\n');
|
|
91
|
-
const lastTag = tags[tags.length - 1];
|
|
92
|
-
const cmd2 = `git rev-list -n 1 ${lastTag}`;
|
|
93
|
-
const HEAD = await this.exce(cmd2);
|
|
94
|
-
this.HEAD = HEAD.trim();
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 获取当前仓库的远程地址
|
|
98
|
-
*/
|
|
99
|
-
async gitUrl() {
|
|
100
|
-
const cmd = 'git remote -v';
|
|
101
|
-
const stdout = await this.exce(cmd);
|
|
102
|
-
let [url] = stdout.split('\n').map(item => item.split('\t')[1]);
|
|
103
|
-
url = url.trim().split(' ')[0];
|
|
104
|
-
this.url = url;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 更新版本号 tag
|
|
108
|
-
*/
|
|
109
|
-
async updateVersion() {
|
|
110
|
-
/** 10进1 */
|
|
111
|
-
const versionArr = this.version.split('.').map((item) => parseInt(item));
|
|
112
|
-
if (versionArr[2] === 9) {
|
|
113
|
-
versionArr[1]++;
|
|
114
|
-
versionArr[2] = 0;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
versionArr[2]++;
|
|
118
|
-
}
|
|
119
|
-
this.version = versionArr.join('.');
|
|
120
|
-
this.packageJson.version = this.version;
|
|
121
|
-
fs.writeFileSync(this.packageDir, JSON.stringify(this.packageJson, null, 2));
|
|
122
|
-
/** tag */
|
|
123
|
-
try {
|
|
124
|
-
await this.exce(`git tag v${this.version}`);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
console.log('tag已存在');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* 封装exce方法
|
|
132
|
-
* @param {string} cmd 执行的命令
|
|
133
|
-
*/
|
|
134
|
-
exce(cmd) {
|
|
135
|
-
return new Promise((resolve, reject) => {
|
|
136
|
-
exec(cmd, { cwd: this.path }, (error, stdout) => {
|
|
137
|
-
if (error) {
|
|
138
|
-
reject(error);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
resolve(stdout);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|