node-karin 0.0.3 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +57 -57
  3. package/config/defSet/App.yaml +37 -37
  4. package/config/defSet/config.yaml +43 -43
  5. package/config/defSet/group.yaml +18 -18
  6. package/config/defSet/pm2.yaml +21 -21
  7. package/config/defSet/server.yaml +42 -42
  8. package/config/view/App.yaml +74 -74
  9. package/config/view/config.yaml +100 -100
  10. package/config/view/group.yaml +62 -62
  11. package/config/view/pm2.yaml +41 -41
  12. package/config/view/redis.yaml +25 -25
  13. package/config/view/server.yaml +93 -93
  14. package/lib/adapter/onebot/onebot11.d.ts +430 -430
  15. package/lib/adapter/onebot/onebot11.js +1265 -1302
  16. package/lib/core/dir.d.ts +1 -0
  17. package/lib/core/dir.js +4 -0
  18. package/lib/core/init.js +4 -4
  19. package/lib/core/karin.d.ts +72 -72
  20. package/lib/core/karin.js +51 -51
  21. package/lib/core/listener.d.ts +121 -121
  22. package/lib/core/listener.js +178 -178
  23. package/lib/core/plugin.app.d.ts +15 -15
  24. package/lib/core/plugin.app.js +18 -18
  25. package/lib/core/plugin.d.ts +182 -182
  26. package/lib/core/plugin.js +132 -132
  27. package/lib/core/plugin.loader.d.ts +149 -149
  28. package/lib/core/plugin.loader.js +451 -451
  29. package/lib/core/server.d.ts +26 -26
  30. package/lib/core/server.js +209 -209
  31. package/lib/db/level.d.ts +20 -20
  32. package/lib/db/level.js +36 -36
  33. package/lib/db/redis.d.ts +41 -41
  34. package/lib/db/redis.js +131 -131
  35. package/lib/db/redis_level.d.ts +113 -113
  36. package/lib/db/redis_level.js +274 -274
  37. package/lib/event/event.d.ts +138 -138
  38. package/lib/event/event.handler.d.ts +29 -29
  39. package/lib/event/event.handler.js +138 -138
  40. package/lib/event/event.js +120 -120
  41. package/lib/event/message.d.ts +102 -102
  42. package/lib/event/message.handler.d.ts +25 -25
  43. package/lib/event/message.handler.js +237 -237
  44. package/lib/event/message.js +69 -69
  45. package/lib/event/notice.d.ts +49 -49
  46. package/lib/event/notice.js +14 -14
  47. package/lib/event/request.d.ts +49 -49
  48. package/lib/event/request.js +14 -14
  49. package/lib/event/review.handler.d.ts +54 -54
  50. package/lib/event/review.handler.js +374 -374
  51. package/lib/index.d.ts +24 -23
  52. package/lib/index.js +40 -40
  53. package/lib/renderer/app.d.ts +53 -53
  54. package/lib/renderer/app.js +88 -88
  55. package/lib/renderer/base.d.ts +30 -30
  56. package/lib/renderer/base.js +68 -68
  57. package/lib/renderer/client.d.ts +30 -30
  58. package/lib/renderer/client.js +155 -155
  59. package/lib/renderer/http.d.ts +19 -19
  60. package/lib/renderer/http.js +50 -50
  61. package/lib/renderer/server.d.ts +42 -42
  62. package/lib/renderer/server.js +110 -110
  63. package/lib/renderer/wormhole.d.ts +1 -1
  64. package/lib/renderer/wormhole.js +154 -154
  65. package/lib/tools/init.d.ts +2 -0
  66. package/lib/tools/init.js +31 -0
  67. package/lib/types/adapter.d.ts +575 -575
  68. package/lib/types/adapter.js +1 -1
  69. package/lib/types/config.d.ts +327 -327
  70. package/lib/types/config.js +1 -1
  71. package/lib/types/element.d.ts +576 -576
  72. package/lib/types/element.js +1 -1
  73. package/lib/types/index.d.ts +8 -8
  74. package/lib/types/index.js +8 -8
  75. package/lib/types/logger.d.ts +109 -109
  76. package/lib/types/logger.js +1 -1
  77. package/lib/types/onebots11.d.ts +1371 -1371
  78. package/lib/types/onebots11.js +1 -1
  79. package/lib/types/plugin.d.ts +282 -282
  80. package/lib/types/plugin.js +1 -1
  81. package/lib/types/render.d.ts +111 -111
  82. package/lib/types/render.js +1 -1
  83. package/lib/types/reply.d.ts +40 -40
  84. package/lib/types/reply.js +1 -1
  85. package/lib/types/types.d.ts +898 -898
  86. package/lib/types/types.js +1 -1
  87. package/lib/utils/YamlEditor.d.ts +62 -62
  88. package/lib/utils/YamlEditor.js +197 -197
  89. package/lib/utils/button.d.ts +49 -49
  90. package/lib/utils/button.js +75 -75
  91. package/lib/utils/common.d.ts +123 -123
  92. package/lib/utils/common.js +396 -396
  93. package/lib/utils/config.d.ts +72 -72
  94. package/lib/utils/config.js +259 -254
  95. package/lib/utils/exec.d.ts +22 -22
  96. package/lib/utils/exec.js +36 -36
  97. package/lib/utils/ffmpeg.d.ts +12 -12
  98. package/lib/utils/ffmpeg.js +25 -25
  99. package/lib/utils/handler.d.ts +76 -76
  100. package/lib/utils/handler.js +98 -98
  101. package/lib/utils/logger.d.ts +3 -3
  102. package/lib/utils/logger.js +104 -104
  103. package/lib/utils/segment.d.ts +276 -276
  104. package/lib/utils/segment.js +420 -420
  105. package/lib/utils/update.d.ts +69 -69
  106. package/lib/utils/update.js +145 -145
  107. package/lib/utils/updateVersion.d.ts +33 -33
  108. package/lib/utils/updateVersion.js +140 -140
  109. package/package.json +95 -91
