alemonjs 2.0.16 → 2.1.0-alpha.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/README.md +3 -3
- package/lib/app/define-bot.d.ts +5 -5
- package/lib/app/define-bot.js +25 -25
- package/lib/app/event-middleware.d.ts +2 -7
- package/lib/app/event-middleware.js +1 -14
- package/lib/app/event-processor-event.js +4 -4
- package/lib/app/event-processor-middleware.js +4 -4
- package/lib/app/event-processor-subscribe.js +32 -4
- package/lib/app/event-response.d.ts +2 -7
- package/lib/app/event-response.js +1 -16
- package/lib/app/hook-use-api.d.ts +51 -14
- package/lib/app/hook-use-api.js +203 -28
- package/lib/app/hook-use-state.d.ts +1 -11
- package/lib/app/hook-use-state.js +1 -27
- package/lib/app/hook-use-subscribe.d.ts +28 -16
- package/lib/app/hook-use-subscribe.js +99 -40
- package/lib/app/load.d.ts +1 -11
- package/lib/app/load.js +7 -34
- package/lib/app/message-api.d.ts +5 -10
- package/lib/app/message-api.js +20 -8
- package/lib/app/store.js +7 -6
- package/lib/app/utils.d.ts +1 -6
- package/lib/app/utils.js +13 -23
- package/lib/cbp/actions.js +48 -0
- package/lib/cbp/config.js +31 -0
- package/lib/cbp/connect.d.ts +23 -0
- package/lib/cbp/connect.js +189 -0
- package/lib/cbp/index.d.ts +32 -0
- package/lib/cbp/index.js +302 -0
- package/lib/cbp/message.js +9 -0
- package/lib/cbp/router.js +15 -0
- package/lib/core/code.js +1 -1
- package/lib/core/config.js +3 -3
- package/lib/core/variable.js +7 -12
- package/lib/global.d.ts +7 -23
- package/lib/index.d.ts +11 -10
- package/lib/index.js +9 -9
- package/lib/jsx.d.ts +83 -74
- package/lib/jsx.js +152 -176
- package/lib/main.d.ts +34 -6
- package/lib/main.js +76 -53
- package/lib/typing/actions.d.ts +42 -0
- package/lib/typing/client/index.d.ts +1 -1
- package/lib/typing/event/base/message.d.ts +4 -0
- package/lib/typing/event/index.d.ts +5 -20
- package/lib/typing/subscribe/index.d.ts +6 -3
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -20,14 +20,14 @@ start('src/index.js')
|
|
|
20
20
|
> src/response/res.js
|
|
21
21
|
|
|
22
22
|
```js
|
|
23
|
-
import {
|
|
23
|
+
import { Text, useMessage } from 'alemonjs'
|
|
24
24
|
// 创建事件类型
|
|
25
25
|
export const selects = onSelects(['message.create'])
|
|
26
26
|
// 导出响应
|
|
27
27
|
export default onResponse(selects, event => {
|
|
28
28
|
// 使用发送函数
|
|
29
|
-
const
|
|
29
|
+
const [message] = useMessage(event)
|
|
30
30
|
// 发送文本
|
|
31
|
-
send(Text('Hello Word!'))
|
|
31
|
+
message.send(format(Text('Hello Word!')))
|
|
32
32
|
})
|
|
33
33
|
```
|
package/lib/app/define-bot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DefinePlatformFunc } from '../typing/event/index.js'
|
|
2
|
-
import '../global.js'
|
|
1
|
+
import { DefinePlatformFunc } from '../typing/event/index.js'
|
|
2
|
+
import '../global.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 定义机器人
|
|
@@ -7,11 +7,11 @@ import '../global.js';
|
|
|
7
7
|
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
declare const definePlatform: DefinePlatformFunc
|
|
10
|
+
declare const definePlatform: DefinePlatformFunc
|
|
11
11
|
/**
|
|
12
12
|
* 废弃,请使用 definePlatform
|
|
13
13
|
* @deprecated
|
|
14
14
|
*/
|
|
15
|
-
declare const defineBot: DefinePlatformFunc
|
|
15
|
+
declare const defineBot: DefinePlatformFunc
|
|
16
16
|
|
|
17
|
-
export { defineBot, definePlatform }
|
|
17
|
+
export { defineBot, definePlatform }
|
package/lib/app/define-bot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResultCode } from '../core/code.js'
|
|
1
|
+
import { ResultCode } from '../core/code.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 定义机器人
|
|
@@ -7,33 +7,33 @@ import { ResultCode } from '../core/code.js';
|
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
9
|
const definePlatform = callback => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
global.definePlatform = definePlatform
|
|
10
|
+
// 判断是否是函数
|
|
11
|
+
if (typeof callback !== 'function') {
|
|
12
|
+
logger.error({
|
|
13
|
+
code: ResultCode.FailParams,
|
|
14
|
+
message: 'Invalid callback: callback must be a function',
|
|
15
|
+
data: null
|
|
16
|
+
})
|
|
17
|
+
throw new Error('Invalid callback: callback must be a function')
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
_name: 'platform',
|
|
21
|
+
callback
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
global.definePlatform = definePlatform
|
|
25
25
|
/**
|
|
26
26
|
* 废弃,请使用 definePlatform
|
|
27
27
|
* @deprecated
|
|
28
28
|
*/
|
|
29
29
|
const defineBot = callback => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
global.defineBot = defineBot
|
|
30
|
+
logger.warn({
|
|
31
|
+
code: ResultCode.Warn,
|
|
32
|
+
message: 'defineBot is deprecated, please use definePlatform',
|
|
33
|
+
data: null
|
|
34
|
+
})
|
|
35
|
+
return definePlatform(callback)
|
|
36
|
+
}
|
|
37
|
+
global.defineBot = defineBot
|
|
38
38
|
|
|
39
|
-
export { defineBot, definePlatform }
|
|
39
|
+
export { defineBot, definePlatform }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OnMiddlewareReversalFunc
|
|
1
|
+
import { OnMiddlewareReversalFunc } from '../typing/event/index.js';
|
|
2
2
|
import '../global.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -16,10 +16,5 @@ import '../global.js';
|
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
18
|
declare const onMiddleware: OnMiddlewareReversalFunc;
|
|
19
|
-
/**
|
|
20
|
-
* 废弃,请使用 onMiddleware
|
|
21
|
-
* @deprecated
|
|
22
|
-
*/
|
|
23
|
-
declare const OnMiddleware: OnMiddlewareFunc;
|
|
24
19
|
|
|
25
|
-
export {
|
|
20
|
+
export { onMiddleware };
|
|
@@ -29,18 +29,5 @@ const onMiddleware = (select, callback) => {
|
|
|
29
29
|
throw new Error('Invalid select: select must be a string or object');
|
|
30
30
|
};
|
|
31
31
|
global.onMiddleware = onMiddleware;
|
|
32
|
-
/**
|
|
33
|
-
* 废弃,请使用 onMiddleware
|
|
34
|
-
* @deprecated
|
|
35
|
-
*/
|
|
36
|
-
const OnMiddleware = (callback, select) => {
|
|
37
|
-
logger.warn({
|
|
38
|
-
code: ResultCode.Warn,
|
|
39
|
-
message: 'OnMiddleware is deprecated, please use onMiddleware',
|
|
40
|
-
data: null
|
|
41
|
-
});
|
|
42
|
-
return { select, current: callback };
|
|
43
|
-
};
|
|
44
|
-
global.OnMiddleware = OnMiddleware;
|
|
45
32
|
|
|
46
|
-
export {
|
|
33
|
+
export { onMiddleware };
|
|
@@ -2,7 +2,7 @@ import { isAsyncFunction } from 'util/types';
|
|
|
2
2
|
import { useState } from './hook-use-state.js';
|
|
3
3
|
import { showErrorModule } from './utils.js';
|
|
4
4
|
import { Response } from './store.js';
|
|
5
|
-
import {
|
|
5
|
+
import { useMessage } from './hook-use-api.js';
|
|
6
6
|
import { EventMessageText } from '../core/variable.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -19,7 +19,7 @@ import { EventMessageText } from '../core/variable.js';
|
|
|
19
19
|
*/
|
|
20
20
|
const expendEvent = async (valueEvent, select, next) => {
|
|
21
21
|
const res = new Response();
|
|
22
|
-
const
|
|
22
|
+
const [message] = useMessage(valueEvent);
|
|
23
23
|
// 得到所有 res
|
|
24
24
|
const StoreResponse = res.value;
|
|
25
25
|
let valueI = 0;
|
|
@@ -107,14 +107,14 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
107
107
|
if (Array.isArray(res)) {
|
|
108
108
|
if (res.length > 0) {
|
|
109
109
|
// 发送数据
|
|
110
|
-
|
|
110
|
+
message.send(res);
|
|
111
111
|
}
|
|
112
112
|
isClose = true;
|
|
113
113
|
}
|
|
114
114
|
else if (typeof res === 'object') {
|
|
115
115
|
if (Array.isArray(res.data)) {
|
|
116
116
|
// 发送数据
|
|
117
|
-
|
|
117
|
+
message.send(res.data);
|
|
118
118
|
}
|
|
119
119
|
if (!res.allowGrouping) {
|
|
120
120
|
isClose = true;
|
|
@@ -2,7 +2,7 @@ import { isAsyncFunction } from 'util/types';
|
|
|
2
2
|
import { useState } from './hook-use-state.js';
|
|
3
3
|
import { showErrorModule } from './utils.js';
|
|
4
4
|
import { Middleware } from './store.js';
|
|
5
|
-
import {
|
|
5
|
+
import { useMessage } from './hook-use-api.js';
|
|
6
6
|
import { EventMessageText } from '../core/variable.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -19,7 +19,7 @@ import { EventMessageText } from '../core/variable.js';
|
|
|
19
19
|
*/
|
|
20
20
|
const expendMiddleware = async (valueEvent, select, next) => {
|
|
21
21
|
const mw = new Middleware();
|
|
22
|
-
const
|
|
22
|
+
const [message] = useMessage(valueEvent);
|
|
23
23
|
// 得到所有 mws
|
|
24
24
|
const mwFiles = mw.value;
|
|
25
25
|
let valueI = 0;
|
|
@@ -109,14 +109,14 @@ const expendMiddleware = async (valueEvent, select, next) => {
|
|
|
109
109
|
else if (Array.isArray(res)) {
|
|
110
110
|
if (res.length > 0) {
|
|
111
111
|
// 发送数据
|
|
112
|
-
|
|
112
|
+
message.send(res);
|
|
113
113
|
}
|
|
114
114
|
isClose = true;
|
|
115
115
|
}
|
|
116
116
|
else if (typeof res === 'object') {
|
|
117
117
|
if (Array.isArray(res.data)) {
|
|
118
118
|
// 发送数据
|
|
119
|
-
|
|
119
|
+
message.send(res.data);
|
|
120
120
|
}
|
|
121
121
|
if (!res.allowGrouping) {
|
|
122
122
|
isClose = true;
|
|
@@ -20,7 +20,7 @@ const expendSubscribe = async (valueEvent, select, next, chioce) => {
|
|
|
20
20
|
}
|
|
21
21
|
const item = subList.value.popNext(); // 弹出下一个节点
|
|
22
22
|
// 可能是 undefined
|
|
23
|
-
if (!item
|
|
23
|
+
if (!item) {
|
|
24
24
|
// 继续 next
|
|
25
25
|
nextObserver(true);
|
|
26
26
|
return;
|
|
@@ -33,17 +33,45 @@ const expendSubscribe = async (valueEvent, select, next, chioce) => {
|
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
const clear = () => {
|
|
37
|
+
const selects = item.data.selects;
|
|
38
|
+
const ID = item.data.id; // 订阅的 ID
|
|
39
|
+
for (const select of selects) {
|
|
40
|
+
const subList = new SubscribeList(chioce, select);
|
|
41
|
+
const remove = () => {
|
|
42
|
+
const item = subList.value.popNext(); // 弹出下一个节点
|
|
43
|
+
if (!item || item.data.id !== ID) {
|
|
44
|
+
remove();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
subList.value.removeCurrent(); // 移除当前节点
|
|
48
|
+
return;
|
|
49
|
+
};
|
|
50
|
+
remove();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
// 恢复
|
|
54
|
+
const restore = () => {
|
|
55
|
+
const selects = item.data.selects;
|
|
56
|
+
for (const select of selects) {
|
|
57
|
+
const subList = new SubscribeList(chioce, select);
|
|
58
|
+
subList.value.append(item.data);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
36
61
|
// 订阅是执行则销毁
|
|
37
|
-
|
|
62
|
+
clear();
|
|
38
63
|
const Continue = (cn, ...cns) => {
|
|
39
64
|
// next() 订阅继续
|
|
40
|
-
|
|
65
|
+
// 重新注册。
|
|
66
|
+
restore();
|
|
67
|
+
// true
|
|
41
68
|
if (cn) {
|
|
42
69
|
nextObserver(...cns);
|
|
43
70
|
return;
|
|
44
71
|
}
|
|
72
|
+
// false
|
|
45
73
|
if (typeof cn === 'boolean') {
|
|
46
|
-
|
|
74
|
+
clear();
|
|
47
75
|
nextObserver(...cns);
|
|
48
76
|
return;
|
|
49
77
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OnResponseReversalFunc
|
|
1
|
+
import { OnResponseReversalFunc } from '../typing/event/index.js';
|
|
2
2
|
import '../global.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,10 +8,5 @@ import '../global.js';
|
|
|
8
8
|
* @returns 回调函数的执行结果
|
|
9
9
|
*/
|
|
10
10
|
declare const onResponse: OnResponseReversalFunc;
|
|
11
|
-
/**
|
|
12
|
-
* 废弃,请使用 onResponse
|
|
13
|
-
* @deprecated
|
|
14
|
-
*/
|
|
15
|
-
declare const OnResponse: OnResponseFunc;
|
|
16
11
|
|
|
17
|
-
export {
|
|
12
|
+
export { onResponse };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ResultCode } from '../core/code.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* 处理响应事件
|
|
5
3
|
* @param select 事件选择
|
|
@@ -10,18 +8,5 @@ const onResponse = (select, callback) => {
|
|
|
10
8
|
return { current: callback, select };
|
|
11
9
|
};
|
|
12
10
|
global.onResponse = onResponse;
|
|
13
|
-
/**
|
|
14
|
-
* 废弃,请使用 onResponse
|
|
15
|
-
* @deprecated
|
|
16
|
-
*/
|
|
17
|
-
const OnResponse = (callback, select) => {
|
|
18
|
-
logger.warn({
|
|
19
|
-
code: ResultCode.Warn,
|
|
20
|
-
message: 'OnResponse is deprecated, please use onResponse',
|
|
21
|
-
data: null
|
|
22
|
-
});
|
|
23
|
-
return { current: callback, select };
|
|
24
|
-
};
|
|
25
|
-
global.OnResponse = OnResponse;
|
|
26
11
|
|
|
27
|
-
export {
|
|
12
|
+
export { onResponse };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { EventKeys, Events } from '../typing/event/map.js';
|
|
2
|
-
import { ClientAPIMessageResult } from '../typing/client/index.js';
|
|
3
|
-
import { DataEnums } from '../typing/message/index.js';
|
|
4
|
-
import '../global.js';
|
|
5
2
|
import { Result } from './utils.js';
|
|
3
|
+
import '../global.js';
|
|
4
|
+
import { DataEnums } from '../typing/message/index.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* 使用提及。
|
|
@@ -26,23 +25,61 @@ declare const useMention: <T extends EventKeys>(event: Events[T]) => {
|
|
|
26
25
|
}) => Promise<Result>;
|
|
27
26
|
}[];
|
|
28
27
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param
|
|
31
|
-
* @
|
|
28
|
+
* 消息处理
|
|
29
|
+
* @param event
|
|
30
|
+
* @returns
|
|
32
31
|
*/
|
|
33
|
-
declare const
|
|
34
|
-
|
|
32
|
+
declare const useMessage: <T extends EventKeys>(event: Events[T]) => {
|
|
33
|
+
send: (val: DataEnums[]) => Promise<Result[]>;
|
|
34
|
+
withdraw: (message_id?: string) => Promise<Result[]>;
|
|
35
|
+
forward: (message_id?: string) => Promise<Result[]>;
|
|
36
|
+
reply: (message_id?: string) => Promise<Result[]>;
|
|
37
|
+
update: (message_id?: string) => Promise<Result[]>;
|
|
38
|
+
pinning: (message_id?: string) => Promise<Result[]>;
|
|
39
|
+
horn: (message_id?: string) => Promise<Result[]>;
|
|
40
|
+
reaction: (message_id?: string) => Promise<Result[]>;
|
|
41
|
+
}[];
|
|
42
|
+
/**
|
|
43
|
+
* 用户处理
|
|
44
|
+
* @deprecated 待支持
|
|
45
|
+
* @param event
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
declare const useMenber: <T extends EventKeys>(event: Events[T]) => {
|
|
49
|
+
information: (user_id?: string) => Promise<Result>;
|
|
50
|
+
mute: (all?: boolean) => Promise<Result>;
|
|
51
|
+
unmute: (all?: boolean) => Promise<Result>;
|
|
52
|
+
remove: (user_id?: string) => Promise<Result>;
|
|
53
|
+
}[];
|
|
54
|
+
/**
|
|
55
|
+
* 频道处理
|
|
56
|
+
* @deprecated 待支持
|
|
57
|
+
* @param event
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
declare const useChannel: <T extends EventKeys>(event: Events[T]) => {
|
|
61
|
+
exit: (channel_id?: string) => Promise<Result>;
|
|
62
|
+
join: (channel_id?: string) => Promise<Result>;
|
|
63
|
+
}[];
|
|
64
|
+
/**
|
|
65
|
+
* 废弃,请使用 useMessage
|
|
66
|
+
* @deprecated
|
|
67
|
+
* @param event
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
|
|
71
|
+
/**
|
|
72
|
+
* 废弃,请使用 useMessage
|
|
73
|
+
* @param event
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
declare const useSends: <T extends EventKeys>(event: Events[T]) => ((val: DataEnums[]) => Promise<Result[]>)[];
|
|
35
77
|
/**
|
|
36
78
|
* 卸载模块
|
|
37
79
|
* @param name
|
|
38
80
|
* @throws {Error} - 如果 name 无效,抛出错误。
|
|
39
81
|
*/
|
|
40
82
|
declare const unChildren: (name?: string) => void;
|
|
41
|
-
/**
|
|
42
|
-
* 废弃,请使用unChildren
|
|
43
|
-
* @deprecated
|
|
44
|
-
*/
|
|
45
|
-
declare const unMount: () => void;
|
|
46
83
|
/**
|
|
47
84
|
* 创建选择器
|
|
48
85
|
* @param values
|
|
@@ -55,4 +92,4 @@ declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
|
55
92
|
*/
|
|
56
93
|
declare const createSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
57
94
|
|
|
58
|
-
export { createSelects, onSelects, unChildren,
|
|
95
|
+
export { createSelects, onSelects, unChildren, useChannel, useMenber, useMention, useMessage, useSend, useSends };
|