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