alemonjs 2.1.0-alpha.2 → 2.1.0-alpha.21
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/README.md +85 -25
- package/lib/app/event-group.d.ts +11 -0
- package/lib/app/event-group.js +28 -0
- package/lib/app/event-middleware.d.ts +10 -2
- package/lib/app/event-middleware.js +11 -1
- package/lib/app/event-processor-event.js +1 -1
- package/lib/app/event-processor-middleware.js +1 -1
- package/lib/app/event-processor.js +1 -1
- package/lib/app/event-response.d.ts +10 -2
- package/lib/app/event-response.js +12 -1
- package/lib/app/hook-use-api.d.ts +19 -24
- package/lib/app/hook-use-api.js +136 -117
- package/lib/app/hook-use-subscribe.d.ts +20 -3
- package/lib/app/hook-use-subscribe.js +13 -1
- package/lib/app/load.js +10 -14
- package/lib/app/message-api.d.ts +28 -8
- package/lib/app/message-api.js +31 -14
- package/lib/app/message-format.d.ts +5 -12
- package/lib/app/message-format.js +16 -7
- package/lib/app/store.js +4 -3
- package/lib/cbp/actions.js +11 -7
- package/lib/cbp/api.js +37 -0
- package/lib/cbp/config.js +8 -2
- package/lib/cbp/connect.d.ts +6 -2
- package/lib/cbp/connect.js +213 -30
- package/lib/cbp/index.js +53 -6
- package/lib/{app → core}/utils.d.ts +2 -3
- package/lib/{app → core}/utils.js +3 -4
- package/lib/core/variable.js +7 -1
- package/lib/global.d.ts +18 -1
- package/lib/index.d.ts +11 -10
- package/lib/index.js +7 -7
- package/lib/main.js +6 -5
- package/lib/typing/actions.d.ts +1 -1
- package/lib/typing/apis.d.ts +18 -0
- package/lib/typing/client/index.d.ts +1 -1
- package/lib/typing/event/base/expansion.d.ts +5 -0
- package/lib/typing/event/base/guild.d.ts +4 -0
- package/lib/typing/event/base/user.d.ts +4 -0
- package/lib/typing/event/channal/index.d.ts +3 -2
- package/lib/typing/event/guild/index.d.ts +3 -2
- package/lib/typing/event/index.d.ts +13 -1
- package/lib/typing/event/interaction/index.d.ts +3 -2
- package/lib/typing/event/map.d.ts +0 -2
- package/lib/typing/event/member/index.d.ts +3 -2
- package/lib/typing/event/message/message.d.ts +6 -5
- package/lib/typing/event/message/private.message.d.ts +4 -3
- package/lib/typing/event/request/index.d.ts +3 -2
- package/lib/typing/message/button.d.ts +6 -5
- package/lib/typing/message/index.d.ts +4 -4
- package/lib/typing/message/markdown.d.ts +13 -3
- package/lib/utils.d.ts +80 -0
- package/lib/utils.js +203 -0
- package/package.json +12 -3
- package/lib/app/define-bot.d.ts +0 -17
- package/lib/app/define-bot.js +0 -39
- package/lib/cbp/index.d.ts +0 -32
- package/lib/cbp/message.js +0 -9
- package/lib/jsx.d.ts +0 -142
- package/lib/jsx.js +0 -234
package/lib/app/hook-use-api.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ResultCode } from '../core/code.js';
|
|
2
2
|
import { ChildrenApp } from './store.js';
|
|
3
|
-
import { createResult } from '
|
|
3
|
+
import { createResult } from '../core/utils.js';
|
|
4
4
|
import { sendAction } from '../cbp/actions.js';
|
|
5
|
+
import { sendAPI } from '../cbp/api.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 使用提及。
|
|
@@ -22,20 +23,16 @@ const useMention = (event) => {
|
|
|
22
23
|
find: async (options) => {
|
|
23
24
|
try {
|
|
24
25
|
if (!res) {
|
|
25
|
-
const
|
|
26
|
+
const results = await sendAction({
|
|
26
27
|
action: 'mention.get',
|
|
27
28
|
payload: {
|
|
28
29
|
event
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
32
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
33
|
+
if (result) {
|
|
34
|
+
res = result.data;
|
|
34
35
|
}
|
|
35
|
-
if (result.code !== ResultCode.Ok) {
|
|
36
|
-
return createResult(result.code, result.message, null);
|
|
37
|
-
}
|
|
38
|
-
res = result.data;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
catch (err) {
|
|
@@ -70,20 +67,16 @@ const useMention = (event) => {
|
|
|
70
67
|
}) => {
|
|
71
68
|
try {
|
|
72
69
|
if (!res) {
|
|
73
|
-
const
|
|
70
|
+
const results = await sendAction({
|
|
74
71
|
action: 'mention.get',
|
|
75
72
|
payload: {
|
|
76
73
|
event
|
|
77
74
|
}
|
|
78
75
|
});
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
if (result.code !== ResultCode.Ok) {
|
|
84
|
-
return createResult(result.code, result.message, null);
|
|
76
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
77
|
+
if (result) {
|
|
78
|
+
res = result.data;
|
|
85
79
|
}
|
|
86
|
-
res = result.data;
|
|
87
80
|
}
|
|
88
81
|
}
|
|
89
82
|
catch (err) {
|
|
@@ -155,60 +148,60 @@ const useMessage = (event) => {
|
|
|
155
148
|
});
|
|
156
149
|
return Array.isArray(result) ? result : [result];
|
|
157
150
|
};
|
|
158
|
-
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const withdraw = async (message_id) => {
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const forward = async (message_id) => {
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const reply = async (message_id) => {
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const update = async (message_id) => {
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const pinning = async (message_id) => {
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const horn = async (message_id) => {
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const reaction = async (message_id) => {
|
|
201
|
-
|
|
202
|
-
}
|
|
151
|
+
// /**
|
|
152
|
+
// * 撤回消息
|
|
153
|
+
// */
|
|
154
|
+
// const withdraw = async (message_id?: string) => {
|
|
155
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
156
|
+
// }
|
|
157
|
+
// /**
|
|
158
|
+
// * 转发消息
|
|
159
|
+
// */
|
|
160
|
+
// const forward = async (message_id?: string) => {
|
|
161
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
162
|
+
// }
|
|
163
|
+
// /**
|
|
164
|
+
// * 回复 quote
|
|
165
|
+
// * ***
|
|
166
|
+
// * 和send区别在于,
|
|
167
|
+
// * 如果对应的平台支持引用时,进行引用回复
|
|
168
|
+
// */
|
|
169
|
+
// const reply = async (message_id?: string) => {
|
|
170
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
171
|
+
// }
|
|
172
|
+
// /**
|
|
173
|
+
// * 更新消息
|
|
174
|
+
// */
|
|
175
|
+
// const update = async (message_id?: string) => {
|
|
176
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
177
|
+
// }
|
|
178
|
+
// /**
|
|
179
|
+
// * 置顶消息
|
|
180
|
+
// */
|
|
181
|
+
// const pinning = async (message_id?: string) => {
|
|
182
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
183
|
+
// }
|
|
184
|
+
// /**
|
|
185
|
+
// * 警告消息
|
|
186
|
+
// */
|
|
187
|
+
// const horn = async (message_id?: string) => {
|
|
188
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
189
|
+
// }
|
|
190
|
+
// /**
|
|
191
|
+
// * 表态
|
|
192
|
+
// */
|
|
193
|
+
// const reaction = async (message_id?: string) => {
|
|
194
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
195
|
+
// }
|
|
203
196
|
const message = {
|
|
204
|
-
send
|
|
205
|
-
withdraw,
|
|
206
|
-
forward,
|
|
207
|
-
reply,
|
|
208
|
-
update,
|
|
209
|
-
pinning,
|
|
210
|
-
horn,
|
|
211
|
-
reaction
|
|
197
|
+
send
|
|
198
|
+
// withdraw,
|
|
199
|
+
// forward,
|
|
200
|
+
// reply,
|
|
201
|
+
// update,
|
|
202
|
+
// pinning,
|
|
203
|
+
// horn,
|
|
204
|
+
// reaction
|
|
212
205
|
};
|
|
213
206
|
return [message];
|
|
214
207
|
};
|
|
@@ -227,43 +220,43 @@ const useMenber = (event) => {
|
|
|
227
220
|
});
|
|
228
221
|
throw new Error('Invalid event: event must be an object');
|
|
229
222
|
}
|
|
230
|
-
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const information = async (user_id) => {
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const mute = async (all = false) => {
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const unmute = async (all = false) => {
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const remove = async (user_id) => {
|
|
260
|
-
|
|
261
|
-
}
|
|
223
|
+
// /**
|
|
224
|
+
// * 获取用户信息
|
|
225
|
+
// * @param user_id
|
|
226
|
+
// * @returns
|
|
227
|
+
// */
|
|
228
|
+
// const information = async (user_id?: string) => {
|
|
229
|
+
// return createResult(ResultCode.Warn, '暂未支持', user_id)
|
|
230
|
+
// }
|
|
231
|
+
// /**
|
|
232
|
+
// * 禁言
|
|
233
|
+
// * @param all 是否是全体
|
|
234
|
+
// * @returns
|
|
235
|
+
// */
|
|
236
|
+
// const mute = async (all: boolean = false) => {
|
|
237
|
+
// return createResult(ResultCode.Warn, '暂未支持', all)
|
|
238
|
+
// }
|
|
239
|
+
// /**
|
|
240
|
+
// * 解除禁言
|
|
241
|
+
// * @param all 是否是全体
|
|
242
|
+
// * @returns
|
|
243
|
+
// */
|
|
244
|
+
// const unmute = async (all: boolean = false) => {
|
|
245
|
+
// return createResult(ResultCode.Warn, '暂未支持', all)
|
|
246
|
+
// }
|
|
247
|
+
// /**
|
|
248
|
+
// * 移除用户
|
|
249
|
+
// * @param user_id
|
|
250
|
+
// * @returns
|
|
251
|
+
// */
|
|
252
|
+
// const remove = async (user_id?: string) => {
|
|
253
|
+
// return createResult(ResultCode.Warn, '暂未支持', user_id)
|
|
254
|
+
// }
|
|
262
255
|
const member = {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
256
|
+
// information,
|
|
257
|
+
// mute,
|
|
258
|
+
// unmute,
|
|
259
|
+
// remove
|
|
267
260
|
};
|
|
268
261
|
return [member];
|
|
269
262
|
};
|
|
@@ -282,17 +275,17 @@ const useChannel = (event) => {
|
|
|
282
275
|
});
|
|
283
276
|
throw new Error('Invalid event: event must be an object');
|
|
284
277
|
}
|
|
285
|
-
// 退出
|
|
286
|
-
const exit = async (channel_id) => {
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
// 加入
|
|
290
|
-
const join = async (channel_id) => {
|
|
291
|
-
|
|
292
|
-
}
|
|
278
|
+
// // 退出
|
|
279
|
+
// const exit = async (channel_id?: string) => {
|
|
280
|
+
// return createResult(ResultCode.Warn, '暂未支持', channel_id)
|
|
281
|
+
// }
|
|
282
|
+
// // 加入
|
|
283
|
+
// const join = async (channel_id?: string) => {
|
|
284
|
+
// return createResult(ResultCode.Warn, '暂未支持', channel_id)
|
|
285
|
+
// }
|
|
293
286
|
const channel = {
|
|
294
|
-
|
|
295
|
-
|
|
287
|
+
// exit,
|
|
288
|
+
// join
|
|
296
289
|
};
|
|
297
290
|
return [channel];
|
|
298
291
|
};
|
|
@@ -311,6 +304,7 @@ const useSend = (event) => {
|
|
|
311
304
|
};
|
|
312
305
|
/**
|
|
313
306
|
* 废弃,请使用 useMessage
|
|
307
|
+
* @deprecated
|
|
314
308
|
* @param event
|
|
315
309
|
* @returns
|
|
316
310
|
*/
|
|
@@ -345,7 +339,32 @@ global.onSelects = onSelects;
|
|
|
345
339
|
/**
|
|
346
340
|
* 废弃,请使用onSelects
|
|
347
341
|
* @deprecated
|
|
342
|
+
* @param values
|
|
343
|
+
* @returns
|
|
348
344
|
*/
|
|
349
345
|
const createSelects = onSelects;
|
|
346
|
+
/**
|
|
347
|
+
* 使用客户端
|
|
348
|
+
* @param event
|
|
349
|
+
* @param _ApiClass
|
|
350
|
+
* @returns
|
|
351
|
+
*/
|
|
352
|
+
const useClient = (event, _ApiClass) => {
|
|
353
|
+
const client = new Proxy({}, {
|
|
354
|
+
get(_target, prop) {
|
|
355
|
+
return (...args) => {
|
|
356
|
+
return sendAPI({
|
|
357
|
+
action: 'client.api',
|
|
358
|
+
payload: {
|
|
359
|
+
event,
|
|
360
|
+
key: String(prop),
|
|
361
|
+
params: args
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
return [client];
|
|
368
|
+
};
|
|
350
369
|
|
|
351
|
-
export { createSelects, onSelects, unChildren, useChannel, useMenber, useMention, useMessage, useSend, useSends };
|
|
370
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber, useMention, useMessage, useSend, useSends };
|
|
@@ -9,7 +9,7 @@ import '../global.js';
|
|
|
9
9
|
* @param select
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
declare const useSubscribe: <T extends EventKeys>(event: Events[T], selects: T | T[]) => {
|
|
12
|
+
declare const useSubscribe: <T extends EventKeys>(event: Events[T], selects: T | T[]) => readonly [{
|
|
13
13
|
create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
14
14
|
selects: T[];
|
|
15
15
|
choose: EventCycleEnum;
|
|
@@ -30,6 +30,23 @@ declare const useSubscribe: <T extends EventKeys>(event: Events[T], selects: T |
|
|
|
30
30
|
selects: T[];
|
|
31
31
|
choose: EventCycleEnum;
|
|
32
32
|
}) => void;
|
|
33
|
-
}
|
|
33
|
+
}];
|
|
34
|
+
/**
|
|
35
|
+
* 使用观察者模式订阅事件
|
|
36
|
+
* @param event
|
|
37
|
+
* @param selects
|
|
38
|
+
* @returns
|
|
39
|
+
* 废弃,请使用 useSubscribe
|
|
40
|
+
* @deprecated
|
|
41
|
+
*/
|
|
42
|
+
declare const useObserver: <T extends EventKeys>(event: Events[T], selects: T | T[]) => readonly [(callback: Current<T>, keys: (keyof Events[T])[]) => {
|
|
43
|
+
selects: T[];
|
|
44
|
+
choose: EventCycleEnum;
|
|
45
|
+
id: string;
|
|
46
|
+
}, (value: {
|
|
47
|
+
id: string;
|
|
48
|
+
selects: T[];
|
|
49
|
+
choose: EventCycleEnum;
|
|
50
|
+
}) => void];
|
|
34
51
|
|
|
35
|
-
export { useSubscribe };
|
|
52
|
+
export { useObserver, useSubscribe };
|
|
@@ -126,5 +126,17 @@ const useSubscribe = (event, selects) => {
|
|
|
126
126
|
};
|
|
127
127
|
return [subscribe];
|
|
128
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* 使用观察者模式订阅事件
|
|
131
|
+
* @param event
|
|
132
|
+
* @param selects
|
|
133
|
+
* @returns
|
|
134
|
+
* 废弃,请使用 useSubscribe
|
|
135
|
+
* @deprecated
|
|
136
|
+
*/
|
|
137
|
+
const useObserver = (event, selects) => {
|
|
138
|
+
const [subscribe] = useSubscribe(event, selects);
|
|
139
|
+
return [subscribe.mount, subscribe.cancel];
|
|
140
|
+
};
|
|
129
141
|
|
|
130
|
-
export { useSubscribe };
|
|
142
|
+
export { useObserver, useSubscribe };
|
package/lib/app/load.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dirname, join } from 'path';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import { showErrorModule, getRecursiveDirFiles, createEventName } from '
|
|
3
|
+
import { showErrorModule, getRecursiveDirFiles, createEventName } from '../core/utils.js';
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
5
|
import { ChildrenApp } from './store.js';
|
|
6
6
|
import { ResultCode } from '../core/code.js';
|
|
@@ -51,7 +51,7 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
51
51
|
// 卸载
|
|
52
52
|
App.un();
|
|
53
53
|
try {
|
|
54
|
-
await app
|
|
54
|
+
app?.unMounted && (await app.unMounted(e));
|
|
55
55
|
}
|
|
56
56
|
catch (e) {
|
|
57
57
|
// 卸载周期出意外,不需要进行卸载
|
|
@@ -59,15 +59,13 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
// onCreated 创建
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
62
|
+
try {
|
|
63
|
+
app?.onCreated && (await app?.onCreated());
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
unMounted(e);
|
|
67
|
+
// 出错了,结束后续的操作。
|
|
68
|
+
return;
|
|
71
69
|
}
|
|
72
70
|
// onMounted 加载
|
|
73
71
|
try {
|
|
@@ -119,9 +117,7 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
119
117
|
App.pushMiddleware(mwData);
|
|
120
118
|
App.on();
|
|
121
119
|
try {
|
|
122
|
-
|
|
123
|
-
await app?.onMounted({ response: resData, middleware: mwData });
|
|
124
|
-
}
|
|
120
|
+
app?.onMounted && (await app.onMounted({ response: resData, middleware: mwData }));
|
|
125
121
|
}
|
|
126
122
|
catch (e) {
|
|
127
123
|
unMounted(e);
|
package/lib/app/message-api.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import { Result } from './utils.js';
|
|
2
1
|
import { OnDataFormatFunc } from '../typing/event/index.js';
|
|
3
|
-
import '../
|
|
2
|
+
import { Result } from '../core/utils.js';
|
|
4
3
|
import { DataEnums } from '../typing/message/index.js';
|
|
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 - 要格式化的数据。
|
|
@@ -10,19 +21,28 @@ import { DataEnums } from '../typing/message/index.js';
|
|
|
10
21
|
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
11
22
|
*/
|
|
12
23
|
declare const format: OnDataFormatFunc;
|
|
24
|
+
/**
|
|
25
|
+
* 创建数据格式。
|
|
26
|
+
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
27
|
+
* @returns {DataEnums[]} - 返回格式化后的数据数组。
|
|
28
|
+
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
29
|
+
* 废弃,请使用 format
|
|
30
|
+
* @deprecated
|
|
31
|
+
*/
|
|
32
|
+
declare const createDataFormat: OnDataFormatFunc;
|
|
13
33
|
/**
|
|
14
34
|
* 向指定频道发送消息。
|
|
15
|
-
* @param {string}
|
|
35
|
+
* @param {string} SpaceId - 空间ID,可能是服务器ID、频道ID、群ID、聊天ID,或者是复合ID。总之,是框架给指定空间的唯一标识。也就是说,不能使用ChannelId作为该参数。
|
|
16
36
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
17
|
-
* @throws {Error} - 如果
|
|
37
|
+
* @throws {Error} - 如果 SpaceId 无效或发送失败,抛出错误。
|
|
18
38
|
*/
|
|
19
|
-
declare const sendToChannel: (
|
|
39
|
+
declare const sendToChannel: (SpaceId: string, data: DataEnums[]) => Promise<Result[]>;
|
|
20
40
|
/**
|
|
21
41
|
* 向指定用户发送消息。
|
|
22
|
-
* @param {string}
|
|
42
|
+
* @param {string} OpenID - 开放ID,可能是用户ID、聊天ID,或是复合ID。总之,是框架给指定用户的唯一标识。也就说,不能使用UserId作为该参数。
|
|
23
43
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
24
44
|
* @throws {Error} - 如果 user_id 无效或发送失败,抛出错误。
|
|
25
45
|
*/
|
|
26
|
-
declare const sendToUser: (
|
|
46
|
+
declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<Result[]>;
|
|
27
47
|
|
|
28
|
-
export { format, sendToChannel, sendToUser };
|
|
48
|
+
export { createDataFormat, 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 - 要格式化的数据。
|
|
@@ -19,25 +27,34 @@ const format = (...data) => {
|
|
|
19
27
|
return data;
|
|
20
28
|
};
|
|
21
29
|
global.format = format;
|
|
30
|
+
/**
|
|
31
|
+
* 创建数据格式。
|
|
32
|
+
* @param {...DataEnums[]} data - 要格式化的数据。
|
|
33
|
+
* @returns {DataEnums[]} - 返回格式化后的数据数组。
|
|
34
|
+
* @throws {Error} - 如果 data 无效,抛出错误。
|
|
35
|
+
* 废弃,请使用 format
|
|
36
|
+
* @deprecated
|
|
37
|
+
*/
|
|
38
|
+
const createDataFormat = format;
|
|
22
39
|
/**
|
|
23
40
|
* 向指定频道发送消息。
|
|
24
|
-
* @param {string}
|
|
41
|
+
* @param {string} SpaceId - 空间ID,可能是服务器ID、频道ID、群ID、聊天ID,或者是复合ID。总之,是框架给指定空间的唯一标识。也就是说,不能使用ChannelId作为该参数。
|
|
25
42
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
26
|
-
* @throws {Error} - 如果
|
|
43
|
+
* @throws {Error} - 如果 SpaceId 无效或发送失败,抛出错误。
|
|
27
44
|
*/
|
|
28
|
-
const sendToChannel = async (
|
|
29
|
-
if (!
|
|
45
|
+
const sendToChannel = async (SpaceId, data) => {
|
|
46
|
+
if (!SpaceId || typeof SpaceId !== 'string') {
|
|
30
47
|
logger.error({
|
|
31
48
|
code: ResultCode.FailParams,
|
|
32
|
-
message: 'Invalid
|
|
49
|
+
message: 'Invalid SpaceId: SpaceId must be a string',
|
|
33
50
|
data: null
|
|
34
51
|
});
|
|
35
|
-
throw new Error('Invalid
|
|
52
|
+
throw new Error('Invalid SpaceId: SpaceId must be a string');
|
|
36
53
|
}
|
|
37
54
|
return await sendAction({
|
|
38
55
|
action: 'message.send.channel',
|
|
39
56
|
payload: {
|
|
40
|
-
ChannelId:
|
|
57
|
+
ChannelId: SpaceId,
|
|
41
58
|
params: {
|
|
42
59
|
format: data
|
|
43
60
|
}
|
|
@@ -46,23 +63,23 @@ const sendToChannel = async (channel_id, data) => {
|
|
|
46
63
|
};
|
|
47
64
|
/**
|
|
48
65
|
* 向指定用户发送消息。
|
|
49
|
-
* @param {string}
|
|
66
|
+
* @param {string} OpenID - 开放ID,可能是用户ID、聊天ID,或是复合ID。总之,是框架给指定用户的唯一标识。也就说,不能使用UserId作为该参数。
|
|
50
67
|
* @param {DataEnums[]} data - 要发送的数据。
|
|
51
68
|
* @throws {Error} - 如果 user_id 无效或发送失败,抛出错误。
|
|
52
69
|
*/
|
|
53
|
-
const sendToUser = async (
|
|
54
|
-
if (!
|
|
70
|
+
const sendToUser = async (OpenID, data) => {
|
|
71
|
+
if (!OpenID || typeof OpenID !== 'string') {
|
|
55
72
|
logger.error({
|
|
56
73
|
code: ResultCode.FailParams,
|
|
57
|
-
message: 'Invalid
|
|
74
|
+
message: 'Invalid OpenID: OpenID must be a string',
|
|
58
75
|
data: null
|
|
59
76
|
});
|
|
60
|
-
throw new Error('Invalid
|
|
77
|
+
throw new Error('Invalid OpenID: OpenID must be a string');
|
|
61
78
|
}
|
|
62
79
|
return await sendAction({
|
|
63
80
|
action: 'message.send.user',
|
|
64
81
|
payload: {
|
|
65
|
-
UserId:
|
|
82
|
+
UserId: OpenID,
|
|
66
83
|
params: {
|
|
67
84
|
format: data
|
|
68
85
|
}
|
|
@@ -70,4 +87,4 @@ const sendToUser = async (user_id, data) => {
|
|
|
70
87
|
});
|
|
71
88
|
};
|
|
72
89
|
|
|
73
|
-
export { format, sendToChannel, sendToUser };
|
|
90
|
+
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../global.js';
|
|
2
|
-
import { DataButton, ButtonRow, DataButtonGroup } from '../typing/message/button.js';
|
|
2
|
+
import { DataButton, ButtonRow, DataButtonGroup, DataButtonTemplate } from '../typing/message/button.js';
|
|
3
3
|
import { DataArkListTip, DataArkListContent, DataArkList, DataArkListItem, DataArkCard, DataArkBigCard } from '../typing/message/ark.js';
|
|
4
|
-
import { DataMarkDown, DataMarkdownTemplate, DataMarkdownText, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline } from '../typing/message/markdown.js';
|
|
4
|
+
import { DataMarkDown, DataMarkdownTemplate, DataMarkdownText, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataMarkdownCode } from '../typing/message/markdown.js';
|
|
5
5
|
import { DataImage, DataImageURL, DataImageFile } from '../typing/message/image.js';
|
|
6
6
|
import { DataText } from '../typing/message/text.js';
|
|
7
7
|
import { DataMention } from '../typing/message/mention.js';
|
|
@@ -54,7 +54,7 @@ declare const Mention: (UserId?: DataMention["value"], options?: DataMention["op
|
|
|
54
54
|
declare const BT: {
|
|
55
55
|
(title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
|
|
56
56
|
group(...rows: ButtonRow[]): DataButtonGroup;
|
|
57
|
-
template(
|
|
57
|
+
template(templateId: DataButtonTemplate["value"]): DataButtonTemplate;
|
|
58
58
|
row(...buttons: DataButton[]): ButtonRow;
|
|
59
59
|
};
|
|
60
60
|
|
|
@@ -101,15 +101,7 @@ declare const Ark: {
|
|
|
101
101
|
*/
|
|
102
102
|
declare const MD: {
|
|
103
103
|
(...values: DataMarkDown["value"]): DataMarkDown;
|
|
104
|
-
template(templateId: DataMarkdownTemplate["value"], params?: DataMarkdownTemplate["options"]["params"]):
|
|
105
|
-
type: string;
|
|
106
|
-
value: string;
|
|
107
|
-
options: {
|
|
108
|
-
params: {
|
|
109
|
-
[key: string]: string;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
};
|
|
104
|
+
template(templateId: DataMarkdownTemplate["value"], params?: DataMarkdownTemplate["options"]["params"]): DataMarkdownTemplate;
|
|
113
105
|
text(text: string): DataMarkdownText;
|
|
114
106
|
title(text: string): DataMarkdownTitle;
|
|
115
107
|
subtitle(text: string): DataMarkdownSubtitle;
|
|
@@ -127,6 +119,7 @@ declare const MD: {
|
|
|
127
119
|
blockquote(text: string): DataMarkdownBlockquote;
|
|
128
120
|
divider(): DataMarkdownDivider;
|
|
129
121
|
newline(value?: boolean): DataMarkdownNewline;
|
|
122
|
+
code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
|
|
130
123
|
};
|
|
131
124
|
|
|
132
125
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text };
|
|
@@ -90,13 +90,15 @@ BT.group = function Group(...rows) {
|
|
|
90
90
|
value: rows
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
/**
|
|
94
|
+
* 创建一个按钮模板
|
|
95
|
+
* @param templateId 模板 ID
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
BT.template = function Template(templateId) {
|
|
94
99
|
return {
|
|
95
|
-
type: '
|
|
96
|
-
value:
|
|
97
|
-
options: {
|
|
98
|
-
template_id: value
|
|
99
|
-
}
|
|
100
|
+
type: 'ButtonTemplate',
|
|
101
|
+
value: templateId
|
|
100
102
|
};
|
|
101
103
|
};
|
|
102
104
|
BT.row = function Row(...buttons) {
|
|
@@ -191,7 +193,7 @@ const MD = (...values) => {
|
|
|
191
193
|
*/
|
|
192
194
|
MD.template = (templateId, params) => {
|
|
193
195
|
return {
|
|
194
|
-
type: '
|
|
196
|
+
type: 'MarkdownTemplate',
|
|
195
197
|
value: templateId,
|
|
196
198
|
options: {
|
|
197
199
|
params
|
|
@@ -353,5 +355,12 @@ MD.newline = (value = false) => {
|
|
|
353
355
|
value: value
|
|
354
356
|
};
|
|
355
357
|
};
|
|
358
|
+
MD.code = (value, options) => {
|
|
359
|
+
return {
|
|
360
|
+
type: 'MD.code',
|
|
361
|
+
value: value,
|
|
362
|
+
options: options
|
|
363
|
+
};
|
|
364
|
+
};
|
|
356
365
|
|
|
357
366
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text };
|