alemonjs 2.1.0-alpha.13 → 2.1.0-alpha.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.
- package/lib/app/hook-use-api.d.ts +7 -7
- package/lib/app/message-api.d.ts +17 -6
- package/lib/app/message-api.js +22 -14
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/typing/event/base/guild.d.ts +4 -0
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ declare const useMention: <T extends EventKeys>(event: Events[T]) => {
|
|
|
29
29
|
* @param event
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
declare const useMessage: <T extends EventKeys>(event: Events[T]) => {
|
|
32
|
+
declare const useMessage: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
33
33
|
send: (val: DataEnums[]) => Promise<Result[]>;
|
|
34
34
|
withdraw: (message_id?: string) => Promise<Result[]>;
|
|
35
35
|
forward: (message_id?: string) => Promise<Result[]>;
|
|
@@ -38,29 +38,29 @@ declare const useMessage: <T extends EventKeys>(event: Events[T]) => {
|
|
|
38
38
|
pinning: (message_id?: string) => Promise<Result[]>;
|
|
39
39
|
horn: (message_id?: string) => Promise<Result[]>;
|
|
40
40
|
reaction: (message_id?: string) => Promise<Result[]>;
|
|
41
|
-
}
|
|
41
|
+
}];
|
|
42
42
|
/**
|
|
43
43
|
* 用户处理
|
|
44
44
|
* @deprecated 待支持
|
|
45
45
|
* @param event
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
|
-
declare const useMenber: <T extends EventKeys>(event: Events[T]) => {
|
|
48
|
+
declare const useMenber: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
49
49
|
information: (user_id?: string) => Promise<Result>;
|
|
50
50
|
mute: (all?: boolean) => Promise<Result>;
|
|
51
51
|
unmute: (all?: boolean) => Promise<Result>;
|
|
52
52
|
remove: (user_id?: string) => Promise<Result>;
|
|
53
|
-
}
|
|
53
|
+
}];
|
|
54
54
|
/**
|
|
55
55
|
* 频道处理
|
|
56
56
|
* @deprecated 待支持
|
|
57
57
|
* @param event
|
|
58
58
|
* @returns
|
|
59
59
|
*/
|
|
60
|
-
declare const useChannel: <T extends EventKeys>(event: Events[T]) => {
|
|
60
|
+
declare const useChannel: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
61
61
|
exit: (channel_id?: string) => Promise<Result>;
|
|
62
62
|
join: (channel_id?: string) => Promise<Result>;
|
|
63
|
-
}
|
|
63
|
+
}];
|
|
64
64
|
/**
|
|
65
65
|
* 废弃,请使用 useMessage
|
|
66
66
|
* @deprecated
|
|
@@ -73,7 +73,7 @@ declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataE
|
|
|
73
73
|
* @param event
|
|
74
74
|
* @returns
|
|
75
75
|
*/
|
|
76
|
-
declare const useSends: <T extends EventKeys>(event: Events[T]) => (
|
|
76
|
+
declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(val: DataEnums[]) => Promise<Result[]>];
|
|
77
77
|
/**
|
|
78
78
|
* 卸载模块
|
|
79
79
|
* @param name
|
package/lib/app/message-api.d.ts
CHANGED
|
@@ -3,6 +3,17 @@ import { Result } from '../core/utils.js';
|
|
|
3
3
|
import { DataEnums } from '../typing/message/index.js';
|
|
4
4
|
import '../global.js';
|
|
5
5
|
|
|
6
|
+
type BaseMap = {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 创建原生value映射
|
|
11
|
+
* @param event
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
declare const createEventValue: <T extends keyof R, R extends BaseMap>(event: {
|
|
15
|
+
value: R[T];
|
|
16
|
+
}) => R[T] | undefined;
|
|
6
17
|
/**
|
|
7
18
|
* 创建数据格式。
|
|
8
19
|
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
@@ -12,17 +23,17 @@ import '../global.js';
|
|
|
12
23
|
declare const format: OnDataFormatFunc;
|
|
13
24
|
/**
|
|
14
25
|
* 向指定频道发送消息。
|
|
15
|
-
* @param {string}
|
|
26
|
+
* @param {string} SpaceId - 空间ID,可能是服务器ID、频道ID、群ID、聊天ID,或者是复合ID。总之,是框架给指定空间的唯一标识。也就是说,不能使用ChannelId作为该参数。
|
|
16
27
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
17
|
-
* @throws {Error} - 如果
|
|
28
|
+
* @throws {Error} - 如果 SpaceId 无效或发送失败,抛出错误。
|
|
18
29
|
*/
|
|
19
|
-
declare const sendToChannel: (
|
|
30
|
+
declare const sendToChannel: (SpaceId: string, data: DataEnums[]) => Promise<Result[]>;
|
|
20
31
|
/**
|
|
21
32
|
* 向指定用户发送消息。
|
|
22
|
-
* @param {string}
|
|
33
|
+
* @param {string} OpenID - 开放ID,可能是用户ID、聊天ID,或是复合ID。总之,是框架给指定用户的唯一标识。也就说,不能使用UserId作为该参数。
|
|
23
34
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
24
35
|
* @throws {Error} - 如果 user_id 无效或发送失败,抛出错误。
|
|
25
36
|
*/
|
|
26
|
-
declare const sendToUser: (
|
|
37
|
+
declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<Result[]>;
|
|
27
38
|
|
|
28
|
-
export { format, sendToChannel, sendToUser };
|
|
39
|
+
export { createEventValue, format, sendToChannel, sendToUser };
|
package/lib/app/message-api.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ResultCode } from '../core/code.js';
|
|
2
2
|
import { sendAction } from '../cbp/actions.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 创建原生value映射
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const createEventValue = (event) => {
|
|
10
|
+
return event.value;
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
13
|
* 创建数据格式。
|
|
6
14
|
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
@@ -21,23 +29,23 @@ const format = (...data) => {
|
|
|
21
29
|
global.format = format;
|
|
22
30
|
/**
|
|
23
31
|
* 向指定频道发送消息。
|
|
24
|
-
* @param {string}
|
|
32
|
+
* @param {string} SpaceId - 空间ID,可能是服务器ID、频道ID、群ID、聊天ID,或者是复合ID。总之,是框架给指定空间的唯一标识。也就是说,不能使用ChannelId作为该参数。
|
|
25
33
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
26
|
-
* @throws {Error} - 如果
|
|
34
|
+
* @throws {Error} - 如果 SpaceId 无效或发送失败,抛出错误。
|
|
27
35
|
*/
|
|
28
|
-
const sendToChannel = async (
|
|
29
|
-
if (!
|
|
36
|
+
const sendToChannel = async (SpaceId, data) => {
|
|
37
|
+
if (!SpaceId || typeof SpaceId !== 'string') {
|
|
30
38
|
logger.error({
|
|
31
39
|
code: ResultCode.FailParams,
|
|
32
|
-
message: 'Invalid
|
|
40
|
+
message: 'Invalid SpaceId: SpaceId must be a string',
|
|
33
41
|
data: null
|
|
34
42
|
});
|
|
35
|
-
throw new Error('Invalid
|
|
43
|
+
throw new Error('Invalid SpaceId: SpaceId must be a string');
|
|
36
44
|
}
|
|
37
45
|
return await sendAction({
|
|
38
46
|
action: 'message.send.channel',
|
|
39
47
|
payload: {
|
|
40
|
-
ChannelId:
|
|
48
|
+
ChannelId: SpaceId,
|
|
41
49
|
params: {
|
|
42
50
|
format: data
|
|
43
51
|
}
|
|
@@ -46,23 +54,23 @@ const sendToChannel = async (channel_id, data) => {
|
|
|
46
54
|
};
|
|
47
55
|
/**
|
|
48
56
|
* 向指定用户发送消息。
|
|
49
|
-
* @param {string}
|
|
57
|
+
* @param {string} OpenID - 开放ID,可能是用户ID、聊天ID,或是复合ID。总之,是框架给指定用户的唯一标识。也就说,不能使用UserId作为该参数。
|
|
50
58
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
51
59
|
* @throws {Error} - 如果 user_id 无效或发送失败,抛出错误。
|
|
52
60
|
*/
|
|
53
|
-
const sendToUser = async (
|
|
54
|
-
if (!
|
|
61
|
+
const sendToUser = async (OpenID, data) => {
|
|
62
|
+
if (!OpenID || typeof OpenID !== 'string') {
|
|
55
63
|
logger.error({
|
|
56
64
|
code: ResultCode.FailParams,
|
|
57
|
-
message: 'Invalid
|
|
65
|
+
message: 'Invalid OpenID: OpenID must be a string',
|
|
58
66
|
data: null
|
|
59
67
|
});
|
|
60
|
-
throw new Error('Invalid
|
|
68
|
+
throw new Error('Invalid OpenID: OpenID must be a string');
|
|
61
69
|
}
|
|
62
70
|
return await sendAction({
|
|
63
71
|
action: 'message.send.user',
|
|
64
72
|
payload: {
|
|
65
|
-
UserId:
|
|
73
|
+
UserId: OpenID,
|
|
66
74
|
params: {
|
|
67
75
|
format: data
|
|
68
76
|
}
|
|
@@ -70,4 +78,4 @@ const sendToUser = async (user_id, data) => {
|
|
|
70
78
|
});
|
|
71
79
|
};
|
|
72
80
|
|
|
73
|
-
export { format, sendToChannel, sendToUser };
|
|
81
|
+
export { createEventValue, format, sendToChannel, sendToUser };
|
package/lib/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber,
|
|
|
28
28
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
|
29
29
|
export { useSubscribe } from './app/hook-use-subscribe.js';
|
|
30
30
|
export { loadChildren, loadChildrenFile } from './app/load.js';
|
|
31
|
-
export { format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
31
|
+
export { createEventValue, format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
32
32
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
33
33
|
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
34
34
|
export { Result, createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber,
|
|
|
10
10
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
|
11
11
|
export { useSubscribe } from './app/hook-use-subscribe.js';
|
|
12
12
|
export { loadChildren, loadChildrenFile } from './app/load.js';
|
|
13
|
-
export { format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
13
|
+
export { createEventValue, format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
14
14
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
15
15
|
export { ChildrenApp, Core, Logger, Middleware, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, State, StateSubscribe, SubscribeList } from './app/store.js';
|
|
16
16
|
export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|