@alemonjs/qq-bot 2.1.0-alpha.10 → 2.1.0-alpha.12
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.js +13 -2
- package/lib/hook.d.ts +7 -3
- package/lib/message/AT_MESSAGE_CREATE.d.ts +37 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +36 -0
- package/lib/message/INTERACTION_CREATE.d.ts +60 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +11 -0
- package/lib/register.js +12 -53
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/config.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { getConfigValue } from 'alemonjs';
|
|
1
|
+
import { getConfigValue, useUserHashKey } from 'alemonjs';
|
|
2
2
|
|
|
3
3
|
const platform = 'qq-bot';
|
|
4
4
|
const getQQBotConfig = () => {
|
|
5
5
|
const value = getConfigValue() || {};
|
|
6
6
|
return value[platform] || {};
|
|
7
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
|
+
};
|
|
8
19
|
|
|
9
|
-
export { getQQBotConfig, platform };
|
|
20
|
+
export { getMaster, getQQBotConfig, platform };
|
package/lib/hook.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { EventKeys, Events } from 'alemonjs';
|
|
2
2
|
import { GROUP_AT_MESSAGE_CREATE_TYPE } from './message/group/GROUP_AT_MESSAGE_CREATE.js';
|
|
3
3
|
import { QQBotAPI } from './sdk/api.js';
|
|
4
|
+
import { AT_MESSAGE_CREATE_TYPE } from './message/AT_MESSAGE_CREATE.js';
|
|
5
|
+
import { INTERACTION_CREATE_TYPE } from './message/INTERACTION_CREATE.js';
|
|
6
|
+
import { DIRECT_MESSAGE_CREATE_TYPE } from './message/DIRECT_MESSAGE_CREATE.js';
|
|
7
|
+
import { C2C_MESSAGE_CREATE_TYPE } from './message/group/C2C_MESSAGE_CREATE.js';
|
|
4
8
|
|
|
5
9
|
type MAP = {
|
|
6
|
-
'message.create': GROUP_AT_MESSAGE_CREATE_TYPE;
|
|
7
|
-
'private.message.create':
|
|
8
|
-
'interaction.create':
|
|
10
|
+
'message.create': GROUP_AT_MESSAGE_CREATE_TYPE | AT_MESSAGE_CREATE_TYPE;
|
|
11
|
+
'private.message.create': DIRECT_MESSAGE_CREATE_TYPE | C2C_MESSAGE_CREATE_TYPE;
|
|
12
|
+
'interaction.create': INTERACTION_CREATE_TYPE;
|
|
9
13
|
'private.interaction.create': undefined;
|
|
10
14
|
'message.update': undefined;
|
|
11
15
|
'message.delete': undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type AT_MESSAGE_CREATE_TYPE = {
|
|
2
|
+
attachments?: {
|
|
3
|
+
id: string;
|
|
4
|
+
url: string;
|
|
5
|
+
content_type: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
size: number;
|
|
8
|
+
height: number;
|
|
9
|
+
width: number;
|
|
10
|
+
}[];
|
|
11
|
+
author: {
|
|
12
|
+
avatar: string;
|
|
13
|
+
bot: boolean;
|
|
14
|
+
id: string;
|
|
15
|
+
username: string;
|
|
16
|
+
};
|
|
17
|
+
channel_id: string;
|
|
18
|
+
content: string;
|
|
19
|
+
guild_id: string;
|
|
20
|
+
id: string;
|
|
21
|
+
member: {
|
|
22
|
+
joined_at: string;
|
|
23
|
+
nick: string;
|
|
24
|
+
roles: string[];
|
|
25
|
+
};
|
|
26
|
+
mentions: {
|
|
27
|
+
avatar: string;
|
|
28
|
+
bot: boolean;
|
|
29
|
+
id: string;
|
|
30
|
+
username: string;
|
|
31
|
+
}[];
|
|
32
|
+
seq: number;
|
|
33
|
+
seq_in_channel: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type { AT_MESSAGE_CREATE_TYPE };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 私信
|
|
3
|
+
* @param event
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
type DIRECT_MESSAGE_CREATE_TYPE = {
|
|
7
|
+
attachments?: {
|
|
8
|
+
content_type: string;
|
|
9
|
+
filename: string;
|
|
10
|
+
height: number;
|
|
11
|
+
id: string;
|
|
12
|
+
size: number;
|
|
13
|
+
url: string;
|
|
14
|
+
width: number;
|
|
15
|
+
}[];
|
|
16
|
+
author: {
|
|
17
|
+
avatar: string;
|
|
18
|
+
bot: boolean;
|
|
19
|
+
id: string;
|
|
20
|
+
username: string;
|
|
21
|
+
};
|
|
22
|
+
channel_id: string;
|
|
23
|
+
content: string;
|
|
24
|
+
direct_message: boolean;
|
|
25
|
+
guild_id: string;
|
|
26
|
+
id: string;
|
|
27
|
+
member: {
|
|
28
|
+
joined_at: string;
|
|
29
|
+
};
|
|
30
|
+
seq: number;
|
|
31
|
+
seq_in_channel: string;
|
|
32
|
+
src_guild_id: string;
|
|
33
|
+
timestamp: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type { DIRECT_MESSAGE_CREATE_TYPE };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 交互消息事件 | 按钮消息
|
|
3
|
+
* @param event
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
type INTERACTION_CREATE_TYPE = {
|
|
7
|
+
application_id: string;
|
|
8
|
+
chat_type: 1;
|
|
9
|
+
data: {
|
|
10
|
+
resolved: {
|
|
11
|
+
button_data: string;
|
|
12
|
+
button_id: number;
|
|
13
|
+
};
|
|
14
|
+
type: number;
|
|
15
|
+
};
|
|
16
|
+
group_member_openid: string;
|
|
17
|
+
group_openid: string;
|
|
18
|
+
id: string;
|
|
19
|
+
scene: 'group';
|
|
20
|
+
timestamp: string;
|
|
21
|
+
type: number;
|
|
22
|
+
version: number;
|
|
23
|
+
} | {
|
|
24
|
+
application_id: string;
|
|
25
|
+
chat_type: 2;
|
|
26
|
+
data: {
|
|
27
|
+
resolved: {
|
|
28
|
+
button_data: string;
|
|
29
|
+
button_id: number;
|
|
30
|
+
};
|
|
31
|
+
type: number;
|
|
32
|
+
};
|
|
33
|
+
id: string;
|
|
34
|
+
scene: 'c2c';
|
|
35
|
+
timestamp: string;
|
|
36
|
+
type: number;
|
|
37
|
+
user_openid: string;
|
|
38
|
+
version: number;
|
|
39
|
+
} | {
|
|
40
|
+
application_id: string;
|
|
41
|
+
chat_type: 0;
|
|
42
|
+
data: {
|
|
43
|
+
resolved: {
|
|
44
|
+
message_id: string;
|
|
45
|
+
button_data: string;
|
|
46
|
+
button_id: number;
|
|
47
|
+
user_id: string;
|
|
48
|
+
};
|
|
49
|
+
type: number;
|
|
50
|
+
};
|
|
51
|
+
id: string;
|
|
52
|
+
scene: 'guild';
|
|
53
|
+
timestamp: string;
|
|
54
|
+
type: number;
|
|
55
|
+
guild_id: string;
|
|
56
|
+
channel_id: string;
|
|
57
|
+
version: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type { INTERACTION_CREATE_TYPE };
|
package/lib/register.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { cbpPlatform,
|
|
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, platform } from './config.js';
|
|
3
|
+
import { getQQBotConfig, getMaster, platform } from './config.js';
|
|
4
4
|
|
|
5
5
|
const register = (client) => {
|
|
6
6
|
const config = getQQBotConfig();
|
|
@@ -22,14 +22,9 @@ const register = (client) => {
|
|
|
22
22
|
};
|
|
23
23
|
// 监听消息
|
|
24
24
|
client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
|
|
25
|
-
const master_key = config?.master_key ?? [];
|
|
26
|
-
const isMaster = master_key.includes(event.author.id);
|
|
27
|
-
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
28
25
|
const UserId = event.author.id;
|
|
29
|
-
const UserKey =
|
|
30
|
-
|
|
31
|
-
UserId: UserId
|
|
32
|
-
});
|
|
26
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
27
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
33
28
|
// 定义消
|
|
34
29
|
const e = {
|
|
35
30
|
name: 'message.create',
|
|
@@ -55,14 +50,9 @@ const register = (client) => {
|
|
|
55
50
|
cbp.send(e);
|
|
56
51
|
});
|
|
57
52
|
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
58
|
-
const master_key = config?.master_key ?? [];
|
|
59
|
-
const isMaster = master_key.includes(event.author.id);
|
|
60
|
-
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
61
53
|
const UserId = event.author.id;
|
|
62
|
-
const UserKey =
|
|
63
|
-
|
|
64
|
-
UserId: UserId
|
|
65
|
-
});
|
|
54
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
55
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
66
56
|
// 定义消
|
|
67
57
|
const e = {
|
|
68
58
|
name: 'private.message.create',
|
|
@@ -92,15 +82,10 @@ const register = (client) => {
|
|
|
92
82
|
// 屏蔽其他机器人的消息
|
|
93
83
|
if (event?.author?.bot)
|
|
94
84
|
return;
|
|
95
|
-
const master_key = config?.master_key ?? [];
|
|
96
|
-
const isMaster = master_key.includes(event.author.id);
|
|
97
85
|
let msg = event?.content ?? '';
|
|
98
86
|
const UserAvatar = event?.author?.avatar;
|
|
99
87
|
const UserId = event.author.id;
|
|
100
|
-
const UserKey =
|
|
101
|
-
Platform: platform,
|
|
102
|
-
UserId: UserId
|
|
103
|
-
});
|
|
88
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
104
89
|
// 定义消
|
|
105
90
|
const e = {
|
|
106
91
|
name: 'private.message.create',
|
|
@@ -129,15 +114,10 @@ const register = (client) => {
|
|
|
129
114
|
// 屏蔽其他机器人的消息
|
|
130
115
|
if (event?.author?.bot)
|
|
131
116
|
return;
|
|
132
|
-
const master_key = config?.master_key ?? [];
|
|
133
|
-
const isMaster = master_key.includes(event.author.id);
|
|
134
117
|
let msg = getMessageContent(event);
|
|
135
118
|
const UserAvatar = event?.author?.avatar;
|
|
136
119
|
const UserId = event.author.id;
|
|
137
|
-
const UserKey =
|
|
138
|
-
Platform: platform,
|
|
139
|
-
UserId: UserId
|
|
140
|
-
});
|
|
120
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
141
121
|
// 定义消
|
|
142
122
|
const e = {
|
|
143
123
|
name: 'message.create',
|
|
@@ -195,15 +175,10 @@ const register = (client) => {
|
|
|
195
175
|
// 撤回消息
|
|
196
176
|
if (new RegExp(/DELETE$/).test(event.eventType))
|
|
197
177
|
return;
|
|
198
|
-
const master_key = config?.master_key ?? [];
|
|
199
178
|
const UserId = event.author.id;
|
|
200
|
-
const isMaster = master_key.includes(UserId);
|
|
201
179
|
const msg = getMessageContent(event);
|
|
202
180
|
const UserAvatar = event?.author?.avatar;
|
|
203
|
-
const UserKey =
|
|
204
|
-
Platform: platform,
|
|
205
|
-
UserId: UserId
|
|
206
|
-
});
|
|
181
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
207
182
|
// 定义消
|
|
208
183
|
const e = {
|
|
209
184
|
name: 'message.create',
|
|
@@ -241,16 +216,10 @@ const register = (client) => {
|
|
|
241
216
|
// } catch (err) {
|
|
242
217
|
// createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
243
218
|
// }
|
|
244
|
-
// 如何区分私聊/群聊
|
|
245
219
|
if (event.scene === 'group') {
|
|
246
|
-
const master_key = config?.master_key ?? [];
|
|
247
|
-
const isMaster = master_key.includes(event.group_member_openid);
|
|
248
220
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
249
221
|
const UserId = event.group_member_openid;
|
|
250
|
-
const UserKey =
|
|
251
|
-
Platform: platform,
|
|
252
|
-
UserId: UserId
|
|
253
|
-
});
|
|
222
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
254
223
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
255
224
|
const e = {
|
|
256
225
|
name: 'interaction.create',
|
|
@@ -276,14 +245,9 @@ const register = (client) => {
|
|
|
276
245
|
cbp.send(e);
|
|
277
246
|
}
|
|
278
247
|
else if (event.scene === 'c2c') {
|
|
279
|
-
const master_key = config?.master_key ?? [];
|
|
280
|
-
const isMaster = master_key.includes(event.user_openid);
|
|
281
248
|
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
282
249
|
const UserId = event.user_openid;
|
|
283
|
-
const UserKey =
|
|
284
|
-
Platform: platform,
|
|
285
|
-
UserId: UserId
|
|
286
|
-
});
|
|
250
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
287
251
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
288
252
|
// 处理消息
|
|
289
253
|
const e = {
|
|
@@ -306,14 +270,9 @@ const register = (client) => {
|
|
|
306
270
|
cbp.send(e);
|
|
307
271
|
}
|
|
308
272
|
else if (event.scene === 'guild') {
|
|
309
|
-
const master_key = config?.master_key ?? [];
|
|
310
|
-
const isMaster = master_key.includes(event.data.resolved.user_id);
|
|
311
273
|
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
312
274
|
const UserId = event.data.resolved.user_id;
|
|
313
|
-
const UserKey =
|
|
314
|
-
Platform: platform,
|
|
315
|
-
UserId: UserId
|
|
316
|
-
});
|
|
275
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
317
276
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
318
277
|
// 处理消息
|
|
319
278
|
const e = {
|