alemonjs 2.0.13 → 2.0.14
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.
|
@@ -2,6 +2,7 @@ import { ResultCode } from '../code.js';
|
|
|
2
2
|
import { expendEvent } from './event-processor-event.js';
|
|
3
3
|
import { expendMiddleware } from './event-processor-middleware.js';
|
|
4
4
|
import { expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './event-processor-subscribe.js';
|
|
5
|
+
import { getConfigValue } from '../config.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 打印日志
|
|
@@ -74,19 +75,11 @@ const expendCycle = async (valueEvent, select) => {
|
|
|
74
75
|
}
|
|
75
76
|
expendMiddleware(valueEvent, select, nextMount);
|
|
76
77
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
logger.error({
|
|
86
|
-
code: ResultCode.FailParams,
|
|
87
|
-
message: 'ALEMONJS_EVENT_LOGS_CHANNEL_ID is not json string',
|
|
88
|
-
data: null
|
|
89
|
-
});
|
|
78
|
+
const value = getConfigValue() ?? {};
|
|
79
|
+
if (Array.isArray(value?.logs?.channel_id)) {
|
|
80
|
+
const channelIds = value?.logs?.channel_id;
|
|
81
|
+
if (channelIds && channelIds.length > 0 && channelIds.includes(valueEvent['ChannelId'])) {
|
|
82
|
+
showLog(valueEvent, select);
|
|
90
83
|
}
|
|
91
84
|
}
|
|
92
85
|
else {
|
|
@@ -61,12 +61,7 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
61
61
|
//
|
|
62
62
|
try {
|
|
63
63
|
const app = await import(`file://${file.path}`);
|
|
64
|
-
if (!app?.default) {
|
|
65
|
-
// 继续
|
|
66
|
-
nextEvent();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (!app.default?.current) {
|
|
64
|
+
if (!app?.default || !app?.default?.current || !app?.default?.select) {
|
|
70
65
|
// 继续
|
|
71
66
|
nextEvent();
|
|
72
67
|
return;
|
|
@@ -80,23 +75,12 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
80
75
|
return;
|
|
81
76
|
}
|
|
82
77
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// 如果不是数组
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// 没有匹配到
|
|
95
|
-
if (app.default?.select !== select) {
|
|
96
|
-
// 继续
|
|
97
|
-
nextEvent();
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
78
|
+
const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
|
|
79
|
+
// 没有匹配到
|
|
80
|
+
if (!selects.includes(select)) {
|
|
81
|
+
// 继续
|
|
82
|
+
nextEvent();
|
|
83
|
+
return;
|
|
100
84
|
}
|
|
101
85
|
// 消息类型数据
|
|
102
86
|
if (EventMessageText.includes(select)) {
|
|
@@ -109,87 +93,57 @@ const expendEvent = async (valueEvent, select, next) => {
|
|
|
109
93
|
}
|
|
110
94
|
}
|
|
111
95
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
else if (typeof res === 'object') {
|
|
127
|
-
if (Array.isArray(res.data)) {
|
|
128
|
-
// 发送数据
|
|
129
|
-
Send(...res.data);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const start = async () => {
|
|
134
|
-
if (i >= app.default.current.length)
|
|
135
|
-
return;
|
|
136
|
-
if (isNext)
|
|
137
|
-
return;
|
|
138
|
-
if (isAsyncFunction(app.default.current[i])) {
|
|
139
|
-
const res = await app.default.current[i](valueEvent, (...cns) => {
|
|
140
|
-
isNext = true;
|
|
141
|
-
nextEvent(...cns);
|
|
142
|
-
});
|
|
143
|
-
onRes(res);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
const res = app.default.current[i](valueEvent, (...cns) => {
|
|
147
|
-
isNext = true;
|
|
148
|
-
nextEvent(...cns);
|
|
149
|
-
});
|
|
150
|
-
onRes(res);
|
|
151
|
-
}
|
|
152
|
-
++i;
|
|
153
|
-
await start();
|
|
154
|
-
};
|
|
155
|
-
await start();
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
let isNext = false;
|
|
159
|
-
const onRes = (res) => {
|
|
160
|
-
if (isNext) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (typeof res === 'boolean') {
|
|
96
|
+
const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
|
|
97
|
+
let index = 0;
|
|
98
|
+
let isClose = false;
|
|
99
|
+
let isNext = false;
|
|
100
|
+
const onRes = (res) => {
|
|
101
|
+
if (!res) {
|
|
102
|
+
isClose = true;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(res)) {
|
|
106
|
+
if (res.length > 0) {
|
|
107
|
+
// 发送数据
|
|
108
|
+
Send(...res);
|
|
164
109
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
110
|
+
isClose = true;
|
|
111
|
+
}
|
|
112
|
+
else if (typeof res === 'object') {
|
|
113
|
+
if (Array.isArray(res.data)) {
|
|
114
|
+
// 发送数据
|
|
115
|
+
Send(...res.data);
|
|
169
116
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// 发送数据
|
|
173
|
-
Send(...res.data);
|
|
174
|
-
}
|
|
117
|
+
if (!res.allowGrouping) {
|
|
118
|
+
isClose = true;
|
|
175
119
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const start = async () => {
|
|
123
|
+
if (index >= currents.length)
|
|
124
|
+
return;
|
|
125
|
+
if (isNext)
|
|
126
|
+
return;
|
|
127
|
+
if (isClose)
|
|
128
|
+
return;
|
|
129
|
+
if (isAsyncFunction(currents[index])) {
|
|
130
|
+
const res = await currents[index](valueEvent, (...cns) => {
|
|
180
131
|
isNext = true;
|
|
181
132
|
nextEvent(...cns);
|
|
182
133
|
});
|
|
183
134
|
onRes(res);
|
|
184
135
|
}
|
|
185
136
|
else {
|
|
186
|
-
const res =
|
|
137
|
+
const res = currents[index](valueEvent, (...cns) => {
|
|
187
138
|
isNext = true;
|
|
188
139
|
nextEvent(...cns);
|
|
189
140
|
});
|
|
190
141
|
onRes(res);
|
|
191
142
|
}
|
|
192
|
-
|
|
143
|
+
++index;
|
|
144
|
+
start();
|
|
145
|
+
};
|
|
146
|
+
start();
|
|
193
147
|
}
|
|
194
148
|
catch (err) {
|
|
195
149
|
showErrorModule(err);
|
|
@@ -61,12 +61,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
|
|
|
61
61
|
}
|
|
62
62
|
try {
|
|
63
63
|
const app = await import(`file://${file.path}`);
|
|
64
|
-
if (!app?.default) {
|
|
65
|
-
// 继续
|
|
66
|
-
nextMiddleware();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (!app.default.current) {
|
|
64
|
+
if (!app?.default || !app?.default?.current || !app?.default?.select) {
|
|
70
65
|
// 继续
|
|
71
66
|
nextMiddleware();
|
|
72
67
|
return;
|
|
@@ -90,108 +85,67 @@ const expendMiddleware = async (valueEvent, select, next) => {
|
|
|
90
85
|
}
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
nextMiddleware();
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
// 不是数组
|
|
88
|
+
const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
|
|
89
|
+
if (!selects.includes(select)) {
|
|
90
|
+
// 继续
|
|
91
|
+
nextMiddleware();
|
|
92
|
+
return;
|
|
102
93
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
|
|
95
|
+
let index = 0;
|
|
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;
|
|
109
106
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* @param res
|
|
117
|
-
* @returns
|
|
118
|
-
*/
|
|
119
|
-
const onRes = (res) => {
|
|
120
|
-
if (isNext) {
|
|
121
|
-
return;
|
|
107
|
+
else if (Array.isArray(res)) {
|
|
108
|
+
if (res.length > 0) {
|
|
109
|
+
// 发送数据
|
|
110
|
+
Send(...res);
|
|
122
111
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
else if (typeof res === 'object') {
|
|
130
|
-
if (Array.isArray(res.data)) {
|
|
131
|
-
// 发送数据
|
|
132
|
-
Send(...res.data);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const start = async () => {
|
|
137
|
-
if (i >= app.default.current.length)
|
|
138
|
-
return;
|
|
139
|
-
if (isNext)
|
|
140
|
-
return;
|
|
141
|
-
if (isAsyncFunction(app.default.current[i])) {
|
|
142
|
-
const res = await app.default.current[i](valueEvent, (...cns) => {
|
|
143
|
-
isNext = true;
|
|
144
|
-
nextMiddleware(...cns);
|
|
145
|
-
});
|
|
146
|
-
onRes(res);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
const res = app.default.current[i](valueEvent, (...cns) => {
|
|
150
|
-
isNext = true;
|
|
151
|
-
nextMiddleware(...cns);
|
|
152
|
-
});
|
|
153
|
-
onRes(res);
|
|
154
|
-
}
|
|
155
|
-
++i;
|
|
156
|
-
await start();
|
|
157
|
-
};
|
|
158
|
-
await start();
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
let isNext = false;
|
|
162
|
-
const onRes = (res) => {
|
|
163
|
-
if (isNext) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (Array.isArray(res)) {
|
|
167
|
-
if (res.length > 0) {
|
|
168
|
-
// 发送数据
|
|
169
|
-
Send(...res);
|
|
170
|
-
}
|
|
112
|
+
isClose = true;
|
|
113
|
+
}
|
|
114
|
+
else if (typeof res === 'object') {
|
|
115
|
+
if (Array.isArray(res.data)) {
|
|
116
|
+
// 发送数据
|
|
117
|
+
Send(...res.data);
|
|
171
118
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// 发送数据
|
|
175
|
-
Send(...res.data);
|
|
176
|
-
}
|
|
119
|
+
if (!res.allowGrouping) {
|
|
120
|
+
isClose = true;
|
|
177
121
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const start = async () => {
|
|
125
|
+
if (index >= currents.length)
|
|
126
|
+
return;
|
|
127
|
+
if (isNext)
|
|
128
|
+
return;
|
|
129
|
+
if (isClose)
|
|
130
|
+
return;
|
|
131
|
+
if (isAsyncFunction(currents[index])) {
|
|
132
|
+
const res = await currents[index](valueEvent, (...cns) => {
|
|
182
133
|
isNext = true;
|
|
183
134
|
nextMiddleware(...cns);
|
|
184
135
|
});
|
|
185
136
|
onRes(res);
|
|
186
137
|
}
|
|
187
138
|
else {
|
|
188
|
-
const res =
|
|
139
|
+
const res = currents[index](valueEvent, (...cns) => {
|
|
189
140
|
isNext = true;
|
|
190
141
|
nextMiddleware(...cns);
|
|
191
142
|
});
|
|
192
143
|
onRes(res);
|
|
193
144
|
}
|
|
194
|
-
|
|
145
|
+
++index;
|
|
146
|
+
start();
|
|
147
|
+
};
|
|
148
|
+
start();
|
|
195
149
|
}
|
|
196
150
|
catch (err) {
|
|
197
151
|
showErrorModule(err);
|
package/lib/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { PublicEventMessageCreate, PublicEventMessageDelete, PublicEventMessageR
|
|
|
10
10
|
export { PrivateEventMessageCreate, PrivateEventMessageDelete, PrivateEventMessageUpdate } from './typing/event/message/private.message.js';
|
|
11
11
|
export { PrivateEventRequestFriendAdd, PrivateEventRequestGuildAdd } from './typing/event/request/index.js';
|
|
12
12
|
export { ActionsEventEnum } from './typing/event/actions.js';
|
|
13
|
-
export { Current, CurrentResult, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue } from './typing/event/index.js';
|
|
13
|
+
export { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue } from './typing/event/index.js';
|
|
14
14
|
export { EventKeys, Events, EventsEnum, EventsKeyEnum, EventsMessageCreate, EventsMessageCreateEnum, EventsMessageCreateKeys } from './typing/event/map.js';
|
|
15
15
|
export { LoggerUtils } from './typing/logger/index.js';
|
|
16
16
|
export { ClientAPI, ClientAPIMessageResult } from './typing/client/index.js';
|
|
@@ -11,10 +11,11 @@ type CurrentResult = {
|
|
|
11
11
|
data?: DataEnums[];
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
};
|
|
14
|
+
type CurrentResultValue = void | CurrentResult['allowGrouping'] | CurrentResult | CurrentResult['data'];
|
|
14
15
|
/**
|
|
15
16
|
* 当前事件
|
|
16
17
|
*/
|
|
17
|
-
type Current<T extends EventKeys> = (event: Events[T], next: Next) =>
|
|
18
|
+
type Current<T extends EventKeys> = (event: Events[T], next: Next) => CurrentResultValue;
|
|
18
19
|
/**
|
|
19
20
|
* 定义一个响应
|
|
20
21
|
*/
|
|
@@ -85,4 +86,4 @@ type DefineBotValue = DefinePlatformValue;
|
|
|
85
86
|
*/
|
|
86
87
|
type DefineBot = DefinePlatformFunc;
|
|
87
88
|
|
|
88
|
-
export type { Current, CurrentResult, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue };
|
|
89
|
+
export type { Current, CurrentResult, CurrentResultValue, DefineBot, DefineBotCallback, DefineBotValue, DefineChildrenCallback, DefineChildrenFunc, DefineChildrenValue, DefinePlatformCallback, DefinePlatformFunc, DefinePlatformValue, OnMiddlewareFunc, OnMiddlewareReversalFunc, OnMiddlewareValue, OnResponseFunc, OnResponseReversalFunc, OnResponseValue };
|