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,4 +1,4 @@
|
|
|
1
|
-
import { KarinMessageType,
|
|
1
|
+
import { KarinMessageType, GroupCfg, KarinEventTypes, PluginCommandInfoType, PluginAcceptInfoType } from '../../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* 事件拦截器
|
|
4
4
|
* 利用可执行函数的特性,热更新所有拦截器
|
|
@@ -19,37 +19,37 @@ export declare const review: {
|
|
|
19
19
|
GroupEnable: (e: KarinEventTypes) => boolean;
|
|
20
20
|
UserEnable: (e: KarinEventTypes) => boolean;
|
|
21
21
|
GroupMsgPrint: (e: KarinEventTypes) => boolean;
|
|
22
|
-
PluginEnable: (app:
|
|
22
|
+
PluginEnable: (app: PluginCommandInfoType | PluginAcceptInfoType, config: GroupCfg) => boolean;
|
|
23
23
|
Private: () => boolean;
|
|
24
24
|
main(): void;
|
|
25
25
|
/**
|
|
26
26
|
* 群聊黑白名单 允许哪个群触发事件
|
|
27
27
|
*/
|
|
28
|
-
"__#
|
|
28
|
+
"__#11@#GroupEnable"(): true | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* 用户黑白名单 允许那个用户触发事件
|
|
31
31
|
*/
|
|
32
|
-
"__#
|
|
32
|
+
"__#11@#UserEnable"(): true | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* 群聊事件日志 是否打印
|
|
35
35
|
*/
|
|
36
|
-
"__#
|
|
36
|
+
"__#11@#GroupMsgPrint"(): true | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* 黑白名单插件 哪个插件可以被触发
|
|
39
39
|
*/
|
|
40
|
-
"__#
|
|
40
|
+
"__#11@#PluginEnable"(): boolean;
|
|
41
41
|
/** 群聊cd */
|
|
42
|
-
"__#
|
|
42
|
+
"__#11@#CD"(): true | undefined;
|
|
43
43
|
/**
|
|
44
44
|
* 响应模式
|
|
45
45
|
*/
|
|
46
|
-
"__#
|
|
46
|
+
"__#11@#mode"(): true | undefined;
|
|
47
47
|
/**
|
|
48
48
|
* 前缀、别名
|
|
49
49
|
*/
|
|
50
|
-
"__#
|
|
50
|
+
"__#11@#alias"(): true | undefined;
|
|
51
51
|
/**
|
|
52
52
|
* 私聊功能
|
|
53
53
|
*/
|
|
54
|
-
"__#
|
|
54
|
+
"__#11@#Private"(): true | undefined;
|
|
55
55
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { logger, config } from '../../utils/index.js';
|
|
2
|
+
import { pluginLoader } from '../../core/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* 事件拦截器
|
|
4
5
|
* 利用可执行函数的特性,热更新所有拦截器
|
|
@@ -193,36 +194,30 @@ export const review = new (class Handler {
|
|
|
193
194
|
/** 同时启用 */
|
|
194
195
|
if (this.App.GroupConfig.enable && this.App.GroupConfig.disable) {
|
|
195
196
|
this.PluginEnable = (app, config) => {
|
|
197
|
+
const plugin = pluginLoader.plugin[app.key];
|
|
196
198
|
/** 白名单不为空 */
|
|
197
199
|
if (Array.isArray(config.enable) && config.enable.length) {
|
|
198
200
|
/** 插件包是否处于功能白名单 */
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (config.enable.includes(app.name))
|
|
206
|
-
return true;
|
|
201
|
+
for (const key of config.enable) {
|
|
202
|
+
if (key.plugin === plugin.plugin)
|
|
203
|
+
return true;
|
|
204
|
+
if (key.name === plugin.file || key.name === app.name)
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
207
|
logger.debug(logger.green(`[功能白名单] 插件名称 [${app.name}] 不存在功能白名单中`));
|
|
208
208
|
return false;
|
|
209
209
|
}
|
|
210
210
|
/** 白名单为空 检查黑名单是否为空 */
|
|
211
211
|
if (Array.isArray(config.disable) && config.disable.length) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
/** 插件名称是否处于功能黑名单 */
|
|
223
|
-
if (config.disable.includes(app.name)) {
|
|
224
|
-
logger.debug(logger.red(`[功能黑名单] 插件名称 [${app.name}] 处于功能黑名单`));
|
|
225
|
-
return false;
|
|
212
|
+
for (const key of config.disable) {
|
|
213
|
+
if (key.plugin === plugin.plugin) {
|
|
214
|
+
logger.debug(logger.red(`[功能黑名单] 插件包 [${app.name}] 处于功能黑名单`));
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (key.name === plugin.file || key.name === app.name) {
|
|
218
|
+
logger.debug(logger.red(`[功能黑名单] 插件 [${app.name}] 处于功能黑名单`));
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
226
221
|
}
|
|
227
222
|
return true;
|
|
228
223
|
}
|
|
@@ -234,13 +229,14 @@ export const review = new (class Handler {
|
|
|
234
229
|
/** 白名单启用 */
|
|
235
230
|
if (this.App.GroupConfig.enable) {
|
|
236
231
|
this.PluginEnable = (app, config) => {
|
|
232
|
+
const plugin = pluginLoader.plugin[app.key];
|
|
237
233
|
if (Array.isArray(config.enable) && config.enable.length) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
234
|
+
for (const key of config.enable) {
|
|
235
|
+
if (key.plugin === plugin.plugin)
|
|
236
|
+
return true;
|
|
237
|
+
if (key.name === plugin.file || key.name === app.name)
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
244
240
|
logger.debug(logger.green(`[功能白名单] 插件名称 [${app.name}] 不存在功能白名单中`));
|
|
245
241
|
return false;
|
|
246
242
|
}
|
|
@@ -251,18 +247,17 @@ export const review = new (class Handler {
|
|
|
251
247
|
/** 黑名单启用 */
|
|
252
248
|
if (this.App.GroupConfig.disable) {
|
|
253
249
|
this.PluginEnable = (app, config) => {
|
|
250
|
+
const plugin = pluginLoader.plugin[app.key];
|
|
254
251
|
if (Array.isArray(config.disable) && config.disable.length) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
logger.debug(logger.red(`[功能黑名单] 插件名称 [${app.name}] 处于功能黑名单`));
|
|
265
|
-
return false;
|
|
252
|
+
for (const key of config.disable) {
|
|
253
|
+
if (key.plugin === plugin.plugin) {
|
|
254
|
+
logger.debug(logger.red(`[功能黑名单] 插件包 [${app.name}] 处于功能黑名单`));
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (key.name === plugin.file || key.name === app.name) {
|
|
258
|
+
logger.debug(logger.red(`[功能黑名单] 插件 [${app.name}] 处于功能黑名单`));
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
266
261
|
}
|
|
267
262
|
return true;
|
|
268
263
|
}
|
|
@@ -361,9 +361,19 @@ export interface GroupCfg {
|
|
|
361
361
|
/**
|
|
362
362
|
* 白名单插件、功能,只有在白名单中的插件、功能才会响应
|
|
363
363
|
*/
|
|
364
|
-
enable:
|
|
364
|
+
enable: {
|
|
365
|
+
/** 插件包名称 */
|
|
366
|
+
plugin: string;
|
|
367
|
+
/** 插件文件名或插件名称 */
|
|
368
|
+
name: string;
|
|
369
|
+
}[];
|
|
365
370
|
/**
|
|
366
371
|
* 黑名单插件、功能,黑名单中的插件、功能不会响应
|
|
367
372
|
*/
|
|
368
|
-
disable:
|
|
373
|
+
disable: {
|
|
374
|
+
/** 插件包名称 */
|
|
375
|
+
plugin: string;
|
|
376
|
+
/** 插件文件名或插件名称 */
|
|
377
|
+
name: string;
|
|
378
|
+
}[];
|
|
369
379
|
}
|
|
@@ -139,122 +139,25 @@ export type EventToSubEvent = {
|
|
|
139
139
|
[EventType.Request]: RequestSubType;
|
|
140
140
|
};
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
142
|
+
* 所有消息事件类型
|
|
143
143
|
*/
|
|
144
|
-
export
|
|
145
|
-
/**
|
|
146
|
-
* - 消息事件: 群消息
|
|
147
|
-
*/
|
|
148
|
-
MessageGroupMessage = "message.group_message",
|
|
149
|
-
/**
|
|
150
|
-
* - 消息事件: 私聊消息
|
|
151
|
-
*/
|
|
152
|
-
MessagePrivateMessage = "message.private_message",
|
|
153
|
-
/**
|
|
154
|
-
* - 消息事件: 频道消息
|
|
155
|
-
*/
|
|
156
|
-
MessageGuildMessage = "message.guild_message",
|
|
157
|
-
/**
|
|
158
|
-
* - 消息事件: 附近消息
|
|
159
|
-
*/
|
|
160
|
-
MessageNearby = "message.nearby",
|
|
161
|
-
/**
|
|
162
|
-
* - 消息事件: 陌生人消息
|
|
163
|
-
*/
|
|
164
|
-
MessageStranger = "message.stranger",
|
|
165
|
-
/**
|
|
166
|
-
* - 通知事件: 私聊戳一戳
|
|
167
|
-
*/
|
|
168
|
-
NoticePrivatePoke = "notice.private_poke",
|
|
169
|
-
/**
|
|
170
|
-
* - 通知事件: 私聊撤回消息
|
|
171
|
-
*/
|
|
172
|
-
NoticePrivateRecall = "notice.private_recall",
|
|
173
|
-
/**
|
|
174
|
-
* - 通知事件: 私聊发送文件
|
|
175
|
-
*/
|
|
176
|
-
NoticePrivateFileUploaded = "notice.private_file_uploaded",
|
|
177
|
-
/**
|
|
178
|
-
* - 通知事件: 群聊戳一戳
|
|
179
|
-
*/
|
|
180
|
-
NoticeGroupPoke = "notice.group_poke",
|
|
181
|
-
/**
|
|
182
|
-
* - 通知事件: 群聊名片变动
|
|
183
|
-
*/
|
|
184
|
-
NoticeGroupCardChanged = "notice.group_card_changed",
|
|
185
|
-
/**
|
|
186
|
-
* - 通知事件: 群聊成员头衔变动
|
|
187
|
-
*/
|
|
188
|
-
NoticeGroupMemberUniqueTitleChanged = "notice.group_member_unique_title_changed",
|
|
189
|
-
/**
|
|
190
|
-
* - 通知事件: 群聊精华消息变动
|
|
191
|
-
*/
|
|
192
|
-
NoticeGroupEssenceChanged = "notice.group_essence_changed",
|
|
193
|
-
/**
|
|
194
|
-
* - 通知事件: 群聊撤回消息
|
|
195
|
-
*/
|
|
196
|
-
NoticeGroupRecall = "notice.group_recall",
|
|
197
|
-
/**
|
|
198
|
-
* - 通知事件: 群聊成员增加
|
|
199
|
-
*/
|
|
200
|
-
NoticeGroupMemberIncrease = "notice.group_member_increase",
|
|
201
|
-
/**
|
|
202
|
-
* - 通知事件: 群聊成员减少
|
|
203
|
-
*/
|
|
204
|
-
NoticeGroupMemberDecrease = "notice.group_member_decrease",
|
|
205
|
-
/**
|
|
206
|
-
* - 通知事件: 群聊管理员变动
|
|
207
|
-
*/
|
|
208
|
-
NoticeGroupAdminChanged = "notice.group_admin_changed",
|
|
209
|
-
/**
|
|
210
|
-
* - 通知事件: 群聊成员禁言
|
|
211
|
-
*/
|
|
212
|
-
NoticeGroupMemberBan = "notice.group_member_ban",
|
|
213
|
-
/**
|
|
214
|
-
* - 通知事件: 群聊签到
|
|
215
|
-
*/
|
|
216
|
-
NoticeGroupSignIn = "notice.group_sign_in",
|
|
217
|
-
/**
|
|
218
|
-
* - 通知事件: 群聊全员禁言
|
|
219
|
-
*/
|
|
220
|
-
NoticeGroupWholeBan = "notice.group_whole_ban",
|
|
221
|
-
/**
|
|
222
|
-
* - 通知事件: 群聊发送文件
|
|
223
|
-
*/
|
|
224
|
-
NoticeGroupFileUploaded = "notice.group_file_uploaded",
|
|
225
|
-
/**
|
|
226
|
-
* - 通知事件: 群聊消息表情动态回应
|
|
227
|
-
*/
|
|
228
|
-
NoticeGroupMessageReaction = "notice.group_message_reaction",
|
|
229
|
-
/**
|
|
230
|
-
* - 请求事件: 好友申请
|
|
231
|
-
*/
|
|
232
|
-
RequestPrivateApply = "request.private_apply",
|
|
233
|
-
/**
|
|
234
|
-
* - 请求事件: 群聊申请
|
|
235
|
-
*/
|
|
236
|
-
RequestGroupApply = "request.group_apply",
|
|
237
|
-
/**
|
|
238
|
-
* - 请求事件: 邀请入群
|
|
239
|
-
*/
|
|
240
|
-
RequestInvitedGroup = "request.invited_group"
|
|
241
|
-
}
|
|
144
|
+
export type AllMessageSubType = `${EventType.Message}` | `${EventType.Message}.${MessageSubType}`;
|
|
242
145
|
/**
|
|
243
|
-
*
|
|
146
|
+
* 所有通知事件类型
|
|
244
147
|
*/
|
|
245
|
-
export type
|
|
148
|
+
export type AllNoticeSubType = `${EventType.Notice}` | `${EventType.Notice}.${NoticeSubType}`;
|
|
246
149
|
/**
|
|
247
|
-
*
|
|
150
|
+
* 所有请求事件类型
|
|
248
151
|
*/
|
|
249
|
-
export type
|
|
152
|
+
export type AllRequestSubType = `${EventType.Request}` | `${EventType.Request}.${RequestSubType}`;
|
|
250
153
|
/**
|
|
251
|
-
*
|
|
154
|
+
* 所有组合事件类型
|
|
252
155
|
*/
|
|
253
|
-
export type
|
|
156
|
+
export type CombinedEventType = AllMessageSubType | AllNoticeSubType | AllRequestSubType;
|
|
254
157
|
/**
|
|
255
158
|
* 所有监听事件
|
|
256
159
|
*/
|
|
257
|
-
export type AllListenEvent =
|
|
160
|
+
export type AllListenEvent = `${EventType}` | `${CombinedEventType}`;
|
|
258
161
|
/**
|
|
259
162
|
* 事件基类定义
|
|
260
163
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './element/qqbot.js';
|
|
|
5
5
|
export * from './event/index.js';
|
|
6
6
|
export * from './logger/logger.js';
|
|
7
7
|
export * from './render/render.js';
|
|
8
|
+
export * from './plugin/app.js';
|
|
8
9
|
export * from './plugin/plugin.js';
|
|
9
10
|
export * from './event/reply.js';
|
|
10
11
|
export * from './adapter/api.js';
|
package/lib/types/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './element/qqbot.js'
|
|
|
5
5
|
export * from './event/index.js'
|
|
6
6
|
export * from './logger/logger.js'
|
|
7
7
|
export * from './render/render.js'
|
|
8
|
+
export * from './plugin/app.js'
|
|
8
9
|
export * from './plugin/plugin.js'
|
|
9
10
|
export * from './event/reply.js'
|
|
10
11
|
export * from './adapter/api.js'
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { MiddlewareType } from '../../core/karin/karin.js';
|
|
2
|
+
import { AllMessageSubType, AllNoticeSubType, AllRequestSubType, KarinMessageType, KarinNoticeType, KarinRequestType, NewMessagePlugin, Permission } from '../../types/index.js';
|
|
3
|
+
export declare const enum AppType {
|
|
4
|
+
Command = "command",
|
|
5
|
+
Task = "task",
|
|
6
|
+
Handler = "handler",
|
|
7
|
+
Button = "button",
|
|
8
|
+
Accept = "accept",
|
|
9
|
+
Use = "use"
|
|
10
|
+
}
|
|
11
|
+
interface AppInfo {
|
|
12
|
+
/** 实现方法 */
|
|
13
|
+
fn: Function;
|
|
14
|
+
/** 插件名称 */
|
|
15
|
+
name: string;
|
|
16
|
+
/** 插件类型 */
|
|
17
|
+
type: `${AppType}`;
|
|
18
|
+
/** 插件优先级 */
|
|
19
|
+
rank: number;
|
|
20
|
+
/** 执行方法打印日志函数 */
|
|
21
|
+
log: Function;
|
|
22
|
+
}
|
|
23
|
+
/** command规则集类型 */
|
|
24
|
+
export interface CommandInfo extends AppInfo {
|
|
25
|
+
fn: (e: KarinMessageType) => Promise<boolean>;
|
|
26
|
+
/** 插件执行方法名称 */
|
|
27
|
+
fnname: string;
|
|
28
|
+
type: `${AppType.Command}`;
|
|
29
|
+
/** 监听事件 */
|
|
30
|
+
event: `${AllMessageSubType}`;
|
|
31
|
+
/** 正则 */
|
|
32
|
+
reg: RegExp;
|
|
33
|
+
/** 权限 */
|
|
34
|
+
perm: `${Permission}`;
|
|
35
|
+
/** class */
|
|
36
|
+
data: NewMessagePlugin | '';
|
|
37
|
+
}
|
|
38
|
+
/** task规则集类型 */
|
|
39
|
+
export interface TaskInfo extends Omit<AppInfo, 'rank'> {
|
|
40
|
+
type: `${AppType.Task}`;
|
|
41
|
+
/** 任务名称 */
|
|
42
|
+
fnname: string;
|
|
43
|
+
/** cron表达式 */
|
|
44
|
+
cron: string;
|
|
45
|
+
}
|
|
46
|
+
/** handler规则集类型 */
|
|
47
|
+
export interface HandlerInfo extends Omit<AppInfo, 'log'> {
|
|
48
|
+
type: `${AppType.Handler}`;
|
|
49
|
+
/** 入口秘钥 */
|
|
50
|
+
key: string;
|
|
51
|
+
}
|
|
52
|
+
/** button规则集类型 */
|
|
53
|
+
export interface ButtonInfo extends AppInfo {
|
|
54
|
+
type: `${AppType.Button}`;
|
|
55
|
+
/** 正则 */
|
|
56
|
+
reg: RegExp;
|
|
57
|
+
}
|
|
58
|
+
/** accept规则集类型 */
|
|
59
|
+
export interface AcceptInfo extends AppInfo {
|
|
60
|
+
fn: (e: KarinNoticeType | KarinRequestType) => Promise<boolean>;
|
|
61
|
+
type: `${AppType.Accept}`;
|
|
62
|
+
/** 监听事件 */
|
|
63
|
+
event: `${AllNoticeSubType}` | `${AllRequestSubType}`;
|
|
64
|
+
}
|
|
65
|
+
/** use规则集类型 */
|
|
66
|
+
export interface UseInfo extends Omit<AppInfo, 'log'> {
|
|
67
|
+
type: `${AppType.Use}`;
|
|
68
|
+
/** 中间件类型key */
|
|
69
|
+
key: `${MiddlewareType}`;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import schedule from 'node-schedule';
|
|
2
2
|
import { Plugin } from '../../core/index.js';
|
|
3
3
|
import { Reply, replyCallback, replyForward } from '../event/reply.js';
|
|
4
|
-
import { KarinNoticeType, KarinRequestType, AllListenEvent, KarinMessageType, PermissionType } from '../event/index.js';
|
|
4
|
+
import { KarinNoticeType, KarinRequestType, AllListenEvent, KarinMessageType, PermissionType, AllMessageSubType, Contact, AllNoticeSubType, AllRequestSubType } from '../event/index.js';
|
|
5
|
+
import { KarinElement } from '../element/element.js';
|
|
5
6
|
/**
|
|
6
7
|
* - 插件根目录名称
|
|
7
8
|
* - 例如: karin-plugin-example
|
|
@@ -15,6 +16,190 @@ export type dirName = `karin-plugin-${string}` | string;
|
|
|
15
16
|
* - 例如: index.js index.ts
|
|
16
17
|
*/
|
|
17
18
|
export type fileName = `${string}.js` | `${string}.ts`;
|
|
19
|
+
/**
|
|
20
|
+
* 插件类型枚举
|
|
21
|
+
*/
|
|
22
|
+
export declare const enum AppsType {
|
|
23
|
+
/** git插件 */
|
|
24
|
+
Git = "git",
|
|
25
|
+
/** npm插件 */
|
|
26
|
+
Npm = "npm",
|
|
27
|
+
/** 单个app插件 */
|
|
28
|
+
Js = "js"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 插件实现方法类型
|
|
32
|
+
*/
|
|
33
|
+
export declare const enum MethodType {
|
|
34
|
+
/** 函数 */
|
|
35
|
+
Function = "function",
|
|
36
|
+
/** 类 */
|
|
37
|
+
Class = "class"
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* plugin基本信息
|
|
41
|
+
*/
|
|
42
|
+
export interface PluginInfoType {
|
|
43
|
+
[key: string]: {
|
|
44
|
+
/** 插件包类型 */
|
|
45
|
+
type: `${AppsType}`;
|
|
46
|
+
/** 插件包名称 例: `karin-plugin-example` `@karinjs/adapter-qqbot` */
|
|
47
|
+
plugin: string;
|
|
48
|
+
/** 插件路径 在type为js下,path为空 */
|
|
49
|
+
path: string;
|
|
50
|
+
/** 插件文件名称 index.js index.ts */
|
|
51
|
+
file: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Command规则集信息
|
|
56
|
+
*/
|
|
57
|
+
export interface PluginCommandInfoType {
|
|
58
|
+
/** 插件基本信息的映射key */
|
|
59
|
+
key: string;
|
|
60
|
+
/** 插件包名称 */
|
|
61
|
+
name: string;
|
|
62
|
+
/** 插件正则 */
|
|
63
|
+
reg: RegExp;
|
|
64
|
+
/** 插件执行方法 */
|
|
65
|
+
fn: (e: KarinMessageType) => Promise<boolean>;
|
|
66
|
+
/** 插件执行方法名称 */
|
|
67
|
+
fnname: string;
|
|
68
|
+
/** 插件类型 */
|
|
69
|
+
type: `${MethodType}`;
|
|
70
|
+
/** 在type为class的时候 data为class 否则为空字符串 */
|
|
71
|
+
data: (() => PluginType) | undefined;
|
|
72
|
+
/** 插件执行权限 */
|
|
73
|
+
perm: `${PermissionType}`;
|
|
74
|
+
/** 执行打印日志方法 */
|
|
75
|
+
log: Function;
|
|
76
|
+
/** 监听的子事件 高于父事件 */
|
|
77
|
+
event: AllMessageSubType;
|
|
78
|
+
/** 优先级 */
|
|
79
|
+
rank: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* accept规则集信息
|
|
83
|
+
*/
|
|
84
|
+
export interface PluginAcceptInfoType {
|
|
85
|
+
/** 插件基本信息的映射key */
|
|
86
|
+
key: string;
|
|
87
|
+
/** 插件包名称 */
|
|
88
|
+
name: string;
|
|
89
|
+
/** 插件执行方法 */
|
|
90
|
+
fn: (e: KarinNoticeType | KarinRequestType) => Promise<boolean>;
|
|
91
|
+
/** 优先级 */
|
|
92
|
+
rank: number;
|
|
93
|
+
/** 监听事件 */
|
|
94
|
+
event: AllNoticeSubType | AllRequestSubType;
|
|
95
|
+
/** 执行打印日志方法 */
|
|
96
|
+
log: Function;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* task规则集信息
|
|
100
|
+
*/
|
|
101
|
+
export interface PluginTaskInfoType {
|
|
102
|
+
/** 插件基本信息的映射key */
|
|
103
|
+
key: string;
|
|
104
|
+
/** 插件包名称 */
|
|
105
|
+
name: string;
|
|
106
|
+
/** 任务名称 */
|
|
107
|
+
taskname: string;
|
|
108
|
+
/** cron表达式 */
|
|
109
|
+
cron: string;
|
|
110
|
+
/** 任务执行方法 */
|
|
111
|
+
fn: Function;
|
|
112
|
+
/** 在type为class的时候 data为class 否则为空字符串 */
|
|
113
|
+
data: (() => PluginType) | undefined;
|
|
114
|
+
/** 执行打印日志方法 */
|
|
115
|
+
log: Function;
|
|
116
|
+
/** 停止函数 */
|
|
117
|
+
schedule: schedule.Job;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* button规则集信息
|
|
121
|
+
*/
|
|
122
|
+
export interface PluginButtonInfoType {
|
|
123
|
+
/** 插件基本信息的映射key */
|
|
124
|
+
key: string;
|
|
125
|
+
/** 插件包名称 */
|
|
126
|
+
name: string;
|
|
127
|
+
/** 插件正则 */
|
|
128
|
+
reg: RegExp;
|
|
129
|
+
/** 插件执行方法 */
|
|
130
|
+
fn: (reject: Function, e?: KarinMessageType) => Promise<any>;
|
|
131
|
+
/** 优先级 */
|
|
132
|
+
rank: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* handler规则集信息
|
|
136
|
+
*/
|
|
137
|
+
export interface PluginHandlerInfoType {
|
|
138
|
+
/** 插件基本信息的映射key */
|
|
139
|
+
key: string;
|
|
140
|
+
/** 插件包名称 */
|
|
141
|
+
name: string;
|
|
142
|
+
/** handler的处理方法 */
|
|
143
|
+
fn: (args: any, reject: (msg?: string) => void) => Promise<any>;
|
|
144
|
+
/** 优先级 */
|
|
145
|
+
rank: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 中间件规则集信息
|
|
149
|
+
*/
|
|
150
|
+
export interface PluginMiddlewareInfoType {
|
|
151
|
+
/** 初始化消息前 */
|
|
152
|
+
recvMsg: Array<{
|
|
153
|
+
/** 插件基本信息的映射key */
|
|
154
|
+
key: string;
|
|
155
|
+
/** 插件包名称 */
|
|
156
|
+
name: string;
|
|
157
|
+
/** 插件执行方法 */
|
|
158
|
+
fn: (
|
|
159
|
+
/** 消息事件方法 */
|
|
160
|
+
e: KarinMessageType,
|
|
161
|
+
/** 是否继续执行插件 */
|
|
162
|
+
next: Function) => Promise<boolean>;
|
|
163
|
+
/** 优先级 */
|
|
164
|
+
rank: number;
|
|
165
|
+
}>;
|
|
166
|
+
/** 回复消息前 */
|
|
167
|
+
replyMsg: Array<{
|
|
168
|
+
/** 插件基本信息的映射key */
|
|
169
|
+
key: string;
|
|
170
|
+
/** 插件包名称 */
|
|
171
|
+
name: string;
|
|
172
|
+
/** 插件执行方法 */
|
|
173
|
+
fn: (
|
|
174
|
+
/** 消息事件方法 */
|
|
175
|
+
e: KarinMessageType,
|
|
176
|
+
/** 回复的消息体 */
|
|
177
|
+
element: KarinElement[],
|
|
178
|
+
/** 是否继续执行插件 */
|
|
179
|
+
next: Function) => Promise<boolean>;
|
|
180
|
+
/** 优先级 */
|
|
181
|
+
rank: number;
|
|
182
|
+
}>;
|
|
183
|
+
/** 发送主动消息前 */
|
|
184
|
+
sendMsg: Array<{
|
|
185
|
+
/** 插件基本信息的映射key */
|
|
186
|
+
key: string;
|
|
187
|
+
/** 插件包名称 */
|
|
188
|
+
name: string;
|
|
189
|
+
/** 插件执行方法 */
|
|
190
|
+
fn: (
|
|
191
|
+
/** 发送的bot */
|
|
192
|
+
uid: string,
|
|
193
|
+
/** 发送目标 */
|
|
194
|
+
contact: Contact,
|
|
195
|
+
/** 发送的消息体 */
|
|
196
|
+
element: KarinElement[],
|
|
197
|
+
/** 是否继续执行插件 */
|
|
198
|
+
next: Function) => Promise<boolean>;
|
|
199
|
+
/** 优先级 */
|
|
200
|
+
rank: number;
|
|
201
|
+
}>;
|
|
202
|
+
}
|
|
18
203
|
/**
|
|
19
204
|
* 上下文状态
|
|
20
205
|
*/
|
|
@@ -45,7 +230,11 @@ export interface PluginRule {
|
|
|
45
230
|
/**
|
|
46
231
|
* - 监听子事件
|
|
47
232
|
*/
|
|
48
|
-
event?:
|
|
233
|
+
event?: AllMessageSubType;
|
|
234
|
+
/**
|
|
235
|
+
* - 优先级 默认为10000
|
|
236
|
+
*/
|
|
237
|
+
priority?: number;
|
|
49
238
|
/**
|
|
50
239
|
* 权限
|
|
51
240
|
*/
|
|
@@ -141,11 +330,6 @@ export interface PluginType {
|
|
|
141
330
|
* - 插件名称
|
|
142
331
|
*/
|
|
143
332
|
name: string;
|
|
144
|
-
/**
|
|
145
|
-
* - 插件描述
|
|
146
|
-
* @deprecated 请使用desc
|
|
147
|
-
*/
|
|
148
|
-
dsc: string;
|
|
149
333
|
/**
|
|
150
334
|
* - 插件描述
|
|
151
335
|
*/
|
|
@@ -153,7 +337,7 @@ export interface PluginType {
|
|
|
153
337
|
/**
|
|
154
338
|
* - 监听事件 默认为message
|
|
155
339
|
*/
|
|
156
|
-
event:
|
|
340
|
+
event: AllMessageSubType;
|
|
157
341
|
/**
|
|
158
342
|
* - 优先级 默认为10000
|
|
159
343
|
*/
|
|
@@ -166,10 +350,6 @@ export interface PluginType {
|
|
|
166
350
|
* - 命令规则
|
|
167
351
|
*/
|
|
168
352
|
rule: Array<PluginRule>;
|
|
169
|
-
/**
|
|
170
|
-
* - 按钮
|
|
171
|
-
*/
|
|
172
|
-
button: Array<PluginButton>;
|
|
173
353
|
/**
|
|
174
354
|
* - handler
|
|
175
355
|
*/
|