@alemonjs/qq-bot 2.1.0-alpha.0 → 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 +232 -91
- 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 -1
- package/dist/assets/index.js +0 -34
- 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
|
/**
|
|
@@ -26,27 +20,11 @@ const register = (client) => {
|
|
|
26
20
|
const createUserAvatarURL = (author_id) => {
|
|
27
21
|
return `https://q.qlogo.cn/qqapp/${config.app_id}/${author_id}/640`;
|
|
28
22
|
};
|
|
29
|
-
const createUserAvatar = (url) => {
|
|
30
|
-
return {
|
|
31
|
-
toBuffer: async () => {
|
|
32
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
33
|
-
return Buffer.from(arrayBuffer);
|
|
34
|
-
},
|
|
35
|
-
toBase64: async () => {
|
|
36
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
37
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
38
|
-
},
|
|
39
|
-
toURL: async () => {
|
|
40
|
-
return url;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
23
|
// 监听消息
|
|
45
24
|
client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
|
|
46
25
|
const master_key = config?.master_key ?? [];
|
|
47
26
|
const isMaster = master_key.includes(event.author.id);
|
|
48
|
-
const
|
|
49
|
-
const UserAvatar = createUserAvatar(url);
|
|
27
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
50
28
|
const UserId = event.author.id;
|
|
51
29
|
const UserKey = useUserHashKey({
|
|
52
30
|
Platform: platform,
|
|
@@ -55,11 +33,11 @@ const register = (client) => {
|
|
|
55
33
|
// 定义消
|
|
56
34
|
const e = {
|
|
57
35
|
name: 'message.create',
|
|
58
|
-
// 事件类型
|
|
59
36
|
Platform: platform,
|
|
60
37
|
// guild
|
|
61
38
|
GuildId: event.group_id,
|
|
62
39
|
ChannelId: event.group_id,
|
|
40
|
+
SpaceId: `GROUP:${event.group_id}`,
|
|
63
41
|
// 用户Id
|
|
64
42
|
UserId: event.author.id,
|
|
65
43
|
UserKey,
|
|
@@ -69,7 +47,7 @@ const register = (client) => {
|
|
|
69
47
|
// 格式化数据
|
|
70
48
|
MessageId: event.id,
|
|
71
49
|
MessageText: event.content?.trim(),
|
|
72
|
-
OpenId: event.author.member_openid
|
|
50
|
+
OpenId: `C2C:${event.author.member_openid}`,
|
|
73
51
|
CreateAt: Date.now(),
|
|
74
52
|
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
75
53
|
value: event
|
|
@@ -79,8 +57,7 @@ const register = (client) => {
|
|
|
79
57
|
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
80
58
|
const master_key = config?.master_key ?? [];
|
|
81
59
|
const isMaster = master_key.includes(event.author.id);
|
|
82
|
-
const
|
|
83
|
-
const UserAvatar = createUserAvatar(url);
|
|
60
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
84
61
|
const UserId = event.author.id;
|
|
85
62
|
const UserKey = useUserHashKey({
|
|
86
63
|
Platform: platform,
|
|
@@ -101,7 +78,7 @@ const register = (client) => {
|
|
|
101
78
|
MessageId: event.id,
|
|
102
79
|
MessageText: event.content?.trim(),
|
|
103
80
|
CreateAt: Date.now(),
|
|
104
|
-
OpenId: event.author.user_openid
|
|
81
|
+
OpenId: `C2C:${event.author.user_openid}`,
|
|
105
82
|
//
|
|
106
83
|
tag: 'C2C_MESSAGE_CREATE',
|
|
107
84
|
value: event
|
|
@@ -118,7 +95,7 @@ const register = (client) => {
|
|
|
118
95
|
const master_key = config?.master_key ?? [];
|
|
119
96
|
const isMaster = master_key.includes(event.author.id);
|
|
120
97
|
let msg = event?.content ?? '';
|
|
121
|
-
const UserAvatar =
|
|
98
|
+
const UserAvatar = event?.author?.avatar;
|
|
122
99
|
const UserId = event.author.id;
|
|
123
100
|
const UserKey = useUserHashKey({
|
|
124
101
|
Platform: platform,
|
|
@@ -129,9 +106,6 @@ const register = (client) => {
|
|
|
129
106
|
name: 'private.message.create',
|
|
130
107
|
// 事件类型
|
|
131
108
|
Platform: platform,
|
|
132
|
-
//
|
|
133
|
-
// GuildId: event.guild_id,
|
|
134
|
-
// ChannelId: event.channel_id,
|
|
135
109
|
// 用户Id
|
|
136
110
|
UserId: event?.author?.id ?? '',
|
|
137
111
|
UserKey,
|
|
@@ -142,7 +116,7 @@ const register = (client) => {
|
|
|
142
116
|
// message
|
|
143
117
|
MessageId: event.id,
|
|
144
118
|
MessageText: msg?.trim(),
|
|
145
|
-
OpenId: event.guild_id
|
|
119
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
146
120
|
CreateAt: Date.now(),
|
|
147
121
|
//
|
|
148
122
|
tag: 'DIRECT_MESSAGE_CREATE',
|
|
@@ -158,7 +132,7 @@ const register = (client) => {
|
|
|
158
132
|
const master_key = config?.master_key ?? [];
|
|
159
133
|
const isMaster = master_key.includes(event.author.id);
|
|
160
134
|
let msg = getMessageContent(event);
|
|
161
|
-
const UserAvatar =
|
|
135
|
+
const UserAvatar = event?.author?.avatar;
|
|
162
136
|
const UserId = event.author.id;
|
|
163
137
|
const UserKey = useUserHashKey({
|
|
164
138
|
Platform: platform,
|
|
@@ -171,6 +145,7 @@ const register = (client) => {
|
|
|
171
145
|
Platform: platform,
|
|
172
146
|
GuildId: event.guild_id,
|
|
173
147
|
ChannelId: event.channel_id,
|
|
148
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
174
149
|
IsMaster: isMaster,
|
|
175
150
|
// 用户Id
|
|
176
151
|
UserId: event?.author?.id ?? '',
|
|
@@ -181,7 +156,7 @@ const register = (client) => {
|
|
|
181
156
|
// message
|
|
182
157
|
MessageId: event.id,
|
|
183
158
|
MessageText: msg?.trim(),
|
|
184
|
-
OpenId: event.guild_id
|
|
159
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
185
160
|
CreateAt: Date.now(),
|
|
186
161
|
//
|
|
187
162
|
tag: 'AT_MESSAGE_CREATE',
|
|
@@ -224,7 +199,7 @@ const register = (client) => {
|
|
|
224
199
|
const UserId = event.author.id;
|
|
225
200
|
const isMaster = master_key.includes(UserId);
|
|
226
201
|
const msg = getMessageContent(event);
|
|
227
|
-
const UserAvatar =
|
|
202
|
+
const UserAvatar = event?.author?.avatar;
|
|
228
203
|
const UserKey = useUserHashKey({
|
|
229
204
|
Platform: platform,
|
|
230
205
|
UserId: UserId
|
|
@@ -237,6 +212,7 @@ const register = (client) => {
|
|
|
237
212
|
//
|
|
238
213
|
GuildId: event.guild_id,
|
|
239
214
|
ChannelId: event.channel_id,
|
|
215
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
240
216
|
UserId: event?.author?.id ?? '',
|
|
241
217
|
UserKey,
|
|
242
218
|
UserName: event?.author?.username ?? '',
|
|
@@ -246,7 +222,7 @@ const register = (client) => {
|
|
|
246
222
|
// message
|
|
247
223
|
MessageId: event.id,
|
|
248
224
|
MessageText: msg?.trim(),
|
|
249
|
-
OpenId: event.guild_id
|
|
225
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
250
226
|
CreateAt: Date.now(),
|
|
251
227
|
//
|
|
252
228
|
tag: 'MESSAGE_CREATE',
|
|
@@ -254,57 +230,212 @@ const register = (client) => {
|
|
|
254
230
|
};
|
|
255
231
|
cbp.send(e);
|
|
256
232
|
});
|
|
257
|
-
client.on('
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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);
|
|
274
277
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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);
|
|
278
307
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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);
|
|
282
341
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const Metions = [];
|
|
290
|
-
// group
|
|
291
|
-
return Metions;
|
|
292
|
-
};
|
|
293
|
-
const sendMessageChannel = async (channel_id, data) => {
|
|
294
|
-
if (!channel_id || typeof channel_id !== 'string') {
|
|
295
|
-
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
|
+
});
|
|
296
348
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
+
}
|
|
304
438
|
}
|
|
305
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
306
|
-
OpenId: user_id
|
|
307
|
-
}, data);
|
|
308
439
|
};
|
|
309
440
|
// 处理行为
|
|
310
441
|
cbp.onactions(async (data, consume) => {
|
|
@@ -313,31 +444,41 @@ const register = (client) => {
|
|
|
313
444
|
const event = data.payload.event;
|
|
314
445
|
const paramFormat = data.payload.params.format;
|
|
315
446
|
// 消费
|
|
316
|
-
const res = await
|
|
447
|
+
const res = await api.use.send(event, paramFormat);
|
|
317
448
|
consume(res);
|
|
318
449
|
}
|
|
319
450
|
else if (data.action === 'mention.get') {
|
|
320
451
|
const event = data.payload.event;
|
|
321
452
|
// 获取提及
|
|
322
|
-
const metions = await
|
|
453
|
+
const metions = await api.use.mention(event);
|
|
323
454
|
// 消费
|
|
324
|
-
consume(metions);
|
|
455
|
+
consume([createResult(ResultCode.Ok, '请求完成', metions)]);
|
|
325
456
|
}
|
|
326
457
|
else if (data.action === 'message.send.channel') {
|
|
327
458
|
// 主动发送消息到频道
|
|
328
459
|
const channel_id = data.payload.ChannelId;
|
|
329
460
|
const paramFormat = data.payload.params.format;
|
|
330
|
-
const res = await
|
|
461
|
+
const res = await api.active.send.channel(channel_id, paramFormat);
|
|
331
462
|
consume(res);
|
|
332
463
|
}
|
|
333
464
|
else if (data.action === 'message.send.user') {
|
|
334
465
|
// 主动发送消息到用户
|
|
335
466
|
const user_id = data.payload.UserId;
|
|
336
467
|
const paramFormat = data.payload.params.format;
|
|
337
|
-
const res = await
|
|
468
|
+
const res = await api.active.send.user(user_id, paramFormat);
|
|
338
469
|
consume(res);
|
|
339
470
|
}
|
|
340
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
|
+
});
|
|
341
482
|
};
|
|
342
483
|
|
|
343
|
-
export {
|
|
484
|
+
export { register };
|