alemonjs 2.1.18 → 2.1.20
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/lib/app/define-response.d.ts +0 -3
- package/lib/app/define-response.js +1 -5
- package/lib/app/define-router.d.ts +5 -0
- package/lib/app/define-router.js +20 -0
- package/lib/app/event-processor-cycleRoute.js +31 -5
- package/lib/app/hook-use-api.d.ts +14 -6
- package/lib/app/hook-use-api.js +80 -82
- package/lib/app/index.d.ts +1 -0
- package/lib/app/index.js +3 -2
- package/lib/app/load_modules/loadChild.js +1 -1
- package/lib/app/message-format.d.ts +30 -1
- package/lib/app/message-format.js +82 -1
- package/lib/app/store.js +14 -2
- package/lib/index.js +3 -2
- package/lib/types/event/index.d.ts +7 -0
- package/package.json +1 -1
- package/lib/app/define-chidren.d.ts +0 -2
- package/lib/app/define-chidren.js +0 -19
- package/lib/app/define-pl.ts +0 -0
- package/lib/cbp/core/connection-manager.d.ts +0 -18
- package/lib/cbp/core/connection-manager.js +0 -67
- package/lib/cbp/core/constants.d.ts +0 -19
- package/lib/cbp/core/constants.js +0 -23
- package/lib/cbp/core/load-balancer.d.ts +0 -37
- package/lib/cbp/core/load-balancer.js +0 -118
- package/lib/cbp/processor/heandle.d.ts +0 -3
- package/lib/cbp/processor/heandle.js +0 -32
- package/lib/cbp/processor/request-handler.d.ts +0 -17
- package/lib/cbp/processor/request-handler.js +0 -65
- package/lib/polyfills/fs-promises.d.ts +0 -41
- package/lib/polyfills/fs-promises.js +0 -138
- package/lib/polyfills/fs.d.ts +0 -103
- package/lib/polyfills/fs.js +0 -229
- package/lib/polyfills/util-types.d.ts +0 -33
- package/lib/polyfills/util-types.js +0 -36
- package/lib/types/event/channal/index.d.ts +0 -10
- package/lib/types/event/channal/index.js +0 -1
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
const lazy = (fnc) => {
|
|
2
|
-
const back = async () => (await fnc()).default;
|
|
3
|
-
return back;
|
|
4
|
-
};
|
|
5
1
|
const defineResponse = responses => {
|
|
6
2
|
return {
|
|
7
3
|
current: responses
|
|
@@ -9,4 +5,4 @@ const defineResponse = responses => {
|
|
|
9
5
|
};
|
|
10
6
|
global.defineResponse = defineResponse;
|
|
11
7
|
|
|
12
|
-
export { defineResponse
|
|
8
|
+
export { defineResponse };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const lazy = (fnc) => {
|
|
2
|
+
let c = null;
|
|
3
|
+
const back = async () => {
|
|
4
|
+
if (c) {
|
|
5
|
+
return c;
|
|
6
|
+
}
|
|
7
|
+
const mod = await fnc();
|
|
8
|
+
if (!mod || !mod.default) ;
|
|
9
|
+
c = mod.default;
|
|
10
|
+
return c;
|
|
11
|
+
};
|
|
12
|
+
return back;
|
|
13
|
+
};
|
|
14
|
+
const defineRouter = routes => {
|
|
15
|
+
return {
|
|
16
|
+
current: routes
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { defineRouter, lazy };
|
|
@@ -4,6 +4,13 @@ import 'path';
|
|
|
4
4
|
import 'yaml';
|
|
5
5
|
import { showErrorModule } from '../core/utils.js';
|
|
6
6
|
|
|
7
|
+
function isAsyncFunction(fn) {
|
|
8
|
+
const AsyncFunction = (async () => { }).constructor;
|
|
9
|
+
return fn instanceof AsyncFunction;
|
|
10
|
+
}
|
|
11
|
+
function isFunction(value) {
|
|
12
|
+
return isAsyncFunction(value) || typeof value === 'function' || value instanceof Function;
|
|
13
|
+
}
|
|
7
14
|
const createRouteProcessChildren = (valueEvent, select, nextCycle, callHandler) => {
|
|
8
15
|
const processChildren = (nodes, middleware, next) => {
|
|
9
16
|
if (!nodes || nodes.length === 0) {
|
|
@@ -25,11 +32,26 @@ const createRouteProcessChildren = (valueEvent, select, nextCycle, callHandler)
|
|
|
25
32
|
return;
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
|
-
if (EventMessageText.includes(select)
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
if (EventMessageText.includes(select)) {
|
|
36
|
+
const text = valueEvent['MessageText'] ?? '';
|
|
37
|
+
if (node.exact !== undefined) {
|
|
38
|
+
if (text !== node.exact) {
|
|
39
|
+
void nextNode();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (node.prefix !== undefined) {
|
|
44
|
+
if (!text.startsWith(node.prefix)) {
|
|
45
|
+
void nextNode();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (node.regular) {
|
|
50
|
+
const reg = new RegExp(node.regular);
|
|
51
|
+
if (!reg.test(text)) {
|
|
52
|
+
void nextNode();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
33
55
|
}
|
|
34
56
|
}
|
|
35
57
|
if (!node.handler) {
|
|
@@ -45,6 +67,10 @@ const createRouteProcessChildren = (valueEvent, select, nextCycle, callHandler)
|
|
|
45
67
|
const currents = [];
|
|
46
68
|
for (const item of currentsAndMiddleware) {
|
|
47
69
|
const app = await item();
|
|
70
|
+
if (isFunction(app)) {
|
|
71
|
+
currents.push(app);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
48
74
|
const selects = Array.isArray(app.select) ? app.select : [app.select];
|
|
49
75
|
if (!selects.includes(select)) {
|
|
50
76
|
void nextNode();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataEnums, EventKeys, Events, User } from '../types';
|
|
2
2
|
import { Result } from '../core/utils';
|
|
3
|
-
import { BT, MD } from './message-format';
|
|
3
|
+
import { BT, Format, MD } from './message-format';
|
|
4
4
|
type Options = {
|
|
5
5
|
UserId?: string;
|
|
6
6
|
UserKey?: string;
|
|
@@ -9,11 +9,15 @@ type Options = {
|
|
|
9
9
|
IsBot?: boolean;
|
|
10
10
|
};
|
|
11
11
|
export declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
|
|
12
|
-
find: (options
|
|
13
|
-
|
|
12
|
+
find: (options?: Options) => Promise<Result<User[]> & {
|
|
13
|
+
count: number;
|
|
14
|
+
}>;
|
|
15
|
+
findOne: (options?: Options) => Promise<Result<User | null> & {
|
|
16
|
+
count: number;
|
|
17
|
+
}>;
|
|
14
18
|
}];
|
|
15
19
|
export declare const useMessage: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
16
|
-
"__#
|
|
20
|
+
"__#8@#format": DataEnums[];
|
|
17
21
|
readonly currentFormat: DataEnums[];
|
|
18
22
|
addText(val: string, options?: {
|
|
19
23
|
style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
|
|
@@ -36,12 +40,16 @@ export declare const useMessage: <T extends EventKeys>(event: Events[T]) => read
|
|
|
36
40
|
}): any;
|
|
37
41
|
addFormat(val: DataEnums[]): any;
|
|
38
42
|
clear(): any;
|
|
39
|
-
send(
|
|
43
|
+
send(params?: {
|
|
44
|
+
format: Format | DataEnums[];
|
|
45
|
+
} | DataEnums[]): Promise<Result[]>;
|
|
40
46
|
}];
|
|
41
47
|
export declare const useMember: <T extends EventKeys>(event: Events[T]) => readonly [{}];
|
|
42
48
|
export declare const useChannel: <T extends EventKeys>(event: Events[T]) => readonly [{}];
|
|
43
49
|
export declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
|
|
44
|
-
export declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(
|
|
50
|
+
export declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(params?: DataEnums[] | {
|
|
51
|
+
format: Format | DataEnums[];
|
|
52
|
+
}) => Promise<Result[]>];
|
|
45
53
|
export declare const unChildren: (name?: string) => void;
|
|
46
54
|
export declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
47
55
|
export declare const createSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
package/lib/app/hook-use-api.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ChildrenApp } from './store.js';
|
|
|
3
3
|
import { createResult } from '../core/utils.js';
|
|
4
4
|
import { sendAction } from '../cbp/processor/actions.js';
|
|
5
5
|
import { sendAPI } from '../cbp/processor/api.js';
|
|
6
|
-
import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format.js';
|
|
6
|
+
import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD, Format } from './message-format.js';
|
|
7
7
|
|
|
8
8
|
const useMention = (event) => {
|
|
9
9
|
if (!event || typeof event !== 'object') {
|
|
@@ -15,94 +15,80 @@ const useMention = (event) => {
|
|
|
15
15
|
throw new Error('Invalid event: event must be an object');
|
|
16
16
|
}
|
|
17
17
|
let res = null;
|
|
18
|
+
const load = async () => {
|
|
19
|
+
if (res) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const results = await sendAction({
|
|
23
|
+
action: 'mention.get',
|
|
24
|
+
payload: { event }
|
|
25
|
+
});
|
|
26
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
27
|
+
if (result) {
|
|
28
|
+
res = result.data;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const match = (item, options) => {
|
|
32
|
+
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (options.IsBot === undefined && item.IsBot) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
18
52
|
const mention = {
|
|
19
53
|
find: async (options = {}) => {
|
|
20
54
|
try {
|
|
21
|
-
|
|
22
|
-
const results = await sendAction({
|
|
23
|
-
action: 'mention.get',
|
|
24
|
-
payload: {
|
|
25
|
-
event
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
29
|
-
if (result) {
|
|
30
|
-
res = result.data;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
55
|
+
await load();
|
|
33
56
|
}
|
|
34
57
|
catch (err) {
|
|
35
|
-
|
|
58
|
+
const result = createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
59
|
+
return {
|
|
60
|
+
...result,
|
|
61
|
+
count: 0
|
|
62
|
+
};
|
|
36
63
|
}
|
|
37
64
|
if (!Array.isArray(res)) {
|
|
38
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
...createResult(ResultCode.Warn, 'No mention data found', null),
|
|
67
|
+
count: 0
|
|
68
|
+
};
|
|
39
69
|
}
|
|
40
|
-
const data = res.filter(item =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
});
|
|
58
|
-
return createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
70
|
+
const data = res.filter(item => match(item, options));
|
|
71
|
+
const result = createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
72
|
+
return {
|
|
73
|
+
...result,
|
|
74
|
+
count: data.length || 0
|
|
75
|
+
};
|
|
59
76
|
},
|
|
60
77
|
findOne: async (options = {}) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
const result = results.find(item => item.code === ResultCode.Ok);
|
|
70
|
-
if (result) {
|
|
71
|
-
res = result.data;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
return createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
77
|
-
}
|
|
78
|
-
if (!Array.isArray(res)) {
|
|
79
|
-
return createResult(ResultCode.Warn, 'No mention data found', null);
|
|
80
|
-
}
|
|
81
|
-
const data = res.find(item => {
|
|
82
|
-
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (item.IsBot) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
});
|
|
102
|
-
if (!data) {
|
|
103
|
-
return createResult(ResultCode.Warn, 'No mention data found', null);
|
|
78
|
+
const results = await mention.find(options);
|
|
79
|
+
if (results.code !== ResultCode.Ok || !results.data?.length) {
|
|
80
|
+
const result = createResult(results.code, results.message, null);
|
|
81
|
+
return {
|
|
82
|
+
...result,
|
|
83
|
+
count: 0
|
|
84
|
+
};
|
|
104
85
|
}
|
|
105
|
-
|
|
86
|
+
const data = results?.data[0];
|
|
87
|
+
const result = createResult(ResultCode.Ok, results.message, data);
|
|
88
|
+
return {
|
|
89
|
+
...result,
|
|
90
|
+
count: results.data?.length || 0
|
|
91
|
+
};
|
|
106
92
|
}
|
|
107
93
|
};
|
|
108
94
|
return [mention];
|
|
@@ -116,7 +102,13 @@ const useMessage = (event) => {
|
|
|
116
102
|
});
|
|
117
103
|
throw new Error('Invalid event: event must be an object');
|
|
118
104
|
}
|
|
119
|
-
const
|
|
105
|
+
const resolveFormat = (params) => {
|
|
106
|
+
if (params.format instanceof Format) {
|
|
107
|
+
return params.format.value;
|
|
108
|
+
}
|
|
109
|
+
return params.format;
|
|
110
|
+
};
|
|
111
|
+
const sendRaw = async (val) => {
|
|
120
112
|
if (!val || val.length === 0) {
|
|
121
113
|
return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
|
|
122
114
|
}
|
|
@@ -184,9 +176,15 @@ const useMessage = (event) => {
|
|
|
184
176
|
this.#format = [];
|
|
185
177
|
return this;
|
|
186
178
|
}
|
|
187
|
-
send(
|
|
188
|
-
|
|
189
|
-
|
|
179
|
+
send(params) {
|
|
180
|
+
if (!params) {
|
|
181
|
+
return sendRaw(this.#format);
|
|
182
|
+
}
|
|
183
|
+
if (Array.isArray(params)) {
|
|
184
|
+
const dataToSend = params.length > 0 ? params : this.#format;
|
|
185
|
+
return sendRaw(dataToSend);
|
|
186
|
+
}
|
|
187
|
+
return sendRaw(resolveFormat(params));
|
|
190
188
|
}
|
|
191
189
|
}
|
|
192
190
|
return [new MessageController()];
|
package/lib/app/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './define-children.js';
|
|
|
4
4
|
export * from './define-platform.js';
|
|
5
5
|
export * from './define-response.js';
|
|
6
6
|
export * from './define-middleware.js';
|
|
7
|
+
export * from './define-router.js';
|
|
7
8
|
export * from './event-group.js';
|
|
8
9
|
export * from './event-middleware';
|
|
9
10
|
export * from './event-processor';
|
package/lib/app/index.js
CHANGED
|
@@ -3,8 +3,9 @@ export { loadModels, run } from './load_modules/load.js';
|
|
|
3
3
|
export { loadChildren, loadChildrenFile } from './load_modules/loadChild.js';
|
|
4
4
|
export { defineChildren } from './define-children.js';
|
|
5
5
|
export { definePlatform } from './define-platform.js';
|
|
6
|
-
export { defineResponse
|
|
6
|
+
export { defineResponse } from './define-response.js';
|
|
7
7
|
export { defineMiddleware } from './define-middleware.js';
|
|
8
|
+
export { defineRouter, lazy } from './define-router.js';
|
|
8
9
|
export { onGroup } from './event-group.js';
|
|
9
10
|
export { OnMiddleware, onMiddleware } from './event-middleware.js';
|
|
10
11
|
export { OnProcessor, onProcessor } from './event-processor.js';
|
|
@@ -17,4 +18,4 @@ export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, use
|
|
|
17
18
|
export { onState, unState, useState } from './hook-use-state.js';
|
|
18
19
|
export { useObserver, useSubscribe } from './hook-use-subscribe.js';
|
|
19
20
|
export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
|
|
20
|
-
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './message-format.js';
|
|
21
|
+
export { Ark, BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent } from './message-format.js';
|
|
@@ -64,7 +64,7 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
64
64
|
}
|
|
65
65
|
const registerMounted = async () => {
|
|
66
66
|
const res = await app?.register();
|
|
67
|
-
if (res && res?.response) {
|
|
67
|
+
if (res && (res?.response || res?.middleware || res?.responseRouter || res?.middlewareRouter)) {
|
|
68
68
|
App.register(res);
|
|
69
69
|
}
|
|
70
70
|
App.on();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode } from '../types';
|
|
1
|
+
import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode, DataEnums, EventKeys, Events } from '../types';
|
|
2
2
|
export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
|
|
3
3
|
export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
|
|
4
4
|
export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
|
|
@@ -48,3 +48,32 @@ declare const MD: {
|
|
|
48
48
|
code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
|
|
49
49
|
};
|
|
50
50
|
export { MD };
|
|
51
|
+
export declare class Format {
|
|
52
|
+
#private;
|
|
53
|
+
static create(): Format;
|
|
54
|
+
get value(): DataEnums[];
|
|
55
|
+
addText(...args: Parameters<typeof Text>): this;
|
|
56
|
+
addTextBreak(): this;
|
|
57
|
+
addLink(...args: Parameters<typeof Link>): this;
|
|
58
|
+
addImage(...args: Parameters<typeof Image>): this;
|
|
59
|
+
addImageFile(...args: Parameters<typeof ImageFile>): this;
|
|
60
|
+
addImageURL(...args: Parameters<typeof ImageURL>): this;
|
|
61
|
+
addMention(...args: Parameters<typeof Mention>): this;
|
|
62
|
+
addButtonGroup(...args: Parameters<typeof BT.group>): this;
|
|
63
|
+
addButtonTemplate(...args: Parameters<typeof BT.template>): this;
|
|
64
|
+
addMarkdown(...args: Parameters<typeof MD>): this;
|
|
65
|
+
addMarkdownTemplate(...args: Parameters<typeof MD.template>): this;
|
|
66
|
+
clear(): this;
|
|
67
|
+
}
|
|
68
|
+
export declare function createEvent<T extends EventKeys>(options: {
|
|
69
|
+
event: any;
|
|
70
|
+
selects: T | T[];
|
|
71
|
+
regular?: RegExp;
|
|
72
|
+
prefix?: string;
|
|
73
|
+
exact?: string;
|
|
74
|
+
}): Events[T] & {
|
|
75
|
+
selects: boolean;
|
|
76
|
+
regular: boolean;
|
|
77
|
+
prefix: boolean;
|
|
78
|
+
exact: boolean;
|
|
79
|
+
};
|
|
@@ -213,5 +213,86 @@ MD.code = (value, options) => {
|
|
|
213
213
|
options: options
|
|
214
214
|
};
|
|
215
215
|
};
|
|
216
|
+
class Format {
|
|
217
|
+
#data = [];
|
|
218
|
+
static create() {
|
|
219
|
+
return new Format();
|
|
220
|
+
}
|
|
221
|
+
get value() {
|
|
222
|
+
return this.#data;
|
|
223
|
+
}
|
|
224
|
+
addText(...args) {
|
|
225
|
+
this.#data.push(Text(...args));
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
addTextBreak() {
|
|
229
|
+
this.#data.push(Text('\n'));
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
addLink(...args) {
|
|
233
|
+
this.#data.push(Link(...args));
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
addImage(...args) {
|
|
237
|
+
this.#data.push(Image(...args));
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
addImageFile(...args) {
|
|
241
|
+
this.#data.push(ImageFile(...args));
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
addImageURL(...args) {
|
|
245
|
+
this.#data.push(ImageURL(...args));
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
addMention(...args) {
|
|
249
|
+
this.#data.push(Mention(...args));
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
addButtonGroup(...args) {
|
|
253
|
+
this.#data.push(BT.group(...args));
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
addButtonTemplate(...args) {
|
|
257
|
+
this.#data.push(BT.template(...args));
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
addMarkdown(...args) {
|
|
261
|
+
this.#data.push(MD(...args));
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
addMarkdownTemplate(...args) {
|
|
265
|
+
this.#data.push(MD.template(...args));
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
clear() {
|
|
269
|
+
this.#data = [];
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function createEvent(options) {
|
|
274
|
+
const { event, selects, regular, prefix, exact } = options;
|
|
275
|
+
const { name, MessageText } = event || {};
|
|
276
|
+
const selectsArr = Array.isArray(selects) ? selects : [selects];
|
|
277
|
+
const o = {
|
|
278
|
+
selects: false,
|
|
279
|
+
regular: false,
|
|
280
|
+
prefix: false,
|
|
281
|
+
exact: false
|
|
282
|
+
};
|
|
283
|
+
if (selectsArr.includes(name)) {
|
|
284
|
+
o.selects = true;
|
|
285
|
+
}
|
|
286
|
+
if (exact && MessageText && MessageText === exact) {
|
|
287
|
+
o.exact = true;
|
|
288
|
+
}
|
|
289
|
+
if (prefix && MessageText?.startsWith(prefix)) {
|
|
290
|
+
o.prefix = true;
|
|
291
|
+
}
|
|
292
|
+
if (regular && MessageText && new RegExp(regular).test(MessageText)) {
|
|
293
|
+
o.regular = true;
|
|
294
|
+
}
|
|
295
|
+
return { ...event, ...o };
|
|
296
|
+
}
|
|
216
297
|
|
|
217
|
-
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text };
|
|
298
|
+
export { Ark, BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent };
|
package/lib/app/store.js
CHANGED
|
@@ -152,7 +152,13 @@ class ResponseRouter {
|
|
|
152
152
|
if (!alemonjsCore.storeChildrenApp[key].register) {
|
|
153
153
|
return [];
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
if (alemonjsCore.storeChildrenApp[key].register?.responseRouter) {
|
|
156
|
+
return alemonjsCore.storeChildrenApp[key].register?.responseRouter?.current ?? [];
|
|
157
|
+
}
|
|
158
|
+
if (alemonjsCore.storeChildrenApp[key].register?.response) {
|
|
159
|
+
return alemonjsCore.storeChildrenApp[key].register?.response?.current ?? [];
|
|
160
|
+
}
|
|
161
|
+
return [];
|
|
156
162
|
});
|
|
157
163
|
return data.flat();
|
|
158
164
|
}
|
|
@@ -163,7 +169,13 @@ class MiddlewareRouter {
|
|
|
163
169
|
if (!alemonjsCore.storeChildrenApp[key].register) {
|
|
164
170
|
return [];
|
|
165
171
|
}
|
|
166
|
-
|
|
172
|
+
if (alemonjsCore.storeChildrenApp[key].register?.middlewareRouter) {
|
|
173
|
+
return alemonjsCore.storeChildrenApp[key].register?.middlewareRouter?.current ?? [];
|
|
174
|
+
}
|
|
175
|
+
if (alemonjsCore.storeChildrenApp[key].register?.middleware) {
|
|
176
|
+
return alemonjsCore.storeChildrenApp[key].register?.middleware?.current ?? [];
|
|
177
|
+
}
|
|
178
|
+
return [];
|
|
167
179
|
});
|
|
168
180
|
return data.flat();
|
|
169
181
|
}
|
package/lib/index.js
CHANGED
|
@@ -10,8 +10,9 @@ export { loadModels, run } from './app/load_modules/load.js';
|
|
|
10
10
|
export { loadChildren, loadChildrenFile } from './app/load_modules/loadChild.js';
|
|
11
11
|
export { defineChildren } from './app/define-children.js';
|
|
12
12
|
export { definePlatform } from './app/define-platform.js';
|
|
13
|
-
export { defineResponse
|
|
13
|
+
export { defineResponse } from './app/define-response.js';
|
|
14
14
|
export { defineMiddleware } from './app/define-middleware.js';
|
|
15
|
+
export { defineRouter, lazy } from './app/define-router.js';
|
|
15
16
|
export { onGroup } from './app/event-group.js';
|
|
16
17
|
export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
|
|
17
18
|
export { OnProcessor, onProcessor } from './app/event-processor.js';
|
|
@@ -24,5 +25,5 @@ export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, use
|
|
|
24
25
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
|
25
26
|
export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
|
|
26
27
|
export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
|
|
27
|
-
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
28
|
+
export { Ark, BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent } from './app/message-format.js';
|
|
28
29
|
export { start } from './main.js';
|
|
@@ -40,6 +40,8 @@ export type OnGroupItem<C = any, T extends EventKeys = EventKeys> = OnResponseVa
|
|
|
40
40
|
export type OnGroupFunc = <C, T extends EventKeys, TFirst extends OnGroupItem<C, T>>(...calls: [TFirst, ...Array<TFirst>]) => TFirst;
|
|
41
41
|
export type ResponseRoute = {
|
|
42
42
|
regular?: RegExp;
|
|
43
|
+
prefix?: string;
|
|
44
|
+
exact?: string;
|
|
43
45
|
selects?: EventKeys | EventKeys[];
|
|
44
46
|
handler: () => Promise<any>;
|
|
45
47
|
children?: ResponseRoute[];
|
|
@@ -47,12 +49,17 @@ export type ResponseRoute = {
|
|
|
47
49
|
export type DefineResponseFunc = (responses: ResponseRoute[]) => {
|
|
48
50
|
current: ResponseRoute[];
|
|
49
51
|
};
|
|
52
|
+
export type DefineRouterFunc = (routes: ResponseRoute[]) => {
|
|
53
|
+
current: ResponseRoute[];
|
|
54
|
+
};
|
|
50
55
|
export type defineMiddlewareFunc = (middleware: ResponseRoute[]) => {
|
|
51
56
|
current: ResponseRoute[];
|
|
52
57
|
};
|
|
53
58
|
export type childrenCallbackRes = {
|
|
54
59
|
response?: ReturnType<DefineResponseFunc>;
|
|
55
60
|
middleware?: ReturnType<defineMiddlewareFunc>;
|
|
61
|
+
responseRouter?: ReturnType<DefineRouterFunc>;
|
|
62
|
+
middlewareRouter?: ReturnType<DefineRouterFunc>;
|
|
56
63
|
} | void;
|
|
57
64
|
export type childrenCallback = ChildrenCycle & {
|
|
58
65
|
register?: () => (childrenCallbackRes | void) | Promise<childrenCallbackRes | void>;
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../core/variable.js';
|
|
2
|
-
|
|
3
|
-
const defineChildren = callback => {
|
|
4
|
-
if (typeof callback === 'function' || typeof callback === 'object') {
|
|
5
|
-
return {
|
|
6
|
-
_name: 'app',
|
|
7
|
-
callback
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
logger.error({
|
|
11
|
-
code: ResultCode.FailParams,
|
|
12
|
-
message: 'Invalid callback: callback must be a object or function',
|
|
13
|
-
data: null
|
|
14
|
-
});
|
|
15
|
-
throw new Error('Invalid callback: callback must be a object or function');
|
|
16
|
-
};
|
|
17
|
-
global.defineChildren = defineChildren;
|
|
18
|
-
|
|
19
|
-
export { defineChildren };
|
package/lib/app/define-pl.ts
DELETED
|
File without changes
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
export interface ConnectionState {
|
|
3
|
-
connections: Map<string, WebSocket>;
|
|
4
|
-
lastActivity: Map<string, number>;
|
|
5
|
-
metadata: Map<string, any>;
|
|
6
|
-
}
|
|
7
|
-
export declare const createConnectionState: () => ConnectionState;
|
|
8
|
-
export declare const addConnection: (state: ConnectionState, id: string, ws: WebSocket, metadata?: any) => ConnectionState;
|
|
9
|
-
export declare const removeConnection: (state: ConnectionState, id: string) => ConnectionState;
|
|
10
|
-
export declare const getConnection: (state: ConnectionState, id: string) => WebSocket | undefined;
|
|
11
|
-
export declare const getHealthyConnectionIds: (state: ConnectionState) => string[];
|
|
12
|
-
export declare const getConnectionStats: (state: ConnectionState) => {
|
|
13
|
-
total: number;
|
|
14
|
-
healthy: number;
|
|
15
|
-
unhealthy: number;
|
|
16
|
-
lastUpdate: number;
|
|
17
|
-
};
|
|
18
|
-
export declare const clearAllConnections: (state: ConnectionState) => ConnectionState;
|