@alemonjs/qq-bot 2.1.0-alpha.1 → 2.1.0-alpha.10
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/config.d.ts +3 -0
- package/lib/config.js +9 -0
- package/lib/hook.d.ts +35 -1
- package/lib/hook.js +23 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.group.js +2 -1
- package/lib/index.guild.js +2 -1
- package/lib/index.js +4 -2
- package/lib/index.webhook.js +2 -1
- package/lib/index.websoket.js +2 -1
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +16 -0
- package/lib/register.js +227 -69
- package/lib/sdk/api.d.ts +750 -966
- package/lib/sdk/api.js +103 -197
- package/lib/sdk/typing.d.ts +52 -54
- package/lib/sends.js +609 -450
- package/package.json +1 -1
- package/dist/assets/index.css +0 -1255
- package/dist/assets/index.js +0 -11393
- package/dist/index.html +0 -15
- package/lib/utils.js +0 -13
package/lib/config.d.ts
ADDED
package/lib/config.js
ADDED
package/lib/hook.d.ts
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
+
import { GROUP_AT_MESSAGE_CREATE_TYPE } from './message/group/GROUP_AT_MESSAGE_CREATE.js';
|
|
3
|
+
import { QQBotAPI } from './sdk/api.js';
|
|
2
4
|
|
|
5
|
+
type MAP = {
|
|
6
|
+
'message.create': GROUP_AT_MESSAGE_CREATE_TYPE;
|
|
7
|
+
'private.message.create': undefined;
|
|
8
|
+
'interaction.create': undefined;
|
|
9
|
+
'private.interaction.create': undefined;
|
|
10
|
+
'message.update': undefined;
|
|
11
|
+
'message.delete': undefined;
|
|
12
|
+
'message.reaction.add': undefined;
|
|
13
|
+
'message.reaction.remove': undefined;
|
|
14
|
+
'channal.create': undefined;
|
|
15
|
+
'channal.delete': undefined;
|
|
16
|
+
'guild.join': undefined;
|
|
17
|
+
'guild.exit': undefined;
|
|
18
|
+
'member.add': undefined;
|
|
19
|
+
'member.remove': undefined;
|
|
20
|
+
'private.message.update': undefined;
|
|
21
|
+
'private.message.delete': undefined;
|
|
22
|
+
'private.friend.add': undefined;
|
|
23
|
+
'private.guild.add': undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param event
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param event
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [QQBotAPI, MAP[T]];
|
|
3
37
|
/**
|
|
4
38
|
* 判断当前模式
|
|
5
39
|
* @param event
|
|
@@ -7,4 +41,4 @@ import { EventKeys, Events } from 'alemonjs';
|
|
|
7
41
|
*/
|
|
8
42
|
declare const useMode: <T extends EventKeys>(event: Events[T]) => (mode: "guild" | "group") => boolean;
|
|
9
43
|
|
|
10
|
-
export { useMode };
|
|
44
|
+
export { useClient, useMode, useValue };
|
package/lib/hook.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
|
+
import { QQBotAPI } from './sdk/api.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const useValue = (event) => {
|
|
10
|
+
const value = createEventValue(event);
|
|
11
|
+
return [value];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param event
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
const useClient = (event) => {
|
|
19
|
+
const [client] = useClient$1(event, QQBotAPI);
|
|
20
|
+
const value = createEventValue(event);
|
|
21
|
+
return [client, value];
|
|
22
|
+
};
|
|
1
23
|
/**
|
|
2
24
|
* 判断当前模式
|
|
3
25
|
* @param event
|
|
@@ -32,4 +54,4 @@ const useMode = (event) => {
|
|
|
32
54
|
return isMode;
|
|
33
55
|
};
|
|
34
56
|
|
|
35
|
-
export { useMode };
|
|
57
|
+
export { useClient, useMode, useValue };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { platform } from './
|
|
2
|
-
export { useMode } from './hook.js';
|
|
1
|
+
export { platform } from './config.js';
|
|
2
|
+
export { useClient, useMode, useValue } from './hook.js';
|
|
3
|
+
export { QQBotAPI as API } from './sdk/api.js';
|
|
3
4
|
|
|
4
5
|
declare const _default: () => void;
|
|
5
6
|
|
package/lib/index.group.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QQBotGroupClient } from './sdk/client.websoket.group.js';
|
|
2
|
-
import {
|
|
2
|
+
import { register } from './register.js';
|
|
3
|
+
import { getQQBotConfig } from './config.js';
|
|
3
4
|
|
|
4
5
|
const start = () => {
|
|
5
6
|
const config = getQQBotConfig();
|
package/lib/index.guild.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,9 +3,11 @@ import { start } from './index.group.js';
|
|
|
3
3
|
import { start as start$1 } from './index.guild.js';
|
|
4
4
|
import { start as start$2 } from './index.webhook.js';
|
|
5
5
|
import { start as start$3 } from './index.websoket.js';
|
|
6
|
-
import { platform } from './
|
|
7
|
-
export { useMode } from './hook.js';
|
|
6
|
+
import { platform } from './config.js';
|
|
7
|
+
export { useClient, useMode, useValue } 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/index.webhook.js
CHANGED
package/lib/index.websoket.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QQBotClients } from './sdk/client.websoket.js';
|
|
2
|
-
import {
|
|
2
|
+
import { register } from './register.js';
|
|
3
|
+
import { getQQBotConfig } from './config.js';
|
|
3
4
|
|
|
4
5
|
const start = () => {
|
|
5
6
|
const config = getQQBotConfig();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 群消息事件 AT 事件
|
|
3
|
+
*/
|
|
4
|
+
interface GROUP_AT_MESSAGE_CREATE_TYPE {
|
|
5
|
+
author: {
|
|
6
|
+
id: string;
|
|
7
|
+
member_openid: string;
|
|
8
|
+
};
|
|
9
|
+
content: string;
|
|
10
|
+
group_openid: string;
|
|
11
|
+
group_id: string;
|
|
12
|
+
id: string;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type { GROUP_AT_MESSAGE_CREATE_TYPE };
|
package/lib/register.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cbpPlatform, useUserHashKey, ResultCode, createResult } from 'alemonjs';
|
|
2
2
|
import { GROUP_AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, AT_MESSAGE_CREATE, MESSAGE_CREATE } from './sends.js';
|
|
3
|
+
import { getQQBotConfig, platform } from './config.js';
|
|
3
4
|
|
|
4
|
-
const platform = 'qq-bot';
|
|
5
|
-
const getQQBotConfig = () => {
|
|
6
|
-
let value = getConfigValue();
|
|
7
|
-
if (!value)
|
|
8
|
-
value = {};
|
|
9
|
-
return value[platform] || {};
|
|
10
|
-
};
|
|
11
5
|
const register = (client) => {
|
|
12
6
|
const config = getQQBotConfig();
|
|
13
7
|
/**
|
|
@@ -39,11 +33,11 @@ const register = (client) => {
|
|
|
39
33
|
// 定义消
|
|
40
34
|
const e = {
|
|
41
35
|
name: 'message.create',
|
|
42
|
-
// 事件类型
|
|
43
36
|
Platform: platform,
|
|
44
37
|
// guild
|
|
45
38
|
GuildId: event.group_id,
|
|
46
39
|
ChannelId: event.group_id,
|
|
40
|
+
SpaceId: `GROUP:${event.group_id}`,
|
|
47
41
|
// 用户Id
|
|
48
42
|
UserId: event.author.id,
|
|
49
43
|
UserKey,
|
|
@@ -53,7 +47,7 @@ const register = (client) => {
|
|
|
53
47
|
// 格式化数据
|
|
54
48
|
MessageId: event.id,
|
|
55
49
|
MessageText: event.content?.trim(),
|
|
56
|
-
OpenId: event.author.member_openid
|
|
50
|
+
OpenId: `C2C:${event.author.member_openid}`,
|
|
57
51
|
CreateAt: Date.now(),
|
|
58
52
|
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
59
53
|
value: event
|
|
@@ -84,7 +78,7 @@ const register = (client) => {
|
|
|
84
78
|
MessageId: event.id,
|
|
85
79
|
MessageText: event.content?.trim(),
|
|
86
80
|
CreateAt: Date.now(),
|
|
87
|
-
OpenId: event.author.user_openid
|
|
81
|
+
OpenId: `C2C:${event.author.user_openid}`,
|
|
88
82
|
//
|
|
89
83
|
tag: 'C2C_MESSAGE_CREATE',
|
|
90
84
|
value: event
|
|
@@ -112,9 +106,6 @@ const register = (client) => {
|
|
|
112
106
|
name: 'private.message.create',
|
|
113
107
|
// 事件类型
|
|
114
108
|
Platform: platform,
|
|
115
|
-
//
|
|
116
|
-
// GuildId: event.guild_id,
|
|
117
|
-
// ChannelId: event.channel_id,
|
|
118
109
|
// 用户Id
|
|
119
110
|
UserId: event?.author?.id ?? '',
|
|
120
111
|
UserKey,
|
|
@@ -125,7 +116,7 @@ const register = (client) => {
|
|
|
125
116
|
// message
|
|
126
117
|
MessageId: event.id,
|
|
127
118
|
MessageText: msg?.trim(),
|
|
128
|
-
OpenId: event.guild_id
|
|
119
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
129
120
|
CreateAt: Date.now(),
|
|
130
121
|
//
|
|
131
122
|
tag: 'DIRECT_MESSAGE_CREATE',
|
|
@@ -154,6 +145,7 @@ const register = (client) => {
|
|
|
154
145
|
Platform: platform,
|
|
155
146
|
GuildId: event.guild_id,
|
|
156
147
|
ChannelId: event.channel_id,
|
|
148
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
157
149
|
IsMaster: isMaster,
|
|
158
150
|
// 用户Id
|
|
159
151
|
UserId: event?.author?.id ?? '',
|
|
@@ -164,7 +156,7 @@ const register = (client) => {
|
|
|
164
156
|
// message
|
|
165
157
|
MessageId: event.id,
|
|
166
158
|
MessageText: msg?.trim(),
|
|
167
|
-
OpenId: event.guild_id
|
|
159
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
168
160
|
CreateAt: Date.now(),
|
|
169
161
|
//
|
|
170
162
|
tag: 'AT_MESSAGE_CREATE',
|
|
@@ -220,6 +212,7 @@ const register = (client) => {
|
|
|
220
212
|
//
|
|
221
213
|
GuildId: event.guild_id,
|
|
222
214
|
ChannelId: event.channel_id,
|
|
215
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
223
216
|
UserId: event?.author?.id ?? '',
|
|
224
217
|
UserKey,
|
|
225
218
|
UserName: event?.author?.username ?? '',
|
|
@@ -229,7 +222,7 @@ const register = (client) => {
|
|
|
229
222
|
// message
|
|
230
223
|
MessageId: event.id,
|
|
231
224
|
MessageText: msg?.trim(),
|
|
232
|
-
OpenId: event.guild_id
|
|
225
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
233
226
|
CreateAt: Date.now(),
|
|
234
227
|
//
|
|
235
228
|
tag: 'MESSAGE_CREATE',
|
|
@@ -237,57 +230,212 @@ const register = (client) => {
|
|
|
237
230
|
};
|
|
238
231
|
cbp.send(e);
|
|
239
232
|
});
|
|
240
|
-
client.on('
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
233
|
+
client.on('INTERACTION_CREATE', async (event) => {
|
|
234
|
+
// try {
|
|
235
|
+
// if (event.scene === 'group' || event.scene === 'c2c') {
|
|
236
|
+
// await client.interactionResponse('group', event.id)
|
|
237
|
+
// }
|
|
238
|
+
// else if (event.scene === 'guild') {
|
|
239
|
+
// await client.interactionResponse('guild', event.id)
|
|
240
|
+
// }
|
|
241
|
+
// } catch (err) {
|
|
242
|
+
// createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
243
|
+
// }
|
|
244
|
+
// 如何区分私聊/群聊
|
|
245
|
+
if (event.scene === 'group') {
|
|
246
|
+
const master_key = config?.master_key ?? [];
|
|
247
|
+
const isMaster = master_key.includes(event.group_member_openid);
|
|
248
|
+
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
249
|
+
const UserId = event.group_member_openid;
|
|
250
|
+
const UserKey = useUserHashKey({
|
|
251
|
+
Platform: platform,
|
|
252
|
+
UserId: UserId
|
|
253
|
+
});
|
|
254
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
255
|
+
const e = {
|
|
256
|
+
name: 'interaction.create',
|
|
257
|
+
Platform: platform,
|
|
258
|
+
// guild
|
|
259
|
+
GuildId: event.group_openid,
|
|
260
|
+
ChannelId: event.group_openid,
|
|
261
|
+
SpaceId: `GROUP:${event.group_openid}`,
|
|
262
|
+
// 用户Id
|
|
263
|
+
UserId: event.group_member_openid,
|
|
264
|
+
UserKey,
|
|
265
|
+
UserAvatar: UserAvatar,
|
|
266
|
+
IsMaster: isMaster,
|
|
267
|
+
IsBot: false,
|
|
268
|
+
// 格式化数据
|
|
269
|
+
MessageId: `INTERACTION_CREATE:${event.id}`,
|
|
270
|
+
MessageText: MessageText,
|
|
271
|
+
OpenId: `C2C:${event.group_member_openid}`,
|
|
272
|
+
tag: 'INTERACTION_CREATE_GROUP',
|
|
273
|
+
CreateAt: Date.now(),
|
|
274
|
+
value: event
|
|
275
|
+
};
|
|
276
|
+
cbp.send(e);
|
|
257
277
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
278
|
+
else if (event.scene === 'c2c') {
|
|
279
|
+
const master_key = config?.master_key ?? [];
|
|
280
|
+
const isMaster = master_key.includes(event.user_openid);
|
|
281
|
+
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
282
|
+
const UserId = event.user_openid;
|
|
283
|
+
const UserKey = useUserHashKey({
|
|
284
|
+
Platform: platform,
|
|
285
|
+
UserId: UserId
|
|
286
|
+
});
|
|
287
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
288
|
+
// 处理消息
|
|
289
|
+
const e = {
|
|
290
|
+
name: 'private.interaction.create',
|
|
291
|
+
Platform: platform,
|
|
292
|
+
// 用户Id
|
|
293
|
+
UserId: event.user_openid,
|
|
294
|
+
UserKey,
|
|
295
|
+
UserAvatar: UserAvatar,
|
|
296
|
+
IsMaster: isMaster,
|
|
297
|
+
IsBot: false,
|
|
298
|
+
// 格式化数据
|
|
299
|
+
MessageId: event.id,
|
|
300
|
+
MessageText: MessageText,
|
|
301
|
+
OpenId: `C2C:${event.user_openid}`,
|
|
302
|
+
CreateAt: Date.now(),
|
|
303
|
+
tag: 'INTERACTION_CREATE_C2C',
|
|
304
|
+
value: event
|
|
305
|
+
};
|
|
306
|
+
cbp.send(e);
|
|
261
307
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
308
|
+
else if (event.scene === 'guild') {
|
|
309
|
+
const master_key = config?.master_key ?? [];
|
|
310
|
+
const isMaster = master_key.includes(event.data.resolved.user_id);
|
|
311
|
+
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
312
|
+
const UserId = event.data.resolved.user_id;
|
|
313
|
+
const UserKey = useUserHashKey({
|
|
314
|
+
Platform: platform,
|
|
315
|
+
UserId: UserId
|
|
316
|
+
});
|
|
317
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
318
|
+
// 处理消息
|
|
319
|
+
const e = {
|
|
320
|
+
name: 'interaction.create',
|
|
321
|
+
Platform: platform,
|
|
322
|
+
// guild
|
|
323
|
+
GuildId: event.guild_id,
|
|
324
|
+
ChannelId: event.channel_id,
|
|
325
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
326
|
+
// 用户Id
|
|
327
|
+
UserId: event.data.resolved.user_id,
|
|
328
|
+
UserKey,
|
|
329
|
+
UserAvatar: UserAvatar,
|
|
330
|
+
IsMaster: isMaster,
|
|
331
|
+
IsBot: false,
|
|
332
|
+
// 格式化数据
|
|
333
|
+
MessageId: event.data.resolved.message_id,
|
|
334
|
+
MessageText: MessageText,
|
|
335
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
336
|
+
CreateAt: Date.now(),
|
|
337
|
+
tag: 'INTERACTION_CREATE_GUILD',
|
|
338
|
+
value: event
|
|
339
|
+
};
|
|
340
|
+
cbp.send(e);
|
|
265
341
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const Metions = [];
|
|
273
|
-
// group
|
|
274
|
-
return Metions;
|
|
275
|
-
};
|
|
276
|
-
const sendMessageChannel = async (channel_id, data) => {
|
|
277
|
-
if (!channel_id || typeof channel_id !== 'string') {
|
|
278
|
-
throw new Error('Invalid channel_id: channel_id must be a string');
|
|
342
|
+
else {
|
|
343
|
+
logger.warn({
|
|
344
|
+
code: ResultCode.Fail,
|
|
345
|
+
message: '暂未更新支持此类型的交互事件',
|
|
346
|
+
data: event
|
|
347
|
+
});
|
|
279
348
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
349
|
+
});
|
|
350
|
+
client.on('ERROR', console.error);
|
|
351
|
+
const api = {
|
|
352
|
+
active: {
|
|
353
|
+
send: {
|
|
354
|
+
channel: async (SpaceId, val) => {
|
|
355
|
+
if (/^GUILD:/.test(SpaceId)) {
|
|
356
|
+
const id = SpaceId.replace('GUILD:', '');
|
|
357
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
358
|
+
ChannelId: id
|
|
359
|
+
}, val);
|
|
360
|
+
}
|
|
361
|
+
if (/^GROUP:/.test(SpaceId)) {
|
|
362
|
+
const id = SpaceId.replace('GROUP:', '');
|
|
363
|
+
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
364
|
+
ChannelId: id
|
|
365
|
+
}, val);
|
|
366
|
+
}
|
|
367
|
+
return [];
|
|
368
|
+
},
|
|
369
|
+
user: async (OpenId, val) => {
|
|
370
|
+
if (/^C2C:/.test(OpenId)) {
|
|
371
|
+
const id = OpenId.replace('C2C:', '');
|
|
372
|
+
return await C2C_MESSAGE_CREATE(client, {
|
|
373
|
+
UserId: id
|
|
374
|
+
}, val);
|
|
375
|
+
}
|
|
376
|
+
else if (/^DIRECT:/.test(OpenId)) {
|
|
377
|
+
const id = OpenId.replace('DIRECT:', '');
|
|
378
|
+
return await DIRECT_MESSAGE_CREATE(client, {
|
|
379
|
+
UserId: id
|
|
380
|
+
}, val);
|
|
381
|
+
}
|
|
382
|
+
else if (/^GUILD:/.test(OpenId)) {
|
|
383
|
+
const id = OpenId.replace('GUILD:', '');
|
|
384
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
385
|
+
ChannelId: id
|
|
386
|
+
}, val);
|
|
387
|
+
}
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
use: {
|
|
393
|
+
send: async (event, val) => {
|
|
394
|
+
if (val.length < 0)
|
|
395
|
+
return [];
|
|
396
|
+
// 打 tag
|
|
397
|
+
const tag = event.tag;
|
|
398
|
+
// 群at
|
|
399
|
+
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
400
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
401
|
+
}
|
|
402
|
+
// 私聊
|
|
403
|
+
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
404
|
+
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
405
|
+
}
|
|
406
|
+
// 频道私聊
|
|
407
|
+
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
408
|
+
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
409
|
+
}
|
|
410
|
+
// 频道at
|
|
411
|
+
if (tag == 'AT_MESSAGE_CREATE') {
|
|
412
|
+
return await AT_MESSAGE_CREATE(client, event, val);
|
|
413
|
+
}
|
|
414
|
+
// 频道消息
|
|
415
|
+
if (tag == 'MESSAGE_CREATE') {
|
|
416
|
+
return await MESSAGE_CREATE(client, event, val);
|
|
417
|
+
}
|
|
418
|
+
// 交互
|
|
419
|
+
if (tag == 'INTERACTION_CREATE_GROUP') {
|
|
420
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
421
|
+
}
|
|
422
|
+
if (tag == 'INTERACTION_CREATE_C2C') {
|
|
423
|
+
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
424
|
+
}
|
|
425
|
+
if (tag == 'INTERACTION_CREATE_GUILD') {
|
|
426
|
+
return await AT_MESSAGE_CREATE(client, event, val);
|
|
427
|
+
}
|
|
428
|
+
return [];
|
|
429
|
+
},
|
|
430
|
+
mention: async (event) => {
|
|
431
|
+
event.value || {};
|
|
432
|
+
event.tag;
|
|
433
|
+
// const event = e.value
|
|
434
|
+
const Metions = [];
|
|
435
|
+
// group
|
|
436
|
+
return Metions;
|
|
437
|
+
}
|
|
287
438
|
}
|
|
288
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
289
|
-
OpenId: user_id
|
|
290
|
-
}, data);
|
|
291
439
|
};
|
|
292
440
|
// 处理行为
|
|
293
441
|
cbp.onactions(async (data, consume) => {
|
|
@@ -296,31 +444,41 @@ const register = (client) => {
|
|
|
296
444
|
const event = data.payload.event;
|
|
297
445
|
const paramFormat = data.payload.params.format;
|
|
298
446
|
// 消费
|
|
299
|
-
const res = await
|
|
447
|
+
const res = await api.use.send(event, paramFormat);
|
|
300
448
|
consume(res);
|
|
301
449
|
}
|
|
302
450
|
else if (data.action === 'mention.get') {
|
|
303
451
|
const event = data.payload.event;
|
|
304
452
|
// 获取提及
|
|
305
|
-
const metions = await
|
|
453
|
+
const metions = await api.use.mention(event);
|
|
306
454
|
// 消费
|
|
307
|
-
consume(metions);
|
|
455
|
+
consume([createResult(ResultCode.Ok, '请求完成', metions)]);
|
|
308
456
|
}
|
|
309
457
|
else if (data.action === 'message.send.channel') {
|
|
310
458
|
// 主动发送消息到频道
|
|
311
459
|
const channel_id = data.payload.ChannelId;
|
|
312
460
|
const paramFormat = data.payload.params.format;
|
|
313
|
-
const res = await
|
|
461
|
+
const res = await api.active.send.channel(channel_id, paramFormat);
|
|
314
462
|
consume(res);
|
|
315
463
|
}
|
|
316
464
|
else if (data.action === 'message.send.user') {
|
|
317
465
|
// 主动发送消息到用户
|
|
318
466
|
const user_id = data.payload.UserId;
|
|
319
467
|
const paramFormat = data.payload.params.format;
|
|
320
|
-
const res = await
|
|
468
|
+
const res = await api.active.send.user(user_id, paramFormat);
|
|
321
469
|
consume(res);
|
|
322
470
|
}
|
|
323
471
|
});
|
|
472
|
+
// 处理 api 调用
|
|
473
|
+
cbp.onapis(async (data, consume) => {
|
|
474
|
+
const key = data.payload?.key;
|
|
475
|
+
if (client[key]) {
|
|
476
|
+
// 如果 client 上有对应的 key,直接调用。
|
|
477
|
+
const params = data.payload.params;
|
|
478
|
+
const res = await client[key](...params);
|
|
479
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
324
482
|
};
|
|
325
483
|
|
|
326
|
-
export {
|
|
484
|
+
export { register };
|