node-karin 0.12.0 → 0.12.2

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/lib/cli/index.js CHANGED
@@ -215,6 +215,9 @@ export class KarinCli {
215
215
  return console.log('[依赖更新] 没有git插件需要更新~');
216
216
  await Promise.all(gitList.map(async (item) => {
217
217
  const dir = path.resolve(process.cwd(), 'plugins', item);
218
+ /** 检查是否是git仓库 */
219
+ if (!fs.existsSync(path.join(dir, '.git')))
220
+ return;
218
221
  try {
219
222
  await this.exec('git pull', { cwd: dir });
220
223
  console.log(`[依赖更新] ${item} 更新完成~`);
@@ -14,10 +14,6 @@ export declare class MessageHandler extends EventBaseHandler {
14
14
  * 响应模式检查 返回false表示未通过
15
15
  */
16
16
  getMode(): boolean;
17
- /**
18
- * 打印
19
- */
20
- print(): void;
21
17
  /**
22
18
  * 处理消息
23
19
  */
@@ -186,11 +186,6 @@ export class MessageHandler extends EventBaseHandler {
186
186
  logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 响应模式不匹配`);
187
187
  return false;
188
188
  }
189
- /**
190
- * 打印
191
- */
192
- print() {
193
- }
194
189
  /**
195
190
  * 处理消息
196
191
  */
@@ -14,44 +14,51 @@ export declare class YamlEditor {
14
14
  * 设置指定路径的值
15
15
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
16
16
  * @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
17
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
17
18
  */
18
- set(path: string, value: YamlValue): boolean;
19
+ set(path: string, value: YamlValue, isSplit?: boolean): boolean;
19
20
  /**
20
21
  * 向指定路径添加新值
21
22
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
22
23
  * @param value - 要添加的值
24
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
23
25
  */
24
- add(path: string, value: YamlValue): boolean;
26
+ add(path: string, value: YamlValue, isSplit?: boolean): boolean;
25
27
  /**
26
28
  * 删除指定路径
27
29
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
30
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
28
31
  * @returns 是否删除成功
29
32
  */
30
- del(path: string): boolean;
33
+ del(path: string, isSplit?: boolean): boolean;
31
34
  /**
32
35
  * 向指定路径的数组添加新值,可以选择添加到数组的开始或结束
33
36
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
34
37
  * @param value - 要添加的值
35
38
  * @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
39
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
36
40
  */
37
- append(path: string, value: string, prepend?: boolean): boolean;
41
+ append(path: string, value: string, prepend?: boolean, isSplit?: boolean): boolean;
38
42
  /**
39
43
  * 向指定路径的数组删除值
40
44
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
41
45
  * @param value - 要删除的值
46
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
42
47
  */
43
- remove(path: string, value: YamlValue): boolean;
48
+ remove(path: string, value: YamlValue, isSplit?: boolean): boolean;
44
49
  /**
45
50
  * 检查指定路径的键是否存在
46
51
  * @param path - 路径,用点号分隔
52
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
47
53
  */
48
- has(path: string): boolean;
54
+ has(path: string, isSplit?: boolean): boolean;
49
55
  /**
50
56
  * 查询指定路径中是否包含指定的值
51
57
  * @param path - 路径,用点号分隔
52
58
  * @param value - 要查询的值
59
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
53
60
  */
54
- hasval(path: string, value: YamlValue): boolean;
61
+ hasval(path: string, value: YamlValue, isSplit?: boolean): boolean;
55
62
  /**
56
63
  * 查询指定路径中是否包含指定的值
57
64
  * @param path - 路径,用点号分隔
@@ -72,27 +79,31 @@ export declare class YamlEditor {
72
79
  /**
73
80
  * 获取指定路径的pair对象
74
81
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
82
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
75
83
  */
76
- getpair(path: string): any;
84
+ getpair(path: string, isSplit?: boolean): any;
77
85
  /**
78
86
  * 设置指定键的注释
79
87
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
80
88
  * @param comment - 要设置的注释
81
89
  * @param prepend - 如果为 true,则添加到注释的开头,否则添加到同一行的末尾
90
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
82
91
  */
83
- comment(path: string, comment: string, prepend: boolean): void;
92
+ comment(path: string, comment: string, prepend: boolean, isSplit?: boolean): void;
84
93
  /**
85
94
  * 删除指定键的注释
86
95
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
87
96
  * @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
97
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
88
98
  */
89
- uncomment(path: string, type?: 'before' | 'after' | 'all'): void;
99
+ uncomment(path: string, type?: 'before' | 'after' | 'all', isSplit?: boolean): void;
90
100
  /**
91
101
  * 检查注释是否存在
92
102
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
93
103
  * @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
104
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
94
105
  */
95
- hascomment(path: string, type: 'before' | 'after'): boolean;
106
+ hascomment(path: string, type: 'before' | 'after', isSplit?: boolean): boolean;
96
107
  /**
97
108
  * 保存文件
98
109
  * 保存失败会抛出异常
@@ -13,7 +13,7 @@ export class YamlEditor {
13
13
  document;
14
14
  constructor(file) {
15
15
  this.filePath = file;
16
- const data = Yaml.parseDocument(fs.readFileSync(file, 'utf8'));
16
+ const data = Yaml.parseDocument(fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : file);
17
17
  this.doc = data;
18
18
  this.document = data;
19
19
  }
@@ -36,10 +36,11 @@ export class YamlEditor {
36
36
  * 设置指定路径的值
37
37
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
38
38
  * @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
39
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
39
40
  */
40
- set(path, value) {
41
+ set(path, value, isSplit = true) {
41
42
  try {
42
- const _path = typeof path === 'string' ? path.split('.') : path;
43
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
43
44
  this.document.setIn(_path, value);
44
45
  return true;
45
46
  }
@@ -52,10 +53,11 @@ export class YamlEditor {
52
53
  * 向指定路径添加新值
53
54
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
54
55
  * @param value - 要添加的值
56
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
55
57
  */
56
- add(path, value) {
58
+ add(path, value, isSplit = true) {
57
59
  try {
58
- const _path = typeof path === 'string' ? path.split('.') : path;
60
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
59
61
  this.document.addIn(_path, value);
60
62
  logger.debug(`[YamlEditor] 已在 ${path} 添加新的值`);
61
63
  return true;
@@ -68,11 +70,12 @@ export class YamlEditor {
68
70
  /**
69
71
  * 删除指定路径
70
72
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
73
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
71
74
  * @returns 是否删除成功
72
75
  */
73
- del(path) {
76
+ del(path, isSplit = true) {
74
77
  try {
75
- const _path = typeof path === 'string' ? path.split('.') : path;
78
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
76
79
  this.document.deleteIn(_path);
77
80
  return true;
78
81
  }
@@ -86,10 +89,11 @@ export class YamlEditor {
86
89
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
87
90
  * @param value - 要添加的值
88
91
  * @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
92
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
89
93
  */
90
- append(path, value, prepend = false) {
94
+ append(path, value, prepend = false, isSplit = true) {
91
95
  try {
92
- const _path = typeof path === 'string' ? path.split('.') : path || [];
96
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
93
97
  let current = this.document.getIn(_path);
94
98
  if (!current) {
95
99
  current = new Yaml.YAMLSeq();
@@ -114,10 +118,11 @@ export class YamlEditor {
114
118
  * 向指定路径的数组删除值
115
119
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
116
120
  * @param value - 要删除的值
121
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
117
122
  */
118
- remove(path, value) {
123
+ remove(path, value, isSplit = true) {
119
124
  try {
120
- const _path = typeof path === 'string' ? path.split('.') : path;
125
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
121
126
  const current = this.document.getIn(_path);
122
127
  if (!current) {
123
128
  logger.error('[YamlEditor] 指定的路径不存在');
@@ -144,10 +149,11 @@ export class YamlEditor {
144
149
  /**
145
150
  * 检查指定路径的键是否存在
146
151
  * @param path - 路径,用点号分隔
152
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
147
153
  */
148
- has(path) {
154
+ has(path, isSplit = true) {
149
155
  try {
150
- const _path = typeof path === 'string' ? path.split('.') : path;
156
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
151
157
  return this.document.hasIn(_path);
152
158
  }
153
159
  catch (error) {
@@ -159,10 +165,11 @@ export class YamlEditor {
159
165
  * 查询指定路径中是否包含指定的值
160
166
  * @param path - 路径,用点号分隔
161
167
  * @param value - 要查询的值
168
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
162
169
  */
163
- hasval(path, value) {
170
+ hasval(path, value, isSplit = true) {
164
171
  try {
165
- const _path = typeof path === 'string' ? path.split('.') : path;
172
+ const _path = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
166
173
  const current = this.document.getIn(_path);
167
174
  if (!current)
168
175
  return false;
@@ -238,11 +245,12 @@ export class YamlEditor {
238
245
  /**
239
246
  * 获取指定路径的pair对象
240
247
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
248
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
241
249
  */
242
- getpair(path) {
250
+ getpair(path, isSplit = true) {
243
251
  if (!path)
244
252
  throw new Error('path is required');
245
- const keys = path.split('.');
253
+ const keys = typeof path === 'string' ? (isSplit ? path.split('.') : [path]) : path;
246
254
  // 好多any啊,我要当any糕手~
247
255
  let pair = this.document.contents;
248
256
  keys.forEach(key => {
@@ -263,11 +271,12 @@ export class YamlEditor {
263
271
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
264
272
  * @param comment - 要设置的注释
265
273
  * @param prepend - 如果为 true,则添加到注释的开头,否则添加到同一行的末尾
274
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
266
275
  */
267
- comment(path, comment, prepend) {
276
+ comment(path, comment, prepend, isSplit = true) {
268
277
  if (!path)
269
278
  throw new Error('[YamlEditor] path 不能为空');
270
- const pair = this.getpair(path);
279
+ const pair = this.getpair(path, isSplit);
271
280
  if (!pair)
272
281
  throw new Error(`[YamlEditor] 未找到节点 ${path}`);
273
282
  comment = ` ${comment}`;
@@ -282,11 +291,12 @@ export class YamlEditor {
282
291
  * 删除指定键的注释
283
292
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
284
293
  * @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
294
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
285
295
  */
286
- uncomment(path, type = 'all') {
296
+ uncomment(path, type = 'all', isSplit = true) {
287
297
  if (!path)
288
298
  throw new Error('[YamlEditor] path 不能为空');
289
- const pair = this.getpair(path);
299
+ const pair = this.getpair(path, isSplit);
290
300
  if (!pair)
291
301
  throw new Error(`[YamlEditor] 未找到节点 ${path}`);
292
302
  if (type === 'all') {
@@ -304,11 +314,12 @@ export class YamlEditor {
304
314
  * 检查注释是否存在
305
315
  * @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
306
316
  * @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
317
+ * @param isSplit - 是否使用分割路径路径,默认为 `true`
307
318
  */
308
- hascomment(path, type) {
319
+ hascomment(path, type, isSplit = true) {
309
320
  if (!path)
310
321
  throw new Error('[YamlEditor] path 不能为空');
311
- const pair = this.getpair(path);
322
+ const pair = this.getpair(path, isSplit);
312
323
  if (!pair)
313
324
  throw new Error(`[YamlEditor] 未找到节点 ${path}`);
314
325
  if (type === 'before') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",
@@ -55,16 +55,6 @@
55
55
  "require": "./lib/modules/express.js",
56
56
  "types": "./lib/modules/express.d.ts"
57
57
  },
58
- "./grpc-js": {
59
- "import": "./lib/modules/grpc-js.js",
60
- "require": "./lib/modules/grpc-js.js",
61
- "types": "./lib/modules/grpc-js.d.ts"
62
- },
63
- "./kritor-proto": {
64
- "import": "./lib/modules/kritor-proto.js",
65
- "require": "./lib/modules/kritor-proto.js",
66
- "types": "./lib/modules/kritor-proto.d.ts"
67
- },
68
58
  "./level": {
69
59
  "import": "./lib/modules/level.js",
70
60
  "require": "./lib/modules/level.js",
@@ -90,11 +80,6 @@
90
80
  "require": "./lib/modules/node-schedule.js",
91
81
  "types": "./lib/modules/node-schedule.d.ts"
92
82
  },
93
- "./proto-loader": {
94
- "import": "./lib/modules/proto-loader.js",
95
- "require": "./lib/modules/proto-loader.js",
96
- "types": "./lib/modules/proto-loader.d.ts"
97
- },
98
83
  "./redis": {
99
84
  "import": "./lib/modules/redis.js",
100
85
  "require": "./lib/modules/redis.js",
@@ -154,7 +139,6 @@
154
139
  "chokidar": "3.6.0",
155
140
  "commander": "^12.1.0",
156
141
  "express": "4.19.2",
157
- "jimp": "^0.22.12",
158
142
  "level": "8.0.1",
159
143
  "lodash": "4.17.21",
160
144
  "log4js": "6.9.1",