@alemonjs/qq-bot 0.0.18 → 0.0.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/README.md +6 -10
- package/lib/hook.d.ts +10 -0
- package/lib/hook.js +35 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.group.js +7 -204
- package/lib/index.guild.js +23 -298
- package/lib/index.js +41 -403
- package/lib/index.webhook.js +26 -0
- package/lib/register.d.ts +3 -0
- package/lib/register.js +405 -0
- package/lib/sdk/api.d.ts +5 -10
- package/lib/sdk/api.js +5 -10
- package/lib/sdk/{websoket.group.js → client.websoket.group.js} +1 -1
- package/lib/sdk/{websoket.guild.js → client.websoket.guild.js} +11 -9
- package/lib/sdk/client.websoket.js +221 -0
- package/lib/sdk/intents.js +12 -23
- package/lib/send/index.js +18 -18
- package/package.json +1 -1
- package/lib/api.d.ts +0 -975
- package/lib/api.js +0 -1188
- package/lib/client.d.ts +0 -26
- package/lib/client.js +0 -212
- package/lib/config.js +0 -3
- package/lib/from.js +0 -37
- package/lib/message/AT_MESSAGE_CREATE.d.ts +0 -37
- package/lib/message/C2C_MESSAGE_CREATE.d.ts +0 -11
- package/lib/message/CHANNEL_CREATE.d.ts +0 -17
- package/lib/message/CHANNEL_DELETE.d.ts +0 -22
- package/lib/message/CHANNEL_UPDATE.d.ts +0 -22
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +0 -36
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +0 -24
- package/lib/message/ERROR.d.ts +0 -3
- package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +0 -16
- package/lib/message/GUILD_CREATE.d.ts +0 -22
- package/lib/message/GUILD_DELETE.d.ts +0 -22
- package/lib/message/GUILD_MEMBER_ADD.d.ts +0 -21
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +0 -21
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +0 -21
- package/lib/message/GUILD_UPDATE.d.ts +0 -22
- package/lib/message/INTERACTION_CREATE.d.ts +0 -8
- package/lib/message/MESSAGE_CREATE.d.ts +0 -11
- package/lib/message/MESSAGE_DELETE.d.ts +0 -11
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +0 -15
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +0 -15
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +0 -21
- package/lib/message/READY.d.ts +0 -11
- package/lib/message.d.ts +0 -49
- package/lib/typing.d.ts +0 -73
- package/lib/webhook.js +0 -51
package/lib/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { getConfigValue
|
|
2
|
-
import { QQBotClient } from './sdk/client.js';
|
|
3
|
-
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
1
|
+
import { getConfigValue } from 'alemonjs';
|
|
4
2
|
import QQBotGroup from './index.group.js';
|
|
5
3
|
import QQBotGuild from './index.guild.js';
|
|
6
|
-
import
|
|
4
|
+
import QQBotHook from './index.webhook.js';
|
|
5
|
+
import { QQBotClients } from './sdk/client.websoket.js';
|
|
6
|
+
import { platform, register, createClientAPI } from './register.js';
|
|
7
|
+
export { useMode } from './hook.js';
|
|
7
8
|
|
|
8
9
|
const client = new Proxy({}, {
|
|
9
10
|
get: (_, prop) => {
|
|
@@ -15,13 +16,12 @@ const client = new Proxy({}, {
|
|
|
15
16
|
return undefined;
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
|
-
const platform = 'qq-bot';
|
|
19
19
|
var index = definePlatform(() => {
|
|
20
20
|
let value = getConfigValue();
|
|
21
21
|
if (!value)
|
|
22
22
|
value = {};
|
|
23
23
|
const config = value[platform];
|
|
24
|
-
if (config
|
|
24
|
+
if (config?.mode == 'guild') {
|
|
25
25
|
if (typeof QQBotGuild.callback == 'function') {
|
|
26
26
|
return QQBotGuild.callback();
|
|
27
27
|
}
|
|
@@ -29,7 +29,7 @@ var index = definePlatform(() => {
|
|
|
29
29
|
return QQBotGuild.callback;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
else if (config
|
|
32
|
+
else if (config?.mode == 'group') {
|
|
33
33
|
if (typeof QQBotGroup.callback == 'function') {
|
|
34
34
|
return QQBotGroup.callback();
|
|
35
35
|
}
|
|
@@ -37,408 +37,46 @@ var index = definePlatform(() => {
|
|
|
37
37
|
return QQBotGroup.callback;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
else if (config?.route || config?.port || config?.ws) {
|
|
41
|
+
if (typeof QQBotHook.callback == 'function') {
|
|
42
|
+
return QQBotHook.callback();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return QQBotHook.callback;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const client = new QQBotClients({
|
|
42
49
|
app_id: config?.app_id,
|
|
43
|
-
|
|
50
|
+
intents: config?.intents ?? config?.is_private ? [
|
|
51
|
+
'GUILDS', // base
|
|
52
|
+
'GUILD_MEMBERS', // base
|
|
53
|
+
'GUILD_MESSAGES',
|
|
54
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
55
|
+
'DIRECT_MESSAGE',
|
|
56
|
+
'INTERACTION',
|
|
57
|
+
'FORUMS_EVENT',
|
|
58
|
+
] : [
|
|
59
|
+
'GUILDS', // base
|
|
60
|
+
'GUILD_MEMBERS', // base
|
|
61
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
62
|
+
'DIRECT_MESSAGE',
|
|
63
|
+
'INTERACTION',
|
|
64
|
+
'PUBLIC_GUILD_MESSAGES',
|
|
65
|
+
'GROUP_AND_C2C_EVENT',
|
|
66
|
+
],
|
|
67
|
+
is_private: config?.is_private ?? false,
|
|
68
|
+
sandbox: config?.sandbox ?? false,
|
|
69
|
+
secret: config?.secret,
|
|
70
|
+
shard: config?.shard ?? [0, 1],
|
|
44
71
|
token: config?.token,
|
|
45
|
-
|
|
46
|
-
ws: config?.ws
|
|
72
|
+
mode: config?.mode ?? 'group'
|
|
47
73
|
});
|
|
48
74
|
// 连接
|
|
49
|
-
client.connect();
|
|
50
|
-
|
|
51
|
-
* group
|
|
52
|
-
*
|
|
53
|
-
* GROUP_AT_MESSAGE_CREATE
|
|
54
|
-
* C2C_MESSAGE_CREATE
|
|
55
|
-
*/
|
|
56
|
-
const createUserAvatarURL = (author_id) => {
|
|
57
|
-
return `https://q.qlogo.cn/qqapp/${config.app_id}/${author_id}/ 640`;
|
|
58
|
-
};
|
|
59
|
-
// 监听消息
|
|
60
|
-
client.on('GROUP_AT_MESSAGE_CREATE', async (event) => {
|
|
61
|
-
const master_key = config?.master_key ?? [];
|
|
62
|
-
const isMaster = master_key.includes(event.author.id);
|
|
63
|
-
const url = createUserAvatarURL(event.author.id);
|
|
64
|
-
const UserAvatar = {
|
|
65
|
-
toBuffer: async () => {
|
|
66
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
67
|
-
return Buffer.from(arrayBuffer);
|
|
68
|
-
},
|
|
69
|
-
toBase64: async () => {
|
|
70
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
71
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
72
|
-
},
|
|
73
|
-
toURL: async () => {
|
|
74
|
-
return url;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const UserId = event.author.id;
|
|
78
|
-
const UserKey = useUserHashKey({
|
|
79
|
-
Platform: platform,
|
|
80
|
-
UserId: UserId
|
|
81
|
-
});
|
|
82
|
-
// 定义消
|
|
83
|
-
const e = {
|
|
84
|
-
name: 'message.create',
|
|
85
|
-
// 事件类型
|
|
86
|
-
Platform: platform,
|
|
87
|
-
// guild
|
|
88
|
-
GuildId: event.group_id,
|
|
89
|
-
ChannelId: event.group_id,
|
|
90
|
-
// 用户Id
|
|
91
|
-
UserId: event.author.id,
|
|
92
|
-
UserKey,
|
|
93
|
-
UserAvatar: UserAvatar,
|
|
94
|
-
IsMaster: isMaster,
|
|
95
|
-
IsBot: false,
|
|
96
|
-
// 格式化数据
|
|
97
|
-
MessageId: event.id,
|
|
98
|
-
MessageText: event.content?.trim(),
|
|
99
|
-
OpenId: event.author.member_openid,
|
|
100
|
-
CreateAt: Date.now(),
|
|
101
|
-
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
102
|
-
value: null
|
|
103
|
-
};
|
|
104
|
-
// 处理消息
|
|
105
|
-
onProcessor('message.create', e, event);
|
|
106
|
-
});
|
|
107
|
-
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
108
|
-
const master_key = config?.master_key ?? [];
|
|
109
|
-
const isMaster = master_key.includes(event.author.id);
|
|
110
|
-
const url = createUserAvatarURL(event.author.id);
|
|
111
|
-
const UserAvatar = {
|
|
112
|
-
toBuffer: async () => {
|
|
113
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
114
|
-
return Buffer.from(arrayBuffer);
|
|
115
|
-
},
|
|
116
|
-
toBase64: async () => {
|
|
117
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
118
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
119
|
-
},
|
|
120
|
-
toURL: async () => {
|
|
121
|
-
return url;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const UserId = event.author.id;
|
|
125
|
-
const UserKey = useUserHashKey({
|
|
126
|
-
Platform: platform,
|
|
127
|
-
UserId: UserId
|
|
128
|
-
});
|
|
129
|
-
// 定义消
|
|
130
|
-
const e = {
|
|
131
|
-
name: 'private.message.create',
|
|
132
|
-
// 事件类型
|
|
133
|
-
Platform: platform,
|
|
134
|
-
// 用户Id
|
|
135
|
-
UserId: event.author.id,
|
|
136
|
-
UserKey,
|
|
137
|
-
UserAvatar: UserAvatar,
|
|
138
|
-
IsMaster: isMaster,
|
|
139
|
-
IsBot: false,
|
|
140
|
-
// 格式化数据
|
|
141
|
-
MessageId: event.id,
|
|
142
|
-
MessageText: event.content?.trim(),
|
|
143
|
-
CreateAt: Date.now(),
|
|
144
|
-
OpenId: event.author.user_openid,
|
|
145
|
-
//
|
|
146
|
-
tag: 'C2C_MESSAGE_CREATE',
|
|
147
|
-
value: null
|
|
148
|
-
};
|
|
149
|
-
// 处理消息
|
|
150
|
-
onProcessor('private.message.create', e, event);
|
|
151
|
-
});
|
|
152
|
-
/**
|
|
153
|
-
* guild
|
|
154
|
-
*/
|
|
155
|
-
client.on('DIRECT_MESSAGE_CREATE', async (event) => {
|
|
156
|
-
// 屏蔽其他机器人的消息
|
|
157
|
-
if (event?.author?.bot)
|
|
158
|
-
return;
|
|
159
|
-
const master_key = config?.master_key ?? [];
|
|
160
|
-
const isMaster = master_key.includes(event.author.id);
|
|
161
|
-
let msg = event?.content ?? '';
|
|
162
|
-
const UserAvatar = {
|
|
163
|
-
toBuffer: async () => {
|
|
164
|
-
const arrayBuffer = await fetch(event.author.avatar).then(res => res.arrayBuffer());
|
|
165
|
-
return Buffer.from(arrayBuffer);
|
|
166
|
-
},
|
|
167
|
-
toBase64: async () => {
|
|
168
|
-
const arrayBuffer = await fetch(event?.author?.avatar).then(res => res.arrayBuffer());
|
|
169
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
170
|
-
},
|
|
171
|
-
toURL: async () => {
|
|
172
|
-
return event?.author?.avatar;
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const UserId = event.author.id;
|
|
176
|
-
const UserKey = useUserHashKey({
|
|
177
|
-
Platform: platform,
|
|
178
|
-
UserId: UserId
|
|
179
|
-
});
|
|
180
|
-
// 定义消
|
|
181
|
-
const e = {
|
|
182
|
-
name: 'private.message.create',
|
|
183
|
-
// 事件类型
|
|
184
|
-
Platform: platform,
|
|
185
|
-
//
|
|
186
|
-
// GuildId: event.guild_id,
|
|
187
|
-
// ChannelId: event.channel_id,
|
|
188
|
-
// 用户Id
|
|
189
|
-
UserId: event?.author?.id ?? '',
|
|
190
|
-
UserKey,
|
|
191
|
-
UserName: event?.author?.username ?? '',
|
|
192
|
-
UserAvatar: UserAvatar,
|
|
193
|
-
IsMaster: isMaster,
|
|
194
|
-
IsBot: event.author?.bot,
|
|
195
|
-
// message
|
|
196
|
-
MessageId: event.id,
|
|
197
|
-
MessageText: msg?.trim(),
|
|
198
|
-
OpenId: event.guild_id,
|
|
199
|
-
CreateAt: Date.now(),
|
|
200
|
-
//
|
|
201
|
-
tag: 'DIRECT_MESSAGE_CREATE',
|
|
202
|
-
//
|
|
203
|
-
value: null
|
|
204
|
-
};
|
|
205
|
-
// 处理消息
|
|
206
|
-
onProcessor('private.message.create', e, event);
|
|
207
|
-
});
|
|
208
|
-
// 监听消息
|
|
209
|
-
client.on('AT_MESSAGE_CREATE', async (event) => {
|
|
210
|
-
// 屏蔽其他机器人的消息
|
|
211
|
-
if (event?.author?.bot)
|
|
212
|
-
return;
|
|
213
|
-
const master_key = config?.master_key ?? [];
|
|
214
|
-
const isMaster = master_key.includes(event.author.id);
|
|
215
|
-
let msg = getMessageContent(event);
|
|
216
|
-
const UserAvatar = {
|
|
217
|
-
toBuffer: async () => {
|
|
218
|
-
const arrayBuffer = await fetch(event.author.avatar).then(res => res.arrayBuffer());
|
|
219
|
-
return Buffer.from(arrayBuffer);
|
|
220
|
-
},
|
|
221
|
-
toBase64: async () => {
|
|
222
|
-
const arrayBuffer = await fetch(event?.author?.avatar).then(res => res.arrayBuffer());
|
|
223
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
224
|
-
},
|
|
225
|
-
toURL: async () => {
|
|
226
|
-
return event?.author?.avatar;
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
const UserId = event.author.id;
|
|
230
|
-
const UserKey = useUserHashKey({
|
|
231
|
-
Platform: platform,
|
|
232
|
-
UserId: UserId
|
|
233
|
-
});
|
|
234
|
-
// 定义消
|
|
235
|
-
const e = {
|
|
236
|
-
name: 'message.create',
|
|
237
|
-
// 事件类型
|
|
238
|
-
Platform: platform,
|
|
239
|
-
GuildId: event.guild_id,
|
|
240
|
-
ChannelId: event.channel_id,
|
|
241
|
-
IsMaster: isMaster,
|
|
242
|
-
// 用户Id
|
|
243
|
-
UserId: event?.author?.id ?? '',
|
|
244
|
-
UserKey,
|
|
245
|
-
UserName: event?.author?.username ?? '',
|
|
246
|
-
UserAvatar: UserAvatar,
|
|
247
|
-
IsBot: event.author?.bot,
|
|
248
|
-
// message
|
|
249
|
-
MessageId: event.id,
|
|
250
|
-
MessageText: msg?.trim(),
|
|
251
|
-
OpenId: event.guild_id,
|
|
252
|
-
CreateAt: Date.now(),
|
|
253
|
-
//
|
|
254
|
-
tag: 'AT_MESSAGE_CREATE',
|
|
255
|
-
//
|
|
256
|
-
value: null
|
|
257
|
-
};
|
|
258
|
-
// 处理消息
|
|
259
|
-
onProcessor('message.create', e, event);
|
|
260
|
-
});
|
|
261
|
-
/**
|
|
262
|
-
*
|
|
263
|
-
* @param event
|
|
264
|
-
* @returns
|
|
265
|
-
*/
|
|
266
|
-
const getMessageContent = event => {
|
|
267
|
-
let msg = event?.content ?? '';
|
|
268
|
-
// 艾特消息处理
|
|
269
|
-
const at_users = [];
|
|
270
|
-
if (event.mentions) {
|
|
271
|
-
// 去掉@ 转为纯消息
|
|
272
|
-
for (const item of event.mentions) {
|
|
273
|
-
at_users.push({
|
|
274
|
-
id: item.id
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
// 循环删除文本中的at信息并去除前后空格
|
|
278
|
-
at_users.forEach(item => {
|
|
279
|
-
msg = msg.replace(`<@!${item.id}>`, '').trim();
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
return msg;
|
|
283
|
-
};
|
|
284
|
-
// 私域 -
|
|
285
|
-
client.on('MESSAGE_CREATE', async (event) => {
|
|
286
|
-
// 屏蔽其他机器人的消息
|
|
287
|
-
if (event.author?.bot)
|
|
288
|
-
return;
|
|
289
|
-
// 撤回消息
|
|
290
|
-
if (new RegExp(/DELETE$/).test(event.eventType))
|
|
291
|
-
return;
|
|
292
|
-
const master_key = config?.master_key ?? [];
|
|
293
|
-
const UserId = event.author.id;
|
|
294
|
-
const isMaster = master_key.includes(UserId);
|
|
295
|
-
const msg = getMessageContent(event);
|
|
296
|
-
const UserAvatar = {
|
|
297
|
-
toBuffer: async () => {
|
|
298
|
-
const arrayBuffer = await fetch(event.author.avatar).then(res => res.arrayBuffer());
|
|
299
|
-
return Buffer.from(arrayBuffer);
|
|
300
|
-
},
|
|
301
|
-
toBase64: async () => {
|
|
302
|
-
const arrayBuffer = await fetch(event?.author?.avatar).then(res => res.arrayBuffer());
|
|
303
|
-
return Buffer.from(arrayBuffer).toString('base64');
|
|
304
|
-
},
|
|
305
|
-
toURL: async () => {
|
|
306
|
-
return event?.author?.avatar;
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
const UserKey = useUserHashKey({
|
|
310
|
-
Platform: platform,
|
|
311
|
-
UserId: UserId
|
|
312
|
-
});
|
|
313
|
-
// 定义消
|
|
314
|
-
const e = {
|
|
315
|
-
name: 'message.create',
|
|
316
|
-
// 事件类型
|
|
317
|
-
Platform: platform,
|
|
318
|
-
//
|
|
319
|
-
GuildId: event.guild_id,
|
|
320
|
-
ChannelId: event.channel_id,
|
|
321
|
-
UserId: event?.author?.id ?? '',
|
|
322
|
-
UserKey,
|
|
323
|
-
UserName: event?.author?.username ?? '',
|
|
324
|
-
UserAvatar: UserAvatar,
|
|
325
|
-
IsMaster: isMaster,
|
|
326
|
-
IsBot: false,
|
|
327
|
-
// message
|
|
328
|
-
MessageId: event.id,
|
|
329
|
-
MessageText: msg?.trim(),
|
|
330
|
-
OpenId: event.guild_id,
|
|
331
|
-
CreateAt: Date.now(),
|
|
332
|
-
//
|
|
333
|
-
tag: 'MESSAGE_CREATE',
|
|
334
|
-
value: null
|
|
335
|
-
};
|
|
336
|
-
// 处理消息
|
|
337
|
-
onProcessor('message.create', e, event);
|
|
338
|
-
});
|
|
339
|
-
client.on('ERROR', console.error);
|
|
75
|
+
client.connect(config?.gatewayURL);
|
|
76
|
+
register(client);
|
|
340
77
|
// FRIEND_ADD
|
|
341
78
|
global.client = client;
|
|
342
|
-
return
|
|
343
|
-
platform,
|
|
344
|
-
api: {
|
|
345
|
-
// 主动消息
|
|
346
|
-
active: {
|
|
347
|
-
send: {
|
|
348
|
-
channel: async (channel_id, data) => {
|
|
349
|
-
if (isGuild(channel_id)) {
|
|
350
|
-
return await AT_MESSAGE_CREATE(client, {
|
|
351
|
-
ChannelId: channel_id
|
|
352
|
-
}, data);
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
// 需要message_id 。如果没有,则是主动消息,在group中,只能发送4条。
|
|
356
|
-
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
357
|
-
GuildId: channel_id
|
|
358
|
-
}, data);
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
user: async (user_id, data) => {
|
|
362
|
-
if (isGuild(user_id)) {
|
|
363
|
-
return await DIRECT_MESSAGE_CREATE(client, {
|
|
364
|
-
OpenId: user_id
|
|
365
|
-
}, data);
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
return await C2C_MESSAGE_CREATE(client, {
|
|
369
|
-
OpenId: user_id
|
|
370
|
-
}, data);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
// 被动消息
|
|
376
|
-
use: {
|
|
377
|
-
send: async (event, val) => {
|
|
378
|
-
if (val.length < 0)
|
|
379
|
-
;
|
|
380
|
-
// 打 tag
|
|
381
|
-
const tag = event.tag;
|
|
382
|
-
try {
|
|
383
|
-
// 群at
|
|
384
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
385
|
-
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
386
|
-
}
|
|
387
|
-
// 私聊
|
|
388
|
-
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
389
|
-
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
390
|
-
}
|
|
391
|
-
// 频道私聊
|
|
392
|
-
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
393
|
-
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
394
|
-
}
|
|
395
|
-
// 频道at
|
|
396
|
-
if (tag == 'AT_MESSAGE_CREATE') {
|
|
397
|
-
return await AT_MESSAGE_CREATE(client, event, val);
|
|
398
|
-
}
|
|
399
|
-
// 频道消息
|
|
400
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
401
|
-
return await MESSAGE_CREATE(client, event, val);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
catch (error) {
|
|
405
|
-
return [error];
|
|
406
|
-
}
|
|
407
|
-
return [];
|
|
408
|
-
},
|
|
409
|
-
mention: async (e) => {
|
|
410
|
-
const event = e.value;
|
|
411
|
-
const tag = e.tag;
|
|
412
|
-
// const event = e.value
|
|
413
|
-
const Metions = [];
|
|
414
|
-
// group
|
|
415
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE' || 'C2C_MESSAGE_CREATE')
|
|
416
|
-
return Metions;
|
|
417
|
-
// guild
|
|
418
|
-
if (event.mentions) {
|
|
419
|
-
const mentions = e.value['mentions'];
|
|
420
|
-
// 艾特消息处理
|
|
421
|
-
const MessageMention = mentions.map(item => {
|
|
422
|
-
return {
|
|
423
|
-
UserId: item.id,
|
|
424
|
-
IsMaster: false,
|
|
425
|
-
UserName: item.username,
|
|
426
|
-
IsBot: item.bot,
|
|
427
|
-
UserKey: useUserHashKey({
|
|
428
|
-
Platform: 'qq-guild-bot',
|
|
429
|
-
UserId: item.id
|
|
430
|
-
})
|
|
431
|
-
};
|
|
432
|
-
}) ?? [];
|
|
433
|
-
return MessageMention;
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
return Metions;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
};
|
|
79
|
+
return createClientAPI(client);
|
|
442
80
|
});
|
|
443
81
|
|
|
444
82
|
export { client, index as default, platform };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getConfigValue } from 'alemonjs';
|
|
2
|
+
import { QQBotClient } from './sdk/client.js';
|
|
3
|
+
import { platform, register, createClientAPI } from './register.js';
|
|
4
|
+
|
|
5
|
+
var QQBotHook = definePlatform(() => {
|
|
6
|
+
let value = getConfigValue();
|
|
7
|
+
if (!value)
|
|
8
|
+
value = {};
|
|
9
|
+
const config = value[platform];
|
|
10
|
+
const client = new QQBotClient({
|
|
11
|
+
secret: config?.secret,
|
|
12
|
+
app_id: config?.app_id,
|
|
13
|
+
route: config?.route,
|
|
14
|
+
token: config?.token,
|
|
15
|
+
port: config?.port,
|
|
16
|
+
ws: config?.ws
|
|
17
|
+
});
|
|
18
|
+
// 连接
|
|
19
|
+
client.connect();
|
|
20
|
+
register(client);
|
|
21
|
+
// FRIEND_ADD
|
|
22
|
+
global.client = client;
|
|
23
|
+
return createClientAPI(client);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export { QQBotHook as default };
|