node-karin 0.10.7 → 0.11.0
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/config/defSet/group.yaml +6 -6
- package/lib/adapter/onebot/11/convert.js +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/karin/karin.d.ts +41 -54
- package/lib/core/karin/karin.js +61 -54
- package/lib/core/listener/listener.js +14 -0
- package/lib/core/plugin/base.d.ts +10 -23
- package/lib/core/plugin/base.js +6 -15
- package/lib/core/plugin/loader.d.ts +79 -102
- package/lib/core/plugin/loader.js +440 -404
- package/lib/core/server/server.d.ts +1 -1
- package/lib/event/handler/base.d.ts +13 -4
- package/lib/event/handler/base.js +38 -20
- package/lib/event/handler/message.d.ts +11 -7
- package/lib/event/handler/message.js +111 -80
- package/lib/event/handler/notice.d.ts +1 -0
- package/lib/event/handler/notice.js +37 -36
- package/lib/event/handler/request.d.ts +1 -0
- package/lib/event/handler/request.js +32 -36
- package/lib/event/handler/review.d.ts +10 -10
- package/lib/event/handler/review.js +34 -39
- package/lib/types/config/config.d.ts +12 -2
- package/lib/types/event/contact.d.ts +1 -1
- package/lib/types/event/event.d.ts +9 -106
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/plugin/app.d.ts +71 -0
- package/lib/types/plugin/app.js +1 -0
- package/lib/types/plugin/plugin.d.ts +192 -12
- package/lib/utils/common/common.d.ts +19 -7
- package/lib/utils/common/common.js +74 -73
- package/lib/utils/config/config.d.ts +2 -2
- package/lib/utils/core/handler.d.ts +0 -14
- package/lib/utils/core/handler.js +7 -76
- package/lib/utils/tools/button.d.ts +1 -1
- package/lib/utils/tools/button.js +18 -29
- package/package.json +1 -1
- package/lib/core/plugin/app.d.ts +0 -19
- package/lib/core/plugin/app.js +0 -19
|
@@ -1,65 +1,27 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { UseInfo, AppsType, TaskInfo, ButtonInfo, AcceptInfo, CommandInfo, HandlerInfo, PluginInfoType, PluginTaskInfoType, PluginButtonInfoType, PluginAcceptInfoType, PluginHandlerInfoType, PluginCommandInfoType, PluginMiddlewareInfoType } from '../../types/index.js';
|
|
3
|
+
type AppType = CommandInfo | TaskInfo | HandlerInfo | ButtonInfo | AcceptInfo | UseInfo;
|
|
4
|
+
export interface AppFile {
|
|
5
|
+
/** 插件包名称 */
|
|
6
|
+
plugin: string;
|
|
7
|
+
/** 插件apps相对路径 */
|
|
8
|
+
path: string;
|
|
9
|
+
/** 插件文件名称 */
|
|
10
|
+
file: string;
|
|
11
|
+
/** 插件类型 */
|
|
12
|
+
type: `${AppsType}`;
|
|
13
|
+
/** 热更新 */
|
|
14
|
+
isWatch: boolean;
|
|
15
|
+
}
|
|
5
16
|
declare class PluginLoader {
|
|
6
17
|
dir: './plugins';
|
|
7
|
-
dirPath: string;
|
|
8
18
|
/**
|
|
9
19
|
* - 插件索引ID
|
|
10
20
|
*/
|
|
11
21
|
index: number;
|
|
12
|
-
/**
|
|
13
|
-
* - 命令插件索引列表
|
|
14
|
-
*/
|
|
15
|
-
ruleIds: Array<number>;
|
|
16
|
-
/**
|
|
17
|
-
* - 按钮插件索引列表
|
|
18
|
-
*/
|
|
19
|
-
buttonIds: Array<number>;
|
|
20
|
-
/**
|
|
21
|
-
* - accept插件索引列表
|
|
22
|
-
*/
|
|
23
|
-
acceptIds: Array<number>;
|
|
24
|
-
/**
|
|
25
|
-
* - handler
|
|
26
|
-
*/
|
|
27
|
-
handlerIds: {
|
|
28
|
-
[key: string]: Array<{
|
|
29
|
-
index: string;
|
|
30
|
-
fnc: string | Function;
|
|
31
|
-
priority: number;
|
|
32
|
-
}>;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* - 插件列表
|
|
36
|
-
*/
|
|
37
|
-
FileList: Array<AppInfo>;
|
|
38
|
-
/**
|
|
39
|
-
* - 是否ts环境
|
|
40
|
-
*/
|
|
41
|
-
isTs: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* - 是否开发环境
|
|
44
|
-
*/
|
|
45
|
-
isDev: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* - 最终缓存的插件列表 通过index索引
|
|
48
|
-
*/
|
|
49
|
-
PluginList: {
|
|
50
|
-
[key: string]: PluginApps;
|
|
51
|
-
};
|
|
52
22
|
/**
|
|
53
23
|
* - 定时任务
|
|
54
24
|
*/
|
|
55
|
-
task: Array<PluginTask & {
|
|
56
|
-
App: NewMessagePlugin;
|
|
57
|
-
schedule?: schedule.Job;
|
|
58
|
-
file: {
|
|
59
|
-
dir: dirName;
|
|
60
|
-
name: fileName;
|
|
61
|
-
};
|
|
62
|
-
}>;
|
|
63
25
|
/**
|
|
64
26
|
* - 监听器
|
|
65
27
|
*/
|
|
@@ -68,94 +30,109 @@ declare class PluginLoader {
|
|
|
68
30
|
* - 热更新列表
|
|
69
31
|
*/
|
|
70
32
|
watchList: Array<{
|
|
71
|
-
|
|
72
|
-
|
|
33
|
+
plugin: string;
|
|
34
|
+
path: string;
|
|
73
35
|
}>;
|
|
74
|
-
/**
|
|
75
|
-
* - 所有插件包package.json
|
|
76
|
-
*/
|
|
77
|
-
pkgJson: {
|
|
78
|
-
[key: string]: any;
|
|
79
|
-
};
|
|
80
36
|
/**
|
|
81
37
|
* - 依赖缺失收集
|
|
82
38
|
*/
|
|
83
39
|
dependErr: {
|
|
84
40
|
[key: string]: {
|
|
85
|
-
|
|
86
|
-
|
|
41
|
+
plugin: string;
|
|
42
|
+
path: string;
|
|
43
|
+
file: string;
|
|
87
44
|
depend: string;
|
|
88
45
|
};
|
|
89
46
|
};
|
|
47
|
+
/** accept */
|
|
48
|
+
accept: PluginAcceptInfoType[];
|
|
49
|
+
/** button */
|
|
50
|
+
button: PluginButtonInfoType[];
|
|
51
|
+
/** command规则集信息 */
|
|
52
|
+
command: PluginCommandInfoType[];
|
|
53
|
+
/** handler */
|
|
54
|
+
handler: {
|
|
55
|
+
[key: string]: PluginHandlerInfoType[];
|
|
56
|
+
};
|
|
57
|
+
/** plugin基本信息 */
|
|
58
|
+
plugin: PluginInfoType;
|
|
59
|
+
/** task定时任务信息 */
|
|
60
|
+
task: PluginTaskInfoType[];
|
|
61
|
+
/** 中间件 */
|
|
62
|
+
use: PluginMiddlewareInfoType;
|
|
63
|
+
/** 加载的文件数组 .js .ts */
|
|
64
|
+
ext: string[];
|
|
90
65
|
constructor();
|
|
91
66
|
/**
|
|
92
67
|
* 插件初始化
|
|
93
68
|
*/
|
|
94
69
|
load(): Promise<this>;
|
|
95
70
|
/**
|
|
96
|
-
*
|
|
71
|
+
* 获取Git插件
|
|
97
72
|
*/
|
|
98
|
-
|
|
73
|
+
getGitPlugin(): Promise<Promise<boolean>[]>;
|
|
99
74
|
/**
|
|
100
|
-
*
|
|
101
|
-
* @param dir - 插件包名称
|
|
102
|
-
* @param isTs - 是否获取ts插件
|
|
103
|
-
*/
|
|
104
|
-
getApps(dir: dirName, isTs: boolean, isWatch?: boolean): void;
|
|
105
|
-
/**
|
|
106
|
-
* 排序并打印插件信息
|
|
107
|
-
* @param isPrint - 是否打印
|
|
108
|
-
*/
|
|
109
|
-
orderBy(isPrint?: boolean): void;
|
|
110
|
-
/**
|
|
111
|
-
* 新增插件
|
|
112
|
-
* @param dir - 插件包路径
|
|
113
|
-
* @param name - 插件名称
|
|
114
|
-
* @param isOrderBy - 是否为动态导入 默认为静态导入
|
|
115
|
-
* @param isNpm - 是否为npm包
|
|
116
|
-
* @param isMain - 是否为主入口文件
|
|
75
|
+
* 获取Npm插件
|
|
117
76
|
*/
|
|
118
|
-
|
|
77
|
+
getNpmPlugin(): Promise<Promise<boolean>[]>;
|
|
119
78
|
/**
|
|
120
|
-
*
|
|
79
|
+
* 加载入口文件 只加载
|
|
80
|
+
* @param root - 插件根目录
|
|
81
|
+
* @param main - 入口文件
|
|
82
|
+
* @param isNpm - 是否为npm插件
|
|
121
83
|
*/
|
|
122
|
-
|
|
84
|
+
loadMain(root: string, main: string, isNpm: boolean): Promise<boolean>;
|
|
123
85
|
/**
|
|
124
|
-
*
|
|
86
|
+
* 获取ts插件入口 编译入口路径
|
|
87
|
+
* @param root - 插件根目录
|
|
88
|
+
* @param pkg - package.json
|
|
125
89
|
*/
|
|
126
|
-
|
|
90
|
+
getTsMain(root: string, pkg: any): Promise<{
|
|
91
|
+
/** 编译产物入口 */
|
|
92
|
+
outDir: string;
|
|
93
|
+
/** ts源码入口 */
|
|
94
|
+
rootDir: string;
|
|
95
|
+
}>;
|
|
127
96
|
/**
|
|
128
|
-
*
|
|
97
|
+
* 加载指定文件夹下的所有插件
|
|
98
|
+
* @param plugin - 插件名称
|
|
99
|
+
* @param _path - 插件apps相对路径
|
|
100
|
+
* @param file - 插件文件名称
|
|
101
|
+
* @param isNpm - 是否为npm插件
|
|
102
|
+
* @param isWatch - 是否监听热更新
|
|
129
103
|
*/
|
|
130
|
-
|
|
104
|
+
loadApps(plugin: string, _path: string, type: `${AppsType}`): Promise<boolean>[];
|
|
131
105
|
/**
|
|
132
|
-
*
|
|
106
|
+
* 排序并打印插件信息
|
|
107
|
+
* @param isPrint - 是否打印
|
|
133
108
|
*/
|
|
134
|
-
|
|
109
|
+
orderBy(isPrint?: boolean): void;
|
|
135
110
|
/**
|
|
136
|
-
*
|
|
111
|
+
* 新增插件
|
|
112
|
+
* @param plugin - 插件名称 例如: karin-plugin-example
|
|
113
|
+
* @param _path - 插件路径 例如: lib/apps 不存在则传空字符串
|
|
114
|
+
* @param file - 插件文件 例如: index.js ts目前解释器支持不够,暂不支持ts
|
|
115
|
+
* @param type - 插件类型 默认为git
|
|
116
|
+
* @param isOrderBy - 是否排序 开启会使用动态导入
|
|
137
117
|
*/
|
|
138
|
-
|
|
118
|
+
createdApp(plugin: string, _path: string, file: string, type?: `${AppsType}`, isOrderBy?: boolean): Promise<boolean>;
|
|
139
119
|
/**
|
|
140
|
-
*
|
|
120
|
+
* 缓存插件
|
|
121
|
+
* @param index - 插件索引
|
|
141
122
|
*/
|
|
142
|
-
|
|
123
|
+
cachePlugin(index: number, plugin: string, file: string, info: AppType, App?: any): Promise<boolean>;
|
|
143
124
|
/**
|
|
144
|
-
*
|
|
125
|
+
* 打印依赖缺失
|
|
145
126
|
*/
|
|
146
|
-
|
|
127
|
+
printDependErr(): void;
|
|
147
128
|
/**
|
|
148
129
|
* 卸载插件
|
|
149
130
|
*/
|
|
150
|
-
uninstallApp(
|
|
151
|
-
/**
|
|
152
|
-
* 监听单个文件热更新
|
|
153
|
-
*/
|
|
154
|
-
watch(dir: dirName, name: fileName): void;
|
|
131
|
+
uninstallApp(plugin: string, _path: string, file: string): void;
|
|
155
132
|
/**
|
|
156
133
|
* 监听文件夹更新
|
|
157
134
|
*/
|
|
158
|
-
watchDir(
|
|
135
|
+
watchDir(plugin: string, _path: string): Promise<boolean>;
|
|
159
136
|
}
|
|
160
137
|
/**
|
|
161
138
|
* 加载插件
|