node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1029 -0
- package/default/comment/config.json +34 -0
- package/default/comment/friendDirect.json +10 -0
- package/default/comment/groupGuild.json +11 -0
- package/default/comment/server.json +17 -0
- package/default/config/adapter.json +28 -0
- package/default/config/config.json +47 -0
- package/default/config/groups.json +47 -0
- package/default/config/groups.yaml +70 -0
- package/default/config/pm2.json +16 -0
- package/default/config/privates.json +23 -0
- package/default/config/privates.yaml +31 -0
- package/default/config/redis.json +10 -0
- package/default/config/render.json +19 -0
- package/default/view/group.yaml +73 -0
- package/dist/index.d.ts +9869 -0
- package/dist/index.js +12643 -0
- package/dist/module/art-template.cjs +11 -0
- package/dist/module/art-template.d.ts +1 -0
- package/dist/module/axios.cjs +22 -0
- package/dist/module/axios.d.ts +2 -0
- package/dist/module/chalk.cjs +22 -0
- package/dist/module/chalk.d.ts +2 -0
- package/dist/module/chokidar.cjs +22 -0
- package/dist/module/chokidar.d.ts +2 -0
- package/dist/module/commander.cjs +35 -0
- package/dist/module/commander.d.ts +3 -0
- package/dist/module/commander.js +3 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/module/express.cjs +112 -0
- package/dist/module/express.d.ts +1 -0
- package/dist/module/express.js +1 -0
- package/dist/module/level.cjs +22 -0
- package/dist/module/level.d.ts +2 -0
- package/dist/module/lodash.cjs +11 -0
- package/dist/module/lodash.d.ts +1 -0
- package/dist/module/log4js.cjs +22 -0
- package/dist/module/log4js.d.ts +2 -0
- package/dist/module/moment.cjs +11 -0
- package/dist/module/moment.d.ts +1 -0
- package/dist/module/node-schedule.cjs +22 -0
- package/dist/module/node-schedule.d.ts +2 -0
- package/dist/module/redis.cjs +22 -0
- package/dist/module/redis.d.ts +2 -0
- package/dist/module/ws.cjs +28 -0
- package/dist/module/ws.d.ts +1 -0
- package/dist/module/ws.js +1 -0
- package/dist/module/yaml.cjs +22 -0
- package/dist/module/yaml.d.ts +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +142 -128
- package/LICENSE +0 -674
- package/README.md +0 -56
- package/config/defSet/App.yaml +0 -42
- package/config/defSet/config.yaml +0 -65
- package/config/defSet/group.yaml +0 -56
- package/config/defSet/pm2.yaml +0 -21
- package/config/defSet/redis.yaml +0 -18
- package/config/defSet/server.yaml +0 -42
- package/config/view/group.yaml +0 -92
- package/lib/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.d.ts +0 -78
- package/lib/adapter/input/index.js +0 -205
- package/lib/adapter/onebot/11/convert.d.ts +0 -12
- package/lib/adapter/onebot/11/convert.js +0 -167
- package/lib/adapter/onebot/11/event.d.ts +0 -25
- package/lib/adapter/onebot/11/event.js +0 -442
- package/lib/adapter/onebot/11/index.d.ts +0 -508
- package/lib/adapter/onebot/11/index.js +0 -1047
- package/lib/cli/index.d.ts +0 -92
- package/lib/cli/index.js +0 -307
- package/lib/cli/init.d.ts +0 -2
- package/lib/cli/init.js +0 -22
- package/lib/cli/karin.d.ts +0 -2
- package/lib/cli/karin.js +0 -16
- package/lib/cli/pkg.d.ts +0 -4
- package/lib/cli/pkg.js +0 -14
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +0 -8
- package/lib/core/index.d.ts +0 -10
- package/lib/core/index.js +0 -10
- package/lib/core/init/config.d.ts +0 -43
- package/lib/core/init/config.js +0 -201
- package/lib/core/init/dir.d.ts +0 -4
- package/lib/core/init/dir.js +0 -7
- package/lib/core/init/init.d.ts +0 -1
- package/lib/core/init/init.js +0 -47
- package/lib/core/karin/karin.d.ts +0 -198
- package/lib/core/karin/karin.js +0 -226
- package/lib/core/listener/listener.d.ts +0 -145
- package/lib/core/listener/listener.js +0 -235
- package/lib/core/plugin/base.d.ts +0 -156
- package/lib/core/plugin/base.js +0 -131
- package/lib/core/plugin/loader.d.ts +0 -141
- package/lib/core/plugin/loader.js +0 -618
- package/lib/core/process/process.d.ts +0 -18
- package/lib/core/process/process.js +0 -96
- package/lib/core/server/server.d.ts +0 -25
- package/lib/core/server/server.js +0 -295
- package/lib/db/index.d.ts +0 -2
- package/lib/db/index.js +0 -2
- package/lib/db/level/level.d.ts +0 -19
- package/lib/db/level/level.js +0 -36
- package/lib/db/redis/redis.d.ts +0 -2
- package/lib/db/redis/redis.js +0 -135
- package/lib/db/redis/redis_level.d.ts +0 -112
- package/lib/db/redis/redis_level.js +0 -281
- package/lib/event/handler/base.d.ts +0 -42
- package/lib/event/handler/base.js +0 -200
- package/lib/event/handler/message.d.ts +0 -29
- package/lib/event/handler/message.js +0 -307
- package/lib/event/handler/notice.d.ts +0 -18
- package/lib/event/handler/notice.js +0 -214
- package/lib/event/handler/request.d.ts +0 -18
- package/lib/event/handler/request.js +0 -115
- package/lib/event/handler/review.d.ts +0 -55
- package/lib/event/handler/review.js +0 -386
- package/lib/event/index.d.ts +0 -5
- package/lib/event/index.js +0 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -8
- package/lib/modules/art-template.d.ts +0 -1
- package/lib/modules/axios.d.ts +0 -2
- package/lib/modules/chalk.d.ts +0 -2
- package/lib/modules/chokidar.d.ts +0 -2
- package/lib/modules/commander.d.ts +0 -2
- package/lib/modules/commander.js +0 -2
- package/lib/modules/express.d.ts +0 -3
- package/lib/modules/express.js +0 -3
- package/lib/modules/level.d.ts +0 -2
- package/lib/modules/lodash.d.ts +0 -1
- package/lib/modules/log4js.d.ts +0 -2
- package/lib/modules/moment.d.ts +0 -1
- package/lib/modules/node-schedule.d.ts +0 -2
- package/lib/modules/redis.d.ts +0 -2
- package/lib/modules/ws.d.ts +0 -3
- package/lib/modules/ws.js +0 -3
- package/lib/modules/yaml.d.ts +0 -2
- package/lib/modules.d.ts +0 -15
- package/lib/modules.js +0 -15
- package/lib/render/app.d.ts +0 -56
- package/lib/render/app.js +0 -120
- package/lib/render/base.d.ts +0 -30
- package/lib/render/base.js +0 -69
- package/lib/render/client.d.ts +0 -41
- package/lib/render/client.js +0 -238
- package/lib/render/http.d.ts +0 -19
- package/lib/render/http.js +0 -50
- package/lib/render/index.d.ts +0 -6
- package/lib/render/index.js +0 -6
- package/lib/render/server.d.ts +0 -25
- package/lib/render/server.js +0 -101
- package/lib/render/wormhole.d.ts +0 -1
- package/lib/render/wormhole.js +0 -156
- package/lib/types/adapter/api.d.ts +0 -399
- package/lib/types/adapter/api.js +0 -1
- package/lib/types/adapter/base.d.ts +0 -560
- package/lib/types/adapter/base.js +0 -1
- package/lib/types/config/config.d.ts +0 -379
- package/lib/types/config/config.js +0 -1
- package/lib/types/element/element.d.ts +0 -565
- package/lib/types/element/element.js +0 -1
- package/lib/types/element/qqbot.d.ts +0 -123
- package/lib/types/element/qqbot.js +0 -1
- package/lib/types/event/contact.d.ts +0 -28
- package/lib/types/event/contact.js +0 -1
- package/lib/types/event/event.d.ts +0 -305
- package/lib/types/event/event.js +0 -1
- package/lib/types/event/index.d.ts +0 -12
- package/lib/types/event/index.js +0 -7
- package/lib/types/event/message.d.ts +0 -109
- package/lib/types/event/message.js +0 -74
- package/lib/types/event/notice.d.ts +0 -513
- package/lib/types/event/notice.js +0 -52
- package/lib/types/event/reply.d.ts +0 -50
- package/lib/types/event/reply.js +0 -1
- package/lib/types/event/request.d.ts +0 -126
- package/lib/types/event/request.js +0 -52
- package/lib/types/event/sender.d.ts +0 -44
- package/lib/types/event/sender.js +0 -1
- package/lib/types/index.d.ts +0 -13
- package/lib/types/index.js +0 -13
- package/lib/types/logger/logger.d.ts +0 -110
- package/lib/types/logger/logger.js +0 -1
- package/lib/types/onebot11/api.d.ts +0 -53
- package/lib/types/onebot11/api.js +0 -1
- package/lib/types/onebot11/event.d.ts +0 -619
- package/lib/types/onebot11/event.js +0 -2
- package/lib/types/onebot11/index.d.ts +0 -6
- package/lib/types/onebot11/index.js +0 -6
- package/lib/types/onebot11/params.d.ts +0 -609
- package/lib/types/onebot11/params.js +0 -1
- package/lib/types/onebot11/response.d.ts +0 -516
- package/lib/types/onebot11/response.js +0 -1
- package/lib/types/onebot11/segment.d.ts +0 -269
- package/lib/types/onebot11/segment.js +0 -1
- package/lib/types/onebot11/sender.d.ts +0 -59
- package/lib/types/onebot11/sender.js +0 -1
- package/lib/types/plugin/app.d.ts +0 -71
- package/lib/types/plugin/app.js +0 -1
- package/lib/types/plugin/plugin.d.ts +0 -473
- package/lib/types/plugin/plugin.js +0 -1
- package/lib/types/render/render.d.ts +0 -118
- package/lib/types/render/render.js +0 -1
- package/lib/types/type/global.d.ts +0 -25
- package/lib/types/type/global.js +0 -1
- package/lib/utils/common/common.d.ts +0 -236
- package/lib/utils/common/common.js +0 -708
- package/lib/utils/config/config.d.ts +0 -193
- package/lib/utils/config/config.js +0 -328
- package/lib/utils/config/updateVersion.d.ts +0 -33
- package/lib/utils/config/updateVersion.js +0 -145
- package/lib/utils/config/yamlEditor.d.ts +0 -101
- package/lib/utils/config/yamlEditor.js +0 -330
- package/lib/utils/core/handler.d.ts +0 -18
- package/lib/utils/core/handler.js +0 -46
- package/lib/utils/core/logger.d.ts +0 -3
- package/lib/utils/core/logger.js +0 -105
- package/lib/utils/core/segment.d.ts +0 -279
- package/lib/utils/core/segment.js +0 -451
- package/lib/utils/index.d.ts +0 -13
- package/lib/utils/index.js +0 -13
- package/lib/utils/tools/button.d.ts +0 -2
- package/lib/utils/tools/button.js +0 -27
- package/lib/utils/tools/exec.d.ts +0 -20
- package/lib/utils/tools/exec.js +0 -54
- package/lib/utils/tools/ffmpeg.d.ts +0 -12
- package/lib/utils/tools/ffmpeg.js +0 -25
- package/lib/utils/tools/restart.d.ts +0 -15
- package/lib/utils/tools/restart.js +0 -39
- package/lib/utils/tools/stop.d.ts +0 -7
- package/lib/utils/tools/stop.js +0 -13
- package/lib/utils/tools/update.d.ts +0 -67
- package/lib/utils/tools/update.js +0 -151
- /package/{config → default}/view/App.yaml +0 -0
- /package/{config → default}/view/config.yaml +0 -0
- /package/{config → default}/view/pm2.yaml +0 -0
- /package/{config → default}/view/redis.yaml +0 -0
- /package/{config → default}/view/server.yaml +0 -0
- /package/{lib/modules → dist/module}/art-template.js +0 -0
- /package/{lib/modules → dist/module}/axios.js +0 -0
- /package/{lib/modules → dist/module}/chalk.js +0 -0
- /package/{lib/modules → dist/module}/chokidar.js +0 -0
- /package/{lib/modules → dist/module}/level.js +0 -0
- /package/{lib/modules → dist/module}/lodash.js +0 -0
- /package/{lib/modules → dist/module}/log4js.js +0 -0
- /package/{lib/modules → dist/module}/moment.js +0 -0
- /package/{lib/modules → dist/module}/node-schedule.js +0 -0
- /package/{lib/modules → dist/module}/redis.js +0 -0
- /package/{lib/modules → dist/module}/yaml.js +0 -0
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import Yaml from 'yaml';
|
|
2
|
-
export type YamlValue = string | boolean | number | object | any[];
|
|
3
|
-
export declare class YamlEditor {
|
|
4
|
-
filePath: string;
|
|
5
|
-
doc: Yaml.Document;
|
|
6
|
-
document: Yaml.Document;
|
|
7
|
-
constructor(file: string);
|
|
8
|
-
/**
|
|
9
|
-
* 获取指定路径的值
|
|
10
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
11
|
-
*/
|
|
12
|
-
get(path: string): any;
|
|
13
|
-
/**
|
|
14
|
-
* 设置指定路径的值
|
|
15
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
16
|
-
* @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
|
|
17
|
-
*/
|
|
18
|
-
set(path: string, value: YamlValue): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* 向指定路径添加新值
|
|
21
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
22
|
-
* @param value - 要添加的值
|
|
23
|
-
*/
|
|
24
|
-
add(path: string, value: YamlValue): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* 删除指定路径
|
|
27
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
28
|
-
* @returns 是否删除成功
|
|
29
|
-
*/
|
|
30
|
-
del(path: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* 向指定路径的数组添加新值,可以选择添加到数组的开始或结束
|
|
33
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
34
|
-
* @param value - 要添加的值
|
|
35
|
-
* @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
|
|
36
|
-
*/
|
|
37
|
-
append(path: string, value: string, prepend?: boolean): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* 向指定路径的数组删除值
|
|
40
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
41
|
-
* @param value - 要删除的值
|
|
42
|
-
*/
|
|
43
|
-
remove(path: string, value: YamlValue): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* 检查指定路径的键是否存在
|
|
46
|
-
* @param path - 路径,用点号分隔
|
|
47
|
-
*/
|
|
48
|
-
has(path: string): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* 查询指定路径中是否包含指定的值
|
|
51
|
-
* @param path - 路径,用点号分隔
|
|
52
|
-
* @param value - 要查询的值
|
|
53
|
-
*/
|
|
54
|
-
hasval(path: string, value: YamlValue): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* 查询指定路径中是否包含指定的值
|
|
57
|
-
* @param path - 路径,用点号分隔
|
|
58
|
-
* @param value - 要查询的值
|
|
59
|
-
* @deprecated 请使用 `hasval` 代替
|
|
60
|
-
*/
|
|
61
|
-
hasVal(path: string, value: YamlValue): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
|
|
64
|
-
* @param value - 要新增的元素
|
|
65
|
-
*/
|
|
66
|
-
pusharr(value: YamlValue): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* 根据索引从根节点数组删除元素
|
|
69
|
-
* @param index - 要删除元素的索引
|
|
70
|
-
*/
|
|
71
|
-
delarr(index: number): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* 获取指定路径的pair对象
|
|
74
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
75
|
-
*/
|
|
76
|
-
getpair(path: string): any;
|
|
77
|
-
/**
|
|
78
|
-
* 设置指定键的注释
|
|
79
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
80
|
-
* @param comment - 要设置的注释
|
|
81
|
-
* @param prepend - 如果为 true,则添加到注释的开头,否则添加到同一行的末尾
|
|
82
|
-
*/
|
|
83
|
-
comment(path: string, comment: string, prepend: boolean): void;
|
|
84
|
-
/**
|
|
85
|
-
* 删除指定键的注释
|
|
86
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
87
|
-
* @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
|
|
88
|
-
*/
|
|
89
|
-
uncomment(path: string, type?: 'before' | 'after' | 'all'): void;
|
|
90
|
-
/**
|
|
91
|
-
* 检查注释是否存在
|
|
92
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
93
|
-
* @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
|
|
94
|
-
*/
|
|
95
|
-
hascomment(path: string, type: 'before' | 'after'): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* 保存文件
|
|
98
|
-
* 保存失败会抛出异常
|
|
99
|
-
*/
|
|
100
|
-
save(): void;
|
|
101
|
-
}
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* YamlEditor - 一个用于编辑 YAML 文件的类
|
|
3
|
-
* 本代码由 ChatGPT4 提供
|
|
4
|
-
* https://github.com/OpenAI
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import lodash from 'lodash';
|
|
8
|
-
import logger from '../core/logger.js';
|
|
9
|
-
import Yaml, { isMap, isSeq, isPair } from 'yaml';
|
|
10
|
-
export class YamlEditor {
|
|
11
|
-
filePath;
|
|
12
|
-
doc;
|
|
13
|
-
document;
|
|
14
|
-
constructor(file) {
|
|
15
|
-
this.filePath = file;
|
|
16
|
-
const data = Yaml.parseDocument(fs.readFileSync(file, 'utf8'));
|
|
17
|
-
this.doc = data;
|
|
18
|
-
this.document = data;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 获取指定路径的值
|
|
22
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
23
|
-
*/
|
|
24
|
-
get(path) {
|
|
25
|
-
try {
|
|
26
|
-
if (!path)
|
|
27
|
-
return this.document.toJSON();
|
|
28
|
-
return lodash.get(this.document.toJSON(), path);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
logger.error(`[YamlEditor] 获取数据时出错:${error}`);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 设置指定路径的值
|
|
37
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
38
|
-
* @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
|
|
39
|
-
*/
|
|
40
|
-
set(path, value) {
|
|
41
|
-
try {
|
|
42
|
-
const _path = typeof path === 'string' ? path.split('.') : path;
|
|
43
|
-
this.document.setIn(_path, value);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
logger.error(`[YamlEditor] 设置数据时出错:${error}`);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 向指定路径添加新值
|
|
53
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
54
|
-
* @param value - 要添加的值
|
|
55
|
-
*/
|
|
56
|
-
add(path, value) {
|
|
57
|
-
try {
|
|
58
|
-
const _path = typeof path === 'string' ? path.split('.') : path;
|
|
59
|
-
this.document.addIn(_path, value);
|
|
60
|
-
logger.debug(`[YamlEditor] 已在 ${path} 添加新的值`);
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
logger.error(`[YamlEditor] 添加数据时出错:${error}`);
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 删除指定路径
|
|
70
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
71
|
-
* @returns 是否删除成功
|
|
72
|
-
*/
|
|
73
|
-
del(path) {
|
|
74
|
-
try {
|
|
75
|
-
const _path = typeof path === 'string' ? path.split('.') : path;
|
|
76
|
-
this.document.deleteIn(_path);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
logger.error(`[YamlEditor] 删除数据时出错:${error}`);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 向指定路径的数组添加新值,可以选择添加到数组的开始或结束
|
|
86
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
87
|
-
* @param value - 要添加的值
|
|
88
|
-
* @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
|
|
89
|
-
*/
|
|
90
|
-
append(path, value, prepend = false) {
|
|
91
|
-
try {
|
|
92
|
-
const _path = typeof path === 'string' ? path.split('.') : path || [];
|
|
93
|
-
let current = this.document.getIn(_path);
|
|
94
|
-
if (!current) {
|
|
95
|
-
current = new Yaml.YAMLSeq();
|
|
96
|
-
this.document.setIn(_path, current);
|
|
97
|
-
}
|
|
98
|
-
else if (!(current instanceof Yaml.YAMLSeq)) {
|
|
99
|
-
logger.error('[YamlEditor] 指定的路径不是数组');
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
prepend ? current.items.unshift(value) : current.add(value);
|
|
104
|
-
}
|
|
105
|
-
logger.debug(`[YamlEditor] 已向 ${path} 数组${prepend ? '开头' : '末尾'}添加新元素:${value}`);
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
logger.error(`[YamlEditor] 向数组添加元素时出错:${error}`);
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* 向指定路径的数组删除值
|
|
115
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
116
|
-
* @param value - 要删除的值
|
|
117
|
-
*/
|
|
118
|
-
remove(path, value) {
|
|
119
|
-
try {
|
|
120
|
-
const _path = typeof path === 'string' ? path.split('.') : path;
|
|
121
|
-
const current = this.document.getIn(_path);
|
|
122
|
-
if (!current) {
|
|
123
|
-
logger.error('[YamlEditor] 指定的路径不存在');
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
if (!(current instanceof Yaml.YAMLSeq)) {
|
|
127
|
-
logger.error('[YamlEditor] 指定的路径不是数组');
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
const index = current.items.findIndex(item => lodash.isEqual(item.toJSON(), value));
|
|
131
|
-
if (index < 0) {
|
|
132
|
-
logger.error('[YamlEditor] 未找到要删除的值');
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
current.items.splice(index, 1);
|
|
136
|
-
logger.debug(`[YamlEditor] 已从 ${path} 数组删除元素:${value}`);
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
logger.error(`[YamlEditor] 从数组删除元素时出错:${error}`);
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 检查指定路径的键是否存在
|
|
146
|
-
* @param path - 路径,用点号分隔
|
|
147
|
-
*/
|
|
148
|
-
has(path) {
|
|
149
|
-
try {
|
|
150
|
-
const _path = typeof path === 'string' ? path.split('.') : path;
|
|
151
|
-
return this.document.hasIn(_path);
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
logger.error(`[YamlEditor] 检查路径是否存在时出错:${error}`);
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* 查询指定路径中是否包含指定的值
|
|
160
|
-
* @param path - 路径,用点号分隔
|
|
161
|
-
* @param value - 要查询的值
|
|
162
|
-
*/
|
|
163
|
-
hasval(path, value) {
|
|
164
|
-
try {
|
|
165
|
-
const _path = typeof path === 'string' ? path.split('.') : path;
|
|
166
|
-
const current = this.document.getIn(_path);
|
|
167
|
-
if (!current)
|
|
168
|
-
return false;
|
|
169
|
-
/** 检查当前节点是否包含指定的值 */
|
|
170
|
-
if (current instanceof Yaml.YAMLSeq) {
|
|
171
|
-
/** 如果是序列,遍历序列查找值 */
|
|
172
|
-
return current.items.some(item => lodash.isEqual(item.toJSON(), value));
|
|
173
|
-
}
|
|
174
|
-
else if (current instanceof Yaml.YAMLMap) {
|
|
175
|
-
/** 如果是映射,检查每个值 */
|
|
176
|
-
return Array.from(current.values()).some((v) => lodash.isEqual(v.toJSON(), value));
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
/** 否则,直接比较值 */
|
|
180
|
-
return lodash.isEqual(current, value);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
logger.error(`[YamlEditor] 检查路径 ${path} 是否包含值时出错:${error}`);
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* 查询指定路径中是否包含指定的值
|
|
190
|
-
* @param path - 路径,用点号分隔
|
|
191
|
-
* @param value - 要查询的值
|
|
192
|
-
* @deprecated 请使用 `hasval` 代替
|
|
193
|
-
*/
|
|
194
|
-
hasVal(path, value) {
|
|
195
|
-
return this.hasval(path, value);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
|
|
199
|
-
* @param value - 要新增的元素
|
|
200
|
-
*/
|
|
201
|
-
pusharr(value) {
|
|
202
|
-
try {
|
|
203
|
-
if (!(this.document.contents instanceof Yaml.YAMLSeq)) {
|
|
204
|
-
// 如果根节点不是数组,则将其转换为数组
|
|
205
|
-
this.document.contents = new Yaml.YAMLSeq();
|
|
206
|
-
logger.debug('[YamlEditor] 根节点已转换为数组');
|
|
207
|
-
}
|
|
208
|
-
this.document.contents.add(value);
|
|
209
|
-
logger.debug('[YamlEditor] 已向根节点数组新增元素:', value);
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
catch (error) {
|
|
213
|
-
logger.error(`[YamlEditor] 向根节点数组新增元素时出错:${error}`);
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* 根据索引从根节点数组删除元素
|
|
219
|
-
* @param index - 要删除元素的索引
|
|
220
|
-
*/
|
|
221
|
-
delarr(index) {
|
|
222
|
-
try {
|
|
223
|
-
if (!(this.document.contents instanceof Yaml.YAMLSeq)) {
|
|
224
|
-
throw new Error('[YamlEditor] 根节点不是数组');
|
|
225
|
-
}
|
|
226
|
-
if (index < 0 || index >= this.document.contents.items.length) {
|
|
227
|
-
throw new Error('[YamlEditor] 索引超出范围');
|
|
228
|
-
}
|
|
229
|
-
this.document.contents.items.splice(index, 1);
|
|
230
|
-
logger.debug('[YamlEditor] 已根据索引从根节点数组删除元素,索引:', index);
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
logger.error(`[YamlEditor] 根据索引删除根节点数组元素时出错:${error}`);
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* 获取指定路径的pair对象
|
|
240
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
241
|
-
*/
|
|
242
|
-
getpair(path) {
|
|
243
|
-
if (!path)
|
|
244
|
-
throw new Error('path is required');
|
|
245
|
-
const keys = path.split('.');
|
|
246
|
-
// 好多any啊,我要当any糕手~
|
|
247
|
-
let pair = this.document.contents;
|
|
248
|
-
keys.forEach(key => {
|
|
249
|
-
if (isMap(pair)) {
|
|
250
|
-
pair = pair.items.find((item) => item.key.value === key);
|
|
251
|
-
}
|
|
252
|
-
else if (isSeq(pair)) {
|
|
253
|
-
pair = pair.items.find((item) => item.value === key);
|
|
254
|
-
}
|
|
255
|
-
else if (isPair(pair)) {
|
|
256
|
-
pair = pair.value.items.find((item) => item.key.value === key);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
return pair;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* 设置指定键的注释
|
|
263
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
264
|
-
* @param comment - 要设置的注释
|
|
265
|
-
* @param prepend - 如果为 true,则添加到注释的开头,否则添加到同一行的末尾
|
|
266
|
-
*/
|
|
267
|
-
comment(path, comment, prepend) {
|
|
268
|
-
if (!path)
|
|
269
|
-
throw new Error('[YamlEditor] path 不能为空');
|
|
270
|
-
const pair = this.getpair(path);
|
|
271
|
-
if (!pair)
|
|
272
|
-
throw new Error(`[YamlEditor] 未找到节点 ${path}`);
|
|
273
|
-
comment = ` ${comment}`;
|
|
274
|
-
if (prepend) {
|
|
275
|
-
pair.key.commentBefore = comment;
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
pair.key.comment = comment;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* 删除指定键的注释
|
|
283
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
284
|
-
* @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
|
|
285
|
-
*/
|
|
286
|
-
uncomment(path, type = 'all') {
|
|
287
|
-
if (!path)
|
|
288
|
-
throw new Error('[YamlEditor] path 不能为空');
|
|
289
|
-
const pair = this.getpair(path);
|
|
290
|
-
if (!pair)
|
|
291
|
-
throw new Error(`[YamlEditor] 未找到节点 ${path}`);
|
|
292
|
-
if (type === 'all') {
|
|
293
|
-
delete pair.key.comment;
|
|
294
|
-
delete pair.key.commentBefore;
|
|
295
|
-
}
|
|
296
|
-
else if (type === 'before') {
|
|
297
|
-
delete pair.key.commentBefore;
|
|
298
|
-
}
|
|
299
|
-
else if (type === 'after') {
|
|
300
|
-
delete pair.key.comment;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* 检查注释是否存在
|
|
305
|
-
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
306
|
-
* @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
|
|
307
|
-
*/
|
|
308
|
-
hascomment(path, type) {
|
|
309
|
-
if (!path)
|
|
310
|
-
throw new Error('[YamlEditor] path 不能为空');
|
|
311
|
-
const pair = this.getpair(path);
|
|
312
|
-
if (!pair)
|
|
313
|
-
throw new Error(`[YamlEditor] 未找到节点 ${path}`);
|
|
314
|
-
if (type === 'before') {
|
|
315
|
-
return !!pair.key.commentBefore;
|
|
316
|
-
}
|
|
317
|
-
else if (type === 'after') {
|
|
318
|
-
return !!pair.key.comment;
|
|
319
|
-
}
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* 保存文件
|
|
324
|
-
* 保存失败会抛出异常
|
|
325
|
-
*/
|
|
326
|
-
save() {
|
|
327
|
-
fs.writeFileSync(this.filePath, this.document.toString());
|
|
328
|
-
logger.debug('[YamlEditor] 文件已保存');
|
|
329
|
-
}
|
|
330
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 事件处理器类
|
|
3
|
-
*/
|
|
4
|
-
export declare const handler: {
|
|
5
|
-
/**
|
|
6
|
-
* 调用事件处理器
|
|
7
|
-
* @param key 事件键
|
|
8
|
-
* @param args 自定义参数 一般用来传递e之类的
|
|
9
|
-
*/
|
|
10
|
-
call(key: string, args: {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
e?: any;
|
|
13
|
-
}): Promise<any>;
|
|
14
|
-
/**
|
|
15
|
-
* 检查是否存在指定键的事件处理器
|
|
16
|
-
*/
|
|
17
|
-
has(key: string): boolean;
|
|
18
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import logger from './logger.js';
|
|
2
|
-
import { pluginLoader as loader } from '../../core/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* 事件处理器类
|
|
5
|
-
*/
|
|
6
|
-
export const handler = new (class EventHandler {
|
|
7
|
-
/**
|
|
8
|
-
* 调用事件处理器
|
|
9
|
-
* @param key 事件键
|
|
10
|
-
* @param args 自定义参数 一般用来传递e之类的
|
|
11
|
-
*/
|
|
12
|
-
async call(key, args) {
|
|
13
|
-
let res;
|
|
14
|
-
for (const info of loader.handler[key] || []) {
|
|
15
|
-
const plugin = loader.plugin.get(info.key);
|
|
16
|
-
try {
|
|
17
|
-
let done = true;
|
|
18
|
-
/**
|
|
19
|
-
* 拒绝处理器 调用后则不再继续执行下一个处理器
|
|
20
|
-
* @param msg 错误信息
|
|
21
|
-
*/
|
|
22
|
-
const reject = (msg = '') => {
|
|
23
|
-
if (msg)
|
|
24
|
-
logger.mark(`[Handler][Reject]: [${plugin.plugin}][${info.name}][${key}] ${msg}`);
|
|
25
|
-
done = false;
|
|
26
|
-
};
|
|
27
|
-
res = await info.fn(args, reject);
|
|
28
|
-
if (done) {
|
|
29
|
-
logger.mark(`[Handler][Done]: [${plugin.plugin}][${info.name}][${key}]`);
|
|
30
|
-
return res;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
// 产生错误继续下一个处理器
|
|
35
|
-
logger.error(`[Handler][Error]: [${plugin.plugin}][${info.name}][${key}] ${e}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return res;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* 检查是否存在指定键的事件处理器
|
|
42
|
-
*/
|
|
43
|
-
has(key) {
|
|
44
|
-
return !!loader.handler[key];
|
|
45
|
-
}
|
|
46
|
-
})();
|
package/lib/utils/core/logger.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import log4js from 'log4js';
|
|
4
|
-
import { config } from '../config/config.js';
|
|
5
|
-
const logsDir = './logs';
|
|
6
|
-
if (!fs.existsSync(logsDir))
|
|
7
|
-
fs.mkdirSync(logsDir);
|
|
8
|
-
const { log_level, log_days_Keep, log4jsCfg } = config.Config;
|
|
9
|
-
const level = log_level || log4jsCfg.level || 'info';
|
|
10
|
-
const daysToKeep = log_days_Keep || log4jsCfg.daysToKeep || 7;
|
|
11
|
-
const { overall, fragments, maxLogSize } = log4jsCfg;
|
|
12
|
-
const defaultOptions = { appenders: ['console'], level, enableCallStack: process.env.KarinMode === 'dev' };
|
|
13
|
-
const options = {
|
|
14
|
-
appenders: {
|
|
15
|
-
console: {
|
|
16
|
-
type: 'console',
|
|
17
|
-
layout: {
|
|
18
|
-
type: 'pattern',
|
|
19
|
-
pattern: `%[[Karin][%d{hh:mm:ss.SSS}][%4.4p]%] ${process.env.KarinMode === 'dev' ? '[%f{3}:%l] ' : ''}%m`,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
categories: { default: defaultOptions },
|
|
24
|
-
};
|
|
25
|
-
if (overall) {
|
|
26
|
-
defaultOptions.appenders.unshift('overall');
|
|
27
|
-
options.appenders.overall = {
|
|
28
|
-
/** 输出到文件 */
|
|
29
|
-
type: 'file',
|
|
30
|
-
filename: 'logs/logger',
|
|
31
|
-
pattern: 'yyyy-MM-dd.log',
|
|
32
|
-
/** 日期后缀 */
|
|
33
|
-
keepFileExt: true,
|
|
34
|
-
/** 日志文件名中包含日期模式 */
|
|
35
|
-
alwaysIncludePattern: true,
|
|
36
|
-
/** 日志文件保留天数 */
|
|
37
|
-
daysToKeep,
|
|
38
|
-
/** 日志输出格式 */
|
|
39
|
-
layout: {
|
|
40
|
-
type: 'pattern',
|
|
41
|
-
pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (fragments) {
|
|
46
|
-
defaultOptions.appenders.unshift('fragments');
|
|
47
|
-
options.appenders.fragments = {
|
|
48
|
-
type: 'file',
|
|
49
|
-
filename: 'logs/app.log',
|
|
50
|
-
pattern: 'MM-dd.log',
|
|
51
|
-
keepFileExt: true,
|
|
52
|
-
alwaysIncludePattern: true,
|
|
53
|
-
daysToKeep,
|
|
54
|
-
maxLogSize: (maxLogSize || 30) * 1024 * 1024,
|
|
55
|
-
/** 最大文件数 */
|
|
56
|
-
numBackups: 9999999,
|
|
57
|
-
/** 日志输出格式 */
|
|
58
|
-
layout: {
|
|
59
|
-
type: 'pattern',
|
|
60
|
-
pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m',
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
log4js.configure(options);
|
|
65
|
-
export const logger = log4js.getLogger('default');
|
|
66
|
-
logger.chalk = chalk;
|
|
67
|
-
logger.red = chalk.red;
|
|
68
|
-
logger.green = chalk.green;
|
|
69
|
-
logger.yellow = chalk.yellow;
|
|
70
|
-
logger.blue = chalk.blue;
|
|
71
|
-
logger.magenta = chalk.magenta;
|
|
72
|
-
logger.cyan = chalk.cyan;
|
|
73
|
-
logger.white = chalk.white;
|
|
74
|
-
logger.gray = chalk.gray;
|
|
75
|
-
logger.violet = chalk.hex('#868ECC');
|
|
76
|
-
logger.fnc = chalk.hex(config.Config.log_color || '#FFFF00');
|
|
77
|
-
logger.bot = (level, id, ...args) => {
|
|
78
|
-
switch (level) {
|
|
79
|
-
case 'trace':
|
|
80
|
-
logger.trace(logger.violet(`[Bot:${id}]`), ...args);
|
|
81
|
-
break;
|
|
82
|
-
case 'debug':
|
|
83
|
-
logger.debug(logger.violet(`[Bot:${id}]`), ...args);
|
|
84
|
-
break;
|
|
85
|
-
case 'mark':
|
|
86
|
-
logger.mark(logger.violet(`[Bot:${id}]`), ...args);
|
|
87
|
-
break;
|
|
88
|
-
case 'info':
|
|
89
|
-
logger.info(logger.violet(`[Bot:${id}]`), ...args);
|
|
90
|
-
break;
|
|
91
|
-
case 'warn':
|
|
92
|
-
logger.warn(logger.violet(`[Bot:${id}]`), ...args);
|
|
93
|
-
break;
|
|
94
|
-
case 'error':
|
|
95
|
-
logger.error(logger.violet(`[Bot:${id}]`), ...args);
|
|
96
|
-
break;
|
|
97
|
-
case 'fatal':
|
|
98
|
-
logger.fatal(logger.violet(`[Bot:${id}]`), ...args);
|
|
99
|
-
break;
|
|
100
|
-
default:
|
|
101
|
-
logger.info(logger.violet(`[Bot:${id}]`), ...args);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
global.logger = logger;
|
|
105
|
-
export default logger;
|