alemonjs 2.1.32 → 2.1.33
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/SinglyLinkedList.d.ts +1 -0
- package/lib/app/SinglyLinkedList.js +10 -1
- package/lib/app/event-processor-cycleRoute.js +1 -0
- package/lib/app/event-processor-subscribe.js +10 -14
- package/lib/app/event-processor.js +10 -8
- package/lib/app/hook-use-state.js +6 -8
- package/lib/app/hook-use-subscribe.js +13 -14
- package/lib/core/variable.js +1 -3
- package/lib/process/direct-channel.js +7 -2
- package/lib/types/event/index.d.ts +3 -3
- package/lib/types/event/member/index.d.ts +1 -1
- package/lib/types/event/request/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -63,13 +63,22 @@ class SinglyLinkedList {
|
|
|
63
63
|
if (this.current === this.tail) {
|
|
64
64
|
this.tail = previous;
|
|
65
65
|
}
|
|
66
|
-
this.current =
|
|
66
|
+
this.current = previous;
|
|
67
67
|
this.size--;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
getSize() {
|
|
71
71
|
return this.size;
|
|
72
72
|
}
|
|
73
|
+
forEach(callback) {
|
|
74
|
+
let node = this.head;
|
|
75
|
+
while (node) {
|
|
76
|
+
if (callback(node) === true) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
node = node.next;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
export { SinglyLinkedList };
|
|
@@ -29,27 +29,23 @@ const expendSubscribe = (valueEvent, select, next, choose) => {
|
|
|
29
29
|
const onActive = () => {
|
|
30
30
|
for (const select of selects) {
|
|
31
31
|
const subListVal = getSubscribeList(choose, select);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
break;
|
|
32
|
+
subListVal.forEach(node => {
|
|
33
|
+
if (node.data.id === ID) {
|
|
34
|
+
node.data.status = SubscribeStatus.active;
|
|
35
|
+
return true;
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
});
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
const onPaused = () => {
|
|
43
41
|
for (const select of selects) {
|
|
44
42
|
const subListVal = getSubscribeList(choose, select);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
break;
|
|
43
|
+
subListVal.forEach(node => {
|
|
44
|
+
if (node.data.id === ID) {
|
|
45
|
+
node.data.status = SubscribeStatus.paused;
|
|
46
|
+
return true;
|
|
50
47
|
}
|
|
51
|
-
|
|
52
|
-
}
|
|
48
|
+
});
|
|
53
49
|
}
|
|
54
50
|
};
|
|
55
51
|
onPaused();
|
|
@@ -86,14 +86,16 @@ const onProcessor = (name, event, data) => {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
const mappingText = value?.mapping_text ?? [];
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
if (event['MessageText']) {
|
|
90
|
+
for (const mapping of mappingText) {
|
|
91
|
+
const { regular, target } = mapping ?? {};
|
|
92
|
+
if (!regular) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const cachedReg = getCachedRegExp(regular);
|
|
96
|
+
if (cachedReg.test(event['MessageText'])) {
|
|
97
|
+
event['MessageText'] = event['MessageText'].replace(cachedReg, target);
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
const masterId = value?.master_id ?? {};
|
|
@@ -29,14 +29,12 @@ const useState = (name, defaultValue = true) => {
|
|
|
29
29
|
cfg.value.core ??= {};
|
|
30
30
|
cfg.value.core.state ??= [];
|
|
31
31
|
const cfgState = cfg.value.core.state;
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
cfg.value.core.state.push(name);
|
|
39
|
-
}
|
|
32
|
+
const exists = cfgState.includes(name);
|
|
33
|
+
if (value && exists) {
|
|
34
|
+
cfg.value.core.state = cfg.value.core.state.filter((i) => i !== name);
|
|
35
|
+
}
|
|
36
|
+
else if (!value && !exists) {
|
|
37
|
+
cfg.value.core.state.push(name);
|
|
40
38
|
}
|
|
41
39
|
cfg.saveValue(cfg.value);
|
|
42
40
|
};
|
|
@@ -22,11 +22,16 @@ const useSubscribe = (event, selects) => {
|
|
|
22
22
|
const register = (callback, keys, choose) => {
|
|
23
23
|
const curSelects = Array.isArray(selects) ? selects : [selects];
|
|
24
24
|
const ID = Date.now().toString(36) + Math.random().toString(36).substring(2, 15);
|
|
25
|
+
if (keys.length === 0) {
|
|
26
|
+
logger.warn({
|
|
27
|
+
code: ResultCode.FailParams,
|
|
28
|
+
message: 'subscribe keys is empty',
|
|
29
|
+
data: null
|
|
30
|
+
});
|
|
31
|
+
return { selects: curSelects, choose, id: ID };
|
|
32
|
+
}
|
|
25
33
|
for (const select of curSelects) {
|
|
26
34
|
const subList = new SubscribeList(choose, select);
|
|
27
|
-
if (keys.length === 0) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
35
|
const values = {};
|
|
31
36
|
for (const key of keys) {
|
|
32
37
|
if (typeof key === 'string' && (typeof event[key] === 'string' || typeof event[key] === 'number' || typeof event[key] === 'boolean')) {
|
|
@@ -69,18 +74,12 @@ const useSubscribe = (event, selects) => {
|
|
|
69
74
|
const ID = value.id;
|
|
70
75
|
for (const select of selects) {
|
|
71
76
|
const subList = new SubscribeList(value.choose, select);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return;
|
|
77
|
+
subList.value.forEach(node => {
|
|
78
|
+
if (node.data.id === ID) {
|
|
79
|
+
node.data.status = SubscribeStatus.paused;
|
|
80
|
+
return true;
|
|
76
81
|
}
|
|
77
|
-
|
|
78
|
-
find();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
item.data.status = SubscribeStatus.paused;
|
|
82
|
-
};
|
|
83
|
-
find();
|
|
82
|
+
});
|
|
84
83
|
}
|
|
85
84
|
};
|
|
86
85
|
const subscribe = {
|
package/lib/core/variable.js
CHANGED
|
@@ -43,9 +43,6 @@ class Result {
|
|
|
43
43
|
if (this.#data[this.#currentIndex]) {
|
|
44
44
|
this.#currentIndex++;
|
|
45
45
|
}
|
|
46
|
-
else {
|
|
47
|
-
this.#currentIndex = 0;
|
|
48
|
-
}
|
|
49
46
|
return this;
|
|
50
47
|
}
|
|
51
48
|
updateMessage(msg) {
|
|
@@ -67,6 +64,7 @@ class Result {
|
|
|
67
64
|
data: data
|
|
68
65
|
};
|
|
69
66
|
}
|
|
67
|
+
this.#data[this.#currentIndex].data = data;
|
|
70
68
|
return this;
|
|
71
69
|
}
|
|
72
70
|
updateCode(callback) {
|
|
@@ -52,10 +52,12 @@ const createDirectServer = (sockPath, onMessage) => {
|
|
|
52
52
|
const parser = createMessageParser(onMessage);
|
|
53
53
|
socket.on('data', parser);
|
|
54
54
|
socket.on('error', () => {
|
|
55
|
-
connection
|
|
55
|
+
if (connection === socket)
|
|
56
|
+
connection = null;
|
|
56
57
|
});
|
|
57
58
|
socket.on('close', () => {
|
|
58
|
-
connection
|
|
59
|
+
if (connection === socket)
|
|
60
|
+
connection = null;
|
|
59
61
|
});
|
|
60
62
|
});
|
|
61
63
|
const cleanup = () => {
|
|
@@ -93,6 +95,9 @@ const createDirectClient = (sockPath, onMessage, maxRetries = 30, retryDelay = 1
|
|
|
93
95
|
return new Promise((resolve, reject) => {
|
|
94
96
|
const parser = createMessageParser(onMessage);
|
|
95
97
|
const socket = net.createConnection(sockPath, () => {
|
|
98
|
+
socket.removeListener('error', reject);
|
|
99
|
+
socket.on('error', () => {
|
|
100
|
+
});
|
|
96
101
|
resolve({
|
|
97
102
|
send: (data) => {
|
|
98
103
|
if (!socket.destroyed) {
|
|
@@ -2,7 +2,7 @@ import { ChildrenCycle, Next } from '../cycle';
|
|
|
2
2
|
import { ClientAPI } from '../client';
|
|
3
3
|
import { EventKeys, Events } from './map';
|
|
4
4
|
import { DataEnums } from '../message';
|
|
5
|
-
export type Current<T extends EventKeys> = (event: Events[T], next: Next) =>
|
|
5
|
+
export type Current<T extends EventKeys> = (event: Events[T], next: Next) => boolean | Promise<boolean> | undefined;
|
|
6
6
|
export type OnResponseValue<C, T extends EventKeys> = {
|
|
7
7
|
current: C;
|
|
8
8
|
select: T | T[];
|
|
@@ -54,8 +54,8 @@ export type childrenCallbackRes = {
|
|
|
54
54
|
middleware?: ReturnType<defineMiddlewareFunc>;
|
|
55
55
|
responseRouter?: ReturnType<DefineRouterFunc>;
|
|
56
56
|
middlewareRouter?: ReturnType<DefineRouterFunc>;
|
|
57
|
-
} |
|
|
57
|
+
} | undefined;
|
|
58
58
|
export type childrenCallback = ChildrenCycle & {
|
|
59
|
-
register?: () => (childrenCallbackRes |
|
|
59
|
+
register?: () => (childrenCallbackRes | undefined) | Promise<childrenCallbackRes | undefined>;
|
|
60
60
|
};
|
|
61
61
|
export type DefineChildrenCallback = (() => Promise<childrenCallback> | childrenCallback) | childrenCallback;
|
|
@@ -4,7 +4,7 @@ import { User } from '../base/user';
|
|
|
4
4
|
import { platform } from '../base/platform';
|
|
5
5
|
import { Expansion } from '../base/expansion';
|
|
6
6
|
export type PublicEventMemberAdd = platform & Guild & Channel & Message & User & {
|
|
7
|
-
|
|
7
|
+
name: 'member.add';
|
|
8
8
|
} & Expansion;
|
|
9
9
|
export type PublicEventMemberRemove = platform & Guild & Channel & Message & User & {
|
|
10
10
|
name: 'member.remove';
|
|
@@ -3,8 +3,8 @@ import { Message } from '../base/message';
|
|
|
3
3
|
import { platform } from '../base/platform';
|
|
4
4
|
import { User } from '../base/user';
|
|
5
5
|
export type PrivateEventRequestFriendAdd = platform & Message & User & {
|
|
6
|
-
name: 'private.
|
|
6
|
+
name: 'private.friend.add';
|
|
7
7
|
} & Expansion;
|
|
8
8
|
export type PrivateEventRequestGuildAdd = platform & Message & User & {
|
|
9
|
-
name: 'private.
|
|
9
|
+
name: 'private.guild.add';
|
|
10
10
|
} & Expansion;
|