@alemonjs/qq-bot 0.0.19 → 0.0.21
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/index.d.ts +2 -2
- package/lib/index.group.js +6 -203
- package/lib/index.guild.js +25 -298
- package/lib/index.js +42 -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/client.websoket.js +221 -0
- package/lib/sdk/intents.js +12 -23
- package/lib/send/index.js +417 -366
- package/lib/sends.js +576 -0
- 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/sdk/{websoket.group.js → client.websoket.group.js} +0 -0
- /package/lib/sdk/{websoket.guild.js → client.websoket.guild.js} +0 -0
package/lib/sends.js
ADDED
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
const createButtonsData = (rows) => {
|
|
5
|
+
let id = 0;
|
|
6
|
+
const data = {
|
|
7
|
+
rows: rows.map(row => {
|
|
8
|
+
const val = row.value;
|
|
9
|
+
return {
|
|
10
|
+
buttons: val.map(button => {
|
|
11
|
+
const value = button.value;
|
|
12
|
+
const options = button.options;
|
|
13
|
+
id++;
|
|
14
|
+
return {
|
|
15
|
+
id: String(id),
|
|
16
|
+
render_data: {
|
|
17
|
+
label: typeof value == 'object' ? value.title : value,
|
|
18
|
+
visited_label: typeof value == 'object' ? value.label : value,
|
|
19
|
+
// tudo
|
|
20
|
+
style: 0
|
|
21
|
+
},
|
|
22
|
+
action: {
|
|
23
|
+
// 0 link 1 callback , 2 command
|
|
24
|
+
type: typeof options.data === 'object' ? 1 : options?.isLink ? 0 : 2,
|
|
25
|
+
permission: {
|
|
26
|
+
// 所有人
|
|
27
|
+
type: 2
|
|
28
|
+
// "specify_role_ids": ["1", "2", "3"]
|
|
29
|
+
},
|
|
30
|
+
// "click_limit": 10,
|
|
31
|
+
unsupport_tips: options?.toolTip ?? '',
|
|
32
|
+
data: options?.data ?? '',
|
|
33
|
+
// reply: true,
|
|
34
|
+
at_bot_show_channel_list: options.showList ?? false,
|
|
35
|
+
enter: options?.autoEnter ?? false
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
const createArkCardData = (value) => {
|
|
45
|
+
return {
|
|
46
|
+
"template_id": 24,
|
|
47
|
+
"kv": [
|
|
48
|
+
{
|
|
49
|
+
"key": "#DESC#",
|
|
50
|
+
"value": value.decs
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"key": "#PROMPT#",
|
|
54
|
+
"value": value.prompt
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"key": "#TITLE#",
|
|
58
|
+
"value": value.title
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"key": "#METADESC#",
|
|
62
|
+
"value": value.metadecs
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"key": "#IMG#",
|
|
66
|
+
"value": value.cover
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"key": "#LINK#",
|
|
70
|
+
"value": value.link
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"key": "#SUBTITLE#",
|
|
74
|
+
"value": value.subtitle
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const createArkBigCardData = (value) => {
|
|
80
|
+
return {
|
|
81
|
+
"template_id": 37,
|
|
82
|
+
"kv": [
|
|
83
|
+
{
|
|
84
|
+
"key": "#PROMPT#",
|
|
85
|
+
"value": value.prompt
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"key": "#METATITLE#",
|
|
89
|
+
"value": value.title
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"key": "#METASUBTITLE#",
|
|
93
|
+
"value": value.subtitle
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"key": "#METACOVER#",
|
|
97
|
+
"value": value.cover
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"key": "#METAURL#",
|
|
101
|
+
"value": value.link
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const createArkList = (value) => {
|
|
107
|
+
const [tip, data] = value;
|
|
108
|
+
return {
|
|
109
|
+
"template_id": 23,
|
|
110
|
+
"kv": [
|
|
111
|
+
{
|
|
112
|
+
"key": "#DESC#",
|
|
113
|
+
"value": tip.value.desc
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"key": "#PROMPT#",
|
|
117
|
+
"value": tip.value.prompt
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"key": "#LIST#",
|
|
121
|
+
"obj": data.value.map(item => {
|
|
122
|
+
const value = item.value;
|
|
123
|
+
if (typeof value === 'string') {
|
|
124
|
+
return {
|
|
125
|
+
"obj_kv": [
|
|
126
|
+
{
|
|
127
|
+
"key": "desc",
|
|
128
|
+
"value": value
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
"obj_kv": [
|
|
135
|
+
{
|
|
136
|
+
"key": "desc",
|
|
137
|
+
"value": value.title
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"key": "link",
|
|
141
|
+
"value": value.link
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
};
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
151
|
+
const content = val
|
|
152
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
153
|
+
.map(item => {
|
|
154
|
+
if (item.type == 'Link') {
|
|
155
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
156
|
+
}
|
|
157
|
+
else if (item.type == 'Mention') {
|
|
158
|
+
if (item.value == 'everyone' ||
|
|
159
|
+
item.value == 'all' ||
|
|
160
|
+
item.value == '' ||
|
|
161
|
+
typeof item.value != 'string') {
|
|
162
|
+
return ``;
|
|
163
|
+
}
|
|
164
|
+
if (item.options?.belong == 'user') {
|
|
165
|
+
return `<@${item.value}>`;
|
|
166
|
+
}
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
else if (item.type == 'Text') {
|
|
170
|
+
return item.value;
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
.join('');
|
|
174
|
+
if (content) {
|
|
175
|
+
return Promise.all([content].map(item => client.groupOpenMessages(event.GuildId, {
|
|
176
|
+
content: item,
|
|
177
|
+
msg_id: event.MessageId,
|
|
178
|
+
msg_type: 0,
|
|
179
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
180
|
+
})));
|
|
181
|
+
}
|
|
182
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
183
|
+
if (images && images.length > 0) {
|
|
184
|
+
return Promise.all(images.map(async (item) => {
|
|
185
|
+
if (item.type == 'ImageURL') {
|
|
186
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
187
|
+
content: '',
|
|
188
|
+
media: {
|
|
189
|
+
file_info: item.value
|
|
190
|
+
},
|
|
191
|
+
msg_id: event.MessageId,
|
|
192
|
+
msg_type: 7,
|
|
193
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const file_data = item.type == 'ImageFile'
|
|
197
|
+
? readFileSync(item.value, 'base64')
|
|
198
|
+
: item.value.toString('base64');
|
|
199
|
+
const file_info = await client
|
|
200
|
+
.postRichMediaByGroup(event.GuildId, {
|
|
201
|
+
file_type: 1,
|
|
202
|
+
file_data: file_data
|
|
203
|
+
})
|
|
204
|
+
.then(res => res?.file_info);
|
|
205
|
+
if (!file_info)
|
|
206
|
+
return Promise.resolve(null);
|
|
207
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
208
|
+
content: '',
|
|
209
|
+
media: {
|
|
210
|
+
file_info
|
|
211
|
+
},
|
|
212
|
+
msg_id: event.MessageId,
|
|
213
|
+
msg_type: 7,
|
|
214
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
215
|
+
});
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
// buttons
|
|
219
|
+
const buttons = val.filter(item => item.type == 'BT.group');
|
|
220
|
+
if (buttons && buttons.length > 0) {
|
|
221
|
+
return Promise.all(buttons.map(async (item) => {
|
|
222
|
+
const template_id = item?.options?.template_id;
|
|
223
|
+
if (template_id) {
|
|
224
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
225
|
+
content: '',
|
|
226
|
+
msg_id: event.MessageId,
|
|
227
|
+
keyboard: {
|
|
228
|
+
id: template_id
|
|
229
|
+
},
|
|
230
|
+
msg_type: 2,
|
|
231
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const rows = item.value;
|
|
235
|
+
// 构造成按钮
|
|
236
|
+
const data = createButtonsData(rows);
|
|
237
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
238
|
+
content: '',
|
|
239
|
+
msg_id: event.MessageId,
|
|
240
|
+
keyboard: {
|
|
241
|
+
content: data
|
|
242
|
+
},
|
|
243
|
+
msg_type: 2,
|
|
244
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
245
|
+
});
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
// ark
|
|
249
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
250
|
+
if (ark && ark.length > 0) {
|
|
251
|
+
return Promise.all(ark.map(async (item) => {
|
|
252
|
+
if (item.type === 'Ark.Card') {
|
|
253
|
+
const arkData = createArkCardData(item.value);
|
|
254
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
255
|
+
msg_id: event.MessageId,
|
|
256
|
+
ark: arkData,
|
|
257
|
+
msg_type: 3,
|
|
258
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (item.type === 'Ark.BigCard') {
|
|
262
|
+
const arkData = createArkBigCardData(item.value);
|
|
263
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
264
|
+
msg_id: event.MessageId,
|
|
265
|
+
ark: arkData,
|
|
266
|
+
msg_type: 3,
|
|
267
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
const arkData = createArkList(item.value);
|
|
271
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
272
|
+
msg_id: event.MessageId,
|
|
273
|
+
ark: arkData,
|
|
274
|
+
msg_type: 3,
|
|
275
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
276
|
+
});
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
return Promise.all([]);
|
|
280
|
+
};
|
|
281
|
+
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
282
|
+
const content = val
|
|
283
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
284
|
+
.map(item => {
|
|
285
|
+
if (item.type == 'Link') {
|
|
286
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
287
|
+
}
|
|
288
|
+
else if (item.type == 'Text') {
|
|
289
|
+
return item.value;
|
|
290
|
+
}
|
|
291
|
+
return '';
|
|
292
|
+
})
|
|
293
|
+
.join('');
|
|
294
|
+
if (content) {
|
|
295
|
+
return Promise.all([content].map(item => client.usersOpenMessages(event.OpenId, {
|
|
296
|
+
content: item,
|
|
297
|
+
msg_id: event.MessageId,
|
|
298
|
+
msg_type: 0,
|
|
299
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
300
|
+
})));
|
|
301
|
+
}
|
|
302
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
303
|
+
if (images && images.length > 0) {
|
|
304
|
+
return Promise.all(images.map(async (item) => {
|
|
305
|
+
if (item.type == 'ImageURL') {
|
|
306
|
+
return client.usersOpenMessages(event.OpenId, {
|
|
307
|
+
content: '',
|
|
308
|
+
media: {
|
|
309
|
+
file_info: item.value
|
|
310
|
+
},
|
|
311
|
+
msg_id: event.MessageId,
|
|
312
|
+
msg_type: 7,
|
|
313
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
const file_data = item.type == 'ImageFile'
|
|
317
|
+
? readFileSync(item.value, 'base64')
|
|
318
|
+
: item.value.toString('base64');
|
|
319
|
+
const file_info = await client
|
|
320
|
+
.postRichMediaByUsers(event.OpenId, {
|
|
321
|
+
file_type: 1,
|
|
322
|
+
file_data: file_data
|
|
323
|
+
})
|
|
324
|
+
.then(res => res?.file_info);
|
|
325
|
+
if (!file_info)
|
|
326
|
+
return Promise.resolve(null);
|
|
327
|
+
return client.usersOpenMessages(event.OpenId, {
|
|
328
|
+
content: '',
|
|
329
|
+
media: {
|
|
330
|
+
file_info
|
|
331
|
+
},
|
|
332
|
+
msg_id: event.MessageId,
|
|
333
|
+
msg_type: 7,
|
|
334
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
335
|
+
});
|
|
336
|
+
}));
|
|
337
|
+
}
|
|
338
|
+
// buttons
|
|
339
|
+
const buttons = val.filter(item => item.type == 'BT.group');
|
|
340
|
+
if (buttons && buttons.length > 0) {
|
|
341
|
+
return Promise.all(buttons.map(async (item) => {
|
|
342
|
+
const template_id = item?.options?.template_id;
|
|
343
|
+
if (template_id) {
|
|
344
|
+
return client.usersOpenMessages(event.GuildId, {
|
|
345
|
+
content: '',
|
|
346
|
+
msg_id: event.MessageId,
|
|
347
|
+
keyboard: {
|
|
348
|
+
id: template_id
|
|
349
|
+
},
|
|
350
|
+
msg_type: 2,
|
|
351
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
const rows = item.value;
|
|
355
|
+
// 看看是否是模板id的
|
|
356
|
+
rows.map(row => {
|
|
357
|
+
return row;
|
|
358
|
+
});
|
|
359
|
+
// 构造成按钮
|
|
360
|
+
const data = createButtonsData(rows);
|
|
361
|
+
return client.usersOpenMessages(event.GuildId, {
|
|
362
|
+
content: '',
|
|
363
|
+
msg_id: event.MessageId,
|
|
364
|
+
keyboard: {
|
|
365
|
+
content: data
|
|
366
|
+
},
|
|
367
|
+
msg_type: 2,
|
|
368
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
369
|
+
});
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
// ark
|
|
373
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
374
|
+
if (ark && ark.length > 0) {
|
|
375
|
+
return Promise.all(ark.map(async (item) => {
|
|
376
|
+
if (item.type === 'Ark.Card') {
|
|
377
|
+
const arkData = createArkCardData(item.value);
|
|
378
|
+
return client.usersOpenMessages(event.GuildId, {
|
|
379
|
+
msg_id: event.MessageId,
|
|
380
|
+
ark: arkData,
|
|
381
|
+
msg_type: 3,
|
|
382
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
if (item.type === 'Ark.BigCard') {
|
|
386
|
+
const arkData = createArkBigCardData(item.value);
|
|
387
|
+
return client.usersOpenMessages(event.GuildId, {
|
|
388
|
+
msg_id: event.MessageId,
|
|
389
|
+
ark: arkData,
|
|
390
|
+
msg_type: 3,
|
|
391
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
const arkData = createArkList(item.value);
|
|
395
|
+
return client.usersOpenMessages(event.GuildId, {
|
|
396
|
+
msg_id: event.MessageId,
|
|
397
|
+
ark: arkData,
|
|
398
|
+
msg_type: 3,
|
|
399
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
400
|
+
});
|
|
401
|
+
}));
|
|
402
|
+
}
|
|
403
|
+
return Promise.all([]);
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* 频道私聊
|
|
407
|
+
* @param client
|
|
408
|
+
* @param event
|
|
409
|
+
* @param val
|
|
410
|
+
* @returns
|
|
411
|
+
*/
|
|
412
|
+
const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
413
|
+
const content = val
|
|
414
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
415
|
+
.map(item => {
|
|
416
|
+
if (item.type == 'Link') {
|
|
417
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
418
|
+
}
|
|
419
|
+
if (item.type == 'Text') {
|
|
420
|
+
return item.value;
|
|
421
|
+
}
|
|
422
|
+
return '';
|
|
423
|
+
})
|
|
424
|
+
.join('');
|
|
425
|
+
if (content) {
|
|
426
|
+
return Promise.all([content].map(item => client.dmsMessage(event.OpenId, {
|
|
427
|
+
content: item,
|
|
428
|
+
msg_id: event.MessageId
|
|
429
|
+
})));
|
|
430
|
+
}
|
|
431
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
432
|
+
if (images) {
|
|
433
|
+
return Promise.all(images.map(async (item) => {
|
|
434
|
+
if (item.value == 'ImageURL') {
|
|
435
|
+
// 请求得到buffer
|
|
436
|
+
const data = await axios
|
|
437
|
+
.get(item.value, {
|
|
438
|
+
responseType: 'arraybuffer'
|
|
439
|
+
})
|
|
440
|
+
.then(res => res.data);
|
|
441
|
+
return client.postDirectImage(event.OpenId, {
|
|
442
|
+
msg_id: event.MessageId,
|
|
443
|
+
image: data
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
447
|
+
return client.postDirectImage(event.OpenId, {
|
|
448
|
+
msg_id: event.MessageId,
|
|
449
|
+
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
450
|
+
});
|
|
451
|
+
}));
|
|
452
|
+
}
|
|
453
|
+
return [];
|
|
454
|
+
};
|
|
455
|
+
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
456
|
+
const content = val
|
|
457
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
458
|
+
.map(item => {
|
|
459
|
+
if (item.type == 'Link') {
|
|
460
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
461
|
+
}
|
|
462
|
+
if (item.type == 'Mention') {
|
|
463
|
+
if (item.value == 'everyone' ||
|
|
464
|
+
item.value == 'all' ||
|
|
465
|
+
item.value == '' ||
|
|
466
|
+
typeof item.value != 'string') {
|
|
467
|
+
return `@everyone`;
|
|
468
|
+
}
|
|
469
|
+
if (item.options?.belong == 'user') {
|
|
470
|
+
return `<@!${item.value}>`;
|
|
471
|
+
}
|
|
472
|
+
else if (item.options?.belong == 'channel') {
|
|
473
|
+
return `<#${item.value}>`;
|
|
474
|
+
}
|
|
475
|
+
return '';
|
|
476
|
+
}
|
|
477
|
+
else if (item.type == 'Text') {
|
|
478
|
+
return item.value;
|
|
479
|
+
}
|
|
480
|
+
})
|
|
481
|
+
.join('');
|
|
482
|
+
if (content) {
|
|
483
|
+
return Promise.all([content].map(item => client.channelsMessagesPost(event.ChannelId, {
|
|
484
|
+
content: item,
|
|
485
|
+
msg_id: event.MessageId
|
|
486
|
+
})));
|
|
487
|
+
}
|
|
488
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
489
|
+
if (images && images.length > 0) {
|
|
490
|
+
return Promise.all(images.map(async (item) => {
|
|
491
|
+
if (item.value == 'ImageURL') {
|
|
492
|
+
// 请求得到buffer
|
|
493
|
+
const data = await axios
|
|
494
|
+
.get(item.value, {
|
|
495
|
+
responseType: 'arraybuffer'
|
|
496
|
+
})
|
|
497
|
+
.then(res => res.data);
|
|
498
|
+
return client.postImage(event.ChannelId, {
|
|
499
|
+
msg_id: event.MessageId,
|
|
500
|
+
image: data
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
504
|
+
return client.postImage(event.ChannelId, {
|
|
505
|
+
msg_id: event.MessageId,
|
|
506
|
+
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
507
|
+
});
|
|
508
|
+
}));
|
|
509
|
+
}
|
|
510
|
+
return Promise.all([]);
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
*
|
|
514
|
+
* @param event
|
|
515
|
+
* @param val
|
|
516
|
+
* @returns
|
|
517
|
+
*/
|
|
518
|
+
const MESSAGE_CREATE = (client, event, val) => {
|
|
519
|
+
const content = val
|
|
520
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
521
|
+
.map(item => {
|
|
522
|
+
if (item.type == 'Link') {
|
|
523
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
524
|
+
}
|
|
525
|
+
if (item.type == 'Mention') {
|
|
526
|
+
if (item.value == 'everyone' ||
|
|
527
|
+
item.value == 'all' ||
|
|
528
|
+
item.value == '' ||
|
|
529
|
+
typeof item.value != 'string') {
|
|
530
|
+
return `@everyone`;
|
|
531
|
+
}
|
|
532
|
+
if (item.options?.belong == 'user') {
|
|
533
|
+
return `<@!${item.value}>`;
|
|
534
|
+
}
|
|
535
|
+
else if (item.options?.belong == 'channel') {
|
|
536
|
+
return `<#${item.value}>`;
|
|
537
|
+
}
|
|
538
|
+
return '';
|
|
539
|
+
}
|
|
540
|
+
else if (item.type == 'Text') {
|
|
541
|
+
return item.value;
|
|
542
|
+
}
|
|
543
|
+
})
|
|
544
|
+
.join('');
|
|
545
|
+
if (content) {
|
|
546
|
+
return Promise.all([content].map(item => client.channelsMessagesPost(event.ChannelId, {
|
|
547
|
+
content: item,
|
|
548
|
+
msg_id: event.MessageId
|
|
549
|
+
})));
|
|
550
|
+
}
|
|
551
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
552
|
+
if (images && images.length > 0) {
|
|
553
|
+
return Promise.all(images.map(async (item) => {
|
|
554
|
+
if (item.value == 'ImageURL') {
|
|
555
|
+
// 请求得到buffer
|
|
556
|
+
const data = await axios
|
|
557
|
+
.get(item.value, {
|
|
558
|
+
responseType: 'arraybuffer'
|
|
559
|
+
})
|
|
560
|
+
.then(res => res.data);
|
|
561
|
+
return client.postImage(event.ChannelId, {
|
|
562
|
+
msg_id: event.MessageId,
|
|
563
|
+
image: data
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value;
|
|
567
|
+
return client.postImage(event.ChannelId, {
|
|
568
|
+
msg_id: event.MessageId,
|
|
569
|
+
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
570
|
+
});
|
|
571
|
+
}));
|
|
572
|
+
}
|
|
573
|
+
return Promise.all([]);
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
export { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE };
|