oicq-icalingua-plus-plus 1.24.3 → 1.24.5

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.
@@ -603,6 +603,7 @@ async function offNTPicDown(user_id, fileResId) {
603
603
  */
604
604
  async function checkImgUrl(url) {
605
605
  const data = await axios.get(url, {
606
+ timeout: 5000,
606
607
  headers: { Range: 'bytes=0-1' }
607
608
  }).then(res => res.data).catch(() => null);
608
609
  return !!data;
@@ -711,6 +712,8 @@ async function getGroupNTPicRkey() {
711
712
  const rsp = await getGroupNTPicURL.call(this, {
712
713
  3: 1,
713
714
  });
715
+ if (!rsp)
716
+ return "&rkey=CAQSKDOc_jvbthUjZrMxJG2jNZ-rIWue47Q3PGKb_GWljzyvOUZOv0-EVao";
714
717
  return '&rkey=' + rsp.match(/&rkey=([^&]+)/)[1];
715
718
  }
716
719
 
@@ -722,6 +725,8 @@ async function getOffNTPicRkey() {
722
725
  const rsp = await getOffNTPicURL.call(this, {
723
726
  3: 1,
724
727
  });
728
+ if (!rsp)
729
+ return "&rkey=CAQSKDOc_jvbthUjZrMxJG2jNZ-rIWue47Q3PGKb_GWljzyvOUZOv0-EVao";
725
730
  return '&rkey=' + rsp.match(/&rkey=([^&]+)/)[1];
726
731
  }
727
732
 
@@ -10,7 +10,7 @@ const pb = require("../algo/pb");
10
10
  const face = require("./face");
11
11
  const { getGroupMsgs } = require("./history");
12
12
  const { int32ip2str } = require("../service");
13
- const { buildImageFileParam, groupNTPicDown, offNTPicDown, checkImgUrl, getOffNTPicURL, getGroupNTPicURL } = require("./image");
13
+ const { buildImageFileParam, groupNTPicDown, offNTPicDown, checkImgUrl, getOffNTPicURL, getGroupNTPicURL, getOffNTPicRkey } = require("./image");
14
14
  const { Gfs, getC2CFileUrl } = require("./file");
15
15
  const { getVideoUrl, getPttUrl } = require("./ptt");
16
16
  const { genC2CMessageId, genGroupMessageId, timestamp, parseFunString, code2uin, genRandom, unzip } = require("../common");
@@ -369,7 +369,7 @@ class Parser {
369
369
  case 46: //markdown button
370
370
  break;
371
371
  case 48: //ntv2richmedia
372
- const imgData = await this.parseNTImgElem(type, elem);
372
+ const imgData = await this.parseNTImgElem(type, elem[2], elem[3]);
373
373
  if (imgData) {
374
374
  msg.type = "image";
375
375
  msg.data = imgData;
@@ -467,7 +467,7 @@ class Parser {
467
467
  } else if (elem[1] === 20) { //json only for mobileqq
468
468
  await this.parseExclusiveElem(51, elem[2]);
469
469
  } else if (elem[1] == 48) { //ntv2richmedia
470
- await this.parsePartialElem(48, elem[2]);
470
+ await this.parsePartialElem(48, elem);
471
471
  if (elem[2] && elem[2][1] && elem[2][1][2] && elem[2][1][2][1] && elem[2][1][2][3])
472
472
  this.imgprefix = "https://" + String(elem[2][1][2][3]) + String(elem[2][1][2][1]);
473
473
  } else if (elem[1] == 45) { //markdown
@@ -492,12 +492,11 @@ class Parser {
492
492
  * @param {number} businessType
493
493
  */
494
494
  async parseNTImgElem(type, elem, businessType = 0) {
495
+ if (![0, 10, 20].includes(businessType)) return null;
495
496
  const data = { };
496
497
  if (!elem[2] || !elem[2][1]) return null;
497
- //const dm = businessType ? businessType === 10 : !!elem[2][1][11];
498
- const dm = !!elem[2][1][11];
499
- const extra = dm ? elem[2][1][11] : elem[2][1][12];
500
- if (!extra) return null;
498
+ const dm = businessType ? businessType === 10 : !!elem[2][1][11];
499
+ const extra = elem[2][1][11] || elem[2][1][12] || { 30: "" };
501
500
  const ntPath = String(extra[30] || "");
502
501
 
503
502
  const imgInfo = elem[1][1];
@@ -532,6 +531,15 @@ class Parser {
532
531
  data.url = newURL;
533
532
  }
534
533
  }
534
+ // QQNT 图片容错,某些 QQNT 的机器人会发出 appid 异常的图片
535
+ data.url = data.url.replace("multimedia.nt.qq.com.cn", "gchat.qpic.cn"); //这个host下面似乎不检查rkey有效期以及appid是否对应
536
+ if (!(await checkImgUrl(data.url))) {
537
+ const appidInURL = data.url.match(/appid=(\d+)/);
538
+ if (appidInURL) {
539
+ const newAppid = appidInURL[1] === "1406" ? "1407" : "1406";
540
+ data.url = data.url.replace(appidInURL[0], `appid=${newAppid}`);
541
+ }
542
+ }
535
543
  return data;
536
544
  }
537
545
 
@@ -564,6 +572,7 @@ class Parser {
564
572
  return data;
565
573
  }
566
574
 
575
+ let ntFileId = null;
567
576
  if (dm) { //私图
568
577
  if (ntPath && ntPath.startsWith("/download") && ntPath.includes("rkey=")) {
569
578
  data.url = "https://gchat.qpic.cn" + ntPath + "&spec=0";
@@ -573,6 +582,7 @@ class Parser {
573
582
  data.url = `https://gchat.qpic.cn/gchatpic_new/0/0-0-${md5.toHex().toUpperCase()}/0`
574
583
  }
575
584
  if (!(await checkImgUrl(data.url))) {
585
+ ntFileId = data.url.match(/&fileid=([^&]+)/);
576
586
  // 图片地址失效,尝试发包获取
577
587
  if (elem[23]) { //QQNT 私聊合并转发到群聊图
578
588
  data.url = await groupNTPicDown.call(this.c, this.gid || 284840486, elem[23], md5);
@@ -589,6 +599,7 @@ class Parser {
589
599
  data.url = `https://gchat.qpic.cn/gchatpic_new/0/0-0-${md5.toHex().toUpperCase()}/0`
590
600
  }
591
601
  if (!(await checkImgUrl(data.url))) {
602
+ ntFileId = data.url.match(/&fileid=([^&]+)/);
592
603
  // 图片地址失效,尝试发包获取
593
604
  if (fileid) { //纯群聊图片
594
605
  data.url = await groupNTPicDown.call(this.c, this.gid || 284840486, fileid, md5);
@@ -597,6 +608,15 @@ class Parser {
597
608
  }
598
609
  }
599
610
  }
611
+ // QQNT 图片容错,某些 QQNT 的机器人会发出 appid 异常的图片
612
+ data.url = data.url.replace("multimedia.nt.qq.com.cn", "gchat.qpic.cn");
613
+ if (ntFileId && !(await checkImgUrl(data.url))) {
614
+ const offNTPicRkey = await getOffNTPicRkey.call(this.c);
615
+ data.url = `https://gchat.qpic.cn/download?appid=1406&fileid=${ntFileId[1]}${offNTPicRkey}}&spec=0`;
616
+ if (!(await checkImgUrl(data.url))) {
617
+ data.url = `https://gchat.qpic.cn/download?appid=1407&fileid=${ntFileId[1]}${offNTPicRkey}}&spec=0`;
618
+ }
619
+ }
600
620
  return data;
601
621
  }
602
622
 
@@ -260,7 +260,10 @@ async function getVideoUrl(elem) {
260
260
  });
261
261
  const blob = await this.sendUni("PttCenterSvr.ShortVideoDownReq", body);
262
262
  const rsp = pb.decode(blob)[4][9];
263
- return String(Array.isArray(rsp[10]) ? rsp[10][0] : rsp[10]) + String(rsp[11]);
263
+ const url = new URL(String(Array.isArray(rsp[10]) ? rsp[10][0] : rsp[10]) + String(rsp[11]));
264
+ url.host = url.pathname === "/download" ? "multimedia.nt.qq.com.cn" : "grouptalk.c2c.qq.com";
265
+ url.protocol = "https";
266
+ return url.toString();
264
267
  }
265
268
 
266
269
  // Thanks @5ec1cff
@@ -314,7 +317,7 @@ async function getVideoUrl(elem) {
314
317
  });
315
318
  const blob = await this.sendUni("PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_DOWNLOAD-1200", body);
316
319
  const url = new URL(pb.decode(blob)[14][30][50].toString());
317
- url.host = "grouptalk.c2c.qq.com";
320
+ url.host = url.pathname === "/download" ? "multimedia.nt.qq.com.cn" : "grouptalk.c2c.qq.com";
318
321
  url.protocol = "https";
319
322
  return url.toString();
320
323
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "oicq-icalingua-plus-plus",
3
3
  "app_name": "oicq-icalingua-plus-plus",
4
- "version": "1.24.3",
5
- "app_version": "1.24.3",
6
- "upday": "2024/04/23",
4
+ "version": "1.24.5",
5
+ "app_version": "1.24.5",
6
+ "upday": "2024/05/01",
7
7
  "protocol_version": "v11",
8
8
  "description": "oicq(https://github.com/takayama-lily/oicq) v1 for Icalingua++",
9
9
  "main": "index.js",