@alemonjs/qq-bot 2.1.0-alpha.16 → 2.1.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -30
- package/lib/desktop.js +3 -2
- package/lib/hook.js +6 -6
- package/lib/index.d.ts +2 -2
- package/lib/index.js +33 -4
- package/lib/index.webhook.js +1 -1
- package/lib/index.websoket.js +10 -15
- package/lib/register.js +68 -36
- package/lib/sdk/api.d.ts +17 -51
- package/lib/sdk/api.js +143 -172
- package/lib/sdk/client.webhook.js +19 -14
- package/lib/sdk/client.websoket.js +38 -38
- package/lib/sdk/instance.js +109 -0
- package/lib/sdk/webhook.secret.js +5 -3
- package/lib/sends.js +68 -73
- package/package.json +1 -1
package/lib/sends.js
CHANGED
|
@@ -21,8 +21,8 @@ const createButtonsData = (rows) => {
|
|
|
21
21
|
return {
|
|
22
22
|
id: String(id),
|
|
23
23
|
render_data: {
|
|
24
|
-
label: typeof value
|
|
25
|
-
visited_label: typeof value
|
|
24
|
+
label: typeof value === 'object' ? value.title : value,
|
|
25
|
+
visited_label: typeof value === 'object' ? value.label : value,
|
|
26
26
|
style: 0
|
|
27
27
|
},
|
|
28
28
|
action: {
|
|
@@ -245,44 +245,42 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
245
245
|
}
|
|
246
246
|
try {
|
|
247
247
|
const content = val
|
|
248
|
-
.filter(item => item.type
|
|
248
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
249
249
|
.map(item => {
|
|
250
|
-
if (item.type
|
|
250
|
+
if (item.type === 'Link') {
|
|
251
251
|
return `[${item.value}](${item?.options?.link})`;
|
|
252
252
|
}
|
|
253
|
-
else if (item.type
|
|
254
|
-
if (item.value
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return ``;
|
|
259
|
-
}
|
|
260
|
-
if (item.options?.belong == 'user') {
|
|
253
|
+
else if (item.type === 'Mention') {
|
|
254
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
255
|
+
return '';
|
|
256
|
+
}
|
|
257
|
+
if (item.options?.belong === 'user') {
|
|
261
258
|
return `<@${item.value}>`;
|
|
262
259
|
}
|
|
263
260
|
return '';
|
|
264
261
|
}
|
|
265
|
-
else if (item.type
|
|
262
|
+
else if (item.type === 'Text') {
|
|
266
263
|
return item.value;
|
|
267
264
|
}
|
|
268
265
|
})
|
|
269
266
|
.join('');
|
|
270
|
-
const images = val.filter(item => item.type
|
|
267
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
271
268
|
if (images && images.length > 0) {
|
|
272
269
|
let url = '';
|
|
273
270
|
for (let i = 0; i < images.length; i++) {
|
|
274
271
|
// 已经处理。
|
|
275
|
-
if (url)
|
|
272
|
+
if (url) {
|
|
276
273
|
break;
|
|
274
|
+
}
|
|
277
275
|
const item = images[i];
|
|
278
|
-
if (item.type
|
|
276
|
+
if (item.type === 'ImageURL') {
|
|
279
277
|
url = item.value;
|
|
280
278
|
}
|
|
281
279
|
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
282
280
|
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
283
|
-
const file_data = item.type
|
|
281
|
+
const file_data = item.type === 'ImageFile' ? getFileBase64() : item.value;
|
|
284
282
|
const file_info = await client
|
|
285
|
-
.
|
|
283
|
+
.postRichMediaByGroup(event.ChannelId, {
|
|
286
284
|
file_type: 1,
|
|
287
285
|
file_data: file_data
|
|
288
286
|
})
|
|
@@ -306,10 +304,10 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
306
304
|
})
|
|
307
305
|
];
|
|
308
306
|
}
|
|
309
|
-
const mdAndButtons = val.filter(item => item.type
|
|
307
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
310
308
|
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
311
309
|
const params = {};
|
|
312
|
-
mdAndButtons.forEach(
|
|
310
|
+
mdAndButtons.forEach(item => {
|
|
313
311
|
if (item.type === 'ButtonTemplate') {
|
|
314
312
|
const template_id = item?.value;
|
|
315
313
|
if (template_id) {
|
|
@@ -345,10 +343,10 @@ const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
345
343
|
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
346
344
|
}
|
|
347
345
|
// ark
|
|
348
|
-
const ark = val.filter(item => item.type
|
|
346
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
349
347
|
if (ark && ark.length > 0) {
|
|
350
348
|
const params = {};
|
|
351
|
-
ark.forEach(
|
|
349
|
+
ark.forEach(item => {
|
|
352
350
|
if (item.type === 'Ark.Card') {
|
|
353
351
|
const arkData = createArkCardData(item.value);
|
|
354
352
|
params['ark'] = arkData;
|
|
@@ -405,44 +403,42 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
405
403
|
}
|
|
406
404
|
try {
|
|
407
405
|
const content = val
|
|
408
|
-
.filter(item => item.type
|
|
406
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
409
407
|
.map(item => {
|
|
410
|
-
if (item.type
|
|
408
|
+
if (item.type === 'Link') {
|
|
411
409
|
return `[${item.value}](${item?.options?.link})`;
|
|
412
410
|
}
|
|
413
|
-
else if (item.type
|
|
414
|
-
if (item.value
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
return ``;
|
|
419
|
-
}
|
|
420
|
-
if (item.options?.belong == 'user') {
|
|
411
|
+
else if (item.type === 'Mention') {
|
|
412
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
413
|
+
return '';
|
|
414
|
+
}
|
|
415
|
+
if (item.options?.belong === 'user') {
|
|
421
416
|
return `<@${item.value}>`;
|
|
422
417
|
}
|
|
423
418
|
return '';
|
|
424
419
|
}
|
|
425
|
-
else if (item.type
|
|
420
|
+
else if (item.type === 'Text') {
|
|
426
421
|
return item.value;
|
|
427
422
|
}
|
|
428
423
|
})
|
|
429
424
|
.join('');
|
|
430
|
-
const images = val.filter(item => item.type
|
|
425
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
431
426
|
if (images && images.length > 0) {
|
|
432
427
|
let url = '';
|
|
433
428
|
for (let i = 0; i < images.length; i++) {
|
|
434
429
|
// 已经处理。
|
|
435
|
-
if (url)
|
|
430
|
+
if (url) {
|
|
436
431
|
break;
|
|
432
|
+
}
|
|
437
433
|
const item = images[i];
|
|
438
|
-
if (item.type
|
|
434
|
+
if (item.type === 'ImageURL') {
|
|
439
435
|
url = item.value;
|
|
440
436
|
}
|
|
441
437
|
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
442
438
|
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
443
|
-
const file_data = item.type
|
|
439
|
+
const file_data = item.type === 'ImageFile' ? getFileBase64() : item.value;
|
|
444
440
|
const file_info = await client
|
|
445
|
-
.
|
|
441
|
+
.postRichMediaByUser(event.UserId, {
|
|
446
442
|
file_type: 1,
|
|
447
443
|
file_data: file_data
|
|
448
444
|
})
|
|
@@ -466,10 +462,10 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
466
462
|
})
|
|
467
463
|
];
|
|
468
464
|
}
|
|
469
|
-
const mdAndButtons = val.filter(item => item.type
|
|
465
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
470
466
|
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
471
467
|
const params = {};
|
|
472
|
-
mdAndButtons.forEach(
|
|
468
|
+
mdAndButtons.forEach(item => {
|
|
473
469
|
if (item.type === 'ButtonTemplate') {
|
|
474
470
|
const template_id = item?.value;
|
|
475
471
|
if (template_id) {
|
|
@@ -505,10 +501,10 @@ const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
505
501
|
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
506
502
|
}
|
|
507
503
|
// ark
|
|
508
|
-
const ark = val.filter(item => item.type
|
|
504
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
509
505
|
if (ark && ark.length > 0) {
|
|
510
506
|
const params = {};
|
|
511
|
-
ark.forEach(
|
|
507
|
+
ark.forEach(item => {
|
|
512
508
|
if (item.type === 'Ark.Card') {
|
|
513
509
|
const arkData = createArkCardData(item.value);
|
|
514
510
|
params['ark'] = arkData;
|
|
@@ -565,26 +561,27 @@ const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
565
561
|
}
|
|
566
562
|
try {
|
|
567
563
|
const content = val
|
|
568
|
-
.filter(item => item.type
|
|
564
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
569
565
|
.map(item => {
|
|
570
|
-
if (item.type
|
|
566
|
+
if (item.type === 'Link') {
|
|
571
567
|
return `[${item.value}](${item?.options?.link})`;
|
|
572
568
|
}
|
|
573
|
-
if (item.type
|
|
569
|
+
if (item.type === 'Text') {
|
|
574
570
|
return item.value;
|
|
575
571
|
}
|
|
576
572
|
return '';
|
|
577
573
|
})
|
|
578
574
|
.join('');
|
|
579
|
-
const images = val.filter(item => item.type
|
|
575
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
580
576
|
if (images && images.length > 0) {
|
|
581
577
|
let imageBuffer = null;
|
|
582
578
|
for (let i = 0; i < images.length; i++) {
|
|
583
579
|
// 已经处理。
|
|
584
|
-
if (imageBuffer)
|
|
580
|
+
if (imageBuffer) {
|
|
585
581
|
break;
|
|
582
|
+
}
|
|
586
583
|
const item = images[i];
|
|
587
|
-
if (item.value
|
|
584
|
+
if (item.value === 'ImageURL') {
|
|
588
585
|
// 请求得到buffer
|
|
589
586
|
const data = await axios
|
|
590
587
|
.get(item.value, {
|
|
@@ -594,7 +591,7 @@ const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
594
591
|
imageBuffer = data;
|
|
595
592
|
}
|
|
596
593
|
else {
|
|
597
|
-
const file_data = item.type
|
|
594
|
+
const file_data = item.type === 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
598
595
|
imageBuffer = file_data;
|
|
599
596
|
}
|
|
600
597
|
}
|
|
@@ -604,10 +601,10 @@ const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
604
601
|
}, imageBuffer);
|
|
605
602
|
return [createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id })];
|
|
606
603
|
}
|
|
607
|
-
const mdAndButtons = val.filter(item => item.type
|
|
604
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
608
605
|
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
609
606
|
const params = {};
|
|
610
|
-
mdAndButtons.forEach(
|
|
607
|
+
mdAndButtons.forEach(item => {
|
|
611
608
|
if (item.type === 'ButtonTemplate') {
|
|
612
609
|
const template_id = item?.value;
|
|
613
610
|
if (template_id) {
|
|
@@ -642,10 +639,10 @@ const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
|
642
639
|
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
643
640
|
}
|
|
644
641
|
// ark
|
|
645
|
-
const ark = val.filter(item => item.type
|
|
642
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
646
643
|
if (ark && ark.length > 0) {
|
|
647
644
|
const params = {};
|
|
648
|
-
ark.forEach(
|
|
645
|
+
ark.forEach(item => {
|
|
649
646
|
if (item.type === 'Ark.Card') {
|
|
650
647
|
const arkData = createArkCardData(item.value);
|
|
651
648
|
params['ark'] = arkData;
|
|
@@ -695,40 +692,38 @@ const MESSAGE_CREATE = async (client, event, val) => {
|
|
|
695
692
|
}
|
|
696
693
|
try {
|
|
697
694
|
const content = val
|
|
698
|
-
.filter(item => item.type
|
|
695
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
699
696
|
.map(item => {
|
|
700
|
-
if (item.type
|
|
697
|
+
if (item.type === 'Link') {
|
|
701
698
|
return `[${item.value}](${item?.options?.link})`;
|
|
702
699
|
}
|
|
703
|
-
if (item.type
|
|
704
|
-
if (item.value
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
return `@everyone`;
|
|
709
|
-
}
|
|
710
|
-
if (item.options?.belong == 'user') {
|
|
700
|
+
if (item.type === 'Mention') {
|
|
701
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
702
|
+
return '@everyone';
|
|
703
|
+
}
|
|
704
|
+
if (item.options?.belong === 'user') {
|
|
711
705
|
return `<@!${item.value}>`;
|
|
712
706
|
}
|
|
713
|
-
else if (item.options?.belong
|
|
707
|
+
else if (item.options?.belong === 'channel') {
|
|
714
708
|
return `<#${item.value}>`;
|
|
715
709
|
}
|
|
716
710
|
return '';
|
|
717
711
|
}
|
|
718
|
-
else if (item.type
|
|
712
|
+
else if (item.type === 'Text') {
|
|
719
713
|
return item.value;
|
|
720
714
|
}
|
|
721
715
|
})
|
|
722
716
|
.join('');
|
|
723
|
-
const images = val.filter(item => item.type
|
|
717
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
724
718
|
if (images && images.length > 0) {
|
|
725
719
|
let imageBuffer = null;
|
|
726
720
|
for (let i = 0; i < images.length; i++) {
|
|
727
721
|
// 已经处理。
|
|
728
|
-
if (imageBuffer)
|
|
722
|
+
if (imageBuffer) {
|
|
729
723
|
break;
|
|
724
|
+
}
|
|
730
725
|
const item = images[i];
|
|
731
|
-
if (item.value
|
|
726
|
+
if (item.value === 'ImageURL') {
|
|
732
727
|
// 请求得到buffer
|
|
733
728
|
const data = await axios
|
|
734
729
|
.get(item.value, {
|
|
@@ -738,7 +733,7 @@ const MESSAGE_CREATE = async (client, event, val) => {
|
|
|
738
733
|
imageBuffer = data;
|
|
739
734
|
}
|
|
740
735
|
else {
|
|
741
|
-
const file_data = item.type
|
|
736
|
+
const file_data = item.type === 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
742
737
|
imageBuffer = file_data;
|
|
743
738
|
}
|
|
744
739
|
}
|
|
@@ -748,10 +743,10 @@ const MESSAGE_CREATE = async (client, event, val) => {
|
|
|
748
743
|
}, imageBuffer);
|
|
749
744
|
return [createResult(ResultCode.Ok, 'client.postImage', { id: res?.id })];
|
|
750
745
|
}
|
|
751
|
-
const mdAndButtons = val.filter(item => item.type
|
|
746
|
+
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
752
747
|
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
753
748
|
const params = {};
|
|
754
|
-
mdAndButtons.forEach(
|
|
749
|
+
mdAndButtons.forEach(item => {
|
|
755
750
|
if (item.type === 'ButtonTemplate') {
|
|
756
751
|
const template_id = item?.value;
|
|
757
752
|
if (template_id) {
|
|
@@ -786,10 +781,10 @@ const MESSAGE_CREATE = async (client, event, val) => {
|
|
|
786
781
|
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
787
782
|
}
|
|
788
783
|
// ark
|
|
789
|
-
const ark = val.filter(item => item.type
|
|
784
|
+
const ark = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
790
785
|
if (ark && ark.length > 0) {
|
|
791
786
|
const params = {};
|
|
792
|
-
ark.forEach(
|
|
787
|
+
ark.forEach(item => {
|
|
793
788
|
if (item.type === 'Ark.Card') {
|
|
794
789
|
const arkData = createArkCardData(item.value);
|
|
795
790
|
params['ark'] = arkData;
|