@alemonjs/qq-bot 2.1.0-alpha.1 → 2.1.0-alpha.11
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 +7 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +20 -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 +218 -101
- 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/README.md
CHANGED
package/lib/config.d.ts
ADDED
package/lib/config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getConfigValue, useUserHashKey } from 'alemonjs';
|
|
2
|
+
|
|
3
|
+
const platform = 'qq-bot';
|
|
4
|
+
const getQQBotConfig = () => {
|
|
5
|
+
const value = getConfigValue() || {};
|
|
6
|
+
return value[platform] || {};
|
|
7
|
+
};
|
|
8
|
+
const getMaster = (UserId) => {
|
|
9
|
+
const config = getQQBotConfig();
|
|
10
|
+
const master_key = config.master_key || [];
|
|
11
|
+
const master_id = config.master_id || [];
|
|
12
|
+
const UserKey = useUserHashKey({
|
|
13
|
+
Platform: platform,
|
|
14
|
+
UserId: UserId
|
|
15
|
+
});
|
|
16
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
17
|
+
return [is, UserKey];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { getMaster, getQQBotConfig, platform };
|
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, 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, getMaster, 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
|
/**
|
|
@@ -28,22 +22,17 @@ const register = (client) => {
|
|
|
28
22
|
};
|
|
29
23
|
// 监听消息
|
|
30
24
|
client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
|
|
31
|
-
const master_key = config?.master_key ?? [];
|
|
32
|
-
const isMaster = master_key.includes(event.author.id);
|
|
33
|
-
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
34
25
|
const UserId = event.author.id;
|
|
35
|
-
const UserKey =
|
|
36
|
-
|
|
37
|
-
UserId: UserId
|
|
38
|
-
});
|
|
26
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
27
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
39
28
|
// 定义消
|
|
40
29
|
const e = {
|
|
41
30
|
name: 'message.create',
|
|
42
|
-
// 事件类型
|
|
43
31
|
Platform: platform,
|
|
44
32
|
// guild
|
|
45
33
|
GuildId: event.group_id,
|
|
46
34
|
ChannelId: event.group_id,
|
|
35
|
+
SpaceId: `GROUP:${event.group_id}`,
|
|
47
36
|
// 用户Id
|
|
48
37
|
UserId: event.author.id,
|
|
49
38
|
UserKey,
|
|
@@ -53,7 +42,7 @@ const register = (client) => {
|
|
|
53
42
|
// 格式化数据
|
|
54
43
|
MessageId: event.id,
|
|
55
44
|
MessageText: event.content?.trim(),
|
|
56
|
-
OpenId: event.author.member_openid
|
|
45
|
+
OpenId: `C2C:${event.author.member_openid}`,
|
|
57
46
|
CreateAt: Date.now(),
|
|
58
47
|
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
59
48
|
value: event
|
|
@@ -61,14 +50,9 @@ const register = (client) => {
|
|
|
61
50
|
cbp.send(e);
|
|
62
51
|
});
|
|
63
52
|
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
64
|
-
const master_key = config?.master_key ?? [];
|
|
65
|
-
const isMaster = master_key.includes(event.author.id);
|
|
66
|
-
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
67
53
|
const UserId = event.author.id;
|
|
68
|
-
const UserKey =
|
|
69
|
-
|
|
70
|
-
UserId: UserId
|
|
71
|
-
});
|
|
54
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
55
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
72
56
|
// 定义消
|
|
73
57
|
const e = {
|
|
74
58
|
name: 'private.message.create',
|
|
@@ -84,7 +68,7 @@ const register = (client) => {
|
|
|
84
68
|
MessageId: event.id,
|
|
85
69
|
MessageText: event.content?.trim(),
|
|
86
70
|
CreateAt: Date.now(),
|
|
87
|
-
OpenId: event.author.user_openid
|
|
71
|
+
OpenId: `C2C:${event.author.user_openid}`,
|
|
88
72
|
//
|
|
89
73
|
tag: 'C2C_MESSAGE_CREATE',
|
|
90
74
|
value: event
|
|
@@ -98,23 +82,15 @@ const register = (client) => {
|
|
|
98
82
|
// 屏蔽其他机器人的消息
|
|
99
83
|
if (event?.author?.bot)
|
|
100
84
|
return;
|
|
101
|
-
const master_key = config?.master_key ?? [];
|
|
102
|
-
const isMaster = master_key.includes(event.author.id);
|
|
103
85
|
let msg = event?.content ?? '';
|
|
104
86
|
const UserAvatar = event?.author?.avatar;
|
|
105
87
|
const UserId = event.author.id;
|
|
106
|
-
const UserKey =
|
|
107
|
-
Platform: platform,
|
|
108
|
-
UserId: UserId
|
|
109
|
-
});
|
|
88
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
110
89
|
// 定义消
|
|
111
90
|
const e = {
|
|
112
91
|
name: 'private.message.create',
|
|
113
92
|
// 事件类型
|
|
114
93
|
Platform: platform,
|
|
115
|
-
//
|
|
116
|
-
// GuildId: event.guild_id,
|
|
117
|
-
// ChannelId: event.channel_id,
|
|
118
94
|
// 用户Id
|
|
119
95
|
UserId: event?.author?.id ?? '',
|
|
120
96
|
UserKey,
|
|
@@ -125,7 +101,7 @@ const register = (client) => {
|
|
|
125
101
|
// message
|
|
126
102
|
MessageId: event.id,
|
|
127
103
|
MessageText: msg?.trim(),
|
|
128
|
-
OpenId: event.guild_id
|
|
104
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
129
105
|
CreateAt: Date.now(),
|
|
130
106
|
//
|
|
131
107
|
tag: 'DIRECT_MESSAGE_CREATE',
|
|
@@ -138,15 +114,10 @@ const register = (client) => {
|
|
|
138
114
|
// 屏蔽其他机器人的消息
|
|
139
115
|
if (event?.author?.bot)
|
|
140
116
|
return;
|
|
141
|
-
const master_key = config?.master_key ?? [];
|
|
142
|
-
const isMaster = master_key.includes(event.author.id);
|
|
143
117
|
let msg = getMessageContent(event);
|
|
144
118
|
const UserAvatar = event?.author?.avatar;
|
|
145
119
|
const UserId = event.author.id;
|
|
146
|
-
const UserKey =
|
|
147
|
-
Platform: platform,
|
|
148
|
-
UserId: UserId
|
|
149
|
-
});
|
|
120
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
150
121
|
// 定义消
|
|
151
122
|
const e = {
|
|
152
123
|
name: 'message.create',
|
|
@@ -154,6 +125,7 @@ const register = (client) => {
|
|
|
154
125
|
Platform: platform,
|
|
155
126
|
GuildId: event.guild_id,
|
|
156
127
|
ChannelId: event.channel_id,
|
|
128
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
157
129
|
IsMaster: isMaster,
|
|
158
130
|
// 用户Id
|
|
159
131
|
UserId: event?.author?.id ?? '',
|
|
@@ -164,7 +136,7 @@ const register = (client) => {
|
|
|
164
136
|
// message
|
|
165
137
|
MessageId: event.id,
|
|
166
138
|
MessageText: msg?.trim(),
|
|
167
|
-
OpenId: event.guild_id
|
|
139
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
168
140
|
CreateAt: Date.now(),
|
|
169
141
|
//
|
|
170
142
|
tag: 'AT_MESSAGE_CREATE',
|
|
@@ -203,15 +175,10 @@ const register = (client) => {
|
|
|
203
175
|
// 撤回消息
|
|
204
176
|
if (new RegExp(/DELETE$/).test(event.eventType))
|
|
205
177
|
return;
|
|
206
|
-
const master_key = config?.master_key ?? [];
|
|
207
178
|
const UserId = event.author.id;
|
|
208
|
-
const isMaster = master_key.includes(UserId);
|
|
209
179
|
const msg = getMessageContent(event);
|
|
210
180
|
const UserAvatar = event?.author?.avatar;
|
|
211
|
-
const UserKey =
|
|
212
|
-
Platform: platform,
|
|
213
|
-
UserId: UserId
|
|
214
|
-
});
|
|
181
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
215
182
|
// 定义消
|
|
216
183
|
const e = {
|
|
217
184
|
name: 'message.create',
|
|
@@ -220,6 +187,7 @@ const register = (client) => {
|
|
|
220
187
|
//
|
|
221
188
|
GuildId: event.guild_id,
|
|
222
189
|
ChannelId: event.channel_id,
|
|
190
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
223
191
|
UserId: event?.author?.id ?? '',
|
|
224
192
|
UserKey,
|
|
225
193
|
UserName: event?.author?.username ?? '',
|
|
@@ -229,7 +197,7 @@ const register = (client) => {
|
|
|
229
197
|
// message
|
|
230
198
|
MessageId: event.id,
|
|
231
199
|
MessageText: msg?.trim(),
|
|
232
|
-
OpenId: event.guild_id
|
|
200
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
233
201
|
CreateAt: Date.now(),
|
|
234
202
|
//
|
|
235
203
|
tag: 'MESSAGE_CREATE',
|
|
@@ -237,57 +205,196 @@ const register = (client) => {
|
|
|
237
205
|
};
|
|
238
206
|
cbp.send(e);
|
|
239
207
|
});
|
|
240
|
-
client.on('
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
208
|
+
client.on('INTERACTION_CREATE', async (event) => {
|
|
209
|
+
// try {
|
|
210
|
+
// if (event.scene === 'group' || event.scene === 'c2c') {
|
|
211
|
+
// await client.interactionResponse('group', event.id)
|
|
212
|
+
// }
|
|
213
|
+
// else if (event.scene === 'guild') {
|
|
214
|
+
// await client.interactionResponse('guild', event.id)
|
|
215
|
+
// }
|
|
216
|
+
// } catch (err) {
|
|
217
|
+
// createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
218
|
+
// }
|
|
219
|
+
if (event.scene === 'group') {
|
|
220
|
+
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
221
|
+
const UserId = event.group_member_openid;
|
|
222
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
223
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
224
|
+
const e = {
|
|
225
|
+
name: 'interaction.create',
|
|
226
|
+
Platform: platform,
|
|
227
|
+
// guild
|
|
228
|
+
GuildId: event.group_openid,
|
|
229
|
+
ChannelId: event.group_openid,
|
|
230
|
+
SpaceId: `GROUP:${event.group_openid}`,
|
|
231
|
+
// 用户Id
|
|
232
|
+
UserId: event.group_member_openid,
|
|
233
|
+
UserKey,
|
|
234
|
+
UserAvatar: UserAvatar,
|
|
235
|
+
IsMaster: isMaster,
|
|
236
|
+
IsBot: false,
|
|
237
|
+
// 格式化数据
|
|
238
|
+
MessageId: `INTERACTION_CREATE:${event.id}`,
|
|
239
|
+
MessageText: MessageText,
|
|
240
|
+
OpenId: `C2C:${event.group_member_openid}`,
|
|
241
|
+
tag: 'INTERACTION_CREATE_GROUP',
|
|
242
|
+
CreateAt: Date.now(),
|
|
243
|
+
value: event
|
|
244
|
+
};
|
|
245
|
+
cbp.send(e);
|
|
249
246
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
247
|
+
else if (event.scene === 'c2c') {
|
|
248
|
+
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
249
|
+
const UserId = event.user_openid;
|
|
250
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
251
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
252
|
+
// 处理消息
|
|
253
|
+
const e = {
|
|
254
|
+
name: 'private.interaction.create',
|
|
255
|
+
Platform: platform,
|
|
256
|
+
// 用户Id
|
|
257
|
+
UserId: event.user_openid,
|
|
258
|
+
UserKey,
|
|
259
|
+
UserAvatar: UserAvatar,
|
|
260
|
+
IsMaster: isMaster,
|
|
261
|
+
IsBot: false,
|
|
262
|
+
// 格式化数据
|
|
263
|
+
MessageId: event.id,
|
|
264
|
+
MessageText: MessageText,
|
|
265
|
+
OpenId: `C2C:${event.user_openid}`,
|
|
266
|
+
CreateAt: Date.now(),
|
|
267
|
+
tag: 'INTERACTION_CREATE_C2C',
|
|
268
|
+
value: event
|
|
269
|
+
};
|
|
270
|
+
cbp.send(e);
|
|
253
271
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
272
|
+
else if (event.scene === 'guild') {
|
|
273
|
+
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
274
|
+
const UserId = event.data.resolved.user_id;
|
|
275
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
276
|
+
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
277
|
+
// 处理消息
|
|
278
|
+
const e = {
|
|
279
|
+
name: 'interaction.create',
|
|
280
|
+
Platform: platform,
|
|
281
|
+
// guild
|
|
282
|
+
GuildId: event.guild_id,
|
|
283
|
+
ChannelId: event.channel_id,
|
|
284
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
285
|
+
// 用户Id
|
|
286
|
+
UserId: event.data.resolved.user_id,
|
|
287
|
+
UserKey,
|
|
288
|
+
UserAvatar: UserAvatar,
|
|
289
|
+
IsMaster: isMaster,
|
|
290
|
+
IsBot: false,
|
|
291
|
+
// 格式化数据
|
|
292
|
+
MessageId: event.data.resolved.message_id,
|
|
293
|
+
MessageText: MessageText,
|
|
294
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
295
|
+
CreateAt: Date.now(),
|
|
296
|
+
tag: 'INTERACTION_CREATE_GUILD',
|
|
297
|
+
value: event
|
|
298
|
+
};
|
|
299
|
+
cbp.send(e);
|
|
257
300
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return await MESSAGE_CREATE(client, event, val);
|
|
265
|
-
}
|
|
266
|
-
return Promise.all([]);
|
|
267
|
-
};
|
|
268
|
-
const getMesion = async (event) => {
|
|
269
|
-
event.value;
|
|
270
|
-
event.tag;
|
|
271
|
-
// const event = e.value
|
|
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');
|
|
301
|
+
else {
|
|
302
|
+
logger.warn({
|
|
303
|
+
code: ResultCode.Fail,
|
|
304
|
+
message: '暂未更新支持此类型的交互事件',
|
|
305
|
+
data: event
|
|
306
|
+
});
|
|
279
307
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
308
|
+
});
|
|
309
|
+
client.on('ERROR', console.error);
|
|
310
|
+
const api = {
|
|
311
|
+
active: {
|
|
312
|
+
send: {
|
|
313
|
+
channel: async (SpaceId, val) => {
|
|
314
|
+
if (/^GUILD:/.test(SpaceId)) {
|
|
315
|
+
const id = SpaceId.replace('GUILD:', '');
|
|
316
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
317
|
+
ChannelId: id
|
|
318
|
+
}, val);
|
|
319
|
+
}
|
|
320
|
+
if (/^GROUP:/.test(SpaceId)) {
|
|
321
|
+
const id = SpaceId.replace('GROUP:', '');
|
|
322
|
+
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
323
|
+
ChannelId: id
|
|
324
|
+
}, val);
|
|
325
|
+
}
|
|
326
|
+
return [];
|
|
327
|
+
},
|
|
328
|
+
user: async (OpenId, val) => {
|
|
329
|
+
if (/^C2C:/.test(OpenId)) {
|
|
330
|
+
const id = OpenId.replace('C2C:', '');
|
|
331
|
+
return await C2C_MESSAGE_CREATE(client, {
|
|
332
|
+
UserId: id
|
|
333
|
+
}, val);
|
|
334
|
+
}
|
|
335
|
+
else if (/^DIRECT:/.test(OpenId)) {
|
|
336
|
+
const id = OpenId.replace('DIRECT:', '');
|
|
337
|
+
return await DIRECT_MESSAGE_CREATE(client, {
|
|
338
|
+
UserId: id
|
|
339
|
+
}, val);
|
|
340
|
+
}
|
|
341
|
+
else if (/^GUILD:/.test(OpenId)) {
|
|
342
|
+
const id = OpenId.replace('GUILD:', '');
|
|
343
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
344
|
+
ChannelId: id
|
|
345
|
+
}, val);
|
|
346
|
+
}
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
use: {
|
|
352
|
+
send: async (event, val) => {
|
|
353
|
+
if (val.length < 0)
|
|
354
|
+
return [];
|
|
355
|
+
// 打 tag
|
|
356
|
+
const tag = event.tag;
|
|
357
|
+
// 群at
|
|
358
|
+
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
359
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
360
|
+
}
|
|
361
|
+
// 私聊
|
|
362
|
+
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
363
|
+
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
364
|
+
}
|
|
365
|
+
// 频道私聊
|
|
366
|
+
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
367
|
+
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
368
|
+
}
|
|
369
|
+
// 频道at
|
|
370
|
+
if (tag == 'AT_MESSAGE_CREATE') {
|
|
371
|
+
return await AT_MESSAGE_CREATE(client, event, val);
|
|
372
|
+
}
|
|
373
|
+
// 频道消息
|
|
374
|
+
if (tag == 'MESSAGE_CREATE') {
|
|
375
|
+
return await MESSAGE_CREATE(client, event, val);
|
|
376
|
+
}
|
|
377
|
+
// 交互
|
|
378
|
+
if (tag == 'INTERACTION_CREATE_GROUP') {
|
|
379
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
380
|
+
}
|
|
381
|
+
if (tag == 'INTERACTION_CREATE_C2C') {
|
|
382
|
+
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
383
|
+
}
|
|
384
|
+
if (tag == 'INTERACTION_CREATE_GUILD') {
|
|
385
|
+
return await AT_MESSAGE_CREATE(client, event, val);
|
|
386
|
+
}
|
|
387
|
+
return [];
|
|
388
|
+
},
|
|
389
|
+
mention: async (event) => {
|
|
390
|
+
event.value || {};
|
|
391
|
+
event.tag;
|
|
392
|
+
// const event = e.value
|
|
393
|
+
const Metions = [];
|
|
394
|
+
// group
|
|
395
|
+
return Metions;
|
|
396
|
+
}
|
|
287
397
|
}
|
|
288
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
289
|
-
OpenId: user_id
|
|
290
|
-
}, data);
|
|
291
398
|
};
|
|
292
399
|
// 处理行为
|
|
293
400
|
cbp.onactions(async (data, consume) => {
|
|
@@ -296,31 +403,41 @@ const register = (client) => {
|
|
|
296
403
|
const event = data.payload.event;
|
|
297
404
|
const paramFormat = data.payload.params.format;
|
|
298
405
|
// 消费
|
|
299
|
-
const res = await
|
|
406
|
+
const res = await api.use.send(event, paramFormat);
|
|
300
407
|
consume(res);
|
|
301
408
|
}
|
|
302
409
|
else if (data.action === 'mention.get') {
|
|
303
410
|
const event = data.payload.event;
|
|
304
411
|
// 获取提及
|
|
305
|
-
const metions = await
|
|
412
|
+
const metions = await api.use.mention(event);
|
|
306
413
|
// 消费
|
|
307
|
-
consume(metions);
|
|
414
|
+
consume([createResult(ResultCode.Ok, '请求完成', metions)]);
|
|
308
415
|
}
|
|
309
416
|
else if (data.action === 'message.send.channel') {
|
|
310
417
|
// 主动发送消息到频道
|
|
311
418
|
const channel_id = data.payload.ChannelId;
|
|
312
419
|
const paramFormat = data.payload.params.format;
|
|
313
|
-
const res = await
|
|
420
|
+
const res = await api.active.send.channel(channel_id, paramFormat);
|
|
314
421
|
consume(res);
|
|
315
422
|
}
|
|
316
423
|
else if (data.action === 'message.send.user') {
|
|
317
424
|
// 主动发送消息到用户
|
|
318
425
|
const user_id = data.payload.UserId;
|
|
319
426
|
const paramFormat = data.payload.params.format;
|
|
320
|
-
const res = await
|
|
427
|
+
const res = await api.active.send.user(user_id, paramFormat);
|
|
321
428
|
consume(res);
|
|
322
429
|
}
|
|
323
430
|
});
|
|
431
|
+
// 处理 api 调用
|
|
432
|
+
cbp.onapis(async (data, consume) => {
|
|
433
|
+
const key = data.payload?.key;
|
|
434
|
+
if (client[key]) {
|
|
435
|
+
// 如果 client 上有对应的 key,直接调用。
|
|
436
|
+
const params = data.payload.params;
|
|
437
|
+
const res = await client[key](...params);
|
|
438
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
324
441
|
};
|
|
325
442
|
|
|
326
|
-
export {
|
|
443
|
+
export { register };
|