@alemonjs/qq-bot 2.1.0-alpha.5 → 2.1.0-alpha.6
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/lib/sends.js +278 -206
- package/package.json +1 -1
package/lib/sends.js
CHANGED
|
@@ -149,7 +149,8 @@ const createArkList = (value) => {
|
|
|
149
149
|
};
|
|
150
150
|
// 数据md转为文本
|
|
151
151
|
const createMarkdownText = (data) => {
|
|
152
|
-
const content = data
|
|
152
|
+
const content = data
|
|
153
|
+
.map(mdItem => {
|
|
153
154
|
if (mdItem.type === 'MD.title') {
|
|
154
155
|
// \n
|
|
155
156
|
return `# ${mdItem.value}\n`;
|
|
@@ -199,7 +200,7 @@ const createMarkdownText = (data) => {
|
|
|
199
200
|
return ` `;
|
|
200
201
|
}
|
|
201
202
|
else if (mdItem.type === 'MD.list') {
|
|
202
|
-
const listStr = mdItem.value.map(
|
|
203
|
+
const listStr = mdItem.value.map(listItem => {
|
|
203
204
|
// 有序
|
|
204
205
|
if (typeof listItem.value === 'object') {
|
|
205
206
|
return `\n${listItem.value.index}. ${listItem.value.text}`;
|
|
@@ -210,7 +211,8 @@ const createMarkdownText = (data) => {
|
|
|
210
211
|
return `${listStr}\n`;
|
|
211
212
|
}
|
|
212
213
|
return;
|
|
213
|
-
})
|
|
214
|
+
})
|
|
215
|
+
.join('');
|
|
214
216
|
return content;
|
|
215
217
|
};
|
|
216
218
|
/**
|
|
@@ -245,17 +247,6 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
245
247
|
}
|
|
246
248
|
})
|
|
247
249
|
.join('');
|
|
248
|
-
if (content) {
|
|
249
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
250
|
-
content: content,
|
|
251
|
-
msg_id: event.MessageId,
|
|
252
|
-
msg_type: 0,
|
|
253
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
254
|
-
});
|
|
255
|
-
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
256
|
-
id: res.id
|
|
257
|
-
})];
|
|
258
|
-
}
|
|
259
250
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
260
251
|
if (images && images.length > 0) {
|
|
261
252
|
let url = '';
|
|
@@ -281,7 +272,7 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
281
272
|
}
|
|
282
273
|
});
|
|
283
274
|
const res = await client.groupOpenMessages(event.GuildId, {
|
|
284
|
-
content:
|
|
275
|
+
content: content,
|
|
285
276
|
media: {
|
|
286
277
|
file_info: url
|
|
287
278
|
},
|
|
@@ -327,18 +318,13 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
327
318
|
}
|
|
328
319
|
});
|
|
329
320
|
const res = await client.groupOpenMessages(event.GuildId, {
|
|
330
|
-
content:
|
|
331
|
-
markdown: {
|
|
332
|
-
content: content,
|
|
333
|
-
},
|
|
321
|
+
content: content,
|
|
334
322
|
msg_id: event.MessageId,
|
|
335
323
|
msg_type: 2,
|
|
336
324
|
msg_seq: client.getMessageSeq(event.MessageId),
|
|
337
325
|
...params
|
|
338
326
|
});
|
|
339
|
-
return [
|
|
340
|
-
createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })
|
|
341
|
-
];
|
|
327
|
+
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
342
328
|
}
|
|
343
329
|
// ark
|
|
344
330
|
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
@@ -359,6 +345,7 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
359
345
|
}
|
|
360
346
|
});
|
|
361
347
|
const res = await client.groupOpenMessages(event.GuildId, {
|
|
348
|
+
content: content,
|
|
362
349
|
msg_id: event.MessageId,
|
|
363
350
|
msg_type: 3,
|
|
364
351
|
msg_seq: client.getMessageSeq(event.MessageId),
|
|
@@ -366,11 +353,22 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
366
353
|
});
|
|
367
354
|
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
368
355
|
}
|
|
356
|
+
if (content) {
|
|
357
|
+
const res = await client.groupOpenMessages(event.GuildId, {
|
|
358
|
+
content: content,
|
|
359
|
+
msg_id: event.MessageId,
|
|
360
|
+
msg_type: 0,
|
|
361
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
362
|
+
});
|
|
363
|
+
return [
|
|
364
|
+
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
365
|
+
id: res.id
|
|
366
|
+
})
|
|
367
|
+
];
|
|
368
|
+
}
|
|
369
369
|
}
|
|
370
370
|
catch (err) {
|
|
371
|
-
return [
|
|
372
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
373
|
-
];
|
|
371
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
374
372
|
}
|
|
375
373
|
return [];
|
|
376
374
|
};
|
|
@@ -406,17 +404,6 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
406
404
|
}
|
|
407
405
|
})
|
|
408
406
|
.join('');
|
|
409
|
-
if (content) {
|
|
410
|
-
const res = await client.usersOpenMessages(event.OpenId, {
|
|
411
|
-
content: content,
|
|
412
|
-
msg_id: event.MessageId,
|
|
413
|
-
msg_type: 0,
|
|
414
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
415
|
-
});
|
|
416
|
-
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
417
|
-
id: res.id
|
|
418
|
-
})];
|
|
419
|
-
}
|
|
420
407
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
421
408
|
if (images && images.length > 0) {
|
|
422
409
|
let url = '';
|
|
@@ -442,7 +429,7 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
442
429
|
}
|
|
443
430
|
});
|
|
444
431
|
const res = await client.usersOpenMessages(event.OpenId, {
|
|
445
|
-
content:
|
|
432
|
+
content: content,
|
|
446
433
|
media: {
|
|
447
434
|
file_info: url
|
|
448
435
|
},
|
|
@@ -488,15 +475,13 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
488
475
|
}
|
|
489
476
|
});
|
|
490
477
|
const res = await client.usersOpenMessages(event.OpenId, {
|
|
491
|
-
content:
|
|
478
|
+
content: content,
|
|
492
479
|
msg_id: event.MessageId,
|
|
493
480
|
msg_type: 2,
|
|
494
481
|
msg_seq: client.getMessageSeq(event.MessageId),
|
|
495
482
|
...params
|
|
496
483
|
});
|
|
497
|
-
return [
|
|
498
|
-
createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })
|
|
499
|
-
];
|
|
484
|
+
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
500
485
|
}
|
|
501
486
|
// ark
|
|
502
487
|
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
@@ -517,6 +502,7 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
517
502
|
}
|
|
518
503
|
});
|
|
519
504
|
const res = await client.usersOpenMessages(event.OpenId, {
|
|
505
|
+
content: content,
|
|
520
506
|
msg_id: event.MessageId,
|
|
521
507
|
msg_type: 3,
|
|
522
508
|
msg_seq: client.getMessageSeq(event.MessageId),
|
|
@@ -524,11 +510,22 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
524
510
|
});
|
|
525
511
|
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
526
512
|
}
|
|
513
|
+
if (content) {
|
|
514
|
+
const res = await client.usersOpenMessages(event.OpenId, {
|
|
515
|
+
content: content,
|
|
516
|
+
msg_id: event.MessageId,
|
|
517
|
+
msg_type: 0,
|
|
518
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
519
|
+
});
|
|
520
|
+
return [
|
|
521
|
+
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
522
|
+
id: res.id
|
|
523
|
+
})
|
|
524
|
+
];
|
|
525
|
+
}
|
|
527
526
|
}
|
|
528
527
|
catch (err) {
|
|
529
|
-
return [
|
|
530
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
531
|
-
];
|
|
528
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
532
529
|
}
|
|
533
530
|
return [];
|
|
534
531
|
};
|
|
@@ -539,195 +536,270 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
539
536
|
* @param val
|
|
540
537
|
* @returns
|
|
541
538
|
*/
|
|
542
|
-
const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
return '';
|
|
553
|
-
})
|
|
554
|
-
.join('');
|
|
555
|
-
if (content) {
|
|
556
|
-
return Promise.all([content].map(async (item) => {
|
|
557
|
-
const res = await client.dmsMessage(event.OpenId, {
|
|
558
|
-
content: item,
|
|
559
|
-
msg_id: event.MessageId
|
|
560
|
-
});
|
|
561
|
-
return createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id });
|
|
562
|
-
})).catch(err => [
|
|
563
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
564
|
-
]);
|
|
565
|
-
}
|
|
566
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
567
|
-
if (images && images.length > 0) {
|
|
568
|
-
return Promise.all(images.map(async (item) => {
|
|
569
|
-
if (item.value == 'ImageURL') {
|
|
570
|
-
// 请求得到buffer
|
|
571
|
-
const data = await axios
|
|
572
|
-
.get(item.value, {
|
|
573
|
-
responseType: 'arraybuffer'
|
|
574
|
-
})
|
|
575
|
-
.then(res => res?.data);
|
|
576
|
-
const res = await client.postDirectImage(event.OpenId, {
|
|
577
|
-
msg_id: event.MessageId,
|
|
578
|
-
image: data
|
|
579
|
-
});
|
|
580
|
-
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
539
|
+
const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
540
|
+
try {
|
|
541
|
+
const content = val
|
|
542
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
543
|
+
.map(item => {
|
|
544
|
+
if (item.type == 'Link') {
|
|
545
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
546
|
+
}
|
|
547
|
+
if (item.type == 'Text') {
|
|
548
|
+
return item.value;
|
|
581
549
|
}
|
|
582
|
-
|
|
550
|
+
return '';
|
|
551
|
+
})
|
|
552
|
+
.join('');
|
|
553
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
554
|
+
if (images && images.length > 0) {
|
|
555
|
+
let imageBuffer = null;
|
|
556
|
+
images.forEach(async (item) => {
|
|
557
|
+
// 已经处理。
|
|
558
|
+
if (imageBuffer)
|
|
559
|
+
return;
|
|
560
|
+
if (item.value == 'ImageURL') {
|
|
561
|
+
// 请求得到buffer
|
|
562
|
+
const data = await axios
|
|
563
|
+
.get(item.value, {
|
|
564
|
+
responseType: 'arraybuffer'
|
|
565
|
+
})
|
|
566
|
+
.then(res => res?.data);
|
|
567
|
+
imageBuffer = data;
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
571
|
+
imageBuffer = file_data;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
583
574
|
const res = await client.postDirectImage(event.OpenId, {
|
|
584
575
|
msg_id: event.MessageId,
|
|
585
|
-
|
|
576
|
+
content: content,
|
|
577
|
+
image: imageBuffer
|
|
586
578
|
});
|
|
587
|
-
return createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id });
|
|
588
|
-
})).catch(err => [
|
|
589
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
590
|
-
]);
|
|
591
|
-
}
|
|
592
|
-
return Promise.all([]);
|
|
593
|
-
};
|
|
594
|
-
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
595
|
-
const content = val
|
|
596
|
-
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
597
|
-
.map(item => {
|
|
598
|
-
if (item.type == 'Link') {
|
|
599
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
579
|
+
return [createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id })];
|
|
600
580
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
581
|
+
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
582
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
583
|
+
const params = {};
|
|
584
|
+
mdAndButtons.forEach(async (item) => {
|
|
585
|
+
if (item.type === 'BT.group') {
|
|
586
|
+
// 如果是按钮,获取参数
|
|
587
|
+
const template_id = item?.options?.template_id;
|
|
588
|
+
if (template_id) {
|
|
589
|
+
params['keyboard'] = {
|
|
590
|
+
id: template_id
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
const rows = item.value;
|
|
595
|
+
// 构造成按钮
|
|
596
|
+
const content = createButtonsData(rows);
|
|
597
|
+
params['keyboard'] = {
|
|
598
|
+
content: content
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
else if (item.type === 'Markdown') {
|
|
603
|
+
// 如果是markdown,获取内容
|
|
604
|
+
const content = createMarkdownText(item.value);
|
|
605
|
+
if (content) {
|
|
606
|
+
params['markdown'] = {
|
|
607
|
+
content: content
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
const res = await client.dmsMessage(event.OpenId, {
|
|
613
|
+
content: '',
|
|
614
|
+
msg_id: event.MessageId,
|
|
615
|
+
...params
|
|
616
|
+
});
|
|
617
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
615
618
|
}
|
|
616
|
-
|
|
617
|
-
|
|
619
|
+
// ark
|
|
620
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
621
|
+
if (ark && ark.length > 0) {
|
|
622
|
+
const params = {};
|
|
623
|
+
ark.forEach(async (item) => {
|
|
624
|
+
if (item.type === 'Ark.Card') {
|
|
625
|
+
const arkData = createArkCardData(item.value);
|
|
626
|
+
params['ark'] = arkData;
|
|
627
|
+
}
|
|
628
|
+
else if (item.type === 'Ark.BigCard') {
|
|
629
|
+
const arkData = createArkBigCardData(item.value);
|
|
630
|
+
params['ark'] = arkData;
|
|
631
|
+
}
|
|
632
|
+
else if (item.type === 'Ark.list') {
|
|
633
|
+
const arkData = createArkList(item.value);
|
|
634
|
+
params['ark'] = arkData;
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
const res = await client.dmsMessage(event.OpenId, {
|
|
638
|
+
content: content,
|
|
639
|
+
msg_id: event.MessageId,
|
|
640
|
+
...params
|
|
641
|
+
});
|
|
642
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
618
643
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
return Promise.all([content].map(async (item) => {
|
|
623
|
-
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
624
|
-
content: item,
|
|
644
|
+
if (content) {
|
|
645
|
+
const res = await client.dmsMessage(event.OpenId, {
|
|
646
|
+
content: content,
|
|
625
647
|
msg_id: event.MessageId
|
|
626
648
|
});
|
|
627
|
-
return createResult(ResultCode.Ok, 'client.
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
]);
|
|
649
|
+
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id })];
|
|
650
|
+
}
|
|
651
|
+
return [];
|
|
631
652
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
return Promise.all(images.map(async (item) => {
|
|
635
|
-
if (item.value == 'ImageURL') {
|
|
636
|
-
// 请求得到buffer
|
|
637
|
-
const data = await axios
|
|
638
|
-
.get(item.value, {
|
|
639
|
-
responseType: 'arraybuffer'
|
|
640
|
-
})
|
|
641
|
-
.then(res => res.data);
|
|
642
|
-
const res = await client.postImage(event.ChannelId, {
|
|
643
|
-
msg_id: event.MessageId,
|
|
644
|
-
image: data
|
|
645
|
-
});
|
|
646
|
-
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
647
|
-
}
|
|
648
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
649
|
-
const res = await client.postImage(event.ChannelId, {
|
|
650
|
-
msg_id: event.MessageId,
|
|
651
|
-
image: file_data
|
|
652
|
-
});
|
|
653
|
-
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
654
|
-
})).catch(err => [
|
|
655
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
656
|
-
]);
|
|
653
|
+
catch (err) {
|
|
654
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
657
655
|
}
|
|
658
|
-
return Promise.all([]);
|
|
659
656
|
};
|
|
660
657
|
/**
|
|
661
|
-
*
|
|
658
|
+
* 频道公聊
|
|
662
659
|
* @param event
|
|
663
660
|
* @param val
|
|
664
661
|
* @returns
|
|
665
662
|
*/
|
|
666
|
-
const MESSAGE_CREATE = (client, event, val) => {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if (item.type == 'Mention') {
|
|
674
|
-
if (item.value == 'everyone' ||
|
|
675
|
-
item.value == 'all' ||
|
|
676
|
-
item.value == '' ||
|
|
677
|
-
typeof item.value != 'string') {
|
|
678
|
-
return `@everyone`;
|
|
663
|
+
const MESSAGE_CREATE = async (client, event, val) => {
|
|
664
|
+
try {
|
|
665
|
+
const content = val
|
|
666
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
667
|
+
.map(item => {
|
|
668
|
+
if (item.type == 'Link') {
|
|
669
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
679
670
|
}
|
|
680
|
-
if (item.
|
|
681
|
-
|
|
671
|
+
if (item.type == 'Mention') {
|
|
672
|
+
if (item.value == 'everyone' ||
|
|
673
|
+
item.value == 'all' ||
|
|
674
|
+
item.value == '' ||
|
|
675
|
+
typeof item.value != 'string') {
|
|
676
|
+
return `@everyone`;
|
|
677
|
+
}
|
|
678
|
+
if (item.options?.belong == 'user') {
|
|
679
|
+
return `<@!${item.value}>`;
|
|
680
|
+
}
|
|
681
|
+
else if (item.options?.belong == 'channel') {
|
|
682
|
+
return `<#${item.value}>`;
|
|
683
|
+
}
|
|
684
|
+
return '';
|
|
682
685
|
}
|
|
683
|
-
else if (item.
|
|
684
|
-
return
|
|
686
|
+
else if (item.type == 'Text') {
|
|
687
|
+
return item.value;
|
|
685
688
|
}
|
|
686
|
-
|
|
689
|
+
})
|
|
690
|
+
.join('');
|
|
691
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
692
|
+
if (images && images.length > 0) {
|
|
693
|
+
let dataBuffer = null;
|
|
694
|
+
images.forEach(async (item) => {
|
|
695
|
+
if (dataBuffer)
|
|
696
|
+
return; // 已经处理。
|
|
697
|
+
if (item.value == 'ImageURL') {
|
|
698
|
+
// 请求得到buffer
|
|
699
|
+
const data = await axios
|
|
700
|
+
.get(item.value, {
|
|
701
|
+
responseType: 'arraybuffer'
|
|
702
|
+
})
|
|
703
|
+
.then(res => res.data);
|
|
704
|
+
dataBuffer = data;
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
708
|
+
dataBuffer = file_data;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
const res = await client.postImage(event.ChannelId, {
|
|
712
|
+
msg_id: event.MessageId,
|
|
713
|
+
content: content,
|
|
714
|
+
image: dataBuffer
|
|
715
|
+
});
|
|
716
|
+
return [createResult(ResultCode.Ok, 'client.postImage', { id: res?.id })];
|
|
717
|
+
}
|
|
718
|
+
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
719
|
+
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
720
|
+
const params = {};
|
|
721
|
+
mdAndButtons.forEach(async (item) => {
|
|
722
|
+
if (item.type === 'BT.group') {
|
|
723
|
+
// 如果是按钮,获取参数
|
|
724
|
+
const template_id = item?.options?.template_id;
|
|
725
|
+
if (template_id) {
|
|
726
|
+
params['keyboard'] = {
|
|
727
|
+
id: template_id
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
const rows = item.value;
|
|
732
|
+
// 构造成按钮
|
|
733
|
+
const content = createButtonsData(rows);
|
|
734
|
+
params['keyboard'] = {
|
|
735
|
+
content: content
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
else if (item.type === 'Markdown') {
|
|
740
|
+
// 如果是markdown,获取内容
|
|
741
|
+
const content = createMarkdownText(item.value);
|
|
742
|
+
if (content) {
|
|
743
|
+
params['markdown'] = {
|
|
744
|
+
content: content
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
750
|
+
content: '',
|
|
751
|
+
msg_id: event.MessageId,
|
|
752
|
+
...params
|
|
753
|
+
});
|
|
754
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
687
755
|
}
|
|
688
|
-
|
|
689
|
-
|
|
756
|
+
// ark
|
|
757
|
+
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
758
|
+
if (ark && ark.length > 0) {
|
|
759
|
+
const params = {};
|
|
760
|
+
ark.forEach(async (item) => {
|
|
761
|
+
if (item.type === 'Ark.Card') {
|
|
762
|
+
const arkData = createArkCardData(item.value);
|
|
763
|
+
params['ark'] = arkData;
|
|
764
|
+
}
|
|
765
|
+
else if (item.type === 'Ark.BigCard') {
|
|
766
|
+
const arkData = createArkBigCardData(item.value);
|
|
767
|
+
params['ark'] = arkData;
|
|
768
|
+
}
|
|
769
|
+
else if (item.type === 'Ark.list') {
|
|
770
|
+
const arkData = createArkList(item.value);
|
|
771
|
+
params['ark'] = arkData;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
const res = await client.channelsMessagesPost(event.GuildId, {
|
|
775
|
+
content: content,
|
|
776
|
+
msg_id: event.MessageId,
|
|
777
|
+
...params
|
|
778
|
+
});
|
|
779
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
690
780
|
}
|
|
691
|
-
|
|
692
|
-
.join('');
|
|
693
|
-
if (content) {
|
|
694
|
-
return Promise.all([content].map(async (item) => {
|
|
781
|
+
if (content) {
|
|
695
782
|
const res = await client.channelsMessagesPost(event.ChannelId, {
|
|
696
|
-
content:
|
|
783
|
+
content: content,
|
|
697
784
|
msg_id: event.MessageId
|
|
698
785
|
});
|
|
699
|
-
return createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id });
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
]);
|
|
786
|
+
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id })];
|
|
787
|
+
}
|
|
788
|
+
return [];
|
|
703
789
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
return Promise.all(images.map(async (item) => {
|
|
707
|
-
if (item.value == 'ImageURL') {
|
|
708
|
-
// 请求得到buffer
|
|
709
|
-
const data = await axios
|
|
710
|
-
.get(item.value, {
|
|
711
|
-
responseType: 'arraybuffer'
|
|
712
|
-
})
|
|
713
|
-
.then(res => res.data);
|
|
714
|
-
const res = await client.postImage(event.ChannelId, {
|
|
715
|
-
msg_id: event.MessageId,
|
|
716
|
-
image: data
|
|
717
|
-
});
|
|
718
|
-
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
719
|
-
}
|
|
720
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
721
|
-
const res = await client.postImage(event.ChannelId, {
|
|
722
|
-
msg_id: event.MessageId,
|
|
723
|
-
image: file_data
|
|
724
|
-
});
|
|
725
|
-
return createResult(ResultCode.Ok, 'client.postImage', { id: res?.id });
|
|
726
|
-
})).catch(err => [
|
|
727
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
728
|
-
]);
|
|
790
|
+
catch (err) {
|
|
791
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
729
792
|
}
|
|
730
|
-
|
|
793
|
+
};
|
|
794
|
+
/**
|
|
795
|
+
* 频道公聊 @
|
|
796
|
+
* @param client
|
|
797
|
+
* @param event
|
|
798
|
+
* @param val
|
|
799
|
+
* @returns
|
|
800
|
+
*/
|
|
801
|
+
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
802
|
+
return MESSAGE_CREATE(client, event, val);
|
|
731
803
|
};
|
|
732
804
|
|
|
733
805
|
export { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE };
|