@ryuu-reinzz/haruka-lib 4.0.0 → 4.0.2
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/main/socket.js +178 -105
- package/package.json +1 -1
package/main/socket.js
CHANGED
|
@@ -51,9 +51,9 @@ import Sticker from './sticker-engine/index.js';
|
|
|
51
51
|
const __filename = fileURLToPath(import.meta.url);
|
|
52
52
|
const __dirname = dirname(__filename);
|
|
53
53
|
let Button,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
ButtonV2,
|
|
55
|
+
Carousel,
|
|
56
|
+
AIRich;
|
|
57
57
|
/**
|
|
58
58
|
* @param {import('baileys').WASocket} socket
|
|
59
59
|
*/
|
|
@@ -1547,111 +1547,180 @@ function addProperty(socket, baileys) {
|
|
|
1547
1547
|
text,
|
|
1548
1548
|
contextInfo = {}
|
|
1549
1549
|
} = content;
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
let buffer;
|
|
1559
|
-
let favBuffer;
|
|
1560
|
-
try {
|
|
1561
|
-
if (!contextInfo?.previewThumbnail) return await sendMessage(jid, content, options);
|
|
1562
|
-
|
|
1563
|
-
if (Buffer.isBuffer(thumbnail)) {
|
|
1564
|
-
buffer = thumbnail;
|
|
1565
|
-
} else if (thumbnail.url) {
|
|
1566
|
-
let response = await fetch(thumbnail.url);
|
|
1567
|
-
if (!response.ok) throw new Error(`Gagal fetch thumbnail: ${response.statusText}`);
|
|
1568
|
-
let arrayBuffer = await response.arrayBuffer();
|
|
1569
|
-
buffer = Buffer.from(arrayBuffer);
|
|
1570
|
-
}
|
|
1571
|
-
if (Buffer.isBuffer(favicon)) {
|
|
1572
|
-
favBuffer = favicon;
|
|
1573
|
-
} else if (favicon?.url) {
|
|
1574
|
-
let response = await fetch(favicon.url);
|
|
1575
|
-
if (!response.ok) throw new Error(`Gagal fetch favicon: ${response.statusText}`);
|
|
1576
|
-
let arrayBuffer = await response.arrayBuffer();
|
|
1577
|
-
favBuffer = Buffer.from(arrayBuffer);
|
|
1578
|
-
} else {
|
|
1550
|
+
|
|
1551
|
+
if (contextInfo?.previewThumbnail) {
|
|
1552
|
+
let {
|
|
1553
|
+
title,
|
|
1554
|
+
description,
|
|
1555
|
+
thumbnail,
|
|
1556
|
+
sourceUrl,
|
|
1557
|
+
largerThumbnail = false,
|
|
1579
1558
|
favicon = false
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1559
|
+
} = contextInfo.previewThumbnail || {};
|
|
1560
|
+
|
|
1561
|
+
let buffer;
|
|
1562
|
+
let favBuffer;
|
|
1563
|
+
|
|
1564
|
+
try {
|
|
1565
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
1566
|
+
buffer = thumbnail;
|
|
1567
|
+
} else if (thumbnail?.url) {
|
|
1568
|
+
let response = await fetch(thumbnail.url);
|
|
1569
|
+
if (!response.ok) throw new Error(`Gagal fetch thumbnail: ${response.statusText}`);
|
|
1570
|
+
let arrayBuffer = await response.arrayBuffer();
|
|
1571
|
+
buffer = Buffer.from(arrayBuffer);
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
if (Buffer.isBuffer(favicon)) {
|
|
1575
|
+
favBuffer = favicon;
|
|
1576
|
+
} else if (favicon?.url) {
|
|
1577
|
+
let response = await fetch(favicon.url);
|
|
1578
|
+
if (!response.ok) throw new Error(`Gagal fetch favicon: ${response.statusText}`);
|
|
1579
|
+
let arrayBuffer = await response.arrayBuffer();
|
|
1580
|
+
favBuffer = Buffer.from(arrayBuffer);
|
|
1581
|
+
} else {
|
|
1582
|
+
favicon = false;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
let miniPreview = (await sharp(buffer).resize(90, 90, {
|
|
1590
1586
|
fit: "cover",
|
|
1591
1587
|
position: "centre"
|
|
1592
|
-
})
|
|
1593
|
-
.jpeg({
|
|
1588
|
+
}).jpeg({
|
|
1594
1589
|
quality: 80
|
|
1595
|
-
})
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1590
|
+
}).toBuffer()).toString("base64");
|
|
1591
|
+
|
|
1592
|
+
let miniFavicon = favicon ? await sharp(favBuffer)
|
|
1593
|
+
.resize(48, 48, {
|
|
1594
|
+
fit: "cover",
|
|
1595
|
+
position: "centre"
|
|
1596
|
+
})
|
|
1597
|
+
.jpeg({
|
|
1598
|
+
quality: 80
|
|
1599
|
+
})
|
|
1600
|
+
.toBuffer() : undefined;
|
|
1601
|
+
|
|
1602
|
+
let Thumbnail = await prepareWAMessageMedia({
|
|
1603
|
+
image: buffer
|
|
1604
|
+
}, {
|
|
1605
|
+
upload: socket.waUploadToServer,
|
|
1606
|
+
mediaTypeOverride: "thumbnail-link"
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
let Favicon = favicon ? await prepareWAMessageMedia({
|
|
1610
|
+
image: miniFavicon
|
|
1611
|
+
}, {
|
|
1612
|
+
upload: socket.waUploadToServer,
|
|
1613
|
+
mediaTypeOverride: "thumbnail-link"
|
|
1614
|
+
}) : undefined;
|
|
1615
|
+
|
|
1616
|
+
let message = {
|
|
1617
|
+
extendedTextMessage: {
|
|
1618
|
+
text: sourceUrl + "\n\n" + text,
|
|
1619
|
+
matchedText: sourceUrl,
|
|
1620
|
+
description: description,
|
|
1621
|
+
title: title,
|
|
1622
|
+
previewType: 'NONE',
|
|
1623
|
+
jpegThumbnail: miniPreview,
|
|
1624
|
+
thumbnailDirectPath: largerThumbnail ? Thumbnail?.imageMessage?.directPath : undefined,
|
|
1625
|
+
thumbnailSha256: largerThumbnail ? Thumbnail?.imageMessage?.fileSha256 : undefined,
|
|
1626
|
+
thumbnailEncSha256: largerThumbnail ? Thumbnail?.imageMessage?.fileEncSha256 : undefined,
|
|
1627
|
+
mediaKey: largerThumbnail ? Thumbnail?.imageMessage?.mediaKey : undefined,
|
|
1630
1628
|
mediaKeyTimestamp: Math.floor(Date.now() / 1000).toString(),
|
|
1631
|
-
thumbnailHeight:
|
|
1632
|
-
thumbnailWidth:
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
}
|
|
1629
|
+
thumbnailHeight: largerThumbnail ? Thumbnail?.imageMessage?.height : undefined,
|
|
1630
|
+
thumbnailWidth: largerThumbnail ? Thumbnail?.imageMessage?.width : undefined,
|
|
1631
|
+
type: "thumbnail",
|
|
1632
|
+
faviconMMSMetadata: {
|
|
1633
|
+
thumbnailDirectPath: Favicon?.imageMessage?.directPath,
|
|
1634
|
+
thumbnailSha256: Favicon?.imageMessage?.fileSha256,
|
|
1635
|
+
thumbnailEncSha256: Favicon?.imageMessage?.fileEncSha256,
|
|
1636
|
+
mediaKey: Favicon?.imageMessage?.mediaKey,
|
|
1637
|
+
mediaKeyTimestamp: Math.floor(Date.now() / 1000).toString(),
|
|
1638
|
+
thumbnailHeight: Favicon?.imageMessage?.height,
|
|
1639
|
+
thumbnailWidth: Favicon?.imageMessage?.width
|
|
1640
|
+
},
|
|
1641
|
+
inviteLinkGroupTypeV2: 'DEFAULT',
|
|
1642
|
+
contextInfo: {
|
|
1643
|
+
...contextInfo,
|
|
1644
|
+
...(options.quoted ? {
|
|
1645
|
+
stanzaId: options.quoted.key.id,
|
|
1646
|
+
participant: options.quoted.key.participant || options.quoted.key.remoteJid,
|
|
1647
|
+
quotedMessage: options.quoted.message,
|
|
1648
|
+
remoteJid: options.quoted.key.remoteJid
|
|
1649
|
+
} : {})
|
|
1650
|
+
}
|
|
1643
1651
|
}
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1652
|
+
};
|
|
1646
1653
|
|
|
1654
|
+
await socket.relayMessage(jid, message, {});
|
|
1655
|
+
return message;
|
|
1656
|
+
} catch (err) {
|
|
1657
|
+
console.error(err);
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1647
1661
|
|
|
1648
|
-
|
|
1662
|
+
if (contextInfo?.previewThumbnailV2) {
|
|
1663
|
+
let {
|
|
1664
|
+
title,
|
|
1665
|
+
description,
|
|
1666
|
+
thumbnail,
|
|
1667
|
+
sourceUrl
|
|
1668
|
+
} = contextInfo.previewThumbnailV2 || {};
|
|
1669
|
+
|
|
1670
|
+
if (typeof jid !== "string") throw new TypeError("jid is not string");
|
|
1671
|
+
if (typeof text !== "string") throw new TypeError("text is not string");
|
|
1672
|
+
if (typeof sourceUrl !== "string") throw new TypeError("sourceUrl (link) is not string");
|
|
1673
|
+
if (typeof title !== "string") throw new TypeError("title is not string");
|
|
1674
|
+
if (description && typeof description !== "string") throw new TypeError("description is not string");
|
|
1675
|
+
if (thumbnail && !Buffer.isBuffer(thumbnail) && typeof thumbnail.url !== "string") {
|
|
1676
|
+
throw new TypeError("thumbnail must be Buffer or object with url key");
|
|
1677
|
+
}
|
|
1649
1678
|
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1679
|
+
try {
|
|
1680
|
+
let bufferV2;
|
|
1681
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
1682
|
+
bufferV2 = thumbnail;
|
|
1683
|
+
} else if (thumbnail?.url) {
|
|
1684
|
+
let response = await fetch(thumbnail.url);
|
|
1685
|
+
if (!response.ok) throw new Error(`Gagal fetch thumbnail V2: ${response.statusText}`);
|
|
1686
|
+
let arrayBuffer = await response.arrayBuffer();
|
|
1687
|
+
bufferV2 = Buffer.from(arrayBuffer);
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
const image = bufferV2 ?
|
|
1691
|
+
await prepareWAMessageMedia({
|
|
1692
|
+
image: bufferV2
|
|
1693
|
+
}, {
|
|
1694
|
+
upload: socket.waUploadToServer,
|
|
1695
|
+
mediaTypeOverride: "thumbnail-link",
|
|
1696
|
+
}).then((v) => v.imageMessage) :
|
|
1697
|
+
undefined;
|
|
1698
|
+
|
|
1699
|
+
text = text.includes(sourceUrl) ? text : `${sourceUrl}\n${text}`;
|
|
1700
|
+
return await socket.sendMessage(
|
|
1701
|
+
jid, {
|
|
1702
|
+
text,
|
|
1703
|
+
linkPreview: {
|
|
1704
|
+
"matched-text": sourceUrl,
|
|
1705
|
+
title,
|
|
1706
|
+
description,
|
|
1707
|
+
jpegThumbnail: image?.jpegThumbnail,
|
|
1708
|
+
highQualityThumbnail: image,
|
|
1709
|
+
},
|
|
1710
|
+
contextInfo: {
|
|
1711
|
+
...contextInfo,
|
|
1712
|
+
previewThumbnailV2: undefined
|
|
1713
|
+
}
|
|
1714
|
+
},
|
|
1715
|
+
options
|
|
1716
|
+
);
|
|
1717
|
+
} catch (err) {
|
|
1718
|
+
console.error(err);
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1653
1721
|
}
|
|
1654
|
-
|
|
1722
|
+
return await socket.sendMessage(jid, content, options);
|
|
1723
|
+
},
|
|
1655
1724
|
messageBuilder: function(jid, options = {}) {
|
|
1656
1725
|
let currentInstancePromise = null;
|
|
1657
1726
|
|
|
@@ -1667,7 +1736,9 @@ function addProperty(socket, baileys) {
|
|
|
1667
1736
|
if (type === 'AIRich') return new AIRich(socket);
|
|
1668
1737
|
if (type === 'tutorial') {
|
|
1669
1738
|
const aiRich = new AIRich(socket);
|
|
1670
|
-
const fullText = await Buffer.from((await axios.get("https://raw.githubusercontent.com/reinzz556/haruka/refs/heads/main/readme.md", {
|
|
1739
|
+
const fullText = await Buffer.from((await axios.get("https://raw.githubusercontent.com/reinzz556/haruka/refs/heads/main/readme.md", {
|
|
1740
|
+
responseType: "arraybuffer"
|
|
1741
|
+
})).data).toString()
|
|
1671
1742
|
const codeBlockRegex = /```(\w*)\n([\s\S]*?)\n```/g;
|
|
1672
1743
|
|
|
1673
1744
|
let lastIndex = 0;
|
|
@@ -1692,7 +1763,7 @@ function addProperty(socket, baileys) {
|
|
|
1692
1763
|
aiRich.addText(remainingText);
|
|
1693
1764
|
}
|
|
1694
1765
|
|
|
1695
|
-
|
|
1766
|
+
|
|
1696
1767
|
return aiRich;
|
|
1697
1768
|
}
|
|
1698
1769
|
throw new Error(`Type ${type} tidak dikenali. Jika belum tau cara penggunaannya, silahkan execute kode ini:\n\`\`\`js\nreturn await socket.messageBuilder(m.chat).setType("tutorial").send()\n\`\`\``);
|
|
@@ -1728,7 +1799,8 @@ function addProperty(socket, baileys) {
|
|
|
1728
1799
|
|
|
1729
1800
|
const proxy = new Proxy({}, handler);
|
|
1730
1801
|
return proxy;
|
|
1731
|
-
},
|
|
1802
|
+
},
|
|
1803
|
+
sendStickerPack: async (jid, packData, options = {}) => {
|
|
1732
1804
|
try {
|
|
1733
1805
|
const {
|
|
1734
1806
|
name,
|
|
@@ -2084,6 +2156,7 @@ function addProperty(socket, baileys) {
|
|
|
2084
2156
|
degreesLatitude: location.degressLatitude || location.degreesLatitude || 0,
|
|
2085
2157
|
degreesLongitude: location.degressLongitude || location.degreesLongitude || 0,
|
|
2086
2158
|
name: location.name || "",
|
|
2159
|
+
jpegThumbnail: location.jpegThumbnail || null,
|
|
2087
2160
|
address: location.address || "",
|
|
2088
2161
|
},
|
|
2089
2162
|
};
|
|
@@ -2444,8 +2517,8 @@ function addProperty(socket, baileys) {
|
|
|
2444
2517
|
|
|
2445
2518
|
export default addProperty;
|
|
2446
2519
|
export {
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2520
|
+
Button,
|
|
2521
|
+
ButtonV2,
|
|
2522
|
+
Carousel,
|
|
2523
|
+
AIRich
|
|
2451
2524
|
};
|