node-karin 0.12.0 → 0.12.2-5.pr.206.24448f3

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.
Files changed (244) hide show
  1. package/CHANGELOG.md +1029 -0
  2. package/LICENSE +21 -674
  3. package/README.md +15 -42
  4. package/default/comment/config.json +34 -0
  5. package/default/comment/friendDirect.json +10 -0
  6. package/default/comment/groupGuild.json +11 -0
  7. package/default/comment/server.json +17 -0
  8. package/default/config/config.yaml +78 -0
  9. package/default/config/friendDirect.yaml +31 -0
  10. package/default/config/groupGuild.yaml +70 -0
  11. package/default/config/pm2.yaml +21 -0
  12. package/default/config/redis.yaml +19 -0
  13. package/default/config/server.yaml +47 -0
  14. package/default/view/group.yaml +73 -0
  15. package/lib/index.js +38 -8
  16. package/package.json +128 -125
  17. package/packages/module/art-template.cjs +11 -0
  18. package/packages/module/art-template.d.ts +1 -0
  19. package/packages/module/axios.cjs +22 -0
  20. package/packages/module/axios.d.ts +2 -0
  21. package/packages/module/chalk.cjs +22 -0
  22. package/packages/module/chalk.d.ts +2 -0
  23. package/packages/module/chokidar.cjs +22 -0
  24. package/packages/module/chokidar.d.ts +2 -0
  25. package/packages/module/commander.cjs +35 -0
  26. package/packages/module/commander.d.ts +3 -0
  27. package/packages/module/commander.js +3 -0
  28. package/packages/module/express.cjs +112 -0
  29. package/packages/module/express.d.ts +1 -0
  30. package/packages/module/express.js +1 -0
  31. package/packages/module/level.cjs +22 -0
  32. package/packages/module/level.d.ts +2 -0
  33. package/packages/module/lodash.cjs +11 -0
  34. package/packages/module/lodash.d.ts +1 -0
  35. package/packages/module/log4js.cjs +22 -0
  36. package/packages/module/log4js.d.ts +2 -0
  37. package/packages/module/moment.cjs +11 -0
  38. package/packages/module/moment.d.ts +1 -0
  39. package/packages/module/node-schedule.cjs +22 -0
  40. package/packages/module/node-schedule.d.ts +2 -0
  41. package/packages/module/redis.cjs +22 -0
  42. package/packages/module/redis.d.ts +2 -0
  43. package/packages/module/ws.cjs +28 -0
  44. package/packages/module/ws.d.ts +1 -0
  45. package/packages/module/ws.js +1 -0
  46. package/packages/module/yaml.cjs +22 -0
  47. package/packages/module/yaml.d.ts +2 -0
  48. package/config/defSet/App.yaml +0 -42
  49. package/config/defSet/config.yaml +0 -65
  50. package/config/defSet/group.yaml +0 -56
  51. package/config/defSet/pm2.yaml +0 -21
  52. package/config/defSet/redis.yaml +0 -18
  53. package/config/defSet/server.yaml +0 -42
  54. package/config/view/group.yaml +0 -92
  55. package/lib/adapter/index.d.ts +0 -2
  56. package/lib/adapter/index.js +0 -2
  57. package/lib/adapter/input/index.d.ts +0 -78
  58. package/lib/adapter/input/index.js +0 -205
  59. package/lib/adapter/onebot/11/convert.d.ts +0 -12
  60. package/lib/adapter/onebot/11/convert.js +0 -167
  61. package/lib/adapter/onebot/11/event.d.ts +0 -25
  62. package/lib/adapter/onebot/11/event.js +0 -442
  63. package/lib/adapter/onebot/11/index.d.ts +0 -508
  64. package/lib/adapter/onebot/11/index.js +0 -1047
  65. package/lib/cli/index.d.ts +0 -92
  66. package/lib/cli/index.js +0 -307
  67. package/lib/cli/init.d.ts +0 -2
  68. package/lib/cli/init.js +0 -22
  69. package/lib/cli/karin.d.ts +0 -2
  70. package/lib/cli/karin.js +0 -16
  71. package/lib/cli/pkg.d.ts +0 -4
  72. package/lib/cli/pkg.js +0 -14
  73. package/lib/cli/start.d.ts +0 -1
  74. package/lib/cli/start.js +0 -8
  75. package/lib/core/index.d.ts +0 -10
  76. package/lib/core/index.js +0 -10
  77. package/lib/core/init/config.d.ts +0 -43
  78. package/lib/core/init/config.js +0 -201
  79. package/lib/core/init/dir.d.ts +0 -4
  80. package/lib/core/init/dir.js +0 -7
  81. package/lib/core/init/init.d.ts +0 -1
  82. package/lib/core/init/init.js +0 -47
  83. package/lib/core/karin/karin.d.ts +0 -198
  84. package/lib/core/karin/karin.js +0 -226
  85. package/lib/core/listener/listener.d.ts +0 -145
  86. package/lib/core/listener/listener.js +0 -235
  87. package/lib/core/plugin/base.d.ts +0 -156
  88. package/lib/core/plugin/base.js +0 -131
  89. package/lib/core/plugin/loader.d.ts +0 -141
  90. package/lib/core/plugin/loader.js +0 -618
  91. package/lib/core/process/process.d.ts +0 -18
  92. package/lib/core/process/process.js +0 -96
  93. package/lib/core/server/server.d.ts +0 -25
  94. package/lib/core/server/server.js +0 -295
  95. package/lib/db/index.d.ts +0 -2
  96. package/lib/db/index.js +0 -2
  97. package/lib/db/level/level.d.ts +0 -19
  98. package/lib/db/level/level.js +0 -36
  99. package/lib/db/redis/redis.d.ts +0 -2
  100. package/lib/db/redis/redis.js +0 -135
  101. package/lib/db/redis/redis_level.d.ts +0 -112
  102. package/lib/db/redis/redis_level.js +0 -281
  103. package/lib/event/handler/base.d.ts +0 -42
  104. package/lib/event/handler/base.js +0 -200
  105. package/lib/event/handler/message.d.ts +0 -29
  106. package/lib/event/handler/message.js +0 -307
  107. package/lib/event/handler/notice.d.ts +0 -18
  108. package/lib/event/handler/notice.js +0 -214
  109. package/lib/event/handler/request.d.ts +0 -18
  110. package/lib/event/handler/request.js +0 -115
  111. package/lib/event/handler/review.d.ts +0 -55
  112. package/lib/event/handler/review.js +0 -386
  113. package/lib/event/index.d.ts +0 -5
  114. package/lib/event/index.js +0 -5
  115. package/lib/index.d.ts +0 -8
  116. package/lib/modules/art-template.d.ts +0 -1
  117. package/lib/modules/axios.d.ts +0 -2
  118. package/lib/modules/chalk.d.ts +0 -2
  119. package/lib/modules/chokidar.d.ts +0 -2
  120. package/lib/modules/commander.d.ts +0 -2
  121. package/lib/modules/commander.js +0 -2
  122. package/lib/modules/express.d.ts +0 -3
  123. package/lib/modules/express.js +0 -3
  124. package/lib/modules/level.d.ts +0 -2
  125. package/lib/modules/lodash.d.ts +0 -1
  126. package/lib/modules/log4js.d.ts +0 -2
  127. package/lib/modules/moment.d.ts +0 -1
  128. package/lib/modules/node-schedule.d.ts +0 -2
  129. package/lib/modules/redis.d.ts +0 -2
  130. package/lib/modules/ws.d.ts +0 -3
  131. package/lib/modules/ws.js +0 -3
  132. package/lib/modules/yaml.d.ts +0 -2
  133. package/lib/modules.d.ts +0 -15
  134. package/lib/modules.js +0 -15
  135. package/lib/render/app.d.ts +0 -56
  136. package/lib/render/app.js +0 -120
  137. package/lib/render/base.d.ts +0 -30
  138. package/lib/render/base.js +0 -69
  139. package/lib/render/client.d.ts +0 -41
  140. package/lib/render/client.js +0 -238
  141. package/lib/render/http.d.ts +0 -19
  142. package/lib/render/http.js +0 -50
  143. package/lib/render/index.d.ts +0 -6
  144. package/lib/render/index.js +0 -6
  145. package/lib/render/server.d.ts +0 -25
  146. package/lib/render/server.js +0 -101
  147. package/lib/render/wormhole.d.ts +0 -1
  148. package/lib/render/wormhole.js +0 -156
  149. package/lib/types/adapter/api.d.ts +0 -399
  150. package/lib/types/adapter/api.js +0 -1
  151. package/lib/types/adapter/base.d.ts +0 -560
  152. package/lib/types/adapter/base.js +0 -1
  153. package/lib/types/config/config.d.ts +0 -379
  154. package/lib/types/config/config.js +0 -1
  155. package/lib/types/element/element.d.ts +0 -565
  156. package/lib/types/element/element.js +0 -1
  157. package/lib/types/element/qqbot.d.ts +0 -123
  158. package/lib/types/element/qqbot.js +0 -1
  159. package/lib/types/event/contact.d.ts +0 -28
  160. package/lib/types/event/contact.js +0 -1
  161. package/lib/types/event/event.d.ts +0 -305
  162. package/lib/types/event/event.js +0 -1
  163. package/lib/types/event/index.d.ts +0 -12
  164. package/lib/types/event/index.js +0 -7
  165. package/lib/types/event/message.d.ts +0 -109
  166. package/lib/types/event/message.js +0 -74
  167. package/lib/types/event/notice.d.ts +0 -513
  168. package/lib/types/event/notice.js +0 -52
  169. package/lib/types/event/reply.d.ts +0 -50
  170. package/lib/types/event/reply.js +0 -1
  171. package/lib/types/event/request.d.ts +0 -126
  172. package/lib/types/event/request.js +0 -52
  173. package/lib/types/event/sender.d.ts +0 -44
  174. package/lib/types/event/sender.js +0 -1
  175. package/lib/types/index.d.ts +0 -13
  176. package/lib/types/index.js +0 -13
  177. package/lib/types/logger/logger.d.ts +0 -110
  178. package/lib/types/logger/logger.js +0 -1
  179. package/lib/types/onebot11/api.d.ts +0 -53
  180. package/lib/types/onebot11/api.js +0 -1
  181. package/lib/types/onebot11/event.d.ts +0 -619
  182. package/lib/types/onebot11/event.js +0 -2
  183. package/lib/types/onebot11/index.d.ts +0 -6
  184. package/lib/types/onebot11/index.js +0 -6
  185. package/lib/types/onebot11/params.d.ts +0 -609
  186. package/lib/types/onebot11/params.js +0 -1
  187. package/lib/types/onebot11/response.d.ts +0 -516
  188. package/lib/types/onebot11/response.js +0 -1
  189. package/lib/types/onebot11/segment.d.ts +0 -269
  190. package/lib/types/onebot11/segment.js +0 -1
  191. package/lib/types/onebot11/sender.d.ts +0 -59
  192. package/lib/types/onebot11/sender.js +0 -1
  193. package/lib/types/plugin/app.d.ts +0 -71
  194. package/lib/types/plugin/app.js +0 -1
  195. package/lib/types/plugin/plugin.d.ts +0 -473
  196. package/lib/types/plugin/plugin.js +0 -1
  197. package/lib/types/render/render.d.ts +0 -118
  198. package/lib/types/render/render.js +0 -1
  199. package/lib/types/type/global.d.ts +0 -25
  200. package/lib/types/type/global.js +0 -1
  201. package/lib/utils/common/common.d.ts +0 -236
  202. package/lib/utils/common/common.js +0 -708
  203. package/lib/utils/config/config.d.ts +0 -193
  204. package/lib/utils/config/config.js +0 -328
  205. package/lib/utils/config/updateVersion.d.ts +0 -33
  206. package/lib/utils/config/updateVersion.js +0 -145
  207. package/lib/utils/config/yamlEditor.d.ts +0 -101
  208. package/lib/utils/config/yamlEditor.js +0 -330
  209. package/lib/utils/core/handler.d.ts +0 -18
  210. package/lib/utils/core/handler.js +0 -46
  211. package/lib/utils/core/logger.d.ts +0 -3
  212. package/lib/utils/core/logger.js +0 -105
  213. package/lib/utils/core/segment.d.ts +0 -279
  214. package/lib/utils/core/segment.js +0 -451
  215. package/lib/utils/index.d.ts +0 -13
  216. package/lib/utils/index.js +0 -13
  217. package/lib/utils/tools/button.d.ts +0 -2
  218. package/lib/utils/tools/button.js +0 -27
  219. package/lib/utils/tools/exec.d.ts +0 -20
  220. package/lib/utils/tools/exec.js +0 -54
  221. package/lib/utils/tools/ffmpeg.d.ts +0 -12
  222. package/lib/utils/tools/ffmpeg.js +0 -25
  223. package/lib/utils/tools/restart.d.ts +0 -15
  224. package/lib/utils/tools/restart.js +0 -39
  225. package/lib/utils/tools/stop.d.ts +0 -7
  226. package/lib/utils/tools/stop.js +0 -13
  227. package/lib/utils/tools/update.d.ts +0 -67
  228. package/lib/utils/tools/update.js +0 -151
  229. /package/{config → default}/view/App.yaml +0 -0
  230. /package/{config → default}/view/config.yaml +0 -0
  231. /package/{config → default}/view/pm2.yaml +0 -0
  232. /package/{config → default}/view/redis.yaml +0 -0
  233. /package/{config → default}/view/server.yaml +0 -0
  234. /package/{lib/modules → packages/module}/art-template.js +0 -0
  235. /package/{lib/modules → packages/module}/axios.js +0 -0
  236. /package/{lib/modules → packages/module}/chalk.js +0 -0
  237. /package/{lib/modules → packages/module}/chokidar.js +0 -0
  238. /package/{lib/modules → packages/module}/level.js +0 -0
  239. /package/{lib/modules → packages/module}/lodash.js +0 -0
  240. /package/{lib/modules → packages/module}/log4js.js +0 -0
  241. /package/{lib/modules → packages/module}/moment.js +0 -0
  242. /package/{lib/modules → packages/module}/node-schedule.js +0 -0
  243. /package/{lib/modules → packages/module}/redis.js +0 -0
  244. /package/{lib/modules → packages/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
- }