@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.
Files changed (40) hide show
  1. package/dist/assets/index.css +476 -0
  2. package/dist/assets/index.js +11032 -0
  3. package/dist/index.html +15 -0
  4. package/lib/api.d.ts +971 -843
  5. package/lib/api.js +1172 -1156
  6. package/lib/client.d.ts +22 -22
  7. package/lib/client.js +201 -217
  8. package/lib/config.js +2 -2
  9. package/lib/desktop.d.ts +2 -2
  10. package/lib/desktop.js +60 -59
  11. package/lib/from.js +27 -34
  12. package/lib/index.d.ts +7 -7
  13. package/lib/index.js +406 -405
  14. package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -35
  15. package/lib/message/C2C_MESSAGE_CREATE.d.ts +9 -9
  16. package/lib/message/CHANNEL_CREATE.d.ts +15 -15
  17. package/lib/message/CHANNEL_DELETE.d.ts +15 -15
  18. package/lib/message/CHANNEL_UPDATE.d.ts +15 -15
  19. package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -29
  20. package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -17
  21. package/lib/message/ERROR.d.ts +2 -2
  22. package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +10 -10
  23. package/lib/message/GUILD_CREATE.d.ts +15 -15
  24. package/lib/message/GUILD_DELETE.d.ts +15 -15
  25. package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -14
  26. package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -14
  27. package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -14
  28. package/lib/message/GUILD_UPDATE.d.ts +15 -15
  29. package/lib/message/INTERACTION_CREATE.d.ts +2 -2
  30. package/lib/message/MESSAGE_CREATE.d.ts +2 -2
  31. package/lib/message/MESSAGE_DELETE.d.ts +2 -2
  32. package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -13
  33. package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -13
  34. package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -15
  35. package/lib/message/READY.d.ts +6 -6
  36. package/lib/message.d.ts +46 -46
  37. package/lib/send/index.js +230 -192
  38. package/lib/typing.d.ts +62 -54
  39. package/lib/webhook.js +46 -48
  40. 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 { GROUP_AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, AT_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
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
- 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;
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
- const platform = 'qq-bot';
22
+ }
23
+ )
24
+ const platform = 'qq-bot'
16
25
  var index = defineBot(() => {
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;
137
- }
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;
163
- }
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;
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
- 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;
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
- // 循环删除文本中的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;
374
+ if (tag == 'MESSAGE_CREATE') {
375
+ return await AT_MESSAGE_CREATE(client, event, val)
309
376
  }
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;
377
+ if (tag == 'MESSAGE_CREATE') {
378
+ return await MESSAGE_CREATE(client, event, val)
342
379
  }
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
- }
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 }