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