@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/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 == 'object' ? value.title : value,
25
- visited_label: typeof value == 'object' ? value.label : 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 == 'Mention' || item.type == 'Text' || item.type == 'Link')
248
+ .filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
249
249
  .map(item => {
250
- if (item.type == 'Link') {
250
+ if (item.type === 'Link') {
251
251
  return `[${item.value}](${item?.options?.link})`;
252
252
  }
253
- else if (item.type == 'Mention') {
254
- if (item.value == 'everyone' ||
255
- item.value == 'all' ||
256
- item.value == '' ||
257
- typeof item.value != 'string') {
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 == 'Text') {
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 == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
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 == 'ImageURL') {
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 == 'ImageFile' ? getFileBase64() : item.value;
281
+ const file_data = item.type === 'ImageFile' ? getFileBase64() : item.value;
284
282
  const file_info = await client
285
- .postRichMediaById(event.ChannelId, {
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 == 'Markdown' || item.type == 'BT.group' || item.type === 'ButtonTemplate');
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(async (item) => {
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 == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
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(async (item) => {
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 == 'Mention' || item.type == 'Text' || item.type == 'Link')
406
+ .filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
409
407
  .map(item => {
410
- if (item.type == 'Link') {
408
+ if (item.type === 'Link') {
411
409
  return `[${item.value}](${item?.options?.link})`;
412
410
  }
413
- else if (item.type == 'Mention') {
414
- if (item.value == 'everyone' ||
415
- item.value == 'all' ||
416
- item.value == '' ||
417
- typeof item.value != 'string') {
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 == 'Text') {
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 == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
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 == 'ImageURL') {
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 == 'ImageFile' ? getFileBase64() : item.value;
439
+ const file_data = item.type === 'ImageFile' ? getFileBase64() : item.value;
444
440
  const file_info = await client
445
- .postRichMediaById(event.UserId, {
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 == 'Markdown' || item.type == 'BT.group' || item.type === 'ButtonTemplate');
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(async (item) => {
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 == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
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(async (item) => {
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 == 'Mention' || item.type == 'Text' || item.type == 'Link')
564
+ .filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
569
565
  .map(item => {
570
- if (item.type == 'Link') {
566
+ if (item.type === 'Link') {
571
567
  return `[${item.value}](${item?.options?.link})`;
572
568
  }
573
- if (item.type == 'Text') {
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 == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
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 == 'ImageURL') {
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 == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
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 == 'Markdown' || item.type == 'BT.group' || item.type === 'ButtonTemplate');
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(async (item) => {
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 == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
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(async (item) => {
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 == 'Mention' || item.type == 'Text' || item.type == 'Link')
695
+ .filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
699
696
  .map(item => {
700
- if (item.type == 'Link') {
697
+ if (item.type === 'Link') {
701
698
  return `[${item.value}](${item?.options?.link})`;
702
699
  }
703
- if (item.type == 'Mention') {
704
- if (item.value == 'everyone' ||
705
- item.value == 'all' ||
706
- item.value == '' ||
707
- typeof item.value != 'string') {
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 == 'channel') {
707
+ else if (item.options?.belong === 'channel') {
714
708
  return `<#${item.value}>`;
715
709
  }
716
710
  return '';
717
711
  }
718
- else if (item.type == 'Text') {
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 == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
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 == 'ImageURL') {
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 == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
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 == 'Markdown' || item.type == 'BT.group' || item.type === 'ButtonTemplate');
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(async (item) => {
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 == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
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(async (item) => {
787
+ ark.forEach(item => {
793
788
  if (item.type === 'Ark.Card') {
794
789
  const arkData = createArkCardData(item.value);
795
790
  params['ark'] = arkData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.0-alpha.16",
3
+ "version": "2.1.0-alpha.18",
4
4
  "description": "阿柠檬qqbot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",