alemonjs 2.1.0-alpha.3 → 2.1.0-alpha.31
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/bin/updateConfig.js +1 -1
- 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 +12 -1
- package/lib/app/event-processor-cycle.js +32 -21
- 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 +29 -38
- package/lib/app/hook-use-api.js +146 -118
- 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 +22 -6
- package/lib/cbp/actions.js +25 -10
- package/lib/cbp/api.js +48 -0
- package/lib/cbp/client.d.ts +10 -0
- package/lib/cbp/client.js +159 -0
- package/lib/cbp/config.js +15 -3
- package/lib/cbp/connect.d.ts +6 -3
- package/lib/cbp/connect.js +44 -190
- package/lib/cbp/index.js +299 -167
- package/lib/cbp/platform.d.ts +19 -0
- package/lib/cbp/platform.js +170 -0
- package/lib/cbp/router.js +5 -4
- package/lib/cbp/server.d.ts +8 -0
- package/lib/cbp/server.js +451 -0
- package/lib/cbp/testone.js +306 -0
- package/lib/cbp/typings.d.ts +13 -0
- package/lib/core/config.js +1 -1
- package/lib/{app → core}/utils.d.ts +5 -6
- package/lib/{app → core}/utils.js +3 -4
- package/lib/core/variable.js +7 -1
- package/lib/global.d.ts +23 -1
- package/lib/index.d.ts +14 -11
- package/lib/index.js +10 -8
- package/lib/main.js +13 -8
- package/lib/typing/actions.d.ts +54 -3
- 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 +18 -8
- package/lib/cbp/index.d.ts +0 -3
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
|
* 使用提及。
|
|
@@ -19,7 +20,7 @@ const useMention = (event) => {
|
|
|
19
20
|
}
|
|
20
21
|
let res = null;
|
|
21
22
|
const mention = {
|
|
22
|
-
find: async (options) => {
|
|
23
|
+
find: async (options = {}) => {
|
|
23
24
|
try {
|
|
24
25
|
if (!res) {
|
|
25
26
|
const results = await sendAction({
|
|
@@ -38,32 +39,30 @@ const useMention = (event) => {
|
|
|
38
39
|
return createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
39
40
|
}
|
|
40
41
|
if (!Array.isArray(res)) {
|
|
41
|
-
return createResult(ResultCode.
|
|
42
|
+
return createResult(ResultCode.Warn, 'No mention data found', null);
|
|
42
43
|
}
|
|
43
44
|
// 过滤出符合条件的数据
|
|
44
45
|
const data = res.filter(item => {
|
|
45
|
-
if (options.UserId && item.UserId !== options.UserId) {
|
|
46
|
+
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
46
47
|
return false;
|
|
47
48
|
}
|
|
48
|
-
if (options.UserKey && item.UserKey !== options.UserKey) {
|
|
49
|
+
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
49
50
|
return false;
|
|
50
51
|
}
|
|
51
|
-
if (options.UserName && item.UserName !== options.UserName) {
|
|
52
|
+
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
52
53
|
return false;
|
|
53
54
|
}
|
|
54
|
-
if (options.IsMaster && item.IsMaster !== options.IsMaster) {
|
|
55
|
+
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
55
56
|
return false;
|
|
56
57
|
}
|
|
57
|
-
if (options.IsBot && item.IsBot !== options.IsBot) {
|
|
58
|
+
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
58
59
|
return false;
|
|
59
60
|
}
|
|
60
61
|
return true;
|
|
61
62
|
});
|
|
62
63
|
return createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
63
64
|
},
|
|
64
|
-
findOne: async (options = {
|
|
65
|
-
IsBot: false
|
|
66
|
-
}) => {
|
|
65
|
+
findOne: async (options = {}) => {
|
|
67
66
|
try {
|
|
68
67
|
if (!res) {
|
|
69
68
|
const results = await sendAction({
|
|
@@ -82,29 +81,32 @@ const useMention = (event) => {
|
|
|
82
81
|
return createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
|
|
83
82
|
}
|
|
84
83
|
if (!Array.isArray(res)) {
|
|
85
|
-
return createResult(ResultCode.
|
|
84
|
+
return createResult(ResultCode.Warn, 'No mention data found', null);
|
|
86
85
|
}
|
|
87
86
|
// 根据条件查找
|
|
88
87
|
const data = res.find(item => {
|
|
89
|
-
if (options.UserId && item.UserId !== options.UserId) {
|
|
88
|
+
if (options.UserId !== undefined && item.UserId !== options.UserId) {
|
|
90
89
|
return false;
|
|
91
90
|
}
|
|
92
|
-
if (options.UserKey && item.UserKey !== options.UserKey) {
|
|
91
|
+
if (options.UserKey !== undefined && item.UserKey !== options.UserKey) {
|
|
93
92
|
return false;
|
|
94
93
|
}
|
|
95
|
-
if (options.UserName && item.UserName !== options.UserName) {
|
|
94
|
+
if (options.UserName !== undefined && item.UserName !== options.UserName) {
|
|
96
95
|
return false;
|
|
97
96
|
}
|
|
98
|
-
if (options.IsMaster && item.IsMaster !== options.IsMaster) {
|
|
97
|
+
if (options.IsMaster !== undefined && item.IsMaster !== options.IsMaster) {
|
|
99
98
|
return false;
|
|
100
99
|
}
|
|
101
|
-
if (options.IsBot && item.IsBot !== options.IsBot) {
|
|
100
|
+
if (options.IsBot !== undefined && item.IsBot !== options.IsBot) {
|
|
102
101
|
return false;
|
|
103
102
|
}
|
|
103
|
+
if (item.IsBot) {
|
|
104
|
+
return false; // 如果是 bot,则不返回
|
|
105
|
+
}
|
|
104
106
|
return true;
|
|
105
107
|
});
|
|
106
108
|
if (!data) {
|
|
107
|
-
return createResult(ResultCode.
|
|
109
|
+
return createResult(ResultCode.Warn, 'No mention data found', null);
|
|
108
110
|
}
|
|
109
111
|
return createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
|
|
110
112
|
}
|
|
@@ -147,60 +149,60 @@ const useMessage = (event) => {
|
|
|
147
149
|
});
|
|
148
150
|
return Array.isArray(result) ? result : [result];
|
|
149
151
|
};
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const withdraw = async (message_id) => {
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const forward = async (message_id) => {
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const reply = async (message_id) => {
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const update = async (message_id) => {
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const pinning = async (message_id) => {
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const horn = async (message_id) => {
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const reaction = async (message_id) => {
|
|
193
|
-
|
|
194
|
-
}
|
|
152
|
+
// /**
|
|
153
|
+
// * 撤回消息
|
|
154
|
+
// */
|
|
155
|
+
// const withdraw = async (message_id?: string) => {
|
|
156
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
157
|
+
// }
|
|
158
|
+
// /**
|
|
159
|
+
// * 转发消息
|
|
160
|
+
// */
|
|
161
|
+
// const forward = async (message_id?: string) => {
|
|
162
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
163
|
+
// }
|
|
164
|
+
// /**
|
|
165
|
+
// * 回复 quote
|
|
166
|
+
// * ***
|
|
167
|
+
// * 和send区别在于,
|
|
168
|
+
// * 如果对应的平台支持引用时,进行引用回复
|
|
169
|
+
// */
|
|
170
|
+
// const reply = async (message_id?: string) => {
|
|
171
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
172
|
+
// }
|
|
173
|
+
// /**
|
|
174
|
+
// * 更新消息
|
|
175
|
+
// */
|
|
176
|
+
// const update = async (message_id?: string) => {
|
|
177
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
178
|
+
// }
|
|
179
|
+
// /**
|
|
180
|
+
// * 置顶消息
|
|
181
|
+
// */
|
|
182
|
+
// const pinning = async (message_id?: string) => {
|
|
183
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
184
|
+
// }
|
|
185
|
+
// /**
|
|
186
|
+
// * 警告消息
|
|
187
|
+
// */
|
|
188
|
+
// const horn = async (message_id?: string) => {
|
|
189
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
190
|
+
// }
|
|
191
|
+
// /**
|
|
192
|
+
// * 表态
|
|
193
|
+
// */
|
|
194
|
+
// const reaction = async (message_id?: string) => {
|
|
195
|
+
// return [createResult(ResultCode.Warn, '暂未支持', message_id)]
|
|
196
|
+
// }
|
|
195
197
|
const message = {
|
|
196
|
-
send
|
|
197
|
-
withdraw,
|
|
198
|
-
forward,
|
|
199
|
-
reply,
|
|
200
|
-
update,
|
|
201
|
-
pinning,
|
|
202
|
-
horn,
|
|
203
|
-
reaction
|
|
198
|
+
send
|
|
199
|
+
// withdraw,
|
|
200
|
+
// forward,
|
|
201
|
+
// reply,
|
|
202
|
+
// update,
|
|
203
|
+
// pinning,
|
|
204
|
+
// horn,
|
|
205
|
+
// reaction
|
|
204
206
|
};
|
|
205
207
|
return [message];
|
|
206
208
|
};
|
|
@@ -219,43 +221,43 @@ const useMenber = (event) => {
|
|
|
219
221
|
});
|
|
220
222
|
throw new Error('Invalid event: event must be an object');
|
|
221
223
|
}
|
|
222
|
-
/**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const information = async (user_id) => {
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const mute = async (all = false) => {
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const unmute = async (all = false) => {
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const remove = async (user_id) => {
|
|
252
|
-
|
|
253
|
-
}
|
|
224
|
+
// /**
|
|
225
|
+
// * 获取用户信息
|
|
226
|
+
// * @param user_id
|
|
227
|
+
// * @returns
|
|
228
|
+
// */
|
|
229
|
+
// const information = async (user_id?: string) => {
|
|
230
|
+
// return createResult(ResultCode.Warn, '暂未支持', user_id)
|
|
231
|
+
// }
|
|
232
|
+
// /**
|
|
233
|
+
// * 禁言
|
|
234
|
+
// * @param all 是否是全体
|
|
235
|
+
// * @returns
|
|
236
|
+
// */
|
|
237
|
+
// const mute = async (all: boolean = false) => {
|
|
238
|
+
// return createResult(ResultCode.Warn, '暂未支持', all)
|
|
239
|
+
// }
|
|
240
|
+
// /**
|
|
241
|
+
// * 解除禁言
|
|
242
|
+
// * @param all 是否是全体
|
|
243
|
+
// * @returns
|
|
244
|
+
// */
|
|
245
|
+
// const unmute = async (all: boolean = false) => {
|
|
246
|
+
// return createResult(ResultCode.Warn, '暂未支持', all)
|
|
247
|
+
// }
|
|
248
|
+
// /**
|
|
249
|
+
// * 移除用户
|
|
250
|
+
// * @param user_id
|
|
251
|
+
// * @returns
|
|
252
|
+
// */
|
|
253
|
+
// const remove = async (user_id?: string) => {
|
|
254
|
+
// return createResult(ResultCode.Warn, '暂未支持', user_id)
|
|
255
|
+
// }
|
|
254
256
|
const member = {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
// information,
|
|
258
|
+
// mute,
|
|
259
|
+
// unmute,
|
|
260
|
+
// remove
|
|
259
261
|
};
|
|
260
262
|
return [member];
|
|
261
263
|
};
|
|
@@ -274,17 +276,17 @@ const useChannel = (event) => {
|
|
|
274
276
|
});
|
|
275
277
|
throw new Error('Invalid event: event must be an object');
|
|
276
278
|
}
|
|
277
|
-
// 退出
|
|
278
|
-
const exit = async (channel_id) => {
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
// 加入
|
|
282
|
-
const join = async (channel_id) => {
|
|
283
|
-
|
|
284
|
-
}
|
|
279
|
+
// // 退出
|
|
280
|
+
// const exit = async (channel_id?: string) => {
|
|
281
|
+
// return createResult(ResultCode.Warn, '暂未支持', channel_id)
|
|
282
|
+
// }
|
|
283
|
+
// // 加入
|
|
284
|
+
// const join = async (channel_id?: string) => {
|
|
285
|
+
// return createResult(ResultCode.Warn, '暂未支持', channel_id)
|
|
286
|
+
// }
|
|
285
287
|
const channel = {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
// exit,
|
|
289
|
+
// join
|
|
288
290
|
};
|
|
289
291
|
return [channel];
|
|
290
292
|
};
|
|
@@ -303,6 +305,7 @@ const useSend = (event) => {
|
|
|
303
305
|
};
|
|
304
306
|
/**
|
|
305
307
|
* 废弃,请使用 useMessage
|
|
308
|
+
* @deprecated
|
|
306
309
|
* @param event
|
|
307
310
|
* @returns
|
|
308
311
|
*/
|
|
@@ -337,7 +340,32 @@ global.onSelects = onSelects;
|
|
|
337
340
|
/**
|
|
338
341
|
* 废弃,请使用onSelects
|
|
339
342
|
* @deprecated
|
|
343
|
+
* @param values
|
|
344
|
+
* @returns
|
|
340
345
|
*/
|
|
341
346
|
const createSelects = onSelects;
|
|
347
|
+
/**
|
|
348
|
+
* 使用客户端
|
|
349
|
+
* @param event
|
|
350
|
+
* @param _ApiClass
|
|
351
|
+
* @returns
|
|
352
|
+
*/
|
|
353
|
+
const useClient = (event, _ApiClass) => {
|
|
354
|
+
const client = new Proxy({}, {
|
|
355
|
+
get(_target, prop) {
|
|
356
|
+
return (...args) => {
|
|
357
|
+
return sendAPI({
|
|
358
|
+
action: 'client.api',
|
|
359
|
+
payload: {
|
|
360
|
+
event,
|
|
361
|
+
key: String(prop),
|
|
362
|
+
params: args
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
return [client];
|
|
369
|
+
};
|
|
342
370
|
|
|
343
|
-
export { createSelects, onSelects, unChildren, useChannel, useMenber, useMention, useMessage, useSend, useSends };
|
|
371
|
+
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 };
|