@alemonjs/qq-bot 2.1.0-alpha.19 → 2.1.0-alpha.20
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 +8 -3
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +0 -10
- package/lib/hook.d.ts +12 -29
- package/lib/hook.js +0 -20
- package/lib/index.d.ts +4 -6
- package/lib/index.js +2 -5
- package/lib/index.webhook.d.ts +1 -0
- package/lib/index.webhook.js +0 -1
- package/lib/index.websoket.d.ts +1 -0
- package/lib/index.websoket.js +4 -5
- package/lib/message/AT_MESSAGE_CREATE.d.ts +1 -3
- package/lib/message/AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/CHANNEL_CREATE.d.ts +15 -0
- package/lib/message/CHANNEL_CREATE.js +1 -0
- package/lib/message/CHANNEL_DELETE.d.ts +15 -0
- package/lib/message/CHANNEL_DELETE.js +1 -0
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
- package/lib/message/CHANNEL_UPDATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +1 -8
- package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
- package/lib/message/ERROR.d.ts +1 -0
- package/lib/message/ERROR.js +1 -0
- package/lib/message/GUILD_CREATE.d.ts +15 -0
- package/lib/message/GUILD_CREATE.js +1 -0
- package/lib/message/GUILD_DELETE.d.ts +15 -0
- package/lib/message/GUILD_DELETE.js +1 -0
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/message/GUILD_UPDATE.d.ts +15 -0
- package/lib/message/GUILD_UPDATE.js +1 -0
- package/lib/message/INTERACTION_CREATE.d.ts +1 -8
- package/lib/message/INTERACTION_CREATE.js +1 -0
- package/lib/message/MESSAGE_CREATE.d.ts +1 -0
- package/lib/message/MESSAGE_CREATE.js +1 -0
- package/lib/message/MESSAGE_DELETE.d.ts +1 -0
- package/lib/message/MESSAGE_DELETE.js +1 -0
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
- package/lib/message/READY.d.ts +6 -0
- package/lib/message/READY.js +1 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +1 -3
- package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
- package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
- package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
- package/lib/message/group/C2C_MSG_REJECT.js +1 -0
- package/lib/message/group/FRIEND_ADD.d.ts +4 -0
- package/lib/message/group/FRIEND_ADD.js +1 -0
- package/lib/message/group/FRIEND_DEL.d.ts +4 -0
- package/lib/message/group/FRIEND_DEL.js +1 -0
- package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +1 -6
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
- package/lib/register.d.ts +2 -0
- package/lib/register.js +0 -97
- package/lib/sdk/api.d.ts +6 -529
- package/lib/sdk/api.js +0 -526
- package/lib/sdk/client.webhook.d.ts +9 -0
- package/lib/sdk/client.webhook.js +0 -39
- package/lib/sdk/client.websoket.d.ts +9 -0
- package/lib/sdk/client.websoket.js +4 -57
- package/lib/sdk/config.d.ts +1 -0
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +3 -19
- package/lib/sdk/intents.d.ts +3 -0
- package/lib/sdk/intents.js +25 -90
- package/lib/sdk/message.d.ts +4 -0
- package/lib/sdk/message.group.d.ts +24 -0
- package/lib/sdk/message.group.js +1 -0
- package/lib/sdk/message.guild.d.ts +38 -0
- package/lib/sdk/message.guild.js +1 -0
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/message.public.d.ts +6 -0
- package/lib/sdk/message.public.js +1 -0
- package/lib/sdk/typing.d.ts +21 -11
- package/lib/sdk/typing.js +1 -0
- package/lib/sdk/webhook.secret.d.ts +14 -0
- package/lib/sdk/webhook.secret.js +2 -19
- package/lib/sends.d.ts +29 -0
- package/lib/sends.js +19 -107
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +8 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* 群消息事件 AT 事件
|
|
3
|
-
*/
|
|
4
|
-
interface GROUP_AT_MESSAGE_CREATE_TYPE {
|
|
1
|
+
export interface GROUP_AT_MESSAGE_CREATE_TYPE {
|
|
5
2
|
author: {
|
|
6
3
|
id: string;
|
|
7
4
|
member_openid: string;
|
|
@@ -12,5 +9,3 @@ interface GROUP_AT_MESSAGE_CREATE_TYPE {
|
|
|
12
9
|
id: string;
|
|
13
10
|
timestamp: string;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
export type { GROUP_AT_MESSAGE_CREATE_TYPE };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/register.js
CHANGED
|
@@ -4,24 +4,13 @@ import { getQQBotConfig, platform, getMaster } from './config.js';
|
|
|
4
4
|
|
|
5
5
|
const register = (client) => {
|
|
6
6
|
const config = getQQBotConfig();
|
|
7
|
-
/**
|
|
8
|
-
* 连接 alemonjs 服务器。
|
|
9
|
-
* 向 alemonjs 推送标准信息
|
|
10
|
-
*/
|
|
11
7
|
const port = process.env?.port || config?.port || 17117;
|
|
12
8
|
const url = `ws://127.0.0.1:${port}`;
|
|
13
9
|
const cbp = cbpPlatform(url);
|
|
14
|
-
/**
|
|
15
|
-
* group
|
|
16
|
-
*
|
|
17
|
-
* GROUP_AT_MESSAGE_CREATE
|
|
18
|
-
* C2C_MESSAGE_CREATE
|
|
19
|
-
*/
|
|
20
10
|
const createUserAvatarURL = (author_id) => {
|
|
21
11
|
return `https://q.qlogo.cn/qqapp/${config.app_id}/${author_id}/640`;
|
|
22
12
|
};
|
|
23
13
|
client.on('GROUP_ADD_ROBOT', event => {
|
|
24
|
-
// 机器人加入群组
|
|
25
14
|
const e = {
|
|
26
15
|
name: 'guild.join',
|
|
27
16
|
Platform: platform,
|
|
@@ -42,7 +31,6 @@ const register = (client) => {
|
|
|
42
31
|
cbp.send(e);
|
|
43
32
|
});
|
|
44
33
|
client.on('GROUP_DEL_ROBOT', event => {
|
|
45
|
-
// 机器人离开群组
|
|
46
34
|
const e = {
|
|
47
35
|
name: 'guild.exit',
|
|
48
36
|
Platform: platform,
|
|
@@ -62,26 +50,21 @@ const register = (client) => {
|
|
|
62
50
|
};
|
|
63
51
|
cbp.send(e);
|
|
64
52
|
});
|
|
65
|
-
// 监听消息
|
|
66
53
|
client.on('GROUP_AT_MESSAGE_CREATE', event => {
|
|
67
54
|
const UserId = event.author.id;
|
|
68
55
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
69
56
|
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
70
|
-
// 定义消
|
|
71
57
|
const e = {
|
|
72
58
|
name: 'message.create',
|
|
73
59
|
Platform: platform,
|
|
74
|
-
// guild
|
|
75
60
|
GuildId: event.group_id,
|
|
76
61
|
ChannelId: event.group_id,
|
|
77
62
|
SpaceId: `GROUP:${event.group_id}`,
|
|
78
|
-
// 用户Id
|
|
79
63
|
UserId: event.author.id,
|
|
80
64
|
UserKey,
|
|
81
65
|
UserAvatar: UserAvatar,
|
|
82
66
|
IsMaster: isMaster,
|
|
83
67
|
IsBot: false,
|
|
84
|
-
// 格式化数据
|
|
85
68
|
MessageId: event.id,
|
|
86
69
|
MessageText: event.content?.trim(),
|
|
87
70
|
OpenId: `C2C:${event.author.member_openid}`,
|
|
@@ -95,33 +78,24 @@ const register = (client) => {
|
|
|
95
78
|
const UserId = event.author.id;
|
|
96
79
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
97
80
|
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
98
|
-
// 定义消
|
|
99
81
|
const e = {
|
|
100
82
|
name: 'private.message.create',
|
|
101
|
-
// 事件类型
|
|
102
83
|
Platform: platform,
|
|
103
|
-
// 用户Id
|
|
104
84
|
UserId: event.author.id,
|
|
105
85
|
UserKey,
|
|
106
86
|
UserAvatar: UserAvatar,
|
|
107
87
|
IsMaster: isMaster,
|
|
108
88
|
IsBot: false,
|
|
109
|
-
// 格式化数据
|
|
110
89
|
MessageId: event.id,
|
|
111
90
|
MessageText: event.content?.trim(),
|
|
112
91
|
CreateAt: Date.now(),
|
|
113
92
|
OpenId: `C2C:${event.author.user_openid}`,
|
|
114
|
-
//
|
|
115
93
|
tag: 'C2C_MESSAGE_CREATE',
|
|
116
94
|
value: event
|
|
117
95
|
};
|
|
118
96
|
cbp.send(e);
|
|
119
97
|
});
|
|
120
|
-
/**
|
|
121
|
-
* guild
|
|
122
|
-
*/
|
|
123
98
|
client.on('DIRECT_MESSAGE_CREATE', event => {
|
|
124
|
-
// 屏蔽其他机器人的消息
|
|
125
99
|
if (event?.author?.bot) {
|
|
126
100
|
return;
|
|
127
101
|
}
|
|
@@ -129,32 +103,25 @@ const register = (client) => {
|
|
|
129
103
|
const UserAvatar = event?.author?.avatar;
|
|
130
104
|
const UserId = event.author.id;
|
|
131
105
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
132
|
-
// 定义消
|
|
133
106
|
const e = {
|
|
134
107
|
name: 'private.message.create',
|
|
135
|
-
// 事件类型
|
|
136
108
|
Platform: platform,
|
|
137
|
-
// 用户Id
|
|
138
109
|
UserId: event?.author?.id ?? '',
|
|
139
110
|
UserKey,
|
|
140
111
|
UserName: event?.author?.username ?? '',
|
|
141
112
|
UserAvatar: UserAvatar,
|
|
142
113
|
IsMaster: isMaster,
|
|
143
114
|
IsBot: event.author?.bot,
|
|
144
|
-
// message
|
|
145
115
|
MessageId: event.id,
|
|
146
116
|
MessageText: msg?.trim(),
|
|
147
117
|
OpenId: `DIRECT:${event.guild_id}`,
|
|
148
118
|
CreateAt: Date.now(),
|
|
149
|
-
//
|
|
150
119
|
tag: 'DIRECT_MESSAGE_CREATE',
|
|
151
120
|
value: event
|
|
152
121
|
};
|
|
153
122
|
cbp.send(e);
|
|
154
123
|
});
|
|
155
|
-
// 监听消息
|
|
156
124
|
client.on('AT_MESSAGE_CREATE', event => {
|
|
157
|
-
// 屏蔽其他机器人的消息
|
|
158
125
|
if (event?.author?.bot) {
|
|
159
126
|
return;
|
|
160
127
|
}
|
|
@@ -162,62 +129,46 @@ const register = (client) => {
|
|
|
162
129
|
const UserAvatar = event?.author?.avatar;
|
|
163
130
|
const UserId = event.author.id;
|
|
164
131
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
165
|
-
// 定义消
|
|
166
132
|
const e = {
|
|
167
133
|
name: 'message.create',
|
|
168
|
-
// 事件类型
|
|
169
134
|
Platform: platform,
|
|
170
135
|
GuildId: event.guild_id,
|
|
171
136
|
ChannelId: event.channel_id,
|
|
172
137
|
SpaceId: `GUILD:${event.channel_id}`,
|
|
173
138
|
IsMaster: isMaster,
|
|
174
|
-
// 用户Id
|
|
175
139
|
UserId: event?.author?.id ?? '',
|
|
176
140
|
UserKey,
|
|
177
141
|
UserName: event?.author?.username ?? '',
|
|
178
142
|
UserAvatar: UserAvatar,
|
|
179
143
|
IsBot: event.author?.bot,
|
|
180
|
-
// message
|
|
181
144
|
MessageId: event.id,
|
|
182
145
|
MessageText: msg?.trim(),
|
|
183
146
|
OpenId: `DIRECT:${event.guild_id}`,
|
|
184
147
|
CreateAt: Date.now(),
|
|
185
|
-
//
|
|
186
148
|
tag: 'AT_MESSAGE_CREATE',
|
|
187
149
|
value: event
|
|
188
150
|
};
|
|
189
151
|
cbp.send(e);
|
|
190
152
|
});
|
|
191
|
-
/**
|
|
192
|
-
*
|
|
193
|
-
* @param event
|
|
194
|
-
* @returns
|
|
195
|
-
*/
|
|
196
153
|
const getMessageContent = event => {
|
|
197
154
|
let msg = event?.content ?? '';
|
|
198
|
-
// 艾特消息处理
|
|
199
155
|
const atUsers = [];
|
|
200
156
|
if (event.mentions) {
|
|
201
|
-
// 去掉@ 转为纯消息
|
|
202
157
|
for (const item of event.mentions) {
|
|
203
158
|
atUsers.push({
|
|
204
159
|
id: item.id
|
|
205
160
|
});
|
|
206
161
|
}
|
|
207
|
-
// 循环删除文本中的at信息并去除前后空格
|
|
208
162
|
atUsers.forEach(item => {
|
|
209
163
|
msg = msg.replace(`<@!${item.id}>`, '').trim();
|
|
210
164
|
});
|
|
211
165
|
}
|
|
212
166
|
return msg;
|
|
213
167
|
};
|
|
214
|
-
// 私域 -
|
|
215
168
|
client.on('MESSAGE_CREATE', event => {
|
|
216
|
-
// 屏蔽其他机器人的消息
|
|
217
169
|
if (event.author?.bot) {
|
|
218
170
|
return;
|
|
219
171
|
}
|
|
220
|
-
// 撤回消息
|
|
221
172
|
if (new RegExp(/DELETE$/).test(event.eventType)) {
|
|
222
173
|
return;
|
|
223
174
|
}
|
|
@@ -225,12 +176,9 @@ const register = (client) => {
|
|
|
225
176
|
const msg = getMessageContent(event);
|
|
226
177
|
const UserAvatar = event?.author?.avatar;
|
|
227
178
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
228
|
-
// 定义消
|
|
229
179
|
const e = {
|
|
230
180
|
name: 'message.create',
|
|
231
|
-
// 事件类型
|
|
232
181
|
Platform: platform,
|
|
233
|
-
//
|
|
234
182
|
GuildId: event.guild_id,
|
|
235
183
|
ChannelId: event.channel_id,
|
|
236
184
|
SpaceId: `GUILD:${event.channel_id}`,
|
|
@@ -240,28 +188,16 @@ const register = (client) => {
|
|
|
240
188
|
UserAvatar: UserAvatar,
|
|
241
189
|
IsMaster: isMaster,
|
|
242
190
|
IsBot: false,
|
|
243
|
-
// message
|
|
244
191
|
MessageId: event.id,
|
|
245
192
|
MessageText: msg?.trim(),
|
|
246
193
|
OpenId: `DIRECT:${event.guild_id}`,
|
|
247
194
|
CreateAt: Date.now(),
|
|
248
|
-
//
|
|
249
195
|
tag: 'MESSAGE_CREATE',
|
|
250
196
|
value: event
|
|
251
197
|
};
|
|
252
198
|
cbp.send(e);
|
|
253
199
|
});
|
|
254
200
|
client.on('INTERACTION_CREATE', event => {
|
|
255
|
-
// try {
|
|
256
|
-
// if (event.scene === 'group' || event.scene === 'c2c') {
|
|
257
|
-
// await client.interactionResponse('group', event.id)
|
|
258
|
-
// }
|
|
259
|
-
// else if (event.scene === 'guild') {
|
|
260
|
-
// await client.interactionResponse('guild', event.id)
|
|
261
|
-
// }
|
|
262
|
-
// } catch (err) {
|
|
263
|
-
// createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
264
|
-
// }
|
|
265
201
|
if (event.scene === 'group') {
|
|
266
202
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
267
203
|
const UserId = event.group_member_openid;
|
|
@@ -270,17 +206,14 @@ const register = (client) => {
|
|
|
270
206
|
const e = {
|
|
271
207
|
name: 'interaction.create',
|
|
272
208
|
Platform: platform,
|
|
273
|
-
// guild
|
|
274
209
|
GuildId: event.group_openid,
|
|
275
210
|
ChannelId: event.group_openid,
|
|
276
211
|
SpaceId: `GROUP:${event.group_openid}`,
|
|
277
|
-
// 用户Id
|
|
278
212
|
UserId: event.group_member_openid,
|
|
279
213
|
UserKey,
|
|
280
214
|
UserAvatar: UserAvatar,
|
|
281
215
|
IsMaster: isMaster,
|
|
282
216
|
IsBot: false,
|
|
283
|
-
// 格式化数据
|
|
284
217
|
MessageId: `INTERACTION_CREATE:${event.id}`,
|
|
285
218
|
MessageText: MessageText,
|
|
286
219
|
OpenId: `C2C:${event.group_member_openid}`,
|
|
@@ -295,17 +228,14 @@ const register = (client) => {
|
|
|
295
228
|
const UserId = event.user_openid;
|
|
296
229
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
297
230
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
298
|
-
// 处理消息
|
|
299
231
|
const e = {
|
|
300
232
|
name: 'private.interaction.create',
|
|
301
233
|
Platform: platform,
|
|
302
|
-
// 用户Id
|
|
303
234
|
UserId: event.user_openid,
|
|
304
235
|
UserKey,
|
|
305
236
|
UserAvatar: UserAvatar,
|
|
306
237
|
IsMaster: isMaster,
|
|
307
238
|
IsBot: false,
|
|
308
|
-
// 格式化数据
|
|
309
239
|
MessageId: event.id,
|
|
310
240
|
MessageText: MessageText,
|
|
311
241
|
OpenId: `C2C:${event.user_openid}`,
|
|
@@ -320,21 +250,17 @@ const register = (client) => {
|
|
|
320
250
|
const UserId = event.data.resolved.user_id;
|
|
321
251
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
322
252
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
323
|
-
// 处理消息
|
|
324
253
|
const e = {
|
|
325
254
|
name: 'interaction.create',
|
|
326
255
|
Platform: platform,
|
|
327
|
-
// guild
|
|
328
256
|
GuildId: event.guild_id,
|
|
329
257
|
ChannelId: event.channel_id,
|
|
330
258
|
SpaceId: `GUILD:${event.channel_id}`,
|
|
331
|
-
// 用户Id
|
|
332
259
|
UserId: event.data.resolved.user_id,
|
|
333
260
|
UserKey,
|
|
334
261
|
UserAvatar: UserAvatar,
|
|
335
262
|
IsMaster: isMaster,
|
|
336
263
|
IsBot: false,
|
|
337
|
-
// 格式化数据
|
|
338
264
|
MessageId: event.data.resolved.message_id,
|
|
339
265
|
MessageText: MessageText,
|
|
340
266
|
OpenId: `DIRECT:${event.guild_id}`,
|
|
@@ -399,29 +325,22 @@ const register = (client) => {
|
|
|
399
325
|
if (val.length < 0) {
|
|
400
326
|
return [];
|
|
401
327
|
}
|
|
402
|
-
// 打 tag
|
|
403
328
|
const tag = event.tag;
|
|
404
|
-
// 群at
|
|
405
329
|
if (tag === 'GROUP_AT_MESSAGE_CREATE') {
|
|
406
330
|
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
407
331
|
}
|
|
408
|
-
// 私聊
|
|
409
332
|
if (tag === 'C2C_MESSAGE_CREATE') {
|
|
410
333
|
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
411
334
|
}
|
|
412
|
-
// 频道私聊
|
|
413
335
|
if (tag === 'DIRECT_MESSAGE_CREATE') {
|
|
414
336
|
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
415
337
|
}
|
|
416
|
-
// 频道at
|
|
417
338
|
if (tag === 'AT_MESSAGE_CREATE') {
|
|
418
339
|
return await AT_MESSAGE_CREATE(client, event, val);
|
|
419
340
|
}
|
|
420
|
-
// 频道消息
|
|
421
341
|
if (tag === 'MESSAGE_CREATE') {
|
|
422
342
|
return await MESSAGE_CREATE(client, event, val);
|
|
423
343
|
}
|
|
424
|
-
// 交互
|
|
425
344
|
if (tag === 'INTERACTION_CREATE_GROUP') {
|
|
426
345
|
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
427
346
|
}
|
|
@@ -436,17 +355,12 @@ const register = (client) => {
|
|
|
436
355
|
mention: event => {
|
|
437
356
|
const value = event.value || {};
|
|
438
357
|
const tag = event.tag;
|
|
439
|
-
// const event = e.value
|
|
440
358
|
const Metions = [];
|
|
441
|
-
// group
|
|
442
359
|
if (tag === 'GROUP_AT_MESSAGE_CREATE' || tag === 'C2C_MESSAGE_CREATE') {
|
|
443
|
-
// return Metions;
|
|
444
360
|
return new Promise(resolve => resolve(Metions));
|
|
445
361
|
}
|
|
446
|
-
// guild
|
|
447
362
|
if (value.mentions) {
|
|
448
363
|
const mentions = event.value['mentions'];
|
|
449
|
-
// 艾特消息处理
|
|
450
364
|
const MessageMention = mentions.map(item => {
|
|
451
365
|
const UserId = item.id;
|
|
452
366
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
@@ -458,11 +372,9 @@ const register = (client) => {
|
|
|
458
372
|
UserKey: UserKey
|
|
459
373
|
};
|
|
460
374
|
});
|
|
461
|
-
// return MessageMention;
|
|
462
375
|
return new Promise(resolve => resolve(MessageMention));
|
|
463
376
|
}
|
|
464
377
|
else {
|
|
465
|
-
// return Metions;
|
|
466
378
|
return new Promise(resolve => resolve(Metions));
|
|
467
379
|
}
|
|
468
380
|
}
|
|
@@ -470,47 +382,38 @@ const register = (client) => {
|
|
|
470
382
|
};
|
|
471
383
|
const onactions = async (data, consume) => {
|
|
472
384
|
if (data.action === 'message.send') {
|
|
473
|
-
// 消息发送
|
|
474
385
|
const event = data.payload.event;
|
|
475
386
|
const paramFormat = data.payload.params.format;
|
|
476
|
-
// 消费
|
|
477
387
|
const res = await api.use.send(event, paramFormat);
|
|
478
388
|
consume(res);
|
|
479
389
|
}
|
|
480
390
|
else if (data.action === 'mention.get') {
|
|
481
391
|
const event = data.payload.event;
|
|
482
|
-
// 获取提及
|
|
483
392
|
const metions = await api.use.mention(event);
|
|
484
|
-
// 消费
|
|
485
393
|
consume([createResult(ResultCode.Ok, '请求完成', metions)]);
|
|
486
394
|
}
|
|
487
395
|
else if (data.action === 'message.send.channel') {
|
|
488
|
-
// 主动发送消息到频道
|
|
489
396
|
const channel_id = data.payload.ChannelId;
|
|
490
397
|
const paramFormat = data.payload.params.format;
|
|
491
398
|
const res = await api.active.send.channel(channel_id, paramFormat);
|
|
492
399
|
consume(res);
|
|
493
400
|
}
|
|
494
401
|
else if (data.action === 'message.send.user') {
|
|
495
|
-
// 主动发送消息到用户
|
|
496
402
|
const user_id = data.payload.UserId;
|
|
497
403
|
const paramFormat = data.payload.params.format;
|
|
498
404
|
const res = await api.active.send.user(user_id, paramFormat);
|
|
499
405
|
consume(res);
|
|
500
406
|
}
|
|
501
407
|
};
|
|
502
|
-
// 处理行为
|
|
503
408
|
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
504
409
|
const onapis = async (data, consume) => {
|
|
505
410
|
const key = data.payload?.key;
|
|
506
411
|
if (client[key]) {
|
|
507
|
-
// 如果 client 上有对应的 key,直接调用。
|
|
508
412
|
const params = data.payload.params;
|
|
509
413
|
const res = await client[key](...params);
|
|
510
414
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
511
415
|
}
|
|
512
416
|
};
|
|
513
|
-
// 处理 api 调用
|
|
514
417
|
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
515
418
|
};
|
|
516
419
|
|