@alemonjs/qq-bot 2.1.0-alpha.6 → 2.1.0-alpha.7
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/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/register.js +79 -2
- package/lib/sdk/api.d.ts +777 -966
- package/lib/sdk/api.js +29 -137
- package/lib/sdk/typing.d.ts +52 -54
- package/lib/sends.js +34 -31
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -5,7 +5,9 @@ import { start as start$2 } from './index.webhook.js';
|
|
|
5
5
|
import { start as start$3 } from './index.websoket.js';
|
|
6
6
|
import { platform } from './register.js';
|
|
7
7
|
export { useMode } from './hook.js';
|
|
8
|
+
export { QQBotAPI as API } from './sdk/api.js';
|
|
8
9
|
|
|
10
|
+
// main
|
|
9
11
|
var index = () => {
|
|
10
12
|
let value = getConfigValue();
|
|
11
13
|
if (!value)
|
package/lib/register.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getConfigValue, cbpPlatform, useUserHashKey, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { GROUP_AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, AT_MESSAGE_CREATE, MESSAGE_CREATE } from './sends.js';
|
|
3
3
|
|
|
4
|
+
// import dayjs from 'dayjs'
|
|
4
5
|
const platform = 'qq-bot';
|
|
5
6
|
const getQQBotConfig = () => {
|
|
6
7
|
let value = getConfigValue();
|
|
@@ -39,7 +40,6 @@ const register = (client) => {
|
|
|
39
40
|
// 定义消
|
|
40
41
|
const e = {
|
|
41
42
|
name: 'message.create',
|
|
42
|
-
// 事件类型
|
|
43
43
|
Platform: platform,
|
|
44
44
|
// guild
|
|
45
45
|
GuildId: event.group_id,
|
|
@@ -237,6 +237,73 @@ const register = (client) => {
|
|
|
237
237
|
};
|
|
238
238
|
cbp.send(e);
|
|
239
239
|
});
|
|
240
|
+
client.on('INTERACTION_CREATE', async (event) => {
|
|
241
|
+
if (event.scene === 'group') {
|
|
242
|
+
const master_key = config?.master_key ?? [];
|
|
243
|
+
const isMaster = master_key.includes(event.group_member_openid);
|
|
244
|
+
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
245
|
+
const UserId = event.group_member_openid;
|
|
246
|
+
const UserKey = useUserHashKey({
|
|
247
|
+
Platform: platform,
|
|
248
|
+
UserId: UserId
|
|
249
|
+
});
|
|
250
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
251
|
+
const e = {
|
|
252
|
+
name: 'interaction.create',
|
|
253
|
+
Platform: platform,
|
|
254
|
+
// guild
|
|
255
|
+
GuildId: event.group_openid,
|
|
256
|
+
ChannelId: event.group_openid,
|
|
257
|
+
// 用户Id
|
|
258
|
+
UserId: event.group_member_openid,
|
|
259
|
+
UserKey,
|
|
260
|
+
UserAvatar: UserAvatar,
|
|
261
|
+
IsMaster: isMaster,
|
|
262
|
+
IsBot: false,
|
|
263
|
+
// 格式化数据
|
|
264
|
+
MessageId: event.id,
|
|
265
|
+
MessageText: MessageText,
|
|
266
|
+
OpenId: event.group_member_openid,
|
|
267
|
+
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
268
|
+
CreateAt: Date.now(),
|
|
269
|
+
value: event,
|
|
270
|
+
};
|
|
271
|
+
cbp.send(e);
|
|
272
|
+
}
|
|
273
|
+
else if (event.scene === 'c2c') {
|
|
274
|
+
const master_key = config?.master_key ?? [];
|
|
275
|
+
const isMaster = master_key.includes(event.user_openid);
|
|
276
|
+
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
277
|
+
const UserId = event.user_openid;
|
|
278
|
+
const UserKey = useUserHashKey({
|
|
279
|
+
Platform: platform,
|
|
280
|
+
UserId: UserId
|
|
281
|
+
});
|
|
282
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
283
|
+
// 处理消息
|
|
284
|
+
const e = {
|
|
285
|
+
name: 'private.interaction.create',
|
|
286
|
+
Platform: platform,
|
|
287
|
+
// guild
|
|
288
|
+
// GuildId: event.group_openid,
|
|
289
|
+
// ChannelId: event.group_openid,
|
|
290
|
+
// 用户Id
|
|
291
|
+
UserId: event.user_openid,
|
|
292
|
+
UserKey,
|
|
293
|
+
UserAvatar: UserAvatar,
|
|
294
|
+
IsMaster: isMaster,
|
|
295
|
+
IsBot: false,
|
|
296
|
+
// 格式化数据
|
|
297
|
+
MessageId: event.id,
|
|
298
|
+
MessageText: MessageText,
|
|
299
|
+
OpenId: event.user_openid,
|
|
300
|
+
CreateAt: Date.now(),
|
|
301
|
+
tag: 'C2C_MESSAGE_CREATE',
|
|
302
|
+
value: event
|
|
303
|
+
};
|
|
304
|
+
cbp.send(e);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
240
307
|
client.on('ERROR', console.error);
|
|
241
308
|
const api = {
|
|
242
309
|
active: {
|
|
@@ -288,7 +355,7 @@ const register = (client) => {
|
|
|
288
355
|
return Promise.all([]);
|
|
289
356
|
},
|
|
290
357
|
mention: async (event) => {
|
|
291
|
-
event.value;
|
|
358
|
+
event.value || {};
|
|
292
359
|
event.tag;
|
|
293
360
|
// const event = e.value
|
|
294
361
|
const Metions = [];
|
|
@@ -329,6 +396,16 @@ const register = (client) => {
|
|
|
329
396
|
consume(res);
|
|
330
397
|
}
|
|
331
398
|
});
|
|
399
|
+
// 处理 api 调用
|
|
400
|
+
cbp?.onapis && cbp.onapis(async (data, consume) => {
|
|
401
|
+
const key = data.payload?.key;
|
|
402
|
+
if (client[key]) {
|
|
403
|
+
// 如果 client 上有对应的 key,直接调用。
|
|
404
|
+
const params = data.payload.params;
|
|
405
|
+
const res = await client[key](...params);
|
|
406
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
332
409
|
};
|
|
333
410
|
|
|
334
411
|
export { getQQBotConfig, platform, register };
|