alemonjs 2.1.41 → 2.1.43
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/define-children.d.ts +8 -0
- package/lib/app/define/define-children.js +25 -0
- package/lib/app/define/define-middleware.d.ts +2 -0
- package/lib/app/define/define-middleware.js +8 -0
- package/lib/app/define/define-platform.d.ts +13 -0
- package/lib/app/define/define-platform.js +40 -0
- package/lib/app/define/define-response.d.ts +2 -0
- package/lib/app/define/define-response.js +8 -0
- package/lib/app/define/define-router.d.ts +17 -0
- package/lib/app/define/define-router.js +34 -0
- package/lib/app/event/event-group.d.ts +9 -0
- package/lib/app/event/event-group.js +29 -0
- package/lib/app/event/event-middleware.d.ts +23 -0
- package/lib/app/event/event-middleware.js +44 -0
- package/lib/app/event/event-response.d.ts +16 -0
- package/lib/app/event/event-response.js +23 -0
- package/lib/app/event/event-selects.d.ts +13 -0
- package/lib/app/event/event-selects.js +15 -0
- package/lib/app/event-processor/event-processor-callHandler.d.ts +1 -0
- package/lib/app/event-processor/event-processor-callHandler.js +43 -0
- package/lib/app/event-processor/event-processor-cycle.d.ts +14 -0
- package/lib/app/event-processor/event-processor-cycle.js +97 -0
- package/lib/app/event-processor/event-processor-cycleFiles.d.ts +11 -0
- package/lib/app/event-processor/event-processor-cycleFiles.js +147 -0
- package/lib/app/event-processor/event-processor-cycleRoute.d.ts +10 -0
- package/lib/app/event-processor/event-processor-cycleRoute.js +133 -0
- package/lib/app/event-processor/event-processor-event.d.ts +24 -0
- package/lib/app/event-processor/event-processor-event.js +41 -0
- package/lib/app/event-processor/event-processor-middleware.d.ts +14 -0
- package/lib/app/event-processor/event-processor-middleware.js +31 -0
- package/lib/app/event-processor/event-processor-subscribe.d.ts +35 -0
- package/lib/app/event-processor/event-processor-subscribe.js +115 -0
- package/lib/app/event-processor/event-processor.d.ts +17 -0
- package/lib/app/event-processor/event-processor.js +207 -0
- package/lib/app/hook-use/hook-use-api.d.ts +6 -0
- package/lib/app/hook-use/hook-use-api.js +22 -0
- package/lib/app/hook-use/hook-use-channel.d.ts +8 -0
- package/lib/app/hook-use/hook-use-channel.js +33 -0
- package/lib/app/hook-use/hook-use-client.d.ts +7 -0
- package/lib/app/hook-use/hook-use-client.js +27 -0
- package/lib/app/hook-use/hook-use-me.d.ts +8 -0
- package/lib/app/hook-use/hook-use-me.js +45 -0
- package/lib/app/hook-use/hook-use-menber.d.ts +8 -0
- package/lib/app/hook-use/hook-use-menber.js +59 -0
- package/lib/app/hook-use/hook-use-mention.d.ts +23 -0
- package/lib/app/hook-use/hook-use-mention.js +105 -0
- package/lib/app/hook-use/hook-use-message.d.ts +29 -0
- package/lib/app/hook-use/hook-use-message.js +88 -0
- package/lib/app/hook-use/hook-use-state.d.ts +30 -0
- package/lib/app/hook-use/hook-use-state.js +101 -0
- package/lib/app/hook-use/hook-use-subscribe.d.ts +46 -0
- package/lib/app/hook-use/hook-use-subscribe.js +143 -0
- package/lib/app/hook-use-api.d.ts +1 -3
- package/lib/app/hook-use-api.js +3 -3
- package/lib/app/index.js +1 -1
- package/lib/app/message/message-api.d.ts +69 -0
- package/lib/app/message/message-api.js +105 -0
- package/lib/app/message/message-format-old.d.ts +143 -0
- package/lib/app/message/message-format-old.js +359 -0
- package/lib/app/message/message-format.d.ts +215 -0
- package/lib/app/message/message-format.js +382 -0
- package/lib/app/message-api.d.ts +13 -0
- package/lib/app/message-api.js +45 -1
- package/lib/app/message-format.old.d.ts +50 -0
- package/lib/app/message-format.old.js +217 -0
- package/lib/cbp/connects/platform.js +3 -3
- package/lib/cbp/processor/actions.js +5 -4
- package/lib/cbp/processor/api.js +5 -4
- package/lib/cbp/processor/handle.d.ts +3 -0
- package/lib/cbp/processor/handle.js +32 -0
- package/lib/core/index.js +1 -1
- package/lib/core/utils.d.ts +1 -0
- package/lib/core/utils.js +5 -1
- package/lib/index.js +2 -2
- package/lib/jsx/index.d.ts +105 -0
- package/lib/jsx/index.js +211 -0
- package/lib/jsx/jsx-dev-runtime.d.ts +2 -0
- package/lib/jsx/jsx-dev-runtime.js +1 -0
- package/lib/jsx/jsx-runtime.d.ts +18 -0
- package/lib/jsx/jsx-runtime.js +24 -0
- package/lib/process/client.js +109 -0
- package/lib/process/direct-channel.js +3 -1
- package/lib/process/ipc-bridge.js +10 -4
- package/lib/store/SinglyLinkedList.d.ts +22 -0
- package/lib/store/SinglyLinkedList.js +97 -0
- package/lib/store/store.d.ts +127 -0
- package/lib/store/store.js +443 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 频道处理
|
|
5
|
+
* @deprecated 待支持
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const useChannel = (event) => {
|
|
10
|
+
if (!event || typeof event !== 'object') {
|
|
11
|
+
logger.error({
|
|
12
|
+
code: ResultCode.FailParams,
|
|
13
|
+
message: 'Invalid event: event must be an object',
|
|
14
|
+
data: null
|
|
15
|
+
});
|
|
16
|
+
throw new Error('Invalid event: event must be an object');
|
|
17
|
+
}
|
|
18
|
+
// // 退出
|
|
19
|
+
// const exit = async (channel_id?: string) => {
|
|
20
|
+
// return createResult(ResultCode.Warn, '暂未支持', channel_id)
|
|
21
|
+
// }
|
|
22
|
+
// // 加入
|
|
23
|
+
// const join = async (channel_id?: string) => {
|
|
24
|
+
// return createResult(ResultCode.Warn, '暂未支持', channel_id)
|
|
25
|
+
// }
|
|
26
|
+
const channel = {
|
|
27
|
+
// exit,
|
|
28
|
+
// join
|
|
29
|
+
};
|
|
30
|
+
return [channel];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { useChannel };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { sendAPI } from '../../cbp/processor/api.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 使用客户端
|
|
5
|
+
* @param event
|
|
6
|
+
* @param _ApiClass
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const useClient = (event, _ApiClass) => {
|
|
10
|
+
const client = new Proxy({}, {
|
|
11
|
+
get(_target, prop) {
|
|
12
|
+
return (...args) => {
|
|
13
|
+
return sendAPI({
|
|
14
|
+
action: 'client.api',
|
|
15
|
+
payload: {
|
|
16
|
+
event,
|
|
17
|
+
key: String(prop),
|
|
18
|
+
params: args
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return [client];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { useClient };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取我相关的数据
|
|
7
|
+
*/
|
|
8
|
+
const useMe = () => {
|
|
9
|
+
/**
|
|
10
|
+
* 个人信息
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
const info = async () => {
|
|
14
|
+
try {
|
|
15
|
+
const results = await sendAction({
|
|
16
|
+
action: 'me.info',
|
|
17
|
+
payload: {}
|
|
18
|
+
});
|
|
19
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
20
|
+
if (result) {
|
|
21
|
+
const data = result?.data ?? null;
|
|
22
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
23
|
+
}
|
|
24
|
+
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 加入的服务器列表
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* 好友列表
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* 私聊线程列表
|
|
38
|
+
*/
|
|
39
|
+
const control = {
|
|
40
|
+
info
|
|
41
|
+
};
|
|
42
|
+
return [control];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { useMe };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 用户处理
|
|
5
|
+
* @deprecated 待支持
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const useMember = (event) => {
|
|
10
|
+
if (!event || typeof event !== 'object') {
|
|
11
|
+
logger.error({
|
|
12
|
+
code: ResultCode.FailParams,
|
|
13
|
+
message: 'Invalid event: event must be an object',
|
|
14
|
+
data: null
|
|
15
|
+
});
|
|
16
|
+
throw new Error('Invalid event: event must be an object');
|
|
17
|
+
}
|
|
18
|
+
// /**
|
|
19
|
+
// * 获取用户信息
|
|
20
|
+
// * @param user_id
|
|
21
|
+
// * @returns
|
|
22
|
+
// */
|
|
23
|
+
// const information = async (user_id?: string) => {
|
|
24
|
+
// return createResult(ResultCode.Warn, '暂未支持', user_id)
|
|
25
|
+
// }
|
|
26
|
+
// /**
|
|
27
|
+
// * 禁言
|
|
28
|
+
// * @param all 是否是全体
|
|
29
|
+
// * @returns
|
|
30
|
+
// */
|
|
31
|
+
// const mute = async (all: boolean = false) => {
|
|
32
|
+
// return createResult(ResultCode.Warn, '暂未支持', all)
|
|
33
|
+
// }
|
|
34
|
+
// /**
|
|
35
|
+
// * 解除禁言
|
|
36
|
+
// * @param all 是否是全体
|
|
37
|
+
// * @returns
|
|
38
|
+
// */
|
|
39
|
+
// const unmute = async (all: boolean = false) => {
|
|
40
|
+
// return createResult(ResultCode.Warn, '暂未支持', all)
|
|
41
|
+
// }
|
|
42
|
+
// /**
|
|
43
|
+
// * 移除用户
|
|
44
|
+
// * @param user_id
|
|
45
|
+
// * @returns
|
|
46
|
+
// */
|
|
47
|
+
// const remove = async (user_id?: string) => {
|
|
48
|
+
// return createResult(ResultCode.Warn, '暂未支持', user_id)
|
|
49
|
+
// }
|
|
50
|
+
const member = {
|
|
51
|
+
// information,
|
|
52
|
+
// mute,
|
|
53
|
+
// unmute,
|
|
54
|
+
// remove
|
|
55
|
+
};
|
|
56
|
+
return [member];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { useMember };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventKeys, Events, User } from '../../types';
|
|
2
|
+
import { Result } from '../../core/utils';
|
|
3
|
+
type Options = {
|
|
4
|
+
UserId?: string;
|
|
5
|
+
UserKey?: string;
|
|
6
|
+
UserName?: string;
|
|
7
|
+
IsMaster?: boolean;
|
|
8
|
+
IsBot?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 使用提及。
|
|
12
|
+
* @param {Object} event - 事件对象,包含触发提及的相关信息。
|
|
13
|
+
* @throws {Error} - 如果 event 无效,抛出错误。
|
|
14
|
+
*/
|
|
15
|
+
export declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
|
|
16
|
+
find: (options?: Options) => Promise<Result<User[]> & {
|
|
17
|
+
count: number;
|
|
18
|
+
}>;
|
|
19
|
+
findOne: (options?: Options) => Promise<Result<User | null> & {
|
|
20
|
+
count: number;
|
|
21
|
+
}>;
|
|
22
|
+
}];
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 使用提及。
|
|
7
|
+
* @param {Object} event - 事件对象,包含触发提及的相关信息。
|
|
8
|
+
* @throws {Error} - 如果 event 无效,抛出错误。
|
|
9
|
+
*/
|
|
10
|
+
const useMention = (event) => {
|
|
11
|
+
if (!event || typeof event !== 'object') {
|
|
12
|
+
logger.error({
|
|
13
|
+
code: ResultCode.FailParams,
|
|
14
|
+
message: 'Invalid event: event must be an object',
|
|
15
|
+
data: null
|
|
16
|
+
});
|
|
17
|
+
throw new Error('Invalid event: event must be an object');
|
|
18
|
+
}
|
|
19
|
+
// 提及数据缓存
|
|
20
|
+
let res = null;
|
|
21
|
+
/** 加载数据(带缓存) */
|
|
22
|
+
const load = async () => {
|
|
23
|
+
if (res) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// 获取提及数据
|
|
27
|
+
const results = await sendAction({
|
|
28
|
+
action: 'mention.get',
|
|
29
|
+
payload: { event }
|
|
30
|
+
});
|
|
31
|
+
// 提及数据通常在 results 中,找到 code 为 Ok 的项目,并将其 data 作为提及数据缓存起来
|
|
32
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
33
|
+
if (result) {
|
|
34
|
+
res = result.data;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** 按条件过滤,默认排除 bot */
|
|
38
|
+
const match = (item, options) => {
|
|
39
|
+
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// 默认排除 bot
|
|
55
|
+
if (options.IsBot === undefined && item.IsBot) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
const mention = {
|
|
61
|
+
find: async (options = {}) => {
|
|
62
|
+
try {
|
|
63
|
+
await load();
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
const result = createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
67
|
+
return {
|
|
68
|
+
...result,
|
|
69
|
+
count: 0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(res)) {
|
|
73
|
+
return {
|
|
74
|
+
...createResult(ResultCode.Warn, 'No mention data found', null),
|
|
75
|
+
count: 0
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const data = res.filter(item => match(item, options));
|
|
79
|
+
const result = createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
80
|
+
return {
|
|
81
|
+
...result,
|
|
82
|
+
count: data.length || 0
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
findOne: async (options = {}) => {
|
|
86
|
+
const results = await mention.find(options);
|
|
87
|
+
if (results.code !== ResultCode.Ok || !results.data?.length) {
|
|
88
|
+
const result = createResult(results.code, results.message, null);
|
|
89
|
+
return {
|
|
90
|
+
...result,
|
|
91
|
+
count: 0
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const data = results?.data[0];
|
|
95
|
+
const result = createResult(ResultCode.Ok, results.message, data);
|
|
96
|
+
return {
|
|
97
|
+
...result,
|
|
98
|
+
count: results.data?.length || 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return [mention];
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { useMention };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DataEnums, EventKeys, Events } from '../../types';
|
|
2
|
+
import { Result } from '../../core/utils';
|
|
3
|
+
import { Format } from '../message/message-format.js';
|
|
4
|
+
/**
|
|
5
|
+
* 消息处理
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const useMessage: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
10
|
+
send(params?: {
|
|
11
|
+
format: Format | DataEnums[];
|
|
12
|
+
} | DataEnums[]): Promise<Result[]>;
|
|
13
|
+
}];
|
|
14
|
+
/**
|
|
15
|
+
* 废弃,请使用 useMessage
|
|
16
|
+
* @deprecated
|
|
17
|
+
* @param event
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
|
|
21
|
+
/**
|
|
22
|
+
* 废弃,请使用 useMessage
|
|
23
|
+
* @deprecated
|
|
24
|
+
* @param event
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
export declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(params?: DataEnums[] | {
|
|
28
|
+
format: Format | DataEnums[];
|
|
29
|
+
}) => Promise<Result[]>];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ResultCode } from '../../core/variable.js';
|
|
2
|
+
import { createResult } from '../../core/utils.js';
|
|
3
|
+
import { sendAction } from '../../cbp/processor/actions.js';
|
|
4
|
+
import { Format } from '../message/message-format.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 消息处理
|
|
8
|
+
* @param event
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
const useMessage = (event) => {
|
|
12
|
+
if (!event || typeof event !== 'object') {
|
|
13
|
+
logger.error({
|
|
14
|
+
code: ResultCode.FailParams,
|
|
15
|
+
message: 'Invalid event: event must be an object',
|
|
16
|
+
data: null
|
|
17
|
+
});
|
|
18
|
+
throw new Error('Invalid event: event must be an object');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 将 format 参数解析为 DataEnums[]
|
|
22
|
+
*/
|
|
23
|
+
const resolveFormat = (params) => {
|
|
24
|
+
if (params.format instanceof Format) {
|
|
25
|
+
return params.format.value;
|
|
26
|
+
}
|
|
27
|
+
return params.format;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 发送消息(内部方法,兼容旧API)
|
|
31
|
+
* @param val
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
const sendRaw = async (val) => {
|
|
35
|
+
if (!val || val.length === 0) {
|
|
36
|
+
return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
|
|
37
|
+
}
|
|
38
|
+
const result = await sendAction({
|
|
39
|
+
action: 'message.send',
|
|
40
|
+
payload: {
|
|
41
|
+
event,
|
|
42
|
+
params: {
|
|
43
|
+
format: val
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return Array.isArray(result) ? result : [result];
|
|
48
|
+
};
|
|
49
|
+
// 新的消息处理接口
|
|
50
|
+
const lightweight = {
|
|
51
|
+
send(params) {
|
|
52
|
+
// send 直接走快速路径,无需创建完整 controller
|
|
53
|
+
if (!params) {
|
|
54
|
+
return sendRaw([]);
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(params)) {
|
|
57
|
+
return sendRaw(params.length > 0 ? params : []);
|
|
58
|
+
}
|
|
59
|
+
return sendRaw(resolveFormat(params));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return [lightweight];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 废弃,请使用 useMessage
|
|
66
|
+
* @deprecated
|
|
67
|
+
* @param event
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
const useSend = (event) => {
|
|
71
|
+
const [message] = useMessage(event);
|
|
72
|
+
const send = (...val) => {
|
|
73
|
+
return message.send(val);
|
|
74
|
+
};
|
|
75
|
+
return send;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* 废弃,请使用 useMessage
|
|
79
|
+
* @deprecated
|
|
80
|
+
* @param event
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
const useSends = (event) => {
|
|
84
|
+
const [message] = useMessage(event);
|
|
85
|
+
return [message.send];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { useMessage, useSend, useSends };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取指定功能是启动还是关闭
|
|
3
|
+
* ***
|
|
4
|
+
* 当有其他地方调用时,
|
|
5
|
+
* 默认值以第一次调用为准
|
|
6
|
+
* ***
|
|
7
|
+
* 功能名相同时,
|
|
8
|
+
* 将会同时改变,因为状态是全局的
|
|
9
|
+
* @param name 功能名
|
|
10
|
+
* @param defaultValue 默认值,默认为 true
|
|
11
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
12
|
+
* @throws {Error} - 如果 name 不是字符串,或者 defaultValue 不是布尔值,抛出错误。
|
|
13
|
+
*/
|
|
14
|
+
export declare const useState: <T extends string>(name: T, defaultValue?: boolean) => [boolean, (value: boolean) => void];
|
|
15
|
+
/**
|
|
16
|
+
* 订阅状态变化
|
|
17
|
+
* @param name 功能名
|
|
18
|
+
* @param callback 回调函数
|
|
19
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
20
|
+
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
21
|
+
*/
|
|
22
|
+
export declare const onState: <T extends string>(name: T, callback: (value: boolean) => void) => void;
|
|
23
|
+
/**
|
|
24
|
+
* 取消订阅状态变化
|
|
25
|
+
* @param name 功能名
|
|
26
|
+
* @param callback 回调函数
|
|
27
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
28
|
+
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
29
|
+
*/
|
|
30
|
+
export declare const unState: <T extends string>(name: T, callback: (value: boolean) => void) => void;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { getConfig } from '../../core/config.js';
|
|
2
|
+
import { ResultCode } from '../../core/variable.js';
|
|
3
|
+
import { State, StateSubscribe } from '../../store/store.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取指定功能是启动还是关闭
|
|
7
|
+
* ***
|
|
8
|
+
* 当有其他地方调用时,
|
|
9
|
+
* 默认值以第一次调用为准
|
|
10
|
+
* ***
|
|
11
|
+
* 功能名相同时,
|
|
12
|
+
* 将会同时改变,因为状态是全局的
|
|
13
|
+
* @param name 功能名
|
|
14
|
+
* @param defaultValue 默认值,默认为 true
|
|
15
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
16
|
+
* @throws {Error} - 如果 name 不是字符串,或者 defaultValue 不是布尔值,抛出错误。
|
|
17
|
+
*/
|
|
18
|
+
const useState = (name, defaultValue = true) => {
|
|
19
|
+
// 检查参数
|
|
20
|
+
if (typeof name !== 'string') {
|
|
21
|
+
logger.error({
|
|
22
|
+
code: ResultCode.FailParams,
|
|
23
|
+
message: 'Invalid name: name must be a string',
|
|
24
|
+
data: null
|
|
25
|
+
});
|
|
26
|
+
throw new Error('Invalid name: name must be a string');
|
|
27
|
+
}
|
|
28
|
+
if (typeof defaultValue !== 'boolean') {
|
|
29
|
+
logger.error({
|
|
30
|
+
code: ResultCode.FailParams,
|
|
31
|
+
message: 'Invalid defaultValue: defaultValue must be a boolean',
|
|
32
|
+
data: null
|
|
33
|
+
});
|
|
34
|
+
throw new Error('Invalid defaultValue: defaultValue must be a boolean');
|
|
35
|
+
}
|
|
36
|
+
const state = new State(name, defaultValue);
|
|
37
|
+
// 设置值的函数
|
|
38
|
+
const setValue = (value) => {
|
|
39
|
+
if (state.value === value) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
state.value = value;
|
|
43
|
+
// 更新config
|
|
44
|
+
const cfg = getConfig();
|
|
45
|
+
cfg.value.core ??= {};
|
|
46
|
+
cfg.value.core.state ??= [];
|
|
47
|
+
const cfgState = cfg.value.core.state;
|
|
48
|
+
const exists = cfgState.includes(name);
|
|
49
|
+
if (value && exists) {
|
|
50
|
+
// 启用:从禁用列表中移除
|
|
51
|
+
cfg.value.core.state = cfg.value.core.state.filter((i) => i !== name);
|
|
52
|
+
}
|
|
53
|
+
else if (!value && !exists) {
|
|
54
|
+
// 禁用:添加到禁用列表
|
|
55
|
+
cfg.value.core.state.push(name);
|
|
56
|
+
}
|
|
57
|
+
cfg.saveValue(cfg.value);
|
|
58
|
+
};
|
|
59
|
+
return [state.value, setValue];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* 订阅状态变化
|
|
63
|
+
* @param name 功能名
|
|
64
|
+
* @param callback 回调函数
|
|
65
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
66
|
+
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
67
|
+
*/
|
|
68
|
+
const onState = (name, callback) => {
|
|
69
|
+
if (typeof callback !== 'function') {
|
|
70
|
+
logger.error({
|
|
71
|
+
code: ResultCode.FailParams,
|
|
72
|
+
message: 'Callback must be a function',
|
|
73
|
+
data: null
|
|
74
|
+
});
|
|
75
|
+
throw new Error('Callback must be a function');
|
|
76
|
+
}
|
|
77
|
+
const sub = new StateSubscribe(name);
|
|
78
|
+
sub.on(callback);
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 取消订阅状态变化
|
|
82
|
+
* @param name 功能名
|
|
83
|
+
* @param callback 回调函数
|
|
84
|
+
* @deprecated 废弃。指令管理可直接配置禁用正则
|
|
85
|
+
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
86
|
+
*/
|
|
87
|
+
const unState = (name, callback) => {
|
|
88
|
+
if (typeof callback !== 'function') {
|
|
89
|
+
logger.error({
|
|
90
|
+
code: ResultCode.FailParams,
|
|
91
|
+
message: 'Callback must be a function',
|
|
92
|
+
data: null
|
|
93
|
+
});
|
|
94
|
+
throw new Error('Callback must be a function');
|
|
95
|
+
}
|
|
96
|
+
// 取消订阅
|
|
97
|
+
const sub = new StateSubscribe(name);
|
|
98
|
+
sub.un(callback);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { onState, unState, useState };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EventCycleEnum, Current, Events, EventKeys } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* 订阅事件
|
|
4
|
+
* @param event
|
|
5
|
+
* @param select
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const useSubscribe: <T extends EventKeys>(event: Events[T], selects: T | T[]) => readonly [{
|
|
9
|
+
create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
10
|
+
selects: T[];
|
|
11
|
+
choose: EventCycleEnum;
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
mount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
15
|
+
selects: T[];
|
|
16
|
+
choose: EventCycleEnum;
|
|
17
|
+
id: string;
|
|
18
|
+
};
|
|
19
|
+
unmount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
20
|
+
selects: T[];
|
|
21
|
+
choose: EventCycleEnum;
|
|
22
|
+
id: string;
|
|
23
|
+
};
|
|
24
|
+
cancel: (value: {
|
|
25
|
+
id: string;
|
|
26
|
+
selects: T[];
|
|
27
|
+
choose: EventCycleEnum;
|
|
28
|
+
}) => void;
|
|
29
|
+
}];
|
|
30
|
+
/**
|
|
31
|
+
* 使用观察者模式订阅事件
|
|
32
|
+
* @param event
|
|
33
|
+
* @param selects
|
|
34
|
+
* @returns
|
|
35
|
+
* 废弃,请使用 useSubscribe
|
|
36
|
+
* @deprecated
|
|
37
|
+
*/
|
|
38
|
+
export declare const useObserver: <T extends EventKeys>(event: Events[T], selects: T | T[]) => readonly [(callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
39
|
+
selects: T[];
|
|
40
|
+
choose: EventCycleEnum;
|
|
41
|
+
id: string;
|
|
42
|
+
}, (value: {
|
|
43
|
+
id: string;
|
|
44
|
+
selects: T[];
|
|
45
|
+
choose: EventCycleEnum;
|
|
46
|
+
}) => void];
|