alemonjs 2.0.2 → 2.0.4
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/bin/start.js +12 -12
- package/lib/app/define-bot.d.ts +15 -0
- package/lib/app/{event-bot.js → define-bot.js} +1 -1
- package/lib/app/define-chidren.d.ts +10 -0
- package/lib/app/{event-chidren.js → define-chidren.js} +1 -1
- package/lib/app/event-middleware.d.ts +9 -10
- package/lib/app/event-middleware.js +8 -8
- package/lib/app/event-processor-event.js +81 -122
- package/lib/app/event-processor-middleware.js +100 -112
- package/lib/app/event-processor-subscribe.js +6 -8
- package/lib/app/event-processor.d.ts +3 -4
- package/lib/app/event-response.d.ts +16 -0
- package/lib/app/{event-utlis.js → event-response.js} +6 -7
- package/lib/app/hook-use-api.d.ts +9 -16
- package/lib/app/hook-use-api.js +11 -37
- package/lib/app/hook-use-state.d.ts +2 -2
- package/lib/app/hook-use-state.js +11 -35
- package/lib/app/hook-use-subscribe.d.ts +3 -4
- package/lib/app/hook-use-subscribe.js +3 -5
- package/lib/app/load.d.ts +22 -0
- package/lib/app/load.js +74 -59
- package/lib/app/{api.d.ts → message-api.d.ts} +0 -1
- package/lib/app/message-format.d.ts +36 -0
- package/lib/app/store.d.ts +90 -0
- package/lib/app/store.js +272 -0
- package/lib/app/utils.d.ts +3 -3
- package/lib/app/utils.js +13 -12
- package/lib/config.d.ts +0 -1
- package/lib/config.js +1 -1
- package/lib/datastructure/SinglyLinkedList.d.ts +3 -3
- package/lib/datastructure/SinglyLinkedList.js +2 -2
- package/lib/global.d.ts +44 -31
- package/lib/global.js +6 -46
- package/lib/index.d.ts +19 -30
- package/lib/index.js +12 -87
- package/lib/jsx.d.ts +10 -12
- package/lib/jsx.js +9 -10
- package/lib/main.d.ts +14 -0
- package/lib/main.js +79 -0
- package/lib/typing/{global → client}/index.d.ts +3 -6
- package/lib/typing/cycle/index.d.ts +2 -2
- package/lib/typing/event/actions.d.ts +37 -0
- package/lib/typing/event/actions.js +72 -0
- package/lib/typing/event/base/user.d.ts +12 -0
- package/lib/typing/event/index.d.ts +54 -30
- package/lib/typing/event/map.d.ts +6 -4
- package/lib/typing/logger/index.d.ts +3 -3
- package/lib/typing/message/index.d.ts +14 -14
- package/lib/typing/store/res.d.ts +20 -10
- package/lib/typing/subscribe/index.d.ts +11 -2
- package/package.json +1 -1
- package/lib/app/event-bot.d.ts +0 -16
- package/lib/app/event-chidren.d.ts +0 -11
- package/lib/app/event-utlis.d.ts +0 -18
- package/lib/app/hook-message-format.d.ts +0 -37
- package/lib/logger.js +0 -84
- /package/lib/app/{api.js → message-api.js} +0 -0
- /package/lib/app/{hook-message-format.js → message-format.js} +0 -0
package/bin/start.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import path from 'path'
|
|
3
|
+
import path from 'path'
|
|
4
4
|
import fs from 'fs'
|
|
5
|
-
import { createRequire } from 'module'
|
|
6
|
-
const require = createRequire(import.meta.url)
|
|
5
|
+
import { createRequire } from 'module'
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
7
7
|
|
|
8
|
-
const createExports =
|
|
8
|
+
const createExports = packageJson => {
|
|
9
9
|
if (packageJson?.exports) {
|
|
10
10
|
if (typeof packageJson.exports === 'string') {
|
|
11
|
-
return packageJson.exports
|
|
11
|
+
return packageJson.exports
|
|
12
12
|
} else if (typeof packageJson.exports === 'object') {
|
|
13
|
-
return packageJson.exports['.'] || packageJson.exports['./index.js']
|
|
13
|
+
return packageJson.exports['.'] || packageJson.exports['./index.js']
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const getInputExportPath =
|
|
19
|
-
const packageJsonPath = path.join(input ?? process.cwd(), 'package.json')
|
|
18
|
+
const getInputExportPath = input => {
|
|
19
|
+
const packageJsonPath = path.join(input ?? process.cwd(), 'package.json')
|
|
20
20
|
if (fs.existsSync(packageJsonPath)) {
|
|
21
|
-
const packageJson = require(packageJsonPath)
|
|
22
|
-
const main = packageJson?.main || createExports(packageJson)
|
|
21
|
+
const packageJson = require(packageJsonPath)
|
|
22
|
+
const main = packageJson?.main || createExports(packageJson)
|
|
23
23
|
if (main) {
|
|
24
|
-
return main
|
|
24
|
+
return main
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -32,7 +32,7 @@ const getInputExportPath = (input) => {
|
|
|
32
32
|
*/
|
|
33
33
|
export const start = () => {
|
|
34
34
|
// 读取配置文件
|
|
35
|
-
const main = getInputExportPath()
|
|
35
|
+
const main = getInputExportPath()
|
|
36
36
|
import('../lib/index.js').then(res => {
|
|
37
37
|
res.start(main)
|
|
38
38
|
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DefinePlatformFunc } from '../typing/event/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 定义机器人
|
|
5
|
+
* @param callback
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare const definePlatform: DefinePlatformFunc;
|
|
9
|
+
/**
|
|
10
|
+
* 废弃,请使用 definePlatform
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
declare const defineBot: DefinePlatformFunc;
|
|
14
|
+
|
|
15
|
+
export { defineBot, definePlatform };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import '../
|
|
2
|
-
import { OnMiddlewareType, OnMiddlewareReversalType } from '../typing/event/index.js';
|
|
1
|
+
import { OnMiddlewareReversalFunc, OnMiddlewareFunc } from '../typing/event/index.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @fileoverview 中间件
|
|
@@ -7,17 +6,17 @@ import { OnMiddlewareType, OnMiddlewareReversalType } from '../typing/event/inde
|
|
|
7
6
|
* @author ningmengchongshui
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* 废弃
|
|
12
|
-
* @deprecated
|
|
13
|
-
*/
|
|
14
|
-
declare const OnMiddleware: OnMiddlewareType;
|
|
15
9
|
/**
|
|
16
10
|
* 中间件
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
11
|
+
* @param select 事件选择
|
|
12
|
+
* @param callback 回调函数,处理事件和 API
|
|
19
13
|
* @returns
|
|
20
14
|
*/
|
|
21
|
-
declare const onMiddleware:
|
|
15
|
+
declare const onMiddleware: OnMiddlewareReversalFunc;
|
|
16
|
+
/**
|
|
17
|
+
* 废弃,请使用 onMiddleware
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
declare const OnMiddleware: OnMiddlewareFunc;
|
|
22
21
|
|
|
23
22
|
export { OnMiddleware, onMiddleware };
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 废弃
|
|
3
|
-
* @deprecated
|
|
4
|
-
*/
|
|
5
|
-
const OnMiddleware = (callback, select) => ({ select, current: callback });
|
|
6
|
-
global.OnMiddleware = OnMiddleware;
|
|
7
1
|
/**
|
|
8
2
|
* 中间件
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
3
|
+
* @param select 事件选择
|
|
4
|
+
* @param callback 回调函数,处理事件和 API
|
|
11
5
|
* @returns
|
|
12
6
|
*/
|
|
13
7
|
const onMiddleware = (select, callback) => ({
|
|
@@ -15,5 +9,11 @@ const onMiddleware = (select, callback) => ({
|
|
|
15
9
|
current: callback
|
|
16
10
|
});
|
|
17
11
|
global.onMiddleware = onMiddleware;
|
|
12
|
+
/**
|
|
13
|
+
* 废弃,请使用 onMiddleware
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
const OnMiddleware = (callback, select) => ({ select, current: callback });
|
|
17
|
+
global.OnMiddleware = OnMiddleware;
|
|
18
18
|
|
|
19
19
|
export { OnMiddleware, onMiddleware };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isAsyncFunction } from 'util/types';
|
|
2
2
|
import { useState } from './hook-use-state.js';
|
|
3
3
|
import { showErrorModule } from './utils.js';
|
|
4
|
+
import { Response } from './store.js';
|
|
5
|
+
import { useSend } from './hook-use-api.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @fileoverview 消息处理快
|
|
@@ -15,12 +17,11 @@ import { showErrorModule } from './utils.js';
|
|
|
15
17
|
* @param key
|
|
16
18
|
*/
|
|
17
19
|
const expendEvent = async (valueEvent, select, next) => {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
//
|
|
21
|
-
const
|
|
20
|
+
const res = new Response();
|
|
21
|
+
const Send = useSend(valueEvent);
|
|
22
|
+
// 得到所有 res
|
|
23
|
+
const StoreResponse = res.value;
|
|
22
24
|
let valueI = 0;
|
|
23
|
-
let valueJ = 0;
|
|
24
25
|
/**
|
|
25
26
|
* 下一步
|
|
26
27
|
* @returns
|
|
@@ -30,18 +31,12 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
30
31
|
next(...cns);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
//
|
|
34
|
+
// 结束了
|
|
34
35
|
if (valueI >= StoreResponse.length) {
|
|
35
|
-
|
|
36
|
-
if (valueJ >= StoreResponseGather.length) {
|
|
37
|
-
next();
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
// 走 j,检查所有分毫类型的
|
|
41
|
-
callj();
|
|
36
|
+
next();
|
|
42
37
|
return;
|
|
43
38
|
}
|
|
44
|
-
//
|
|
39
|
+
// 检查所有
|
|
45
40
|
calli();
|
|
46
41
|
};
|
|
47
42
|
/**
|
|
@@ -67,20 +62,20 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
67
62
|
const app = await import(`file://${file.path}`);
|
|
68
63
|
if (!app?.default) {
|
|
69
64
|
// 继续
|
|
70
|
-
|
|
65
|
+
nextEvent();
|
|
71
66
|
return;
|
|
72
67
|
}
|
|
73
68
|
if (!app.default?.current) {
|
|
74
69
|
// 继续
|
|
75
|
-
|
|
70
|
+
nextEvent();
|
|
76
71
|
return;
|
|
77
72
|
}
|
|
78
73
|
// 检查状态
|
|
79
|
-
if (file?.
|
|
80
|
-
const [state] = useState(file?.
|
|
74
|
+
if (file?.stateKey) {
|
|
75
|
+
const [state] = useState(file?.stateKey);
|
|
81
76
|
if (state == false) {
|
|
82
77
|
// 继续
|
|
83
|
-
|
|
78
|
+
nextEvent();
|
|
84
79
|
return;
|
|
85
80
|
}
|
|
86
81
|
}
|
|
@@ -101,33 +96,14 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
101
96
|
nextEvent();
|
|
102
97
|
return;
|
|
103
98
|
}
|
|
104
|
-
// 不是数组写法的。会触发分类
|
|
105
|
-
// 判断是否已经分类
|
|
106
|
-
if (!alemonjsCore.storeResponseGather[select].find(v => v.path === file.path)) {
|
|
107
|
-
// 得到index
|
|
108
|
-
const index = alemonjsCore.storeResponse.findIndex(v => v.path === file.path);
|
|
109
|
-
// 分类
|
|
110
|
-
alemonjsCore.storeResponse.splice(index, 1);
|
|
111
|
-
// 转移存储
|
|
112
|
-
alemonjsCore.storeResponseGather[select].push({
|
|
113
|
-
source: file.source,
|
|
114
|
-
dir: file.dir,
|
|
115
|
-
path: file.path,
|
|
116
|
-
name: file.name,
|
|
117
|
-
node: file.node,
|
|
118
|
-
value: {
|
|
119
|
-
select: app.default.select
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
99
|
}
|
|
124
100
|
// 消息类型数据
|
|
125
|
-
if (
|
|
101
|
+
if (['message.create', 'private.message.create'].includes(select)) {
|
|
126
102
|
if (app?.regular) {
|
|
127
103
|
const reg = new RegExp(app.regular);
|
|
128
104
|
if (!reg.test(valueEvent['MessageText'])) {
|
|
129
105
|
// 继续
|
|
130
|
-
|
|
106
|
+
nextEvent();
|
|
131
107
|
return;
|
|
132
108
|
}
|
|
133
109
|
}
|
|
@@ -135,6 +111,31 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
135
111
|
if (Array.isArray(app.default.current)) {
|
|
136
112
|
let i = 0;
|
|
137
113
|
let T = true;
|
|
114
|
+
let isNext = false;
|
|
115
|
+
const onRes = (res) => {
|
|
116
|
+
if (isNext) {
|
|
117
|
+
// 内部调用了next
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (typeof res === 'boolean') {
|
|
121
|
+
T = res;
|
|
122
|
+
}
|
|
123
|
+
else if (Array.isArray(res)) {
|
|
124
|
+
if (res.length > 0) {
|
|
125
|
+
// 发送数据
|
|
126
|
+
Send(...res);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (typeof res === 'object') {
|
|
130
|
+
if (typeof res?.allowGrouping === 'boolean') {
|
|
131
|
+
T = res.allowGrouping;
|
|
132
|
+
}
|
|
133
|
+
if (Array.isArray(res.data)) {
|
|
134
|
+
// 发送数据
|
|
135
|
+
Send(...res.data);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
138
139
|
const start = async () => {
|
|
139
140
|
if (i >= app.default.current.length)
|
|
140
141
|
return;
|
|
@@ -142,10 +143,18 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
142
143
|
if (!T)
|
|
143
144
|
return;
|
|
144
145
|
if (isAsyncFunction(app.default.current[i])) {
|
|
145
|
-
|
|
146
|
+
const res = await app.default.current[i](valueEvent, (...cns) => {
|
|
147
|
+
isNext = true;
|
|
148
|
+
nextEvent(...cns);
|
|
149
|
+
});
|
|
150
|
+
onRes(res);
|
|
146
151
|
}
|
|
147
152
|
else {
|
|
148
|
-
|
|
153
|
+
const res = app.default.current[i](valueEvent, (...cns) => {
|
|
154
|
+
isNext = true;
|
|
155
|
+
nextEvent(...cns);
|
|
156
|
+
});
|
|
157
|
+
onRes(res);
|
|
149
158
|
}
|
|
150
159
|
++i;
|
|
151
160
|
await start();
|
|
@@ -153,101 +162,51 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
153
162
|
await start();
|
|
154
163
|
}
|
|
155
164
|
else {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
else {
|
|
161
|
-
app.default?.current(valueEvent, nextEvent);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (err) {
|
|
166
|
-
showErrorModule(err);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* 被分类好的
|
|
171
|
-
* @returns
|
|
172
|
-
*/
|
|
173
|
-
const callj = async () => {
|
|
174
|
-
// 调用完了
|
|
175
|
-
if (valueJ >= StoreResponseGather.length) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
valueJ++;
|
|
179
|
-
const file = StoreResponseGather[valueJ - 1];
|
|
180
|
-
if (!file?.path) {
|
|
181
|
-
nextEvent();
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const app = await import(`file://${file.path}`);
|
|
186
|
-
if (!app?.default) {
|
|
187
|
-
// 继续
|
|
188
|
-
await nextEvent();
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (!app.default?.current) {
|
|
192
|
-
// 继续
|
|
193
|
-
await nextEvent();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
// 检查状态
|
|
197
|
-
if (file?.state) {
|
|
198
|
-
const [state] = useState(file?.state);
|
|
199
|
-
if (state == false) {
|
|
200
|
-
// 继续
|
|
201
|
-
await nextEvent();
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
// 消息类型数据
|
|
206
|
-
if (select == 'message.create' || select == 'private.message.create') {
|
|
207
|
-
if (app?.regular) {
|
|
208
|
-
const reg = new RegExp(app.regular);
|
|
209
|
-
if (!reg.test(valueEvent['MessageText'])) {
|
|
210
|
-
// 继续
|
|
211
|
-
await nextEvent();
|
|
165
|
+
let isNext = false;
|
|
166
|
+
const onRes = (res) => {
|
|
167
|
+
if (isNext) {
|
|
168
|
+
// 内部调用了next
|
|
212
169
|
return;
|
|
213
170
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (Array.isArray(app.default.current)) {
|
|
217
|
-
let i = 0;
|
|
218
|
-
let T = true;
|
|
219
|
-
const start = async () => {
|
|
220
|
-
if (i >= app.default.current.length)
|
|
221
|
-
return;
|
|
222
|
-
// 不是真的事件 退出
|
|
223
|
-
if (!T)
|
|
224
|
-
return;
|
|
225
|
-
if (isAsyncFunction(app.default.current[i])) {
|
|
226
|
-
T = await app.default.current[i](valueEvent, nextEvent);
|
|
171
|
+
if (typeof res === 'boolean') {
|
|
172
|
+
// T = res
|
|
227
173
|
}
|
|
228
|
-
else {
|
|
229
|
-
|
|
174
|
+
else if (Array.isArray(res)) {
|
|
175
|
+
if (res.length > 0) {
|
|
176
|
+
// 发送数据
|
|
177
|
+
Send(...res);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (typeof res === 'object') {
|
|
181
|
+
if (typeof res?.allowGrouping === 'boolean') {
|
|
182
|
+
// T = res.allowGrouping
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(res.data)) {
|
|
185
|
+
// 发送数据
|
|
186
|
+
Send(...res.data);
|
|
187
|
+
}
|
|
230
188
|
}
|
|
231
|
-
++i;
|
|
232
|
-
await start();
|
|
233
189
|
};
|
|
234
|
-
await start();
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
190
|
// 这里是否继续时 next 说了算
|
|
238
191
|
if (isAsyncFunction(app.default?.current)) {
|
|
239
|
-
app.default?.current(valueEvent,
|
|
192
|
+
const res = await app.default?.current(valueEvent, (...cns) => {
|
|
193
|
+
isNext = true;
|
|
194
|
+
nextEvent(...cns);
|
|
195
|
+
});
|
|
196
|
+
onRes(res);
|
|
240
197
|
}
|
|
241
198
|
else {
|
|
242
|
-
app.default?.current(valueEvent,
|
|
199
|
+
const res = app.default?.current(valueEvent, (...cns) => {
|
|
200
|
+
isNext = true;
|
|
201
|
+
nextEvent(...cns);
|
|
202
|
+
});
|
|
203
|
+
onRes(res);
|
|
243
204
|
}
|
|
244
205
|
}
|
|
245
|
-
//
|
|
246
206
|
}
|
|
247
207
|
catch (err) {
|
|
248
208
|
showErrorModule(err);
|
|
249
209
|
}
|
|
250
|
-
//
|
|
251
210
|
};
|
|
252
211
|
nextEvent();
|
|
253
212
|
};
|