@@ -1,72 +1,72 @@
1
- import { Redis, App, Config, Server, Package, GroupCfg } from '../types/config.js';
2
- import { Logger } from 'log4js';
3
- /** 配置文件 */
4
- declare const _default: {
5
- dir: string;
6
- _path: string;
7
- _pathDef: string;
8
- change: Map<string, any>;
9
- watcher: Map<string, any>;
10
- review: boolean;
11
- loggger: Logger;
12
- /** 初始化配置 */
13
- initCfg(): Promise<void>;
14
- getPlugins(): string[];
15
- /**
16
- * 为每一个插件建立对应的文件夹
17
- */
18
- dirPath(name: string, plugins: string[]): Promise<void>;
19
- /**
20
- * 超时时间
21
- */
22
- timeout(type?: 'ws' | 'grpc'): number;
23
- /**
24
- * Redis 配置
25
- * 采用实时读取优化性能
26
- */
27
- readonly redis: Redis;
28
- /**
29
- * 主人列表
30
- * @returns {string[]}
31
- */
32
- readonly master: string[];
33
- /**
34
- * 管理员列表
35
- */
36
- readonly admin: string[];
37
- /** App管理 */
38
- readonly App: App;
39
- /**
40
- * 基本配置
41
- */
42
- readonly Config: Config;
43
- /**
44
- * Server 配置文档
45
- */
46
- readonly Server: Server;
47
- /**
48
- * packageon
49
- * 实时获取packageon文件
50
- */
51
- readonly package: Package;
52
- /**
53
- * 获取群配置
54
- */
55
- group(group_id?: string): GroupCfg;
56
- /**
57
- * 获取配置yaml
58
- */
59
- getYaml(type: 'defSet' | 'config', name: string, isWatch?: boolean): any;
60
- /**
61
- * 监听配置文件
62
- * @param {'defSet'|'config'} type 类型
63
- * @param {string} name 文件名称 不带后缀
64
- * @param {string} file 文件路径
65
- */
66
- watch(type: 'defSet' | 'config', name: string, file: string): Promise<true | undefined>;
67
- change_App(): Promise<void>;
68
- change_config(): Promise<void>;
69
- change_group(): Promise<void>;
70
- "__#1@#review"(): Promise<void>;
71
- };
72
- export default _default;
1
+ import { Redis, App, Config, Server, Package, GroupCfg } from '../types/config.js';
2
+ import { Logger } from 'log4js';
3
+ /** 配置文件 */
4
+ declare const _default: {
5
+ dir: string;
6
+ _path: string;
7
+ _pathDef: string;
8
+ change: Map<string, any>;
9
+ watcher: Map<string, any>;
10
+ review: boolean;
11
+ loggger: Logger;
12
+ /** 初始化配置 */
13
+ initCfg(): Promise<void>;
14
+ getPlugins(): string[];
15
+ /**
16
+ * 为每一个插件建立对应的文件夹
17
+ */
18
+ dirPath(name: string, plugins: string[]): Promise<void>;
19
+ /**
20
+ * 超时时间
21
+ */
22
+ timeout(type?: 'ws' | 'grpc'): number;
23
+ /**
24
+ * Redis 配置
25
+ * 采用实时读取优化性能
26
+ */
27
+ readonly redis: Redis;
28
+ /**
29
+ * 主人列表
30
+ * @returns {string[]}
31
+ */
32
+ readonly master: string[];
33
+ /**
34
+ * 管理员列表
35
+ */
36
+ readonly admin: string[];
37
+ /** App管理 */
38
+ readonly App: App;
39
+ /**
40
+ * 基本配置
41
+ */
42
+ readonly Config: Config;
43
+ /**
44
+ * Server 配置文档
45
+ */
46
+ readonly Server: Server;
47
+ /**
48
+ * packageon
49
+ * 实时获取packageon文件
50
+ */
51
+ readonly package: Package;
52
+ /**
53
+ * 获取群配置
54
+ */
55
+ group(group_id?: string): GroupCfg;
56
+ /**
57
+ * 获取配置yaml
58
+ */
59
+ getYaml(type: 'defSet' | 'config', name: string, isWatch?: boolean): any;
60
+ /**
61
+ * 监听配置文件
62
+ * @param {'defSet'|'config'} type 类型
63
+ * @param {string} name 文件名称 不带后缀
64
+ * @param {string} file 文件路径
65
+ */
66
+ watch(type: 'defSet' | 'config', name: string, file: string): Promise<true | undefined>;
67
+ change_App(): Promise<void>;
68
+ change_config(): Promise<void>;
69
+ change_group(): Promise<void>;
70
+ "__#1@#review"(): Promise<void>;
71
+ };
72
+ export default _default;
@@ -1,254 +1,259 @@
1
- import fs from 'fs'
2
- import Yaml from 'yaml'
3
- import chokidar from 'chokidar'
4
- /** 配置文件 */
5
- export default new (class Cfg {
6
- dir
7
- _path
8
- _pathDef
9
- change
10
- watcher
11
- review
12
- loggger
13
- constructor () {
14
- this.dir = process.cwd()
15
- this._path = this.dir + '/config/config'
16
- this._pathDef = this.dir + '/config/defSet'
17
- /** 缓存 */
18
- this.change = new Map()
19
- /** 监听文件 */
20
- this.watcher = new Map()
21
- /** 拦截器状态 */
22
- this.review = false
23
- this.initCfg()
24
- }
25
-
26
- /** 初始化配置 */
27
- async initCfg () {
28
- if (!fs.existsSync(this._path)) { fs.mkdirSync(this._path) }
29
- const files = fs.readdirSync(this._pathDef).filter(file => file.endsWith('.yaml'))
30
- for (const file of files) {
31
- const path = `${this._path}/${file}`
32
- const pathDef = `${this._pathDef}/${file}`
33
- if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
34
- }
35
- // 创建插件文件夹文件夹
36
- const plugins = this.getPlugins()
37
- this.dirPath('data', plugins)
38
- this.dirPath('temp', plugins)
39
- this.dirPath('resources', plugins)
40
- this.dirPath('temp/html', plugins)
41
- this.loggger = (await import('./logger.js')).default
42
- }
43
-
44
- getPlugins () {
45
- const files = fs.readdirSync('./plugins', { withFileTypes: true })
46
- // 过滤掉非karin-plugin-开头或karin-adapter-开头的文件夹
47
- return files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-') || file.name.startsWith('karin-adapter-'))).map(dir => dir.name)
48
- }
49
-
50
- /**
51
- * 为每一个插件建立对应的文件夹
52
- */
53
- async dirPath (name, plugins) {
54
- name = `./${name}`
55
- if (!fs.existsSync(name)) { fs.mkdirSync(name) }
56
- for (const plugin of plugins) {
57
- const path = `${name}/${plugin}`
58
- if (!fs.existsSync(path)) { fs.mkdirSync(path) }
59
- }
60
- }
61
-
62
- /**
63
- * 超时时间
64
- */
65
- timeout (type = 'ws') {
66
- let timeout = 60
67
- if (type === 'ws') {
68
- timeout = this.Server.websocket.timeout
69
- } else {
70
- timeout = this.Server.grpc.timeout
71
- }
72
- return timeout || 60
73
- }
74
-
75
- /**
76
- * Redis 配置
77
- * 采用实时读取优化性能
78
- */
79
- get redis () {
80
- const config = this.getYaml('config', 'redis', false)
81
- const defSet = this.getYaml('defSet', 'redis', false)
82
- const data = { ...defSet, ...config }
83
- return data
84
- }
85
-
86
- /**
87
- * 主人列表
88
- * @returns {string[]}
89
- */
90
- get master () {
91
- return this.Config.master || []
92
- }
93
-
94
- /**
95
- * 管理员列表
96
- */
97
- get admin () {
98
- return this.Config.admin || []
99
- }
100
-
101
- /** App管理 */
102
- get App () {
103
- const key = 'change.App'
104
- const res = this.change.get(key)
105
- /** 取缓存 */
106
- if (res) { return res }
107
- /** 取配置 */
108
- const config = this.getYaml('config', 'App', true)
109
- const defSet = this.getYaml('defSet', 'App', true)
110
- const data = { ...defSet, ...config }
111
- /** 缓存 */
112
- this.change.set(key, data)
113
- return data
114
- }
115
-
116
- /**
117
- * 基本配置
118
- */
119
- get Config () {
120
- const key = 'change.config'
121
- const res = this.change.get(key)
122
- /** 取缓存 */
123
- if (res) { return res }
124
- /** 取配置 */
125
- const config = this.getYaml('config', 'config', true)
126
- const defSet = this.getYaml('defSet', 'config', false)
127
- const data = { ...defSet, ...config }
128
- /** 缓存 */
129
- this.change.set(key, data)
130
- return data
131
- }
132
-
133
- /**
134
- * Server 配置文档
135
- */
136
- get Server () {
137
- const key = 'change.server'
138
- /** 取缓存 */
139
- const res = this.change.get(key)
140
- if (res) { return res }
141
- /** 取配置 */
142
- const config = this.getYaml('config', 'server', true)
143
- const defSet = this.getYaml('defSet', 'server', false)
144
- const data = { ...defSet, ...config }
145
- /** 缓存 */
146
- this.change.set(key, data)
147
- return data
148
- }
149
-
150
- /**
151
- * packageon
152
- * 实时获取packageon文件
153
- */
154
- get package () {
155
- const data = fs.readFileSync('./package.json', 'utf8')
156
- const pack = JSON.parse(data)
157
- return pack
158
- }
159
-
160
- /**
161
- * 获取群配置
162
- */
163
- group (group_id = '') {
164
- const key = 'change.group'
165
- /** 取缓存 */
166
- let res = this.change.get(key)
167
- if (res) {
168
- res = { ...res.defCfg.default, ...res.Config.default, ...(res.Config[group_id] || {}) }
169
- return res
170
- }
171
- /** 取配置 */
172
- const Config = this.getYaml('config', 'group')
173
- const defCfg = this.getYaml('defSet', 'group')
174
- const data = { Config, defCfg }
175
- /** 缓存 */
176
- res = this.change.set(key, data)
177
- res = { ...defCfg.default, ...Config.default, ...(Config[group_id] || {}) }
178
- return res
179
- }
180
-
181
- /**
182
- * 获取配置yaml
183
- */
184
- getYaml (type, name, isWatch = false) {
185
- /** 文件路径 */
186
- const file = `./config/${type}/${name}.yaml`
187
- /** 读取文件 */
188
- const data = Yaml.parse(fs.readFileSync(file, 'utf8'))
189
- /** 监听文件 */
190
- if (isWatch) { this.watch(type, name, file) }
191
- return data
192
- }
193
-
194
- /**
195
- * 监听配置文件
196
- * @param {'defSet'|'config'} type 类型
197
- * @param {string} name 文件名称 不带后缀
198
- * @param {string} file 文件路径
199
- */
200
- async watch (type, name, file) {
201
- const key = `change.${name}`
202
- /** 已经监听过了 */
203
- const res = this.change.get(key)
204
- if (res) { return true }
205
- /** 监听文件 */
206
- const watcher = chokidar.watch(file)
207
- /** 监听文件变化 */
208
- watcher.on('change', () => {
209
- this.change.delete(key)
210
- this.loggger.mark(`[修改配置文件][${type}][${name}]`)
211
- /** 文件修改后调用对应的方法 */
212
- switch (`change_${name}`) {
213
- case 'change_App':
214
- this.change_App()
215
- break
216
- case 'change_config':
217
- this.change_config()
218
- break
219
- case 'change_group':
220
- this.change_group()
221
- break
222
- }
223
- })
224
- /** 缓存 防止重复监听 */
225
- this.watcher.set(key, watcher)
226
- }
227
-
228
- async change_App () {
229
- await this.#review()
230
- }
231
-
232
- async change_config () {
233
- /** 修改日志等级 */
234
- this.loggger.level = this.Config.log_level
235
- await this.#review()
236
- // if (this.Server.HotUpdate) {
237
- // const { Bot } = await import('../index.js')
238
- // Bot.emit('restart_http', {})
239
- // Bot.emit('restart_grpc', {})
240
- // }
241
- }
242
-
243
- async change_group () {
244
- await this.#review()
245
- }
246
-
247
- async #review () {
248
- // if (this.review) return
249
- // this.review = true
250
- // const review = await import('../event/review')
251
- // review.default.main()
252
- // this.review = false
253
- }
254
- })()
1
+ import fs from 'fs'
2
+ import Yaml from 'yaml'
3
+ import chokidar from 'chokidar'
4
+ import { karinDir } from '../core/dir.js'
5
+ /** 配置文件 */
6
+ export default new (class Cfg {
7
+ dir
8
+ _path
9
+ _pathDef
10
+ change
11
+ watcher
12
+ review
13
+ loggger
14
+ constructor () {
15
+ this.dir = karinDir
16
+ this._path = process.cwd() + '/config'
17
+ this._pathDef = this.dir + '/config/defSet'
18
+ /** 缓存 */
19
+ this.change = new Map()
20
+ /** 监听文件 */
21
+ this.watcher = new Map()
22
+ /** 拦截器状态 */
23
+ this.review = false
24
+ this.initCfg()
25
+ }
26
+
27
+ /** 初始化配置 */
28
+ async initCfg () {
29
+ if (!fs.existsSync(this._path)) { fs.mkdirSync(this._path) }
30
+ this._path = process.cwd() + '/config/config'
31
+ if (!fs.existsSync(this._path)) { fs.mkdirSync(this._path) }
32
+ const files = fs.readdirSync(this._pathDef).filter(file => file.endsWith('.yaml'))
33
+ for (const file of files) {
34
+ const path = `${this._path}/${file}`
35
+ const pathDef = `${this._pathDef}/${file}`
36
+ if (!fs.existsSync(path)) { fs.copyFileSync(pathDef, path) }
37
+ }
38
+ // 创建插件文件夹文件夹
39
+ if (!fs.existsSync('./plugins')) { fs.mkdirSync('./plugins') }
40
+ if (!fs.existsSync('./plugins/karin-plugin-example')) { fs.mkdirSync('./plugins/karin-plugin-example') }
41
+ const plugins = this.getPlugins()
42
+ this.dirPath('data', plugins)
43
+ this.dirPath('temp', plugins)
44
+ this.dirPath('resources', plugins)
45
+ this.dirPath('temp/html', plugins)
46
+ this.loggger = (await import('./logger.js')).default
47
+ }
48
+
49
+ getPlugins () {
50
+ const files = fs.readdirSync('./plugins', { withFileTypes: true })
51
+ // 过滤掉非karin-plugin-开头或karin-adapter-开头的文件夹
52
+ return files.filter(file => file.isDirectory() && (file.name.startsWith('karin-plugin-'))).map(dir => dir.name)
53
+ }
54
+
55
+ /**
56
+ * 为每一个插件建立对应的文件夹
57
+ */
58
+ async dirPath (name, plugins) {
59
+ name = `./${name}`
60
+ if (!fs.existsSync(name)) { fs.mkdirSync(name) }
61
+ for (const plugin of plugins) {
62
+ const path = `${name}/${plugin}`
63
+ if (!fs.existsSync(path)) { fs.mkdirSync(path) }
64
+ }
65
+ }
66
+
67
+ /**
68
+ * 超时时间
69
+ */
70
+ timeout (type = 'ws') {
71
+ let timeout = 60
72
+ if (type === 'ws') {
73
+ timeout = this.Server.websocket.timeout
74
+ } else {
75
+ timeout = this.Server.grpc.timeout
76
+ }
77
+ return timeout || 60
78
+ }
79
+
80
+ /**
81
+ * Redis 配置
82
+ * 采用实时读取优化性能
83
+ */
84
+ get redis () {
85
+ const config = this.getYaml('config', 'redis', false)
86
+ const defSet = this.getYaml('defSet', 'redis', false)
87
+ const data = { ...defSet, ...config }
88
+ return data
89
+ }
90
+
91
+ /**
92
+ * 主人列表
93
+ * @returns {string[]}
94
+ */
95
+ get master () {
96
+ return this.Config.master || []
97
+ }
98
+
99
+ /**
100
+ * 管理员列表
101
+ */
102
+ get admin () {
103
+ return this.Config.admin || []
104
+ }
105
+
106
+ /** App管理 */
107
+ get App () {
108
+ const key = 'change.App'
109
+ const res = this.change.get(key)
110
+ /** 取缓存 */
111
+ if (res) { return res }
112
+ /** 取配置 */
113
+ const config = this.getYaml('config', 'App', true)
114
+ const defSet = this.getYaml('defSet', 'App', true)
115
+ const data = { ...defSet, ...config }
116
+ /** 缓存 */
117
+ this.change.set(key, data)
118
+ return data
119
+ }
120
+
121
+ /**
122
+ * 基本配置
123
+ */
124
+ get Config () {
125
+ const key = 'change.config'
126
+ const res = this.change.get(key)
127
+ /** 取缓存 */
128
+ if (res) { return res }
129
+ /** 取配置 */
130
+ const config = this.getYaml('config', 'config', true)
131
+ const defSet = this.getYaml('defSet', 'config', false)
132
+ const data = { ...defSet, ...config }
133
+ /** 缓存 */
134
+ this.change.set(key, data)
135
+ return data
136
+ }
137
+
138
+ /**
139
+ * Server 配置文档
140
+ */
141
+ get Server () {
142
+ const key = 'change.server'
143
+ /** 取缓存 */
144
+ const res = this.change.get(key)
145
+ if (res) { return res }
146
+ /** 取配置 */
147
+ const config = this.getYaml('config', 'server', true)
148
+ const defSet = this.getYaml('defSet', 'server', false)
149
+ const data = { ...defSet, ...config }
150
+ /** 缓存 */
151
+ this.change.set(key, data)
152
+ return data
153
+ }
154
+
155
+ /**
156
+ * packageon
157
+ * 实时获取packageon文件
158
+ */
159
+ get package () {
160
+ const data = fs.readFileSync('./package.json', 'utf8')
161
+ const pack = JSON.parse(data)
162
+ return pack
163
+ }
164
+
165
+ /**
166
+ * 获取群配置
167
+ */
168
+ group (group_id = '') {
169
+ const key = 'change.group'
170
+ /** 取缓存 */
171
+ let res = this.change.get(key)
172
+ if (res) {
173
+ res = { ...res.defCfg.default, ...res.Config.default, ...(res.Config[group_id] || {}) }
174
+ return res
175
+ }
176
+ /** 取配置 */
177
+ const Config = this.getYaml('config', 'group')
178
+ const defCfg = this.getYaml('defSet', 'group')
179
+ const data = { Config, defCfg }
180
+ /** 缓存 */
181
+ res = this.change.set(key, data)
182
+ res = { ...defCfg.default, ...Config.default, ...(Config[group_id] || {}) }
183
+ return res
184
+ }
185
+
186
+ /**
187
+ * 获取配置yaml
188
+ */
189
+ getYaml (type, name, isWatch = false) {
190
+ /** 文件路径 */
191
+ const file = `./config/${type}/${name}.yaml`
192
+ /** 读取文件 */
193
+ const data = Yaml.parse(fs.readFileSync(file, 'utf8'))
194
+ /** 监听文件 */
195
+ if (isWatch) { this.watch(type, name, file) }
196
+ return data
197
+ }
198
+
199
+ /**
200
+ * 监听配置文件
201
+ * @param {'defSet'|'config'} type 类型
202
+ * @param {string} name 文件名称 不带后缀
203
+ * @param {string} file 文件路径
204
+ */
205
+ async watch (type, name, file) {
206
+ const key = `change.${name}`
207
+ /** 已经监听过了 */
208
+ const res = this.change.get(key)
209
+ if (res) { return true }
210
+ /** 监听文件 */
211
+ const watcher = chokidar.watch(file)
212
+ /** 监听文件变化 */
213
+ watcher.on('change', () => {
214
+ this.change.delete(key)
215
+ this.loggger.mark(`[修改配置文件][${type}][${name}]`)
216
+ /** 文件修改后调用对应的方法 */
217
+ switch (`change_${name}`) {
218
+ case 'change_App':
219
+ this.change_App()
220
+ break
221
+ case 'change_config':
222
+ this.change_config()
223
+ break
224
+ case 'change_group':
225
+ this.change_group()
226
+ break
227
+ }
228
+ })
229
+ /** 缓存 防止重复监听 */
230
+ this.watcher.set(key, watcher)
231
+ }
232
+
233
+ async change_App () {
234
+ await this.#review()
235
+ }
236
+
237
+ async change_config () {
238
+ /** 修改日志等级 */
239
+ this.loggger.level = this.Config.log_level
240
+ await this.#review()
241
+ // if (this.Server.HotUpdate) {
242
+ // const { Bot } = await import('../index.js')
243
+ // Bot.emit('restart_http', {})
244
+ // Bot.emit('restart_grpc', {})
245
+ // }
246
+ }
247
+
248
+ async change_group () {
249
+ await this.#review()
250
+ }
251
+
252
+ async #review () {
253
+ // if (this.review) return
254
+ // this.review = true
255
+ // const review = await import('../event/review')
256
+ // review.default.main()
257
+ // this.review = false
258
+ }
259
+ })()