alemonjs 2.1.0-alpha.48 → 2.1.0-alpha.49
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_CONFIG.md +58 -0
- package/lib/app/event-processor-middleware-callHandler.js +69 -0
- package/lib/app/event-processor-middleware.d.ts +8 -0
- package/lib/app/event-processor-middleware.js +18 -67
- package/lib/app/event-processor.js +56 -8
- package/lib/app/hook-use-state.d.ts +3 -0
- package/lib/app/hook-use-state.js +6 -7
- package/lib/app/store.d.ts +7 -1
- package/lib/app/store.js +27 -1
- package/lib/core/variable.js +6 -6
- package/lib/global.d.ts +2 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/main.js +25 -11
- package/lib/types/event/index.d.ts +1 -1
- package/package.json +1 -1
package/README_CONFIG.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# 环境变量
|
|
2
|
+
|
|
3
|
+
`platform`:`string` 平台
|
|
4
|
+
|
|
5
|
+
`login`:`string` 登录
|
|
6
|
+
|
|
7
|
+
`LOG_PATH`:`string` log 地址
|
|
8
|
+
|
|
9
|
+
`PKG_PATH`:`string` package.json 地址
|
|
10
|
+
|
|
11
|
+
`NODE_ENV`:`development | production` 环境判断
|
|
12
|
+
|
|
13
|
+
`CFG_PATH`: `string`
|
|
14
|
+
|
|
15
|
+
# 配置
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
# 常规配置
|
|
19
|
+
port: 17117 # 端口,快捷参数 --port
|
|
20
|
+
input: 'lib/index.js' # 入口地址,快捷参数 --input
|
|
21
|
+
login: 'discord' # 选择登录的平台,快捷参数 --login
|
|
22
|
+
url: 'ws://127.0.0.1:17117' # 连接阿柠檬服务URL,快捷参数 --url
|
|
23
|
+
is_full_receive: false # 不全量接收消息(用于分流处理)
|
|
24
|
+
# 禁用设置
|
|
25
|
+
disabled_text_regular: '/闭关' # 设置正则,若匹配则禁用
|
|
26
|
+
disabled_selects: # 禁用事件。若匹配则禁用
|
|
27
|
+
'private.message.create': true # 禁用私聊
|
|
28
|
+
disabled_user_id:
|
|
29
|
+
'1715713638': true # 若匹配则禁用
|
|
30
|
+
disabled_user_key:
|
|
31
|
+
'123456': true # 多匹配则禁用
|
|
32
|
+
# 重定向:把指定的文本,转为指定的内容 (禁用规则比重定向优先)
|
|
33
|
+
redirect_regular: '^#' # 识别前缀 #
|
|
34
|
+
redirect_target: '/' # 替换为 /
|
|
35
|
+
# ismaster 设置
|
|
36
|
+
master_id:
|
|
37
|
+
'1715713638': true
|
|
38
|
+
master_key:
|
|
39
|
+
'123456': true
|
|
40
|
+
# bot 设置
|
|
41
|
+
bot_id:
|
|
42
|
+
'1715713638': true # 把指定 id 视为 isBot
|
|
43
|
+
bot_key:
|
|
44
|
+
'123456': true # 把指定bot kye 视为 isBot
|
|
45
|
+
# 处理器
|
|
46
|
+
processor:
|
|
47
|
+
repeated_event_time: 60000 # 过滤掉 1分钟内出现相同 MessageId 的 event
|
|
48
|
+
repeated_user_time: 1000 # 过滤掉 1秒内出现相同UserId 的 event
|
|
49
|
+
# 加载子模块 (支持 array 写法)
|
|
50
|
+
apps:
|
|
51
|
+
'alemonjs-openai': true
|
|
52
|
+
# 模块配置, 约定。
|
|
53
|
+
# 模块对应的配置名,应是模块名。
|
|
54
|
+
alemonjs-openai:
|
|
55
|
+
baseURL: 'https://api.deepseek.com'
|
|
56
|
+
apiKey: ''
|
|
57
|
+
model: 'deepseek-chat'
|
|
58
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isAsyncFunction } from 'util/types';
|
|
2
|
+
import { useMessage } from './hook-use-api.js';
|
|
3
|
+
|
|
4
|
+
const createMiddlewareCallHandler = valueEvent => {
|
|
5
|
+
const [message] = useMessage(valueEvent);
|
|
6
|
+
// 开始处理 heandler
|
|
7
|
+
const callHandler = (currents, nextMiddleware) => {
|
|
8
|
+
let index = 0;
|
|
9
|
+
let isClose = false;
|
|
10
|
+
let isNext = false;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param res
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
const onRes = (res) => {
|
|
17
|
+
if (!res) {
|
|
18
|
+
isClose = true;
|
|
19
|
+
}
|
|
20
|
+
else if (Array.isArray(res)) {
|
|
21
|
+
if (res.length > 0) {
|
|
22
|
+
// 发送数据
|
|
23
|
+
void message.send(res);
|
|
24
|
+
}
|
|
25
|
+
isClose = true;
|
|
26
|
+
}
|
|
27
|
+
else if (typeof res === 'object') {
|
|
28
|
+
if (Array.isArray(res.data)) {
|
|
29
|
+
// 发送数据
|
|
30
|
+
void message.send(res.data);
|
|
31
|
+
}
|
|
32
|
+
if (!res.allowGrouping) {
|
|
33
|
+
isClose = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const start = async () => {
|
|
38
|
+
if (index >= currents.length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (isNext) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (isClose) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (isAsyncFunction(currents[index])) {
|
|
48
|
+
const res = await currents[index](valueEvent, (...cns) => {
|
|
49
|
+
isNext = true;
|
|
50
|
+
nextMiddleware(...cns);
|
|
51
|
+
});
|
|
52
|
+
onRes(res);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const res = currents[index](valueEvent, (...cns) => {
|
|
56
|
+
isNext = true;
|
|
57
|
+
nextMiddleware(...cns);
|
|
58
|
+
});
|
|
59
|
+
onRes(res);
|
|
60
|
+
}
|
|
61
|
+
++index;
|
|
62
|
+
void start();
|
|
63
|
+
};
|
|
64
|
+
void start();
|
|
65
|
+
};
|
|
66
|
+
return callHandler;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { createMiddlewareCallHandler };
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { Next } from '../types/cycle/index.js';
|
|
2
2
|
import { EventKeys, Events } from '../types/event/map.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview 消息处理快
|
|
6
|
+
* 登录模块向核心模块发送数据
|
|
7
|
+
* 核心模块调用模块索引
|
|
8
|
+
* @module processor
|
|
9
|
+
* @author ningmengchongshui
|
|
10
|
+
*/
|
|
11
|
+
|
|
4
12
|
/**
|
|
5
13
|
* 处理中间件
|
|
6
14
|
* @param event
|
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import { isAsyncFunction } from 'util/types';
|
|
2
1
|
import { useState } from './hook-use-state.js';
|
|
3
2
|
import { showErrorModule } from '../core/utils.js';
|
|
4
3
|
import { Middleware } from './store.js';
|
|
5
|
-
import { useMessage } from './hook-use-api.js';
|
|
6
4
|
import { EventMessageText } from '../core/variable.js';
|
|
5
|
+
import { createMiddlewareCallHandler } from './event-processor-middleware-callHandler.js';
|
|
7
6
|
|
|
8
|
-
/**
|
|
9
|
-
* @fileoverview 消息处理快
|
|
10
|
-
* 登录模块向核心模块发送数据
|
|
11
|
-
* 核心模块调用模块索引
|
|
12
|
-
* @module processor
|
|
13
|
-
* @author ningmengchongshui
|
|
14
|
-
*/
|
|
15
7
|
/**
|
|
16
8
|
* 处理中间件
|
|
17
9
|
* @param event
|
|
18
10
|
* @param select
|
|
19
11
|
*/
|
|
20
12
|
const expendMiddleware = (valueEvent, select, next) => {
|
|
13
|
+
// const mdR = new MiddlewareR();
|
|
14
|
+
// const r = mdR.value;
|
|
15
|
+
// let index = 0;
|
|
16
|
+
// const nextMiddlewareR = (cn?: boolean, ...cns: boolean[]) => {
|
|
17
|
+
// if (cn) {
|
|
18
|
+
// next(...cns);
|
|
19
|
+
// return;
|
|
20
|
+
// }
|
|
21
|
+
// if (index >= r.length) {
|
|
22
|
+
// next();
|
|
23
|
+
// return;
|
|
24
|
+
// }
|
|
25
|
+
// const route = r[index];
|
|
26
|
+
// index++;
|
|
27
|
+
// };
|
|
21
28
|
const mw = new Middleware();
|
|
22
|
-
const [message] = useMessage(valueEvent);
|
|
23
29
|
// 得到所有 mws
|
|
24
30
|
const mwFiles = mw.value;
|
|
25
31
|
let valueI = 0;
|
|
26
32
|
// let valueJ = 0
|
|
33
|
+
const callHandler = createMiddlewareCallHandler(valueEvent);
|
|
27
34
|
/**
|
|
28
35
|
* 下一步
|
|
29
36
|
* @returns
|
|
@@ -92,63 +99,7 @@ const expendMiddleware = (valueEvent, select, next) => {
|
|
|
92
99
|
return;
|
|
93
100
|
}
|
|
94
101
|
const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
|
|
95
|
-
|
|
96
|
-
let isClose = false;
|
|
97
|
-
let isNext = false;
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
* @param res
|
|
101
|
-
* @returns
|
|
102
|
-
*/
|
|
103
|
-
const onRes = (res) => {
|
|
104
|
-
if (!res) {
|
|
105
|
-
isClose = true;
|
|
106
|
-
}
|
|
107
|
-
else if (Array.isArray(res)) {
|
|
108
|
-
if (res.length > 0) {
|
|
109
|
-
// 发送数据
|
|
110
|
-
void message.send(res);
|
|
111
|
-
}
|
|
112
|
-
isClose = true;
|
|
113
|
-
}
|
|
114
|
-
else if (typeof res === 'object') {
|
|
115
|
-
if (Array.isArray(res.data)) {
|
|
116
|
-
// 发送数据
|
|
117
|
-
void message.send(res.data);
|
|
118
|
-
}
|
|
119
|
-
if (!res.allowGrouping) {
|
|
120
|
-
isClose = true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const start = async () => {
|
|
125
|
-
if (index >= currents.length) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (isNext) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (isClose) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (isAsyncFunction(currents[index])) {
|
|
135
|
-
const res = await currents[index](valueEvent, (...cns) => {
|
|
136
|
-
isNext = true;
|
|
137
|
-
nextMiddleware(...cns);
|
|
138
|
-
});
|
|
139
|
-
onRes(res);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
const res = currents[index](valueEvent, (...cns) => {
|
|
143
|
-
isNext = true;
|
|
144
|
-
nextMiddleware(...cns);
|
|
145
|
-
});
|
|
146
|
-
onRes(res);
|
|
147
|
-
}
|
|
148
|
-
++index;
|
|
149
|
-
void start();
|
|
150
|
-
};
|
|
151
|
-
void start();
|
|
102
|
+
callHandler(currents, nextMiddleware);
|
|
152
103
|
}
|
|
153
104
|
catch (err) {
|
|
154
105
|
showErrorModule(err);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getConfigValue } from '../core/config.js';
|
|
2
|
-
import {
|
|
2
|
+
import { processorRepeatedClearTimeMin, processorRepeatedClearTimeMax, processorRepeatedEventTime, processorRepeatedUserTime, processorPepeatedClearSize } from '../core/variable.js';
|
|
3
3
|
import { expendCycle } from './event-processor-cycle.js';
|
|
4
4
|
import { ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap } from './store.js';
|
|
5
5
|
import { createHash } from '../core/utils.js';
|
|
@@ -39,8 +39,8 @@ const cleanupStore = ({ Now, store, INTERVAL }) => {
|
|
|
39
39
|
const cleanupStoreAll = () => {
|
|
40
40
|
const Now = Date.now();
|
|
41
41
|
const value = getConfigValue();
|
|
42
|
-
const EVENT_INTERVAL = value?.processor?.repeated_event_time ??
|
|
43
|
-
const USER_INTERVAL = value?.processor?.repeated_user_time ??
|
|
42
|
+
const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processorRepeatedEventTime;
|
|
43
|
+
const USER_INTERVAL = value?.processor?.repeated_user_time ?? processorRepeatedUserTime;
|
|
44
44
|
cleanupStore({ Now, INTERVAL: EVENT_INTERVAL, store: ProcessorEventAutoClearMap });
|
|
45
45
|
cleanupStore({ Now, INTERVAL: USER_INTERVAL, store: ProcessorEventUserAudoClearMap });
|
|
46
46
|
};
|
|
@@ -50,10 +50,10 @@ const callback = () => {
|
|
|
50
50
|
// 下一次清理的时间,应该随着长度的增加而减少
|
|
51
51
|
const length = ProcessorEventAutoClearMap.size + ProcessorEventUserAudoClearMap.size;
|
|
52
52
|
// 长度控制在37个以内
|
|
53
|
-
const time = length >
|
|
53
|
+
const time = length > processorPepeatedClearSize ? processorRepeatedClearTimeMin : processorRepeatedClearTimeMax;
|
|
54
54
|
setTimeout(callback, time);
|
|
55
55
|
};
|
|
56
|
-
setTimeout(callback,
|
|
56
|
+
setTimeout(callback, processorRepeatedClearTimeMin);
|
|
57
57
|
/**
|
|
58
58
|
* 消息处理器
|
|
59
59
|
* @param name
|
|
@@ -62,10 +62,57 @@ setTimeout(callback, processor_repeated_clear_time_min);
|
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
64
|
const onProcessor = (name, event, data) => {
|
|
65
|
-
|
|
65
|
+
// 禁用规则设置
|
|
66
66
|
const value = getConfigValue();
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const disabledTextRegular = value?.disabled_text_regular;
|
|
68
|
+
// 检查文本禁用规则
|
|
69
|
+
if (disabledTextRegular && event['MessageText']) {
|
|
70
|
+
const reg = new RegExp(disabledTextRegular);
|
|
71
|
+
if (reg.test(event['MessageText'])) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const disabledSelects = value?.disabled_selects ?? {};
|
|
76
|
+
// 检查事件禁用规则
|
|
77
|
+
if (disabledSelects[name]) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const disabledUserId = value?.disabled_user_id ?? {};
|
|
81
|
+
if (event['UserId'] && disabledUserId[event['UserId']]) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const disabledUserKey = value?.disabled_user_key ?? {};
|
|
85
|
+
if (event['UserKey'] && disabledUserKey[event['UserKey']]) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const redirectRegular = value?.redirect_regular;
|
|
89
|
+
const redirectTarget = value?.redirect_target;
|
|
90
|
+
if (redirectRegular && redirectTarget && event['MessageText']) {
|
|
91
|
+
const reg = new RegExp(redirectRegular);
|
|
92
|
+
if (reg.test(event['MessageText'])) {
|
|
93
|
+
event['MessageText'] = event['MessageText'].replace(reg, redirectTarget);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const masterId = value?.master_id ?? {};
|
|
97
|
+
const masterKey = value?.master_key ?? {};
|
|
98
|
+
// 检查是否是 master
|
|
99
|
+
if ((event['UserId'] && masterId[event['UserId']])) {
|
|
100
|
+
event['isMaster'] = true;
|
|
101
|
+
}
|
|
102
|
+
else if ((event['UserKey'] && masterKey[event['UserKey']])) {
|
|
103
|
+
event['isMaster'] = true;
|
|
104
|
+
}
|
|
105
|
+
const botId = value?.bot_id ?? {};
|
|
106
|
+
const botKey = value?.bot_key ?? {};
|
|
107
|
+
// 检查是否是 bot
|
|
108
|
+
if (event['UserId'] && botId[event['UserId']]) {
|
|
109
|
+
event['isBot'] = true;
|
|
110
|
+
}
|
|
111
|
+
else if ((event['UserKey'] && botKey[event['UserKey']])) {
|
|
112
|
+
event['isBot'] = true;
|
|
113
|
+
}
|
|
114
|
+
const Now = Date.now();
|
|
115
|
+
const EVENT_INTERVAL = value?.processor?.repeated_event_time ?? processorRepeatedEventTime;
|
|
69
116
|
if (event['MessageId']) {
|
|
70
117
|
// 消息过长,要减少消息的长度
|
|
71
118
|
const MessageId = createHash(event['MessageId']);
|
|
@@ -74,6 +121,7 @@ const onProcessor = (name, event, data) => {
|
|
|
74
121
|
return;
|
|
75
122
|
}
|
|
76
123
|
}
|
|
124
|
+
const USER_INTERVAL = value?.processor?.repeated_user_time ?? processorRepeatedUserTime;
|
|
77
125
|
if (event['UserId']) {
|
|
78
126
|
// 编号过长,要减少编号的长度
|
|
79
127
|
const UserId = createHash(event['UserId']);
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 将会同时改变,因为状态是全局的
|
|
9
9
|
* @param name 功能名
|
|
10
10
|
* @param defaultValue 默认值,默认为 true
|
|
11
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
11
12
|
* @throws {Error} - 如果 name 不是字符串,或者 defaultValue 不是布尔值,抛出错误。
|
|
12
13
|
*/
|
|
13
14
|
declare const useState: <T extends string>(name: T, defaultValue?: boolean) => [boolean, (value: boolean) => void];
|
|
@@ -15,6 +16,7 @@ declare const useState: <T extends string>(name: T, defaultValue?: boolean) => [
|
|
|
15
16
|
* 订阅状态变化
|
|
16
17
|
* @param name 功能名
|
|
17
18
|
* @param callback 回调函数
|
|
19
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
18
20
|
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
19
21
|
*/
|
|
20
22
|
declare const onState: <T extends string>(name: T, callback: (value: boolean) => void) => void;
|
|
@@ -22,6 +24,7 @@ declare const onState: <T extends string>(name: T, callback: (value: boolean) =>
|
|
|
22
24
|
* 取消订阅状态变化
|
|
23
25
|
* @param name 功能名
|
|
24
26
|
* @param callback 回调函数
|
|
27
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
25
28
|
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
26
29
|
*/
|
|
27
30
|
declare const unState: <T extends string>(name: T, callback: (value: boolean) => void) => void;
|
|
@@ -12,6 +12,7 @@ import { State, StateSubscribe } from './store.js';
|
|
|
12
12
|
* 将会同时改变,因为状态是全局的
|
|
13
13
|
* @param name 功能名
|
|
14
14
|
* @param defaultValue 默认值,默认为 true
|
|
15
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
15
16
|
* @throws {Error} - 如果 name 不是字符串,或者 defaultValue 不是布尔值,抛出错误。
|
|
16
17
|
*/
|
|
17
18
|
const useState = (name, defaultValue = true) => {
|
|
@@ -35,18 +36,14 @@ const useState = (name, defaultValue = true) => {
|
|
|
35
36
|
const state = new State(name, defaultValue);
|
|
36
37
|
// 设置值的函数
|
|
37
38
|
const setValue = (value) => {
|
|
38
|
-
if (state.value
|
|
39
|
+
if (state.value === value) {
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
42
|
state.value = value;
|
|
42
43
|
// 更新config
|
|
43
44
|
const cfg = getConfig();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
if (!cfg.value.core.state) {
|
|
48
|
-
cfg.value.core.state = [];
|
|
49
|
-
}
|
|
45
|
+
cfg.value.core ??= {};
|
|
46
|
+
cfg.value.core.state ??= [];
|
|
50
47
|
const cfgState = cfg.value.core.state;
|
|
51
48
|
const cur = cfgState.find((i) => i === name);
|
|
52
49
|
if (cur !== value) {
|
|
@@ -65,6 +62,7 @@ const useState = (name, defaultValue = true) => {
|
|
|
65
62
|
* 订阅状态变化
|
|
66
63
|
* @param name 功能名
|
|
67
64
|
* @param callback 回调函数
|
|
65
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
68
66
|
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
69
67
|
*/
|
|
70
68
|
const onState = (name, callback) => {
|
|
@@ -83,6 +81,7 @@ const onState = (name, callback) => {
|
|
|
83
81
|
* 取消订阅状态变化
|
|
84
82
|
* @param name 功能名
|
|
85
83
|
* @param callback 回调函数
|
|
84
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
86
85
|
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
87
86
|
*/
|
|
88
87
|
const unState = (name, callback) => {
|
package/lib/app/store.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ declare class Response {
|
|
|
33
33
|
declare class ResponseRouter {
|
|
34
34
|
get value(): ResponseRoute[];
|
|
35
35
|
}
|
|
36
|
+
declare class MiddlewareR {
|
|
37
|
+
get value(): any[];
|
|
38
|
+
}
|
|
36
39
|
declare class Middleware {
|
|
37
40
|
get value(): StoreMiddlewareItem[];
|
|
38
41
|
}
|
|
@@ -48,6 +51,9 @@ declare class StateSubscribe {
|
|
|
48
51
|
un(callback: (value: boolean) => void): void;
|
|
49
52
|
get value(): ((value: boolean) => void)[];
|
|
50
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
56
|
+
*/
|
|
51
57
|
declare class State {
|
|
52
58
|
#private;
|
|
53
59
|
/**
|
|
@@ -94,4 +100,4 @@ declare class ChildrenApp {
|
|
|
94
100
|
declare const ProcessorEventAutoClearMap: Map<any, any>;
|
|
95
101
|
declare const ProcessorEventUserAudoClearMap: Map<any, any>;
|
|
96
102
|
|
|
97
|
-
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList };
|
|
103
|
+
export { ChildrenApp, Core, Logger, Middleware, MiddlewareR, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList };
|
package/lib/app/store.js
CHANGED
|
@@ -138,11 +138,31 @@ class Response {
|
|
|
138
138
|
class ResponseRouter {
|
|
139
139
|
get value() {
|
|
140
140
|
const data = Object.keys(alemonjsCore.storeChildrenApp).map(key => {
|
|
141
|
+
if (!alemonjsCore.storeChildrenApp[key].register) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
141
144
|
return alemonjsCore.storeChildrenApp[key].register?.response?.current ?? [];
|
|
142
145
|
});
|
|
143
146
|
return data.flat();
|
|
144
147
|
}
|
|
145
148
|
}
|
|
149
|
+
class MiddlewareR {
|
|
150
|
+
get value() {
|
|
151
|
+
// 得到所有 app,得到所有 res
|
|
152
|
+
const data = Object.keys(alemonjsCore.storeChildrenApp).map(key => {
|
|
153
|
+
if (!alemonjsCore.storeChildrenApp[key].register) {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
const current = alemonjsCore.storeChildrenApp[key].register?.middleware?.current;
|
|
157
|
+
if (!current) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const currents = Array.isArray(current) ? current : [current];
|
|
161
|
+
return currents;
|
|
162
|
+
});
|
|
163
|
+
return data.flat();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
146
166
|
class Middleware {
|
|
147
167
|
get value() {
|
|
148
168
|
// 得到所有 app,得到所有 res
|
|
@@ -185,6 +205,9 @@ class StateSubscribe {
|
|
|
185
205
|
return alemonjsCore.storeStateSubscribe[this.#name];
|
|
186
206
|
}
|
|
187
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
210
|
+
*/
|
|
188
211
|
class StateProxy {
|
|
189
212
|
create(value = {}) {
|
|
190
213
|
return new Proxy(value, {
|
|
@@ -204,6 +227,9 @@ class StateProxy {
|
|
|
204
227
|
});
|
|
205
228
|
}
|
|
206
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
232
|
+
*/
|
|
207
233
|
class State {
|
|
208
234
|
#name = null;
|
|
209
235
|
/**
|
|
@@ -300,4 +326,4 @@ class ChildrenApp {
|
|
|
300
326
|
const ProcessorEventAutoClearMap = new Map();
|
|
301
327
|
const ProcessorEventUserAudoClearMap = new Map();
|
|
302
328
|
|
|
303
|
-
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList };
|
|
329
|
+
export { ChildrenApp, Core, Logger, Middleware, MiddlewareR, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList };
|
package/lib/core/variable.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
const processorRepeatedEventTime = 1000 * 60;
|
|
2
|
+
const processorRepeatedUserTime = 1000 * 1;
|
|
3
|
+
const processorRepeatedClearTimeMin = 1000 * 3;
|
|
4
|
+
const processorRepeatedClearTimeMax = 1000 * 10;
|
|
5
|
+
const processorPepeatedClearSize = 37;
|
|
6
6
|
// 中间件文件后缀正则
|
|
7
7
|
const fileSuffixMiddleware = /^mw(\.|\..*\.)(js|ts|jsx|tsx)$/;
|
|
8
8
|
// 相应文件后缀正则
|
|
@@ -43,4 +43,4 @@ const ResultCode = {
|
|
|
43
43
|
FailInternal
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, ResultCode, Warn, defaultPlatformCommonPrefix, defaultPort, filePrefixCommon, fileSuffixMiddleware, fileSuffixResponse,
|
|
46
|
+
export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, ResultCode, Warn, defaultPlatformCommonPrefix, defaultPort, filePrefixCommon, fileSuffixMiddleware, fileSuffixResponse, processorPepeatedClearSize, processorRepeatedClearTimeMax, processorRepeatedClearTimeMin, processorRepeatedEventTime, processorRepeatedUserTime };
|
package/lib/global.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare global {
|
|
|
21
21
|
storeState: ResponseState;
|
|
22
22
|
/**
|
|
23
23
|
* 状态订阅
|
|
24
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
24
25
|
*/
|
|
25
26
|
storeStateSubscribe: StateSubscribeMap;
|
|
26
27
|
/**
|
|
@@ -96,6 +97,7 @@ declare const core: {
|
|
|
96
97
|
storeState: ResponseState;
|
|
97
98
|
/**
|
|
98
99
|
* 状态订阅
|
|
100
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
99
101
|
*/
|
|
100
102
|
storeStateSubscribe: StateSubscribeMap;
|
|
101
103
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
|
|
|
35
35
|
export { loadChildren, loadChildrenFile } from './app/load.js';
|
|
36
36
|
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
37
37
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
38
|
-
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
38
|
+
export { ChildrenApp, Core, Logger, Middleware, MiddlewareR, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
39
39
|
export { ResultCode } from './core/variable.js';
|
|
40
40
|
export { ConfigCore, getConfig, getConfigValue } from './core/config.js';
|
|
41
41
|
export { Result, createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
package/lib/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
|
|
|
16
16
|
export { loadChildren, loadChildrenFile } from './app/load.js';
|
|
17
17
|
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
18
18
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
19
|
-
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
19
|
+
export { ChildrenApp, Core, Logger, Middleware, MiddlewareR, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseRouter, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
20
20
|
export { ResultCode } from './core/variable.js';
|
|
21
21
|
export { ConfigCore, getConfig, getConfigValue } from './core/config.js';
|
|
22
22
|
export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
package/lib/main.js
CHANGED
|
@@ -18,9 +18,10 @@ const loadState = () => {
|
|
|
18
18
|
};
|
|
19
19
|
const loadApps = () => {
|
|
20
20
|
const cfg = getConfig();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const apps = Array.isArray(cfg.value?.apps) ? cfg.value.apps : Object.keys(cfg.value?.apps ?? {}).filter(Boolean);
|
|
22
|
+
// 去重
|
|
23
|
+
const uniqueApps = Array.from(new Set(apps));
|
|
24
|
+
void Promise.all(uniqueApps.map(app => loadChildrenFile(app)));
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* @description 运行本地模块
|
|
@@ -55,15 +56,25 @@ const start = (options = {}) => {
|
|
|
55
56
|
// 注入配置。
|
|
56
57
|
loadState();
|
|
57
58
|
const cfg = getConfig();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
// 临时参数
|
|
60
|
+
const curURL = options?.url ?? cfg.argv?.url;
|
|
61
|
+
// 临时参数
|
|
62
|
+
const curLogin = options?.login ?? cfg.argv?.login;
|
|
63
|
+
// 临时参数
|
|
64
|
+
const curPlatform = options?.platform ?? cfg.argv?.platform;
|
|
65
|
+
const url = curURL ?? cfg.value?.url;
|
|
66
|
+
if (curURL) {
|
|
67
|
+
logger.info(`[Connecting to CBP server at ${curURL}]`);
|
|
68
|
+
cbpClient(curURL);
|
|
69
|
+
}
|
|
70
|
+
else if (!curLogin && !curPlatform && url) {
|
|
61
71
|
logger.info(`[Connecting to CBP server at ${url}]`);
|
|
62
72
|
cbpClient(url);
|
|
63
73
|
}
|
|
64
74
|
else {
|
|
65
75
|
// 创建 cbp 服务器
|
|
66
|
-
const
|
|
76
|
+
const curPort = options?.port ?? cfg.argv?.port;
|
|
77
|
+
const port = curPort ?? cfg.value?.port ?? defaultPort;
|
|
67
78
|
// 设置环境变量
|
|
68
79
|
process.env.port = port;
|
|
69
80
|
cbpServer(port, () => {
|
|
@@ -71,11 +82,13 @@ const start = (options = {}) => {
|
|
|
71
82
|
const wsURL = `ws://127.0.0.1:${port}`;
|
|
72
83
|
logger.info(`[CBP server started at ${httpURL}]`);
|
|
73
84
|
logger.info(`[CBP server started at ${wsURL}]`);
|
|
74
|
-
const
|
|
85
|
+
const curIsFullReceive = options?.is_full_receive ?? cfg.argv?.is_full_receive;
|
|
86
|
+
// 是否全量接收
|
|
87
|
+
const isFullReceive = curIsFullReceive ?? cfg.value?.is_full_receive ?? true;
|
|
75
88
|
cbpClient(httpURL, { isFullReceive });
|
|
76
89
|
// 加载平台服务
|
|
77
|
-
const platform =
|
|
78
|
-
const login =
|
|
90
|
+
const platform = curPlatform ?? cfg.value?.platform;
|
|
91
|
+
const login = curLogin ?? cfg.value?.login;
|
|
79
92
|
// 不登录平台
|
|
80
93
|
if (!platform && !login) {
|
|
81
94
|
// 没有指定平台和登录名,则启动 sandbox 模式
|
|
@@ -109,7 +122,8 @@ const start = (options = {}) => {
|
|
|
109
122
|
});
|
|
110
123
|
}
|
|
111
124
|
// 获取入口文件
|
|
112
|
-
const
|
|
125
|
+
const curInput = options?.input ?? cfg.argv?.input;
|
|
126
|
+
const input = curInput ?? cfg.value?.input ?? getInputExportPath();
|
|
113
127
|
process.env.input = input;
|
|
114
128
|
// 运行本地模块
|
|
115
129
|
run(input);
|
|
@@ -61,7 +61,7 @@ type DefineResponseFunc = (responses: ResponseRoute[]) => {
|
|
|
61
61
|
};
|
|
62
62
|
type childrenCallbackRes = {
|
|
63
63
|
response?: ReturnType<DefineResponseFunc>;
|
|
64
|
-
};
|
|
64
|
+
} | void;
|
|
65
65
|
type childrenCallback = ChildrenCycle & {
|
|
66
66
|
register?: () => (childrenCallbackRes | void) | Promise<childrenCallbackRes | void>;
|
|
67
67
|
};
|