alemonjs 2.1.0-alpha.50 → 2.1.0-alpha.52
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/README.md +0 -88
- package/lib/{datastructure → app}/SinglyLinkedList.d.ts +2 -3
- package/lib/{datastructure → app}/SinglyLinkedList.js +14 -18
- package/lib/app/define-chidren.d.ts +2 -11
- package/lib/app/define-chidren.js +0 -6
- package/lib/app/define-middleware.d.ts +2 -5
- package/lib/app/define-response.d.ts +3 -11
- package/lib/app/define-response.js +0 -5
- package/lib/app/event-group.d.ts +1 -9
- package/lib/app/event-group.js +0 -7
- package/lib/app/event-middleware.d.ts +3 -27
- package/lib/app/event-middleware.js +0 -16
- package/lib/app/event-processor-callHandler.d.ts +1 -0
- package/lib/app/event-processor-callHandler.js +0 -3
- package/lib/app/event-processor-cycle.d.ts +2 -18
- package/lib/app/event-processor-cycle.js +0 -15
- package/lib/app/event-processor-cycleFiles.d.ts +2 -0
- package/lib/app/event-processor-cycleFiles.js +91 -0
- package/lib/app/event-processor-cycleRoute.d.ts +2 -0
- package/lib/app/{event-processor-event-route.js → event-processor-cycleRoute.js} +5 -34
- package/lib/app/event-processor-event.d.ts +2 -19
- package/lib/app/event-processor-event.js +9 -92
- package/lib/app/event-processor-middleware.d.ts +2 -19
- package/lib/app/event-processor-middleware.js +9 -89
- package/lib/app/event-processor-subscribe.d.ts +5 -40
- package/lib/app/event-processor-subscribe.js +4 -44
- package/lib/app/event-processor.d.ts +3 -20
- package/lib/app/event-processor.js +0 -46
- package/lib/app/event-response.d.ts +3 -19
- package/lib/app/event-response.js +0 -13
- package/lib/app/hook-use-api.d.ts +13 -73
- package/lib/app/hook-use-api.js +5 -168
- package/lib/app/hook-use-state.d.ts +3 -32
- package/lib/app/hook-use-state.js +0 -31
- package/lib/app/hook-use-subscribe.d.ts +3 -22
- package/lib/app/hook-use-subscribe.js +3 -48
- package/lib/app/index.d.ts +18 -0
- package/lib/app/index.js +19 -0
- package/lib/app/load_modules/index.d.ts +2 -0
- package/lib/app/load_modules/index.js +2 -0
- package/lib/app/load_modules/load.d.ts +2 -0
- package/lib/app/load_modules/load.js +34 -0
- package/lib/app/load_modules/loadChild.d.ts +2 -0
- package/lib/app/{load.js → load_modules/loadChild.js} +21 -38
- package/lib/app/message-api.d.ts +7 -43
- package/lib/app/message-api.js +1 -32
- package/lib/app/message-format.d.ts +10 -84
- package/lib/app/message-format.js +0 -149
- package/lib/app/store.d.ts +36 -63
- package/lib/app/store.js +45 -73
- package/lib/cbp/connects/client.d.ts +2 -0
- package/lib/cbp/{client.js → connects/client.js} +25 -33
- package/lib/cbp/connects/connect.d.ts +9 -0
- package/lib/cbp/{connect.js → connects/connect.js} +10 -9
- package/lib/cbp/connects/platform.d.ts +9 -0
- package/lib/cbp/{platform.js → connects/platform.js} +15 -43
- package/lib/cbp/index.d.ts +3 -0
- package/lib/cbp/index.js +3 -434
- package/lib/cbp/processor/actions.d.ts +3 -0
- package/lib/cbp/processor/actions.js +28 -0
- package/lib/cbp/processor/api.d.ts +3 -0
- package/lib/cbp/processor/api.js +28 -0
- package/lib/cbp/processor/config.d.ts +26 -0
- package/lib/cbp/{config.js → processor/config.js} +3 -19
- package/lib/cbp/processor/hello.html.d.ts +1 -0
- package/lib/cbp/routers/middleware.d.ts +2 -0
- package/lib/cbp/{router-middleware.js → routers/middleware.js} +2 -13
- package/lib/cbp/routers/router.d.ts +3 -0
- package/lib/cbp/{router.js → routers/router.js} +9 -21
- package/lib/cbp/routers/utils.d.ts +2 -0
- package/lib/cbp/{router-utils.js → routers/utils.js} +0 -1
- package/lib/cbp/server/main.d.ts +1 -0
- package/lib/cbp/server/main.js +418 -0
- package/lib/cbp/server/testone.d.ts +8 -0
- package/lib/cbp/{testone.js → server/testone.js} +22 -87
- package/lib/cbp/typings.d.ts +17 -9
- package/lib/cbp/typings.js +1 -0
- package/lib/client.d.ts +2 -0
- package/lib/client.js +77 -0
- package/lib/core/config.d.ts +4 -37
- package/lib/core/config.js +0 -40
- package/lib/core/index.d.ts +3 -0
- package/lib/core/index.js +3 -0
- package/lib/core/utils.d.ts +10 -62
- package/lib/core/utils.js +0 -50
- package/lib/core/variable.d.ts +22 -9
- package/lib/core/variable.js +7 -24
- package/lib/global.d.ts +1 -85
- package/lib/global.js +0 -7
- package/lib/index.d.ts +6 -53
- package/lib/index.js +10 -21
- package/lib/main.d.ts +2 -42
- package/lib/main.js +51 -121
- package/lib/process/index.d.ts +2 -0
- package/lib/process/index.js +2 -0
- package/lib/process/module.d.ts +1 -0
- package/lib/process/module.js +76 -0
- package/lib/process/platform.d.ts +1 -0
- package/lib/{adapter.js → process/platform.js} +7 -13
- package/lib/types/actions.d.ts +12 -14
- package/lib/types/actions.js +1 -0
- package/lib/types/apis.d.ts +1 -9
- package/lib/types/apis.js +1 -0
- package/lib/types/client/index.d.ts +6 -47
- package/lib/types/client/index.js +1 -0
- package/lib/types/cycle/index.d.ts +8 -35
- package/lib/types/cycle/index.js +1 -0
- package/lib/types/event/actions.d.ts +1 -3
- package/lib/types/event/actions.js +0 -34
- package/lib/types/event/base/expansion.d.ts +1 -3
- package/lib/types/event/base/expansion.js +1 -0
- package/lib/types/event/base/guild.d.ts +2 -13
- package/lib/types/event/base/guild.js +1 -0
- package/lib/types/event/base/message.d.ts +3 -20
- package/lib/types/event/base/message.js +1 -0
- package/lib/types/event/base/platform.d.ts +1 -12
- package/lib/types/event/base/platform.js +1 -0
- package/lib/types/event/base/user.d.ts +1 -27
- package/lib/types/event/base/user.js +1 -0
- package/lib/types/event/channal/index.d.ts +6 -9
- package/lib/types/event/channal/index.js +1 -0
- package/lib/types/event/guild/index.d.ts +6 -9
- package/lib/types/event/guild/index.js +1 -0
- package/lib/types/event/index.d.ts +30 -74
- package/lib/types/event/index.js +1 -1
- package/lib/types/event/interaction/index.d.ts +7 -10
- package/lib/types/event/interaction/index.js +1 -0
- package/lib/types/event/map.d.ts +13 -16
- package/lib/types/event/map.js +1 -0
- package/lib/types/event/member/index.d.ts +7 -10
- package/lib/types/event/member/index.js +1 -0
- package/lib/types/event/message/message.d.ts +10 -13
- package/lib/types/event/message/message.js +1 -0
- package/lib/types/event/message/private.message.d.ts +7 -10
- package/lib/types/event/message/private.message.js +1 -0
- package/lib/types/event/request/index.d.ts +6 -9
- package/lib/types/event/request/index.js +1 -0
- package/lib/types/index.d.ts +26 -0
- package/lib/types/index.js +1 -0
- package/lib/types/logger/index.d.ts +1 -41
- package/lib/types/logger/index.js +1 -0
- package/lib/types/message/ark.d.ts +6 -8
- package/lib/types/message/ark.js +1 -0
- package/lib/types/message/button.d.ts +4 -6
- package/lib/types/message/button.js +1 -0
- package/lib/types/message/image.d.ts +3 -14
- package/lib/types/message/image.js +1 -0
- package/lib/types/message/index.d.ts +16 -16
- package/lib/types/message/index.js +1 -0
- package/lib/types/message/link.d.ts +1 -6
- package/lib/types/message/link.js +1 -0
- package/lib/types/message/markdown.d.ts +18 -22
- package/lib/types/message/markdown.js +1 -0
- package/lib/types/message/mention.d.ts +3 -9
- package/lib/types/message/mention.js +1 -0
- package/lib/types/message/text.d.ts +1 -6
- package/lib/types/message/text.js +1 -0
- package/lib/types/package/index.d.ts +1 -3
- package/lib/types/package/index.js +1 -0
- package/lib/types/run.d.ts +13 -0
- package/lib/types/run.js +1 -0
- package/lib/types/state/index.d.ts +1 -3
- package/lib/types/state/index.js +1 -0
- package/lib/types/store/res.d.ts +11 -47
- package/lib/types/store/res.js +1 -0
- package/lib/types/subscribe/index.d.ts +7 -16
- package/lib/types/subscribe/index.js +1 -0
- package/lib/utils.d.ts +6 -56
- package/lib/utils.js +0 -49
- package/package.json +3 -3
- package/lib/app/event-processor-event-callHandler.js +0 -75
- package/lib/app/event-processor-middleware-callHandler.js +0 -69
- package/lib/app/event-processor-middleware-route.js +0 -103
- package/lib/app/load.d.ts +0 -14
- package/lib/cbp/actions.js +0 -48
- package/lib/cbp/api.js +0 -48
- package/lib/cbp/client.d.ts +0 -10
- package/lib/cbp/connect.d.ts +0 -27
- package/lib/cbp/platform.d.ts +0 -18
- package/lib/cbp/server.d.ts +0 -8
- package/lib/cbp/server.js +0 -449
- package/lib/core/code.d.ts +0 -16
- package/lib/core/code.js +0 -17
- package/lib/typing/actions.d.ts +0 -93
- package/lib/typing/apis.d.ts +0 -18
- package/lib/typing/client/index.d.ts +0 -67
- package/lib/typing/cycle/index.d.ts +0 -42
- package/lib/typing/event/actions.d.ts +0 -37
- package/lib/typing/event/actions.js +0 -72
- package/lib/typing/event/base/expansion.d.ts +0 -5
- package/lib/typing/event/base/guild.d.ts +0 -18
- package/lib/typing/event/base/message.d.ts +0 -28
- package/lib/typing/event/base/platform.d.ts +0 -16
- package/lib/typing/event/base/user.d.ts +0 -34
- package/lib/typing/event/channal/index.d.ts +0 -13
- package/lib/typing/event/guild/index.d.ts +0 -13
- package/lib/typing/event/index.d.ts +0 -94
- package/lib/typing/event/interaction/index.d.ts +0 -14
- package/lib/typing/event/map.d.ts +0 -36
- package/lib/typing/event/map.js +0 -20
- package/lib/typing/event/member/index.d.ts +0 -14
- package/lib/typing/event/message/message.d.ts +0 -23
- package/lib/typing/event/message/private.message.d.ts +0 -16
- package/lib/typing/event/request/index.d.ts +0 -13
- package/lib/typing/logger/index.d.ts +0 -49
- package/lib/typing/message/ark.d.ts +0 -46
- package/lib/typing/message/button.d.ts +0 -32
- package/lib/typing/message/image.d.ts +0 -23
- package/lib/typing/message/index.d.ts +0 -16
- package/lib/typing/message/link.d.ts +0 -12
- package/lib/typing/message/markdown.d.ts +0 -91
- package/lib/typing/message/mention.d.ts +0 -16
- package/lib/typing/message/text.d.ts +0 -12
- package/lib/typing/package/index.d.ts +0 -12
- package/lib/typing/state/index.d.ts +0 -5
- package/lib/typing/store/res.d.ts +0 -75
- package/lib/typing/subscribe/index.d.ts +0 -30
- /package/lib/cbp/{hello.html.js → processor/hello.html.js} +0 -0
|
@@ -1,101 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { showErrorModule } from '../core/utils.js';
|
|
3
|
-
import { Response } from './store.js';
|
|
4
|
-
import { EventMessageText } from '../core/variable.js';
|
|
5
|
-
import { expendEventRoute } from './event-processor-event-route.js';
|
|
1
|
+
import { Response, ResponseRouter } from './store.js';
|
|
6
2
|
import { createCallHandler } from './event-processor-callHandler.js';
|
|
3
|
+
import { createNextStep } from './event-processor-cycleFiles.js';
|
|
4
|
+
import { createRouteProcessChildren } from './event-processor-cycleRoute.js';
|
|
7
5
|
|
|
8
|
-
/**
|
|
9
|
-
* 消息体处理机制
|
|
10
|
-
* @param event
|
|
11
|
-
* @param key
|
|
12
|
-
*/
|
|
13
6
|
const expendEvent = (valueEvent, select, next) => {
|
|
14
7
|
const res = new Response();
|
|
15
|
-
// 得到所有 response
|
|
16
8
|
const StoreResponse = res.value;
|
|
17
|
-
let valueI = 0;
|
|
18
|
-
// 开始处理 heandler
|
|
19
9
|
const callHandler = createCallHandler(valueEvent);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
next(...cns);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
// 结束了
|
|
30
|
-
if (valueI >= StoreResponse.length) {
|
|
31
|
-
next();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// 检查所有
|
|
35
|
-
void calli();
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* 执行 i
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
const calli = async () => {
|
|
42
|
-
// 调用完了
|
|
43
|
-
if (valueI >= StoreResponse.length) {
|
|
44
|
-
// 开始调用j
|
|
45
|
-
nextEvent();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
valueI++;
|
|
49
|
-
const file = StoreResponse[valueI - 1];
|
|
50
|
-
if (!file?.path) {
|
|
51
|
-
// 继续
|
|
52
|
-
nextEvent();
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
//
|
|
56
|
-
try {
|
|
57
|
-
const app = await import(`file://${file.path}`);
|
|
58
|
-
if (!app?.default?.current || !app?.default?.select) {
|
|
59
|
-
// 继续
|
|
60
|
-
nextEvent();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// 检查状态
|
|
64
|
-
if (file?.stateKey) {
|
|
65
|
-
const [state] = useState(file?.stateKey);
|
|
66
|
-
if (state === false) {
|
|
67
|
-
// 继续
|
|
68
|
-
nextEvent();
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
|
|
73
|
-
// 没有匹配到
|
|
74
|
-
if (!selects.includes(select)) {
|
|
75
|
-
// 继续
|
|
76
|
-
nextEvent();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
// 消息类型数据
|
|
80
|
-
if (EventMessageText.includes(select)) {
|
|
81
|
-
if (app?.regular) {
|
|
82
|
-
const reg = new RegExp(app.regular);
|
|
83
|
-
if (!reg.test(valueEvent['MessageText'])) {
|
|
84
|
-
// 继续
|
|
85
|
-
nextEvent();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
|
|
91
|
-
callHandler(currents, nextEvent);
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
showErrorModule(err);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
// 路由优先。路由的搞完了。再处理其他
|
|
98
|
-
expendEventRoute(valueEvent, select, nextEvent);
|
|
10
|
+
const nextEvent = createNextStep(valueEvent, select, next, StoreResponse, callHandler);
|
|
11
|
+
const resRoute = new ResponseRouter();
|
|
12
|
+
const routes = resRoute.value;
|
|
13
|
+
const callRouteHandler = createCallHandler(valueEvent);
|
|
14
|
+
const processChildren = createRouteProcessChildren(valueEvent, select, nextEvent, callRouteHandler);
|
|
15
|
+
void processChildren(routes, [], nextEvent);
|
|
99
16
|
};
|
|
100
17
|
|
|
101
18
|
export { expendEvent };
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
import { Next } from '../types
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @fileoverview 消息处理快
|
|
6
|
-
* 登录模块向核心模块发送数据
|
|
7
|
-
* 核心模块调用模块索引
|
|
8
|
-
* @module processor
|
|
9
|
-
* @author ningmengchongshui
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 处理中间件
|
|
14
|
-
* @param event
|
|
15
|
-
* @param select
|
|
16
|
-
*/
|
|
17
|
-
declare const expendMiddleware: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
18
|
-
|
|
19
|
-
export { expendMiddleware };
|
|
1
|
+
import { Next, Events, EventKeys } from '../types';
|
|
2
|
+
export declare const expendMiddleware: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
@@ -1,98 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { showErrorModule } from '../core/utils.js';
|
|
3
|
-
import { Middleware } from './store.js';
|
|
4
|
-
import { EventMessageText } from '../core/variable.js';
|
|
5
|
-
import { expendMiddlewareRoute } from './event-processor-middleware-route.js';
|
|
1
|
+
import { Middleware, MiddlewareRouter } from './store.js';
|
|
6
2
|
import { createCallHandler } from './event-processor-callHandler.js';
|
|
3
|
+
import { createNextStep } from './event-processor-cycleFiles.js';
|
|
4
|
+
import { createRouteProcessChildren } from './event-processor-cycleRoute.js';
|
|
7
5
|
|
|
8
|
-
/**
|
|
9
|
-
* 处理中间件
|
|
10
|
-
* @param event
|
|
11
|
-
* @param select
|
|
12
|
-
*/
|
|
13
6
|
const expendMiddleware = (valueEvent, select, next) => {
|
|
14
7
|
const mw = new Middleware();
|
|
15
|
-
// 得到所有 mws
|
|
16
8
|
const mwFiles = mw.value;
|
|
17
|
-
let valueI = 0;
|
|
18
|
-
// let valueJ = 0
|
|
19
9
|
const callHandler = createCallHandler(valueEvent);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
next(...cns);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
// 结束了
|
|
30
|
-
if (valueI >= mwFiles.length) {
|
|
31
|
-
next();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// 检查所有
|
|
35
|
-
void calli();
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* 执行 i
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
const calli = async () => {
|
|
42
|
-
// 调用完了
|
|
43
|
-
if (valueI >= mwFiles.length) {
|
|
44
|
-
// 开始调用j
|
|
45
|
-
nextMiddleware();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
valueI++;
|
|
49
|
-
const file = mwFiles[valueI - 1];
|
|
50
|
-
if (!file?.path) {
|
|
51
|
-
// 继续
|
|
52
|
-
nextMiddleware();
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
const app = await import(`file://${file.path}`);
|
|
57
|
-
if (!app?.default?.current || !app?.default?.select) {
|
|
58
|
-
// 继续
|
|
59
|
-
nextMiddleware();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// 检查状态
|
|
63
|
-
if (file?.stateKey) {
|
|
64
|
-
const [state] = useState(file?.stateKey);
|
|
65
|
-
if (state === false) {
|
|
66
|
-
// 继续
|
|
67
|
-
nextMiddleware();
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (EventMessageText.includes(select)) {
|
|
72
|
-
if (app?.regular) {
|
|
73
|
-
const reg = new RegExp(app.regular);
|
|
74
|
-
if (!reg.test(valueEvent['MessageText'])) {
|
|
75
|
-
// 继续
|
|
76
|
-
nextMiddleware();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
|
|
82
|
-
if (!selects.includes(select)) {
|
|
83
|
-
// 继续
|
|
84
|
-
nextMiddleware();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
|
|
88
|
-
callHandler(currents, nextMiddleware);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
showErrorModule(err);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
// 开始修正模式
|
|
95
|
-
expendMiddlewareRoute(valueEvent, select, nextMiddleware);
|
|
10
|
+
const nextMiddleware = createNextStep(valueEvent, select, next, mwFiles, callHandler);
|
|
11
|
+
const resRoute = new MiddlewareRouter();
|
|
12
|
+
const routes = resRoute.value;
|
|
13
|
+
const callRouteHandler = createCallHandler(valueEvent);
|
|
14
|
+
const processChildren = createRouteProcessChildren(valueEvent, select, nextMiddleware, callRouteHandler);
|
|
15
|
+
void processChildren(routes, [], nextMiddleware);
|
|
96
16
|
};
|
|
97
17
|
|
|
98
18
|
export { expendMiddleware };
|
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
import { Next, EventCycleEnum } from '../types
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @module processor
|
|
7
|
-
* @author ningmengchongshui
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 处理订阅
|
|
12
|
-
* @param valueEvent
|
|
13
|
-
* @param select
|
|
14
|
-
* @param next
|
|
15
|
-
* @param chioce
|
|
16
|
-
*/
|
|
17
|
-
declare const expendSubscribe: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next, chioce: EventCycleEnum) => void;
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param valueEvent
|
|
21
|
-
* @param select
|
|
22
|
-
* @param next
|
|
23
|
-
*/
|
|
24
|
-
declare const expendSubscribeCreate: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param valueEvent
|
|
28
|
-
* @param select
|
|
29
|
-
* @param next
|
|
30
|
-
*/
|
|
31
|
-
declare const expendSubscribeMount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @param valueEvent
|
|
35
|
-
* @param select
|
|
36
|
-
* @param next
|
|
37
|
-
*/
|
|
38
|
-
declare const expendSubscribeUnmount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
39
|
-
|
|
40
|
-
export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount };
|
|
1
|
+
import { Next, Events, EventCycleEnum, EventKeys } from '../types';
|
|
2
|
+
export declare const expendSubscribe: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next, chioce: EventCycleEnum) => void;
|
|
3
|
+
export declare const expendSubscribeCreate: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
4
|
+
export declare const expendSubscribeMount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
5
|
+
export declare const expendSubscribeUnmount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import { SubscribeList } from './store.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* 处理订阅
|
|
5
|
-
* @param valueEvent
|
|
6
|
-
* @param select
|
|
7
|
-
* @param next
|
|
8
|
-
* @param chioce
|
|
9
|
-
*/
|
|
10
3
|
const expendSubscribe = (valueEvent, select, next, chioce) => {
|
|
11
4
|
const subList = new SubscribeList(chioce, select);
|
|
12
|
-
/**
|
|
13
|
-
* 观察者下一步
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
5
|
const nextObserver = (cn, ...cns) => {
|
|
17
6
|
if (cn) {
|
|
18
7
|
next(...cns);
|
|
19
8
|
return;
|
|
20
9
|
}
|
|
21
|
-
const item = subList.value.popNext();
|
|
22
|
-
// 可能是 undefined
|
|
10
|
+
const item = subList.value.popNext();
|
|
23
11
|
if (!item) {
|
|
24
|
-
// 继续 next
|
|
25
12
|
nextObserver(true);
|
|
26
13
|
return;
|
|
27
14
|
}
|
|
28
|
-
// 检查 keys
|
|
29
15
|
for (const key in item.data.keys) {
|
|
30
|
-
// 只要发现不符合的,就继续
|
|
31
16
|
if (item.data.keys[key] !== valueEvent[key]) {
|
|
32
17
|
nextObserver();
|
|
33
18
|
return;
|
|
@@ -35,21 +20,20 @@ const expendSubscribe = (valueEvent, select, next, chioce) => {
|
|
|
35
20
|
}
|
|
36
21
|
const clear = () => {
|
|
37
22
|
const selects = item.data.selects;
|
|
38
|
-
const ID = item.data.id;
|
|
23
|
+
const ID = item.data.id;
|
|
39
24
|
for (const select of selects) {
|
|
40
25
|
const subList = new SubscribeList(chioce, select);
|
|
41
26
|
const remove = () => {
|
|
42
|
-
const item = subList.value.popNext();
|
|
27
|
+
const item = subList.value.popNext();
|
|
43
28
|
if (!item || item.data.id !== ID) {
|
|
44
29
|
remove();
|
|
45
30
|
return;
|
|
46
31
|
}
|
|
47
|
-
subList.value.removeCurrent();
|
|
32
|
+
subList.value.removeCurrent();
|
|
48
33
|
};
|
|
49
34
|
remove();
|
|
50
35
|
}
|
|
51
36
|
};
|
|
52
|
-
// 恢复
|
|
53
37
|
const restore = () => {
|
|
54
38
|
const selects = item.data.selects;
|
|
55
39
|
for (const select of selects) {
|
|
@@ -57,18 +41,13 @@ const expendSubscribe = (valueEvent, select, next, chioce) => {
|
|
|
57
41
|
subList.value.append(item.data);
|
|
58
42
|
}
|
|
59
43
|
};
|
|
60
|
-
// 订阅是执行则销毁
|
|
61
44
|
clear();
|
|
62
45
|
const Continue = (cn, ...cns) => {
|
|
63
|
-
// next() 订阅继续
|
|
64
|
-
// 重新注册。
|
|
65
46
|
restore();
|
|
66
|
-
// true
|
|
67
47
|
if (cn) {
|
|
68
48
|
nextObserver(...cns);
|
|
69
49
|
return;
|
|
70
50
|
}
|
|
71
|
-
// false
|
|
72
51
|
if (typeof cn === 'boolean') {
|
|
73
52
|
clear();
|
|
74
53
|
nextObserver(...cns);
|
|
@@ -76,33 +55,14 @@ const expendSubscribe = (valueEvent, select, next, chioce) => {
|
|
|
76
55
|
};
|
|
77
56
|
item.data.current(valueEvent, Continue);
|
|
78
57
|
};
|
|
79
|
-
// 先从观察者开始
|
|
80
58
|
nextObserver();
|
|
81
59
|
};
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @param valueEvent
|
|
85
|
-
* @param select
|
|
86
|
-
* @param next
|
|
87
|
-
*/
|
|
88
60
|
const expendSubscribeCreate = (valueEvent, select, next) => {
|
|
89
61
|
expendSubscribe(valueEvent, select, next, 'create');
|
|
90
62
|
};
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
* @param valueEvent
|
|
94
|
-
* @param select
|
|
95
|
-
* @param next
|
|
96
|
-
*/
|
|
97
63
|
const expendSubscribeMount = (valueEvent, select, next) => {
|
|
98
64
|
expendSubscribe(valueEvent, select, next, 'mount');
|
|
99
65
|
};
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param valueEvent
|
|
103
|
-
* @param select
|
|
104
|
-
* @param next
|
|
105
|
-
*/
|
|
106
66
|
const expendSubscribeUnmount = (valueEvent, select, next) => {
|
|
107
67
|
expendSubscribe(valueEvent, select, next, 'unmount');
|
|
108
68
|
};
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
import { EventKeys, Events } from '../types
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 消息处理器
|
|
5
|
-
* @param name
|
|
6
|
-
* @param event
|
|
7
|
-
* @param data
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
declare const onProcessor: <T extends EventKeys>(name: T, event: Events[T], data?: any) => void;
|
|
11
|
-
/**
|
|
12
|
-
* 消息处理器
|
|
13
|
-
* @param event
|
|
14
|
-
* @param name
|
|
15
|
-
* @deprecated 该方法已被弃用,请使用 onProcessor() 替代。
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
declare const OnProcessor: <T extends EventKeys>(event: Events[T], name: T) => void;
|
|
19
|
-
|
|
20
|
-
export { OnProcessor, onProcessor };
|
|
1
|
+
import { EventKeys, Events } from '../types';
|
|
2
|
+
export declare const onProcessor: <T extends EventKeys>(name: T, event: Events[T], data?: any) => void;
|
|
3
|
+
export declare const OnProcessor: <T extends EventKeys>(event: Events[T], name: T) => void;
|
|
@@ -4,38 +4,23 @@ import { expendCycle } from './event-processor-cycle.js';
|
|
|
4
4
|
import { ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap } from './store.js';
|
|
5
5
|
import { createHash } from '../core/utils.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* 过滤掉重复消息
|
|
9
|
-
* @param param0
|
|
10
|
-
* @param MessageId
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
7
|
const filter = ({ Now, store, INTERVAL }, MessageId) => {
|
|
14
8
|
if (store.has(MessageId)) {
|
|
15
9
|
const time = store.get(MessageId);
|
|
16
10
|
if (Now - time < INTERVAL) {
|
|
17
|
-
// 1s内重复消息
|
|
18
11
|
store.set(MessageId, Date.now());
|
|
19
12
|
return true;
|
|
20
13
|
}
|
|
21
14
|
}
|
|
22
15
|
store.set(MessageId, Date.now());
|
|
23
16
|
};
|
|
24
|
-
/**
|
|
25
|
-
* 清理旧消息
|
|
26
|
-
*/
|
|
27
17
|
const cleanupStore = ({ Now, store, INTERVAL }) => {
|
|
28
18
|
for (const [ID, timestamp] of store.entries()) {
|
|
29
|
-
// 超过时间间隔
|
|
30
19
|
if (Now - timestamp > INTERVAL) {
|
|
31
|
-
// 删除
|
|
32
20
|
store.delete(ID);
|
|
33
21
|
}
|
|
34
22
|
}
|
|
35
23
|
};
|
|
36
|
-
/**
|
|
37
|
-
* 清理所有消息
|
|
38
|
-
*/
|
|
39
24
|
const cleanupStoreAll = () => {
|
|
40
25
|
const Now = Date.now();
|
|
41
26
|
const value = getConfigValue();
|
|
@@ -44,28 +29,16 @@ const cleanupStoreAll = () => {
|
|
|
44
29
|
cleanupStore({ Now, INTERVAL: EVENT_INTERVAL, store: ProcessorEventAutoClearMap });
|
|
45
30
|
cleanupStore({ Now, INTERVAL: USER_INTERVAL, store: ProcessorEventUserAudoClearMap });
|
|
46
31
|
};
|
|
47
|
-
// 清理消息
|
|
48
32
|
const callback = () => {
|
|
49
33
|
cleanupStoreAll();
|
|
50
|
-
// 下一次清理的时间,应该随着长度的增加而减少
|
|
51
34
|
const length = ProcessorEventAutoClearMap.size + ProcessorEventUserAudoClearMap.size;
|
|
52
|
-
// 长度控制在37个以内
|
|
53
35
|
const time = length > processorPepeatedClearSize ? processorRepeatedClearTimeMin : processorRepeatedClearTimeMax;
|
|
54
36
|
setTimeout(callback, time);
|
|
55
37
|
};
|
|
56
38
|
setTimeout(callback, processorRepeatedClearTimeMin);
|
|
57
|
-
/**
|
|
58
|
-
* 消息处理器
|
|
59
|
-
* @param name
|
|
60
|
-
* @param event
|
|
61
|
-
* @param data
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
39
|
const onProcessor = (name, event, data) => {
|
|
65
|
-
// 禁用规则设置
|
|
66
40
|
const value = getConfigValue();
|
|
67
41
|
const disabledTextRegular = value?.disabled_text_regular;
|
|
68
|
-
// 检查文本禁用规则
|
|
69
42
|
if (disabledTextRegular && event['MessageText']) {
|
|
70
43
|
const reg = new RegExp(disabledTextRegular);
|
|
71
44
|
if (reg.test(event['MessageText'])) {
|
|
@@ -73,23 +46,19 @@ const onProcessor = (name, event, data) => {
|
|
|
73
46
|
}
|
|
74
47
|
}
|
|
75
48
|
const disabledSelects = value?.disabled_selects ?? {};
|
|
76
|
-
// 检查事件禁用规则
|
|
77
49
|
if (disabledSelects[name]) {
|
|
78
50
|
return;
|
|
79
51
|
}
|
|
80
52
|
const disabledUserId = value?.disabled_user_id ?? {};
|
|
81
|
-
// 检查用户禁用规则
|
|
82
53
|
if (event['UserId'] && disabledUserId[event['UserId']]) {
|
|
83
54
|
return;
|
|
84
55
|
}
|
|
85
56
|
const disabledUserKey = value?.disabled_user_key ?? {};
|
|
86
|
-
// 检查用户禁用规则
|
|
87
57
|
if (event['UserKey'] && disabledUserKey[event['UserKey']]) {
|
|
88
58
|
return;
|
|
89
59
|
}
|
|
90
60
|
const redirectRegular = value?.redirect_regular ?? value?.redirect_text_regular;
|
|
91
61
|
const redirectTarget = value?.redirect_target ?? value?.redirect_text_target;
|
|
92
|
-
// 检查文本重定向规则
|
|
93
62
|
if (redirectRegular && redirectTarget && event['MessageText']) {
|
|
94
63
|
const reg = new RegExp(redirectRegular);
|
|
95
64
|
if (reg.test(event['MessageText'])) {
|
|
@@ -97,7 +66,6 @@ const onProcessor = (name, event, data) => {
|
|
|
97
66
|
}
|
|
98
67
|
}
|
|
99
68
|
const mappingText = value?.mapping_text ?? [];
|
|
100
|
-
// 检查文本映射规则
|
|
101
69
|
for (const mapping of mappingText) {
|
|
102
70
|
const { regular, target } = mapping ?? {};
|
|
103
71
|
if (!regular) {
|
|
@@ -110,7 +78,6 @@ const onProcessor = (name, event, data) => {
|
|
|
110
78
|
}
|
|
111
79
|
const masterId = value?.master_id ?? {};
|
|
112
80
|
const masterKey = value?.master_key ?? {};
|
|
113
|
-
// 检查是否是 master
|
|
114
81
|
if (event['UserId'] && masterId[event['UserId']]) {
|
|
115
82
|
event['isMaster'] = true;
|
|
116
83
|
}
|
|
@@ -119,7 +86,6 @@ const onProcessor = (name, event, data) => {
|
|
|
119
86
|
}
|
|
120
87
|
const botId = value?.bot_id ?? {};
|
|
121
88
|
const botKey = value?.bot_key ?? {};
|
|
122
|
-
// 检查是否是 bot
|
|
123
89
|
if (event['UserId'] && botId[event['UserId']]) {
|
|
124
90
|
event['isBot'] = true;
|
|
125
91
|
}
|
|
@@ -129,24 +95,19 @@ const onProcessor = (name, event, data) => {
|
|
|
129
95
|
const Now = Date.now();
|
|
130
96
|
const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processorRepeatedEventTime;
|
|
131
97
|
if (event['MessageId']) {
|
|
132
|
-
// 消息过长,要减少消息的长度
|
|
133
98
|
const MessageId = createHash(event['MessageId']);
|
|
134
|
-
// 重复消息
|
|
135
99
|
if (filter({ Now, INTERVAL: EVENT_INTERVAL, store: ProcessorEventAutoClearMap }, MessageId)) {
|
|
136
100
|
return;
|
|
137
101
|
}
|
|
138
102
|
}
|
|
139
103
|
const USER_INTERVAL = value?.processor?.repeated_user_time ?? processorRepeatedUserTime;
|
|
140
104
|
if (event['UserId']) {
|
|
141
|
-
// 编号过长,要减少编号的长度
|
|
142
105
|
const UserId = createHash(event['UserId']);
|
|
143
|
-
// 频繁操作
|
|
144
106
|
if (filter({ Now, INTERVAL: USER_INTERVAL, store: ProcessorEventUserAudoClearMap }, UserId)) {
|
|
145
107
|
return;
|
|
146
108
|
}
|
|
147
109
|
}
|
|
148
110
|
if (data) {
|
|
149
|
-
// 当访问value的时候获取原始的data
|
|
150
111
|
Object.defineProperty(event, 'value', {
|
|
151
112
|
get() {
|
|
152
113
|
return data;
|
|
@@ -156,13 +117,6 @@ const onProcessor = (name, event, data) => {
|
|
|
156
117
|
event['name'] = name;
|
|
157
118
|
expendCycle(event, name);
|
|
158
119
|
};
|
|
159
|
-
/**
|
|
160
|
-
* 消息处理器
|
|
161
|
-
* @param event
|
|
162
|
-
* @param name
|
|
163
|
-
* @deprecated 该方法已被弃用,请使用 onProcessor() 替代。
|
|
164
|
-
* @returns
|
|
165
|
-
*/
|
|
166
120
|
const OnProcessor = (event, name) => {
|
|
167
121
|
onProcessor(name, event);
|
|
168
122
|
};
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import { OnResponseReversalFunc, OnResponseReversalFuncBack } from '../types
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 处理响应事件
|
|
5
|
-
* @param select 事件选择
|
|
6
|
-
* @param callback 回调函数,处理事件和 API
|
|
7
|
-
* @returns 回调函数的执行结果
|
|
8
|
-
*/
|
|
9
|
-
declare const onResponse: OnResponseReversalFunc;
|
|
10
|
-
/**
|
|
11
|
-
* 废弃,请使用 onResponse
|
|
12
|
-
* @deprecated
|
|
13
|
-
* @param callback
|
|
14
|
-
* @param select
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
declare const OnResponse: OnResponseReversalFuncBack;
|
|
18
|
-
|
|
19
|
-
export { OnResponse, onResponse };
|
|
1
|
+
import { OnResponseReversalFunc, OnResponseReversalFuncBack } from '../types';
|
|
2
|
+
export declare const onResponse: OnResponseReversalFunc;
|
|
3
|
+
export declare const OnResponse: OnResponseReversalFuncBack;
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 处理响应事件
|
|
3
|
-
* @param select 事件选择
|
|
4
|
-
* @param callback 回调函数,处理事件和 API
|
|
5
|
-
* @returns 回调函数的执行结果
|
|
6
|
-
*/
|
|
7
1
|
const onResponse = (select, callback) => {
|
|
8
2
|
return { current: callback, select };
|
|
9
3
|
};
|
|
10
4
|
global.onResponse = onResponse;
|
|
11
|
-
/**
|
|
12
|
-
* 废弃,请使用 onResponse
|
|
13
|
-
* @deprecated
|
|
14
|
-
* @param callback
|
|
15
|
-
* @param select
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
5
|
const OnResponse = (callback, select) => {
|
|
19
6
|
return onResponse(select, callback);
|
|
20
7
|
};
|