@alemonjs/qq-bot 0.0.9 → 0.0.10
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/dist/assets/index.css +476 -0
- package/dist/assets/index.js +11032 -0
- package/dist/index.html +15 -0
- package/lib/api.d.ts +971 -843
- package/lib/api.js +1172 -1156
- package/lib/client.d.ts +22 -22
- package/lib/client.js +201 -217
- package/lib/config.js +2 -2
- package/lib/desktop.d.ts +2 -2
- package/lib/desktop.js +60 -59
- package/lib/from.js +27 -34
- package/lib/index.d.ts +7 -7
- package/lib/index.js +406 -405
- 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 +230 -192
- package/lib/typing.d.ts +62 -54
- package/lib/webhook.js +46 -48
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,418 +1,419 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs'
|
|
2
|
-
import { QQBotClient } from './client.js'
|
|
3
|
-
import {
|
|
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'
|
|
4
10
|
|
|
5
|
-
const client = new Proxy(
|
|
11
|
+
const client = new Proxy(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
6
14
|
get: (_, prop) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
if (prop in global.client) {
|
|
16
|
+
const original = global.client[prop]
|
|
17
|
+
// 防止函数内this丢失
|
|
18
|
+
return typeof original === 'function' ? original.bind(global.client) : original
|
|
19
|
+
}
|
|
20
|
+
return undefined
|
|
13
21
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
const platform = 'qq-bot'
|
|
16
25
|
var index = defineBot(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
26
|
+
let value = getConfigValue()
|
|
27
|
+
if (!value) value = {}
|
|
28
|
+
const config = value[platform]
|
|
29
|
+
const client = new QQBotClient({
|
|
30
|
+
secret: config?.secret,
|
|
31
|
+
app_id: config?.app_id,
|
|
32
|
+
route: config?.route,
|
|
33
|
+
token: config?.token,
|
|
34
|
+
port: config?.port,
|
|
35
|
+
ws: config?.ws
|
|
36
|
+
})
|
|
37
|
+
// 连接
|
|
38
|
+
client.connect()
|
|
39
|
+
/**
|
|
40
|
+
* group
|
|
41
|
+
*
|
|
42
|
+
* GROUP_AT_MESSAGE_CREATE
|
|
43
|
+
* C2C_MESSAGE_CREATE
|
|
44
|
+
*/
|
|
45
|
+
// 监听消息
|
|
46
|
+
client.on('GROUP_AT_MESSAGE_CREATE', async event => {
|
|
47
|
+
const master_key = config?.master_key ?? []
|
|
48
|
+
const isMaster = master_key.includes(event.author.id)
|
|
49
|
+
const url = `https://q.qlogo.cn/qqapp/${config.app_id}/${event.author.id}/640`
|
|
50
|
+
const UserAvatar = {
|
|
51
|
+
toBuffer: async () => {
|
|
52
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
|
53
|
+
return Buffer.from(arrayBuffer)
|
|
54
|
+
},
|
|
55
|
+
toBase64: async () => {
|
|
56
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
|
57
|
+
return Buffer.from(arrayBuffer).toString('base64')
|
|
58
|
+
},
|
|
59
|
+
toURL: async () => {
|
|
60
|
+
return url
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const UserId = event.author.id
|
|
64
|
+
const UserKey = useUserHashKey({
|
|
65
|
+
Platform: platform,
|
|
66
|
+
UserId: UserId
|
|
67
|
+
})
|
|
68
|
+
// 定义消
|
|
69
|
+
const e = {
|
|
70
|
+
name: 'message.create',
|
|
71
|
+
// 事件类型
|
|
72
|
+
Platform: platform,
|
|
73
|
+
// guild
|
|
74
|
+
GuildId: event.group_id,
|
|
75
|
+
ChannelId: event.group_id,
|
|
76
|
+
// 用户Id
|
|
77
|
+
UserId: event.author.id,
|
|
78
|
+
UserKey,
|
|
79
|
+
UserAvatar: UserAvatar,
|
|
80
|
+
IsMaster: isMaster,
|
|
81
|
+
IsBot: false,
|
|
82
|
+
// 格式化数据
|
|
83
|
+
MessageId: event.id,
|
|
84
|
+
MessageText: event.content?.trim(),
|
|
85
|
+
OpenId: event.author.member_openid,
|
|
86
|
+
CreateAt: Date.now(),
|
|
87
|
+
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
88
|
+
value: null
|
|
89
|
+
}
|
|
90
|
+
// 当访问的时候获取
|
|
91
|
+
Object.defineProperty(e, 'value', {
|
|
92
|
+
get() {
|
|
93
|
+
return event
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
// 处理消息
|
|
97
|
+
OnProcessor(e, 'message.create')
|
|
98
|
+
})
|
|
99
|
+
client.on('C2C_MESSAGE_CREATE', async event => {
|
|
100
|
+
const master_key = config?.master_key ?? []
|
|
101
|
+
const isMaster = master_key.includes(event.author.id)
|
|
102
|
+
const url = `https://q.qlogo.cn/qqapp/${config.app_id}/${event.author.id}/640`
|
|
103
|
+
const UserAvatar = {
|
|
104
|
+
toBuffer: async () => {
|
|
105
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
|
106
|
+
return Buffer.from(arrayBuffer)
|
|
107
|
+
},
|
|
108
|
+
toBase64: async () => {
|
|
109
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
|
110
|
+
return Buffer.from(arrayBuffer).toString('base64')
|
|
111
|
+
},
|
|
112
|
+
toURL: async () => {
|
|
113
|
+
return url
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const UserId = event.author.id
|
|
117
|
+
const UserKey = useUserHashKey({
|
|
118
|
+
Platform: platform,
|
|
119
|
+
UserId: UserId
|
|
120
|
+
})
|
|
121
|
+
// 定义消
|
|
122
|
+
const e = {
|
|
123
|
+
name: 'private.message.create',
|
|
124
|
+
// 事件类型
|
|
125
|
+
Platform: platform,
|
|
126
|
+
// 用户Id
|
|
127
|
+
UserId: event.author.id,
|
|
128
|
+
UserKey,
|
|
129
|
+
UserAvatar: UserAvatar,
|
|
130
|
+
IsMaster: isMaster,
|
|
131
|
+
IsBot: false,
|
|
132
|
+
// 格式化数据
|
|
133
|
+
MessageId: event.id,
|
|
134
|
+
MessageText: event.content?.trim(),
|
|
135
|
+
CreateAt: Date.now(),
|
|
136
|
+
OpenId: event.author.user_openid,
|
|
137
|
+
//
|
|
138
|
+
tag: 'C2C_MESSAGE_CREATE',
|
|
139
|
+
value: null
|
|
140
|
+
}
|
|
141
|
+
// 当访问的时候获取
|
|
142
|
+
Object.defineProperty(e, 'value', {
|
|
143
|
+
get() {
|
|
144
|
+
return event
|
|
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)
|
|
199
364
|
}
|
|
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;
|
|
365
|
+
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
366
|
+
return await C2C_MESSAGE_CREATE(client, event, val)
|
|
223
367
|
}
|
|
224
|
-
|
|
225
|
-
|
|
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;
|
|
368
|
+
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
369
|
+
return await DIRECT_MESSAGE_CREATE(client, event, val)
|
|
258
370
|
}
|
|
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
|
-
});
|
|
371
|
+
if (tag == 'AT_MESSAGE_CREATE') {
|
|
372
|
+
return await AT_MESSAGE_CREATE(client, event, val)
|
|
278
373
|
}
|
|
279
|
-
|
|
280
|
-
|
|
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;
|
|
374
|
+
if (tag == 'MESSAGE_CREATE') {
|
|
375
|
+
return await AT_MESSAGE_CREATE(client, event, val)
|
|
309
376
|
}
|
|
310
|
-
|
|
311
|
-
|
|
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;
|
|
377
|
+
if (tag == 'MESSAGE_CREATE') {
|
|
378
|
+
return await MESSAGE_CREATE(client, event, val)
|
|
342
379
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
}
|
|
380
|
+
} catch (error) {
|
|
381
|
+
return [error]
|
|
382
|
+
}
|
|
383
|
+
return []
|
|
384
|
+
},
|
|
385
|
+
mention: async e => {
|
|
386
|
+
const event = e.value
|
|
387
|
+
const tag = e.tag
|
|
388
|
+
// const event = e.value
|
|
389
|
+
const Metions = []
|
|
390
|
+
// group
|
|
391
|
+
if (tag == 'GROUP_AT_MESSAGE_CREATE' || 'C2C_MESSAGE_CREATE') return Metions
|
|
392
|
+
// guild
|
|
393
|
+
if (event.mentions) {
|
|
394
|
+
const mentions = e.value['mentions']
|
|
395
|
+
// 艾特消息处理
|
|
396
|
+
const MessageMention =
|
|
397
|
+
mentions.map(item => {
|
|
398
|
+
return {
|
|
399
|
+
UserId: item.id,
|
|
400
|
+
IsMaster: false,
|
|
401
|
+
UserName: item.username,
|
|
402
|
+
IsBot: item.bot,
|
|
403
|
+
UserKey: useUserHashKey({
|
|
404
|
+
Platform: 'qq-guild-bot',
|
|
405
|
+
UserId: item.id
|
|
406
|
+
})
|
|
412
407
|
}
|
|
413
|
-
|
|
408
|
+
}) ?? []
|
|
409
|
+
return MessageMention
|
|
410
|
+
} else {
|
|
411
|
+
return Metions
|
|
412
|
+
}
|
|
414
413
|
}
|
|
415
|
-
|
|
416
|
-
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
})
|
|
417
418
|
|
|
418
|
-
export { client, index as default, platform }
|
|
419
|
+
export { client, index as default, platform }
|