alemonjs 2.1.53 → 2.1.55
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-router.d.ts +1 -0
- package/lib/app/define-router.js +6 -1
- package/lib/app/event-format.js +1 -1
- package/lib/app/event-processor-cycleFiles.js +2 -6
- package/lib/app/expose.d.ts +16 -0
- package/lib/app/expose.js +190 -0
- package/lib/app/index.d.ts +1 -0
- package/lib/app/index.js +2 -1
- package/lib/app/load_modules/loadChild.js +4 -0
- package/lib/app/store.d.ts +9 -9
- package/lib/app/store.js +2 -0
- package/lib/index.js +2 -1
- package/lib/types/event/index.d.ts +2 -0
- package/lib/types/expose/index.d.ts +41 -0
- package/lib/types/expose/index.js +1 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/lib/app/define/define-children.d.ts +0 -8
- package/lib/app/define/define-children.js +0 -25
- package/lib/app/define/define-middleware.d.ts +0 -2
- package/lib/app/define/define-middleware.js +0 -8
- package/lib/app/define/define-platform.d.ts +0 -13
- package/lib/app/define/define-platform.js +0 -40
- package/lib/app/define/define-response.d.ts +0 -2
- package/lib/app/define/define-response.js +0 -8
- package/lib/app/define/define-router.d.ts +0 -17
- package/lib/app/define/define-router.js +0 -34
- package/lib/app/event/event-group.d.ts +0 -9
- package/lib/app/event/event-group.js +0 -29
- package/lib/app/event/event-middleware.d.ts +0 -23
- package/lib/app/event/event-middleware.js +0 -44
- package/lib/app/event/event-response.d.ts +0 -16
- package/lib/app/event/event-response.js +0 -23
- package/lib/app/event/event-selects.d.ts +0 -13
- package/lib/app/event/event-selects.js +0 -15
- package/lib/app/event-processor/event-processor-callHandler.d.ts +0 -1
- package/lib/app/event-processor/event-processor-callHandler.js +0 -43
- package/lib/app/event-processor/event-processor-cycle.d.ts +0 -14
- package/lib/app/event-processor/event-processor-cycle.js +0 -97
- package/lib/app/event-processor/event-processor-cycleFiles.d.ts +0 -11
- package/lib/app/event-processor/event-processor-cycleFiles.js +0 -147
- package/lib/app/event-processor/event-processor-cycleRoute.d.ts +0 -10
- package/lib/app/event-processor/event-processor-cycleRoute.js +0 -133
- package/lib/app/event-processor/event-processor-event.d.ts +0 -24
- package/lib/app/event-processor/event-processor-event.js +0 -41
- package/lib/app/event-processor/event-processor-middleware.d.ts +0 -14
- package/lib/app/event-processor/event-processor-middleware.js +0 -31
- package/lib/app/event-processor/event-processor-subscribe.d.ts +0 -35
- package/lib/app/event-processor/event-processor-subscribe.js +0 -115
- package/lib/app/event-processor/event-processor.d.ts +0 -17
- package/lib/app/event-processor/event-processor.js +0 -207
- package/lib/app/hook-use/hook-use-api.d.ts +0 -6
- package/lib/app/hook-use/hook-use-api.js +0 -22
- package/lib/app/hook-use/hook-use-channel.d.ts +0 -8
- package/lib/app/hook-use/hook-use-channel.js +0 -33
- package/lib/app/hook-use/hook-use-client.d.ts +0 -7
- package/lib/app/hook-use/hook-use-client.js +0 -27
- package/lib/app/hook-use/hook-use-me.d.ts +0 -8
- package/lib/app/hook-use/hook-use-me.js +0 -45
- package/lib/app/hook-use/hook-use-menber.d.ts +0 -8
- package/lib/app/hook-use/hook-use-menber.js +0 -59
- package/lib/app/hook-use/hook-use-mention.d.ts +0 -23
- package/lib/app/hook-use/hook-use-mention.js +0 -105
- package/lib/app/hook-use/hook-use-message.d.ts +0 -29
- package/lib/app/hook-use/hook-use-message.js +0 -88
- package/lib/app/hook-use/hook-use-state.d.ts +0 -30
- package/lib/app/hook-use/hook-use-state.js +0 -101
- package/lib/app/hook-use/hook-use-subscribe.d.ts +0 -46
- package/lib/app/hook-use/hook-use-subscribe.js +0 -143
- package/lib/app/hook-use-api.d.ts +0 -268
- package/lib/app/hook-use-api.js +0 -1213
- package/lib/app/hook-use-state.d.ts +0 -3
- package/lib/app/hook-use-state.js +0 -68
- package/lib/app/hook-use-subscribe.d.ts +0 -73
- package/lib/app/hook-use-subscribe.js +0 -112
- package/lib/app/message/message-api.d.ts +0 -69
- package/lib/app/message/message-api.js +0 -105
- package/lib/app/message/message-format-old.d.ts +0 -143
- package/lib/app/message/message-format-old.js +0 -359
- package/lib/app/message/message-format.d.ts +0 -215
- package/lib/app/message/message-format.js +0 -382
- package/lib/app/message-controller.d.ts +0 -25
- package/lib/app/message-controller.js +0 -66
- package/lib/app/message-format.old.d.ts +0 -50
- package/lib/app/message-format.old.js +0 -217
- package/lib/cbp/processor/handle.d.ts +0 -3
- package/lib/cbp/processor/handle.js +0 -32
- package/lib/jsx/index.d.ts +0 -105
- package/lib/jsx/index.js +0 -211
- package/lib/jsx/jsx-dev-runtime.d.ts +0 -2
- package/lib/jsx/jsx-dev-runtime.js +0 -1
- package/lib/jsx/jsx-runtime.d.ts +0 -18
- package/lib/jsx/jsx-runtime.js +0 -24
- package/lib/process/client.js +0 -109
- package/lib/store/SinglyLinkedList.d.ts +0 -22
- package/lib/store/SinglyLinkedList.js +0 -97
- package/lib/store/store.d.ts +0 -127
- package/lib/store/store.js +0 -443
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const useState: <T extends string>(name: T, defaultValue?: boolean) => [boolean, (value: boolean) => void];
|
|
2
|
-
export declare const onState: <T extends string>(name: T, callback: (value: boolean) => void) => void;
|
|
3
|
-
export declare const unState: <T extends string>(name: T, callback: (value: boolean) => void) => void;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { getConfig } from '../core/config.js';
|
|
2
|
-
import { ResultCode } from '../core/variable.js';
|
|
3
|
-
import { State, StateSubscribe } from './store.js';
|
|
4
|
-
|
|
5
|
-
const useState = (name, defaultValue = true) => {
|
|
6
|
-
if (typeof name !== 'string') {
|
|
7
|
-
logger.error({
|
|
8
|
-
code: ResultCode.FailParams,
|
|
9
|
-
message: 'Invalid name: name must be a string',
|
|
10
|
-
data: null
|
|
11
|
-
});
|
|
12
|
-
throw new Error('Invalid name: name must be a string');
|
|
13
|
-
}
|
|
14
|
-
if (typeof defaultValue !== 'boolean') {
|
|
15
|
-
logger.error({
|
|
16
|
-
code: ResultCode.FailParams,
|
|
17
|
-
message: 'Invalid defaultValue: defaultValue must be a boolean',
|
|
18
|
-
data: null
|
|
19
|
-
});
|
|
20
|
-
throw new Error('Invalid defaultValue: defaultValue must be a boolean');
|
|
21
|
-
}
|
|
22
|
-
const state = new State(name, defaultValue);
|
|
23
|
-
const setValue = (value) => {
|
|
24
|
-
if (state.value === value) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
state.value = value;
|
|
28
|
-
const cfg = getConfig();
|
|
29
|
-
cfg.value.core ??= {};
|
|
30
|
-
cfg.value.core.state ??= [];
|
|
31
|
-
const cfgState = cfg.value.core.state;
|
|
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);
|
|
38
|
-
}
|
|
39
|
-
cfg.saveValue(cfg.value);
|
|
40
|
-
};
|
|
41
|
-
return [state.value, setValue];
|
|
42
|
-
};
|
|
43
|
-
const onState = (name, callback) => {
|
|
44
|
-
if (typeof callback !== 'function') {
|
|
45
|
-
logger.error({
|
|
46
|
-
code: ResultCode.FailParams,
|
|
47
|
-
message: 'Callback must be a function',
|
|
48
|
-
data: null
|
|
49
|
-
});
|
|
50
|
-
throw new Error('Callback must be a function');
|
|
51
|
-
}
|
|
52
|
-
const sub = new StateSubscribe(name);
|
|
53
|
-
sub.on(callback);
|
|
54
|
-
};
|
|
55
|
-
const unState = (name, callback) => {
|
|
56
|
-
if (typeof callback !== 'function') {
|
|
57
|
-
logger.error({
|
|
58
|
-
code: ResultCode.FailParams,
|
|
59
|
-
message: 'Callback must be a function',
|
|
60
|
-
data: null
|
|
61
|
-
});
|
|
62
|
-
throw new Error('Callback must be a function');
|
|
63
|
-
}
|
|
64
|
-
const sub = new StateSubscribe(name);
|
|
65
|
-
sub.un(callback);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { onState, unState, useState };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { EventCycleEnum, Current, Events, EventKeys } from '../types';
|
|
2
|
-
export declare function useSubscribe<T extends EventKeys>(selects: T | T[]): readonly [
|
|
3
|
-
{
|
|
4
|
-
create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
5
|
-
id: string;
|
|
6
|
-
selects: T[];
|
|
7
|
-
choose: EventCycleEnum;
|
|
8
|
-
};
|
|
9
|
-
mount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
10
|
-
id: string;
|
|
11
|
-
selects: T[];
|
|
12
|
-
choose: EventCycleEnum;
|
|
13
|
-
};
|
|
14
|
-
unmount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
15
|
-
id: string;
|
|
16
|
-
selects: T[];
|
|
17
|
-
choose: EventCycleEnum;
|
|
18
|
-
};
|
|
19
|
-
cancel: (value: {
|
|
20
|
-
id: string;
|
|
21
|
-
selects: T[];
|
|
22
|
-
choose: EventCycleEnum;
|
|
23
|
-
}) => void;
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
export declare function useSubscribe<T extends EventKeys>(event: Events[T] | undefined, selects: T | T[]): readonly [
|
|
27
|
-
{
|
|
28
|
-
create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
29
|
-
id: string;
|
|
30
|
-
selects: T[];
|
|
31
|
-
choose: EventCycleEnum;
|
|
32
|
-
};
|
|
33
|
-
mount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
34
|
-
id: string;
|
|
35
|
-
selects: T[];
|
|
36
|
-
choose: EventCycleEnum;
|
|
37
|
-
};
|
|
38
|
-
unmount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
39
|
-
id: string;
|
|
40
|
-
selects: T[];
|
|
41
|
-
choose: EventCycleEnum;
|
|
42
|
-
};
|
|
43
|
-
cancel: (value: {
|
|
44
|
-
id: string;
|
|
45
|
-
selects: T[];
|
|
46
|
-
choose: EventCycleEnum;
|
|
47
|
-
}) => void;
|
|
48
|
-
}
|
|
49
|
-
];
|
|
50
|
-
export declare function useObserver<T extends EventKeys>(selects: T | T[]): readonly [
|
|
51
|
-
(callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
52
|
-
id: string;
|
|
53
|
-
selects: T[];
|
|
54
|
-
choose: EventCycleEnum;
|
|
55
|
-
},
|
|
56
|
-
(value: {
|
|
57
|
-
id: string;
|
|
58
|
-
selects: T[];
|
|
59
|
-
choose: EventCycleEnum;
|
|
60
|
-
}) => void
|
|
61
|
-
];
|
|
62
|
-
export declare function useObserver<T extends EventKeys>(event: Events[T] | undefined, selects: T | T[]): readonly [
|
|
63
|
-
(callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
64
|
-
id: string;
|
|
65
|
-
selects: T[];
|
|
66
|
-
choose: EventCycleEnum;
|
|
67
|
-
},
|
|
68
|
-
(value: {
|
|
69
|
-
id: string;
|
|
70
|
-
selects: T[];
|
|
71
|
-
choose: EventCycleEnum;
|
|
72
|
-
}) => void
|
|
73
|
-
];
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../core/variable.js';
|
|
2
|
-
import { SubscribeList } from './store.js';
|
|
3
|
-
import { SubscribeStatus } from './config.js';
|
|
4
|
-
import { getCurrentEvent } from './hook-event-context.js';
|
|
5
|
-
|
|
6
|
-
function useSubscribe(eventOrSelects, maybeSelects) {
|
|
7
|
-
const selects = (maybeSelects === undefined ? eventOrSelects : maybeSelects);
|
|
8
|
-
const event = (maybeSelects === undefined ? undefined : eventOrSelects);
|
|
9
|
-
const valueEvent = event ?? getCurrentEvent();
|
|
10
|
-
if (typeof valueEvent !== 'object' || valueEvent === null) {
|
|
11
|
-
logger.error({
|
|
12
|
-
code: ResultCode.FailParams,
|
|
13
|
-
message: 'event is not object',
|
|
14
|
-
data: null
|
|
15
|
-
});
|
|
16
|
-
throw new Error('event is not object');
|
|
17
|
-
}
|
|
18
|
-
if (typeof selects !== 'string' && !Array.isArray(selects)) {
|
|
19
|
-
logger.error({
|
|
20
|
-
code: ResultCode.FailParams,
|
|
21
|
-
message: 'select is not string or array',
|
|
22
|
-
data: null
|
|
23
|
-
});
|
|
24
|
-
throw new Error('select is not string or array');
|
|
25
|
-
}
|
|
26
|
-
const register = (callback, keys, choose) => {
|
|
27
|
-
const curSelects = Array.isArray(selects) ? selects : [selects];
|
|
28
|
-
const ID = Date.now().toString(36) + Math.random().toString(36).substring(2, 15);
|
|
29
|
-
if (keys.length === 0) {
|
|
30
|
-
logger.warn({
|
|
31
|
-
code: ResultCode.FailParams,
|
|
32
|
-
message: 'subscribe keys is empty',
|
|
33
|
-
data: null
|
|
34
|
-
});
|
|
35
|
-
return { selects: curSelects, choose, id: ID };
|
|
36
|
-
}
|
|
37
|
-
for (const select of curSelects) {
|
|
38
|
-
const subList = new SubscribeList(choose, select);
|
|
39
|
-
const values = {};
|
|
40
|
-
for (const key of keys) {
|
|
41
|
-
if (typeof key === 'string' && (typeof valueEvent[key] === 'string' || typeof valueEvent[key] === 'number' || typeof valueEvent[key] === 'boolean')) {
|
|
42
|
-
values[key] = valueEvent[key];
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
logger.warn({
|
|
46
|
-
code: ResultCode.FailParams,
|
|
47
|
-
message: `Invalid key: ${key?.toString()} must be a string, number or boolean`,
|
|
48
|
-
data: null
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
subList.value.append({
|
|
53
|
-
choose,
|
|
54
|
-
selects: curSelects,
|
|
55
|
-
keys: values,
|
|
56
|
-
current: callback,
|
|
57
|
-
status: SubscribeStatus.active,
|
|
58
|
-
id: ID
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
selects: curSelects,
|
|
63
|
-
choose,
|
|
64
|
-
id: ID
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
const create = (callback, keys) => {
|
|
68
|
-
return register(callback, keys, 'create');
|
|
69
|
-
};
|
|
70
|
-
const mountBefore = (callback, keys) => {
|
|
71
|
-
return register(callback, keys, 'mount');
|
|
72
|
-
};
|
|
73
|
-
const unmount = (callback, keys) => {
|
|
74
|
-
return register(callback, keys, 'unmount');
|
|
75
|
-
};
|
|
76
|
-
const cancel = (value) => {
|
|
77
|
-
const selects = value.selects;
|
|
78
|
-
const ID = value.id;
|
|
79
|
-
for (const select of selects) {
|
|
80
|
-
const subList = new SubscribeList(value.choose, select);
|
|
81
|
-
subList.value.forEach(node => {
|
|
82
|
-
if (node.data.id === ID) {
|
|
83
|
-
node.data.status = SubscribeStatus.paused;
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const subscribe = {
|
|
90
|
-
create,
|
|
91
|
-
mount: mountBefore,
|
|
92
|
-
unmount,
|
|
93
|
-
cancel
|
|
94
|
-
};
|
|
95
|
-
return [subscribe];
|
|
96
|
-
}
|
|
97
|
-
function useObserver(eventOrSelects, maybeSelects) {
|
|
98
|
-
const selects = (maybeSelects === undefined ? eventOrSelects : maybeSelects);
|
|
99
|
-
const event = (maybeSelects === undefined ? undefined : eventOrSelects);
|
|
100
|
-
if (selects === undefined) {
|
|
101
|
-
logger.error({
|
|
102
|
-
code: ResultCode.FailParams,
|
|
103
|
-
message: 'select is not string or array',
|
|
104
|
-
data: null
|
|
105
|
-
});
|
|
106
|
-
throw new Error('select is not string or array');
|
|
107
|
-
}
|
|
108
|
-
const [subscribe] = useSubscribe(event, selects);
|
|
109
|
-
return [subscribe.mount, subscribe.cancel];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export { useObserver, useSubscribe };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { DataEnums, OnDataFormatFunc } from '../../types';
|
|
2
|
-
import { Result } from '../../core/utils';
|
|
3
|
-
type BaseMap = {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* 创建原生value映射
|
|
8
|
-
* @param event
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export declare const createEventValue: <T extends keyof R, R extends BaseMap>(event: {
|
|
12
|
-
value: R[T];
|
|
13
|
-
}) => R[T];
|
|
14
|
-
/**
|
|
15
|
-
* 创建数据格式。
|
|
16
|
-
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
17
|
-
* @returns {DataEnums[]} - 返回格式化后的数据数组。
|
|
18
|
-
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
19
|
-
*/
|
|
20
|
-
export declare const format: OnDataFormatFunc;
|
|
21
|
-
/**
|
|
22
|
-
* 创建数据格式。
|
|
23
|
-
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
24
|
-
* @returns {DataEnums[]} - 返回格式化后的数据数组。
|
|
25
|
-
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
26
|
-
* 废弃,请使用 format
|
|
27
|
-
* @deprecated
|
|
28
|
-
*/
|
|
29
|
-
export declare const createDataFormat: OnDataFormatFunc;
|
|
30
|
-
/**
|
|
31
|
-
* 向指定频道发送消息。
|
|
32
|
-
* @param {string} SpaceId - 空间ID,可能是服务器ID、频道ID、群ID、聊天ID,或者是复合ID。总之,是框架给指定空间的唯一标识。也就是说,不能使用ChannelId作为该参数。
|
|
33
|
-
* @param {DataEnums[]} data - 要发送的数据。
|
|
34
|
-
* @throws {Error} - 如果 SpaceId 无效或发送失败,抛出错误。
|
|
35
|
-
*/
|
|
36
|
-
export declare const sendToChannel: (SpaceId: string, data: DataEnums[]) => Promise<Result[]>;
|
|
37
|
-
/**
|
|
38
|
-
* 向指定用户发送消息。
|
|
39
|
-
* @param {string} OpenID - 开放ID,可能是用户ID、聊天ID,或是复合ID。总之,是框架给指定用户的唯一标识。也就说,不能使用UserId作为该参数。
|
|
40
|
-
* @param {DataEnums[]} data - 要发送的数据。
|
|
41
|
-
* @throws {Error} - 如果 user_id 无效或发送失败,抛出错误。
|
|
42
|
-
*/
|
|
43
|
-
export declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<Result[]>;
|
|
44
|
-
type IntentResult = {
|
|
45
|
-
[key: string]: boolean | number;
|
|
46
|
-
maxImageCount?: number;
|
|
47
|
-
maxImageSize?: number;
|
|
48
|
-
maxTextLength?: number;
|
|
49
|
-
maxMarkdownLength?: number;
|
|
50
|
-
allowMarkdownLink?: boolean;
|
|
51
|
-
allowMarkdownImage?: boolean;
|
|
52
|
-
allowMarkdownMention?: boolean;
|
|
53
|
-
maxFileCount?: number;
|
|
54
|
-
maxFileSize?: number;
|
|
55
|
-
maxVideoCount?: number;
|
|
56
|
-
maxVideoSize?: number;
|
|
57
|
-
allowButton?: boolean;
|
|
58
|
-
allowMixImageText?: boolean;
|
|
59
|
-
allowMixMarkdownButton?: boolean;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* 得到消息意图。
|
|
63
|
-
* 用于多平台下的降级消费。
|
|
64
|
-
* @param event
|
|
65
|
-
* @param data
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
export declare const getMessageIntent: () => Promise<Result<IntentResult>>;
|
|
69
|
-
export {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../../core/variable.js';
|
|
2
|
-
import { sendAction } from '../../cbp/processor/actions.js';
|
|
3
|
-
import { createResult } from '../../core/utils.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 创建原生value映射
|
|
7
|
-
* @param event
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
const createEventValue = (event) => {
|
|
11
|
-
return event.value;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* 创建数据格式。
|
|
15
|
-
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
16
|
-
* @returns {DataEnums[]} - 返回格式化后的数据数组。
|
|
17
|
-
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
18
|
-
*/
|
|
19
|
-
const format = (...data) => {
|
|
20
|
-
if (!data || data.length === 0) {
|
|
21
|
-
logger.error({
|
|
22
|
-
code: ResultCode.FailParams,
|
|
23
|
-
message: 'Invalid data: data cannot be empty',
|
|
24
|
-
data: null
|
|
25
|
-
});
|
|
26
|
-
throw new Error('Invalid data: data cannot be empty');
|
|
27
|
-
}
|
|
28
|
-
return data;
|
|
29
|
-
};
|
|
30
|
-
global.format = format;
|
|
31
|
-
/**
|
|
32
|
-
* 创建数据格式。
|
|
33
|
-
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
34
|
-
* @returns {DataEnums[]} - 返回格式化后的数据数组。
|
|
35
|
-
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
36
|
-
* 废弃,请使用 format
|
|
37
|
-
* @deprecated
|
|
38
|
-
*/
|
|
39
|
-
const createDataFormat = format;
|
|
40
|
-
/**
|
|
41
|
-
* 向指定频道发送消息。
|
|
42
|
-
* @param {string} SpaceId - 空间ID,可能是服务器ID、频道ID、群ID、聊天ID,或者是复合ID。总之,是框架给指定空间的唯一标识。也就是说,不能使用ChannelId作为该参数。
|
|
43
|
-
* @param {DataEnums[]} data - 要发送的数据。
|
|
44
|
-
* @throws {Error} - 如果 SpaceId 无效或发送失败,抛出错误。
|
|
45
|
-
*/
|
|
46
|
-
const sendToChannel = async (SpaceId, data) => {
|
|
47
|
-
if (!SpaceId || typeof SpaceId !== 'string') {
|
|
48
|
-
logger.error({
|
|
49
|
-
code: ResultCode.FailParams,
|
|
50
|
-
message: 'Invalid SpaceId: SpaceId must be a string',
|
|
51
|
-
data: null
|
|
52
|
-
});
|
|
53
|
-
throw new Error('Invalid SpaceId: SpaceId must be a string');
|
|
54
|
-
}
|
|
55
|
-
return await sendAction({
|
|
56
|
-
action: 'message.send.channel',
|
|
57
|
-
payload: {
|
|
58
|
-
ChannelId: SpaceId,
|
|
59
|
-
params: {
|
|
60
|
-
format: data
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* 向指定用户发送消息。
|
|
67
|
-
* @param {string} OpenID - 开放ID,可能是用户ID、聊天ID,或是复合ID。总之,是框架给指定用户的唯一标识。也就说,不能使用UserId作为该参数。
|
|
68
|
-
* @param {DataEnums[]} data - 要发送的数据。
|
|
69
|
-
* @throws {Error} - 如果 user_id 无效或发送失败,抛出错误。
|
|
70
|
-
*/
|
|
71
|
-
const sendToUser = async (OpenID, data) => {
|
|
72
|
-
if (!OpenID || typeof OpenID !== 'string') {
|
|
73
|
-
logger.error({
|
|
74
|
-
code: ResultCode.FailParams,
|
|
75
|
-
message: 'Invalid OpenID: OpenID must be a string',
|
|
76
|
-
data: null
|
|
77
|
-
});
|
|
78
|
-
throw new Error('Invalid OpenID: OpenID must be a string');
|
|
79
|
-
}
|
|
80
|
-
return await sendAction({
|
|
81
|
-
action: 'message.send.user',
|
|
82
|
-
payload: {
|
|
83
|
-
UserId: OpenID,
|
|
84
|
-
params: {
|
|
85
|
-
format: data
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* 得到消息意图。
|
|
92
|
-
* 用于多平台下的降级消费。
|
|
93
|
-
* @param event
|
|
94
|
-
* @param data
|
|
95
|
-
* @returns
|
|
96
|
-
*/
|
|
97
|
-
const getMessageIntent = async () => {
|
|
98
|
-
const results = await sendAction({
|
|
99
|
-
action: 'message.intent',
|
|
100
|
-
payload: {}
|
|
101
|
-
});
|
|
102
|
-
return createResult(ResultCode.Ok, '获取成功', results[0]?.data ?? null);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser };
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, DataButtonRow, DataButtonGroup, DataButton, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataMarkdownCode, DataMarkdownOriginal, DataAttachment, DataAudio, DataVideo, DataMarkdownMention, DataMarkdownContent, DataMarkdownButton } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* 文本消息
|
|
4
|
-
* @param val
|
|
5
|
-
* @param options
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
|
|
9
|
-
/**
|
|
10
|
-
* 链接消息
|
|
11
|
-
* @deprecated 废弃,这个应该是md语法里的
|
|
12
|
-
* @param val 要显示的文本
|
|
13
|
-
* @param options 内容选项
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
|
|
17
|
-
/**
|
|
18
|
-
* 图片链接,http 或 https 开头
|
|
19
|
-
* @deprecated 废弃,推荐使用 Image
|
|
20
|
-
* @param val
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
|
|
24
|
-
/**
|
|
25
|
-
* 本地图片文件
|
|
26
|
-
* @deprecated 废弃,推荐使用 Image
|
|
27
|
-
* @param val
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
export declare const ImageFile: (val: DataImageFile["value"]) => DataImageFile;
|
|
31
|
-
/**
|
|
32
|
-
* 图片消息
|
|
33
|
-
* @param val Buffer 或带协议的字符串(https:// | http:// | file:// | base64://)
|
|
34
|
-
* @returns
|
|
35
|
-
*/
|
|
36
|
-
declare const Image: {
|
|
37
|
-
(val: Buffer | string): DataImage;
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated 废弃,推荐使用 Image
|
|
40
|
-
*/
|
|
41
|
-
url: (val: DataImageURL["value"]) => DataImageURL;
|
|
42
|
-
/**
|
|
43
|
-
* @deprecated 废弃,推荐使用 Image
|
|
44
|
-
*/
|
|
45
|
-
file: (val: DataImageFile["value"]) => DataImageFile;
|
|
46
|
-
};
|
|
47
|
-
export { Image };
|
|
48
|
-
/**
|
|
49
|
-
* 提及
|
|
50
|
-
* @param UserId 默认 @ 所有人
|
|
51
|
-
* @param options 默认 user
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
export declare const Mention: (UserId?: DataMention["value"], options?: DataMention["options"]) => DataMention;
|
|
55
|
-
export declare const Button: {
|
|
56
|
-
(title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
|
|
57
|
-
group: (...rows: DataButtonRow[]) => DataButtonGroup;
|
|
58
|
-
row: (...buttons: DataButton[]) => DataButtonRow;
|
|
59
|
-
};
|
|
60
|
-
export declare const BT: {
|
|
61
|
-
(title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
|
|
62
|
-
group: (...rows: DataButtonRow[]) => DataButtonGroup;
|
|
63
|
-
row: (...buttons: DataButton[]) => DataButtonRow;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param values 要显示的文本
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
declare const Markdown: {
|
|
71
|
-
(...values: DataMarkDown["value"]): DataMarkDown;
|
|
72
|
-
text(text: string): DataMarkdownText;
|
|
73
|
-
mention(uid?: string, options?: DataMarkdownMention["options"]): DataMarkdownMention;
|
|
74
|
-
button(title: string, data: DataMarkdownButton["options"]): DataMarkdownButton;
|
|
75
|
-
content(text: string): DataMarkdownContent;
|
|
76
|
-
title(text: string): DataMarkdownTitle;
|
|
77
|
-
subtitle(text: string): DataMarkdownSubtitle;
|
|
78
|
-
bold(text: string): DataMarkdownBold;
|
|
79
|
-
italic(text: string): DataMarkdownItalic;
|
|
80
|
-
italicStar(text: string): DataMarkdownItalicStar;
|
|
81
|
-
strikethrough(text: string): DataMarkdownStrikethrough;
|
|
82
|
-
link(text: string, url: string): DataMarkdownLink;
|
|
83
|
-
image(url: string, options?: {
|
|
84
|
-
width?: number;
|
|
85
|
-
height?: number;
|
|
86
|
-
}): DataMarkdownImage;
|
|
87
|
-
list(...items: any[]): DataMarkdownList;
|
|
88
|
-
listItem(indexOrText: number | string, text?: string): DataMarkdownListItem;
|
|
89
|
-
blockquote(text: string): DataMarkdownBlockquote;
|
|
90
|
-
divider(): DataMarkdownDivider;
|
|
91
|
-
newline(value?: boolean): DataMarkdownNewline;
|
|
92
|
-
code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
|
|
93
|
-
};
|
|
94
|
-
export declare const MD: {
|
|
95
|
-
(...values: DataMarkDown["value"]): DataMarkDown;
|
|
96
|
-
text(text: string): DataMarkdownText;
|
|
97
|
-
mention(uid?: string, options?: DataMarkdownMention["options"]): DataMarkdownMention;
|
|
98
|
-
button(title: string, data: DataMarkdownButton["options"]): DataMarkdownButton;
|
|
99
|
-
content(text: string): DataMarkdownContent;
|
|
100
|
-
title(text: string): DataMarkdownTitle;
|
|
101
|
-
subtitle(text: string): DataMarkdownSubtitle;
|
|
102
|
-
bold(text: string): DataMarkdownBold;
|
|
103
|
-
italic(text: string): DataMarkdownItalic;
|
|
104
|
-
italicStar(text: string): DataMarkdownItalicStar;
|
|
105
|
-
strikethrough(text: string): DataMarkdownStrikethrough;
|
|
106
|
-
link(text: string, url: string): DataMarkdownLink;
|
|
107
|
-
image(url: string, options?: {
|
|
108
|
-
width?: number;
|
|
109
|
-
height?: number;
|
|
110
|
-
}): DataMarkdownImage;
|
|
111
|
-
list(...items: any[]): DataMarkdownList;
|
|
112
|
-
listItem(indexOrText: number | string, text?: string): DataMarkdownListItem;
|
|
113
|
-
blockquote(text: string): DataMarkdownBlockquote;
|
|
114
|
-
divider(): DataMarkdownDivider;
|
|
115
|
-
newline(value?: boolean): DataMarkdownNewline;
|
|
116
|
-
code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
|
|
117
|
-
};
|
|
118
|
-
export { Markdown };
|
|
119
|
-
/**
|
|
120
|
-
* 纯 Markdown 文本
|
|
121
|
-
* @param val 原始 Markdown 字符串
|
|
122
|
-
* @returns
|
|
123
|
-
*/
|
|
124
|
-
export declare const MarkdownOriginal: (val: string) => DataMarkdownOriginal;
|
|
125
|
-
/**
|
|
126
|
-
* 附件消息
|
|
127
|
-
* @param val 带协议的字符串(https:// | http:// | file:// | base64://)
|
|
128
|
-
* @param options 附件选项
|
|
129
|
-
* @returns
|
|
130
|
-
*/
|
|
131
|
-
export declare const Attachment: (val: string, options?: DataAttachment["options"]) => DataAttachment;
|
|
132
|
-
/**
|
|
133
|
-
* 音频消息
|
|
134
|
-
* @param val 带协议的字符串(https:// | http:// | file:// | base64://)
|
|
135
|
-
* @returns
|
|
136
|
-
*/
|
|
137
|
-
export declare const Audio: (val: string) => DataAudio;
|
|
138
|
-
/**
|
|
139
|
-
* 视频消息
|
|
140
|
-
* @param val 带协议的字符串(https:// | http:// | file:// | base64://)
|
|
141
|
-
* @returns
|
|
142
|
-
*/
|
|
143
|
-
export declare const Video: (val: string) => DataVideo;
|