alemonjs 2.0.12 → 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,101 +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
|
-
if (res.length > 0) {
|
|
126
|
-
// 发送数据
|
|
127
|
-
Send(...res);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (typeof res === 'object') {
|
|
131
|
-
if (typeof res?.allowGrouping === 'boolean') {
|
|
132
|
-
T = res.allowGrouping;
|
|
133
|
-
}
|
|
134
|
-
if (Array.isArray(res.data)) {
|
|
135
|
-
// 发送数据
|
|
136
|
-
Send(...res.data);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
const start = async () => {
|
|
141
|
-
if (i >= app.default.current.length)
|
|
142
|
-
return;
|
|
143
|
-
// 不是真的
|
|
144
|
-
if (!T)
|
|
145
|
-
return;
|
|
146
|
-
if (isAsyncFunction(app.default.current[i])) {
|
|
147
|
-
const res = await app.default.current[i](valueEvent, (...cns) => {
|
|
148
|
-
isNext = true;
|
|
149
|
-
nextEvent(...cns);
|
|
150
|
-
});
|
|
151
|
-
onRes(res);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
const res = app.default.current[i](valueEvent, (...cns) => {
|
|
155
|
-
isNext = true;
|
|
156
|
-
nextEvent(...cns);
|
|
157
|
-
});
|
|
158
|
-
onRes(res);
|
|
159
|
-
}
|
|
160
|
-
++i;
|
|
161
|
-
await start();
|
|
162
|
-
};
|
|
163
|
-
await start();
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
let isNext = false;
|
|
167
|
-
const onRes = (res) => {
|
|
168
|
-
if (isNext) {
|
|
169
|
-
// 内部调用了next
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (typeof res === 'boolean') {
|
|
173
|
-
// T = res
|
|
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);
|
|
174
109
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
110
|
+
isClose = true;
|
|
111
|
+
}
|
|
112
|
+
else if (typeof res === 'object') {
|
|
113
|
+
if (Array.isArray(res.data)) {
|
|
114
|
+
// 发送数据
|
|
115
|
+
Send(...res.data);
|
|
180
116
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// T = res.allowGrouping
|
|
184
|
-
}
|
|
185
|
-
if (Array.isArray(res.data)) {
|
|
186
|
-
// 发送数据
|
|
187
|
-
Send(...res.data);
|
|
188
|
-
}
|
|
117
|
+
if (!res.allowGrouping) {
|
|
118
|
+
isClose = true;
|
|
189
119
|
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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) => {
|
|
194
131
|
isNext = true;
|
|
195
132
|
nextEvent(...cns);
|
|
196
133
|
});
|
|
197
134
|
onRes(res);
|
|
198
135
|
}
|
|
199
136
|
else {
|
|
200
|
-
const res =
|
|
137
|
+
const res = currents[index](valueEvent, (...cns) => {
|
|
201
138
|
isNext = true;
|
|
202
139
|
nextEvent(...cns);
|
|
203
140
|
});
|
|
204
141
|
onRes(res);
|
|
205
142
|
}
|
|
206
|
-
|
|
143
|
+
++index;
|
|
144
|
+
start();
|
|
145
|
+
};
|
|
146
|
+
start();
|
|
207
147
|
}
|
|
208
148
|
catch (err) {
|
|
209
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,124 +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
|
-
let isNext = false;
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
* @param res
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
const onRes = (res) => {
|
|
121
|
-
if (isNext) {
|
|
122
|
-
// 被调用了next
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (typeof res === 'boolean') {
|
|
126
|
-
T = res;
|
|
107
|
+
else if (Array.isArray(res)) {
|
|
108
|
+
if (res.length > 0) {
|
|
109
|
+
// 发送数据
|
|
110
|
+
Send(...res);
|
|
127
111
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
else if (typeof res === 'object') {
|
|
135
|
-
if (typeof res?.allowGrouping === 'boolean') {
|
|
136
|
-
T = res.allowGrouping;
|
|
137
|
-
}
|
|
138
|
-
if (Array.isArray(res.data)) {
|
|
139
|
-
// 发送数据
|
|
140
|
-
Send(...res.data);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const start = async () => {
|
|
145
|
-
if (i >= app.default.current.length)
|
|
146
|
-
return;
|
|
147
|
-
// 不是真的
|
|
148
|
-
if (!T)
|
|
149
|
-
return;
|
|
150
|
-
if (isAsyncFunction(app.default.current[i])) {
|
|
151
|
-
const res = await app.default.current[i](valueEvent, (...cns) => {
|
|
152
|
-
isNext = true;
|
|
153
|
-
nextMiddleware(...cns);
|
|
154
|
-
});
|
|
155
|
-
onRes(res);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
const res = app.default.current[i](valueEvent, (...cns) => {
|
|
159
|
-
isNext = true;
|
|
160
|
-
nextMiddleware(...cns);
|
|
161
|
-
});
|
|
162
|
-
onRes(res);
|
|
163
|
-
}
|
|
164
|
-
++i;
|
|
165
|
-
await start();
|
|
166
|
-
};
|
|
167
|
-
await start();
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
let isNext = false;
|
|
171
|
-
const onRes = (res) => {
|
|
172
|
-
if (isNext) {
|
|
173
|
-
// 被调用了next
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (typeof res === 'boolean') {
|
|
177
|
-
// T = res
|
|
178
|
-
}
|
|
179
|
-
else if (Array.isArray(res)) {
|
|
180
|
-
if (res.length > 0) {
|
|
181
|
-
// 发送数据
|
|
182
|
-
Send(...res);
|
|
183
|
-
}
|
|
112
|
+
isClose = true;
|
|
113
|
+
}
|
|
114
|
+
else if (typeof res === 'object') {
|
|
115
|
+
if (Array.isArray(res.data)) {
|
|
116
|
+
// 发送数据
|
|
117
|
+
Send(...res.data);
|
|
184
118
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// T = res.allowGrouping
|
|
188
|
-
}
|
|
189
|
-
if (Array.isArray(res.data)) {
|
|
190
|
-
// 发送数据
|
|
191
|
-
Send(...res.data);
|
|
192
|
-
}
|
|
119
|
+
if (!res.allowGrouping) {
|
|
120
|
+
isClose = true;
|
|
193
121
|
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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) => {
|
|
198
133
|
isNext = true;
|
|
199
134
|
nextMiddleware(...cns);
|
|
200
135
|
});
|
|
201
136
|
onRes(res);
|
|
202
137
|
}
|
|
203
138
|
else {
|
|
204
|
-
const res =
|
|
139
|
+
const res = currents[index](valueEvent, (...cns) => {
|
|
205
140
|
isNext = true;
|
|
206
141
|
nextMiddleware(...cns);
|
|
207
142
|
});
|
|
208
143
|
onRes(res);
|
|
209
144
|
}
|
|
210
|
-
|
|
145
|
+
++index;
|
|
146
|
+
start();
|
|
147
|
+
};
|
|
148
|
+
start();
|
|
211
149
|
}
|
|
212
150
|
catch (err) {
|
|
213
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 };
|