@ryuu-reinzz/haruka-lib 3.2.5 → 3.3.0
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 +97 -10
- package/package.json +1 -1
package/main/socket.js
CHANGED
|
@@ -28,6 +28,89 @@ export default function addProperty(socket, baileys) {
|
|
|
28
28
|
} = baileys;
|
|
29
29
|
|
|
30
30
|
Object.assign(socket, {
|
|
31
|
+
sendStickerPack: async (jid, packData, options = {}) => {
|
|
32
|
+
try {
|
|
33
|
+
const {
|
|
34
|
+
name,
|
|
35
|
+
publisher,
|
|
36
|
+
description,
|
|
37
|
+
cover,
|
|
38
|
+
stickers
|
|
39
|
+
} = packData;
|
|
40
|
+
const quoted = options.quoted || null;
|
|
41
|
+
|
|
42
|
+
const mediaMessage = await prepareWAMessageMedia({
|
|
43
|
+
document: cover,
|
|
44
|
+
mimetype: 'image/webp',
|
|
45
|
+
fileName: 'cover.webp'
|
|
46
|
+
}, {
|
|
47
|
+
upload: sock.waUploadToServer
|
|
48
|
+
});
|
|
49
|
+
const docInfo = mediaMessage.documentMessage;
|
|
50
|
+
if (!docInfo) throw new Error("Gagal mengunggah gambar cover.");
|
|
51
|
+
|
|
52
|
+
const uploadedStickers = [];
|
|
53
|
+
|
|
54
|
+
for (const s of stickers) {
|
|
55
|
+
const stickerMessage = await prepareWAMessageMedia({
|
|
56
|
+
document: s.data,
|
|
57
|
+
mimetype: 'image/webp',
|
|
58
|
+
fileName: 'sticker.webp'
|
|
59
|
+
}, {
|
|
60
|
+
upload: sock.waUploadToServer
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const sDoc = stickerMessage.documentMessage;
|
|
64
|
+
if (sDoc) {
|
|
65
|
+
uploadedStickers.push({
|
|
66
|
+
fileLength: sDoc.fileLength,
|
|
67
|
+
fileSha256: sDoc.fileSha256,
|
|
68
|
+
fileEncSha256: sDoc.fileEncSha256,
|
|
69
|
+
mediaKey: sDoc.mediaKey,
|
|
70
|
+
directPath: sDoc.directPath,
|
|
71
|
+
mediaKeyTimestamp: sDoc.mediaKeyTimestamp || Math.floor(Date.now() / 1000).toString(),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const stickerPackId = generateMessageID();
|
|
77
|
+
|
|
78
|
+
const stickerPackMessage = {
|
|
79
|
+
stickerPackId: stickerPackId,
|
|
80
|
+
name: name,
|
|
81
|
+
publisher: publisher,
|
|
82
|
+
packDescription: description || '',
|
|
83
|
+
|
|
84
|
+
stickers: uploadedStickers,
|
|
85
|
+
|
|
86
|
+
fileLength: docInfo.fileLength,
|
|
87
|
+
fileSha256: docInfo.fileSha256,
|
|
88
|
+
fileEncSha256: docInfo.fileEncSha256,
|
|
89
|
+
mediaKey: docInfo.mediaKey,
|
|
90
|
+
directPath: docInfo.directPath,
|
|
91
|
+
mediaKeyTimestamp: docInfo.mediaKeyTimestamp || Math.floor(Date.now() / 1000).toString(),
|
|
92
|
+
|
|
93
|
+
trayIconFileName: `${stickerPackId}.webp`,
|
|
94
|
+
imageDataHash: docInfo.fileSha256.toString('base64'),
|
|
95
|
+
stickerPackSize: docInfo.fileLength,
|
|
96
|
+
stickerPackOrigin: 'THIRD_PARTY',
|
|
97
|
+
contextInfo: options.contextInfo || (quoted ? {
|
|
98
|
+
stanzaId: quoted.key.id,
|
|
99
|
+
participant: quoted.key.participant || quoted.key.remoteJid,
|
|
100
|
+
quotedMessage: quoted.message
|
|
101
|
+
} : {})
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return await sock.relayMessage(jid, {
|
|
105
|
+
stickerPackMessage
|
|
106
|
+
}, {});
|
|
107
|
+
|
|
108
|
+
} catch (err) {
|
|
109
|
+
console.error('❌ Error in sendStickerPack wrapper:', err);
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
|
|
31
114
|
sendCard: async (jid, options = {}) => {
|
|
32
115
|
const {
|
|
33
116
|
text = "",
|
|
@@ -121,7 +204,10 @@ export default function addProperty(socket, baileys) {
|
|
|
121
204
|
})
|
|
122
205
|
},
|
|
123
206
|
|
|
124
|
-
sendSticker: async (jid, options = {}) => {
|
|
207
|
+
sendSticker: async (jid, options = {}, other = {}) => {
|
|
208
|
+
const {
|
|
209
|
+
contextInfo = {}
|
|
210
|
+
} = options;
|
|
125
211
|
try {
|
|
126
212
|
if (!options.sticker)
|
|
127
213
|
throw new Error('Please enter the path or buffer of the sticker.')
|
|
@@ -151,8 +237,9 @@ export default function addProperty(socket, baileys) {
|
|
|
151
237
|
|
|
152
238
|
const buffer = await sticker.build()
|
|
153
239
|
const result = await socket.sendMessage(jid, {
|
|
154
|
-
sticker: buffer
|
|
155
|
-
|
|
240
|
+
sticker: buffer,
|
|
241
|
+
contextInfo
|
|
242
|
+
}, other)
|
|
156
243
|
|
|
157
244
|
if (Buffer.isBuffer(options.sticker)) fs.unlinkSync(stickerPath)
|
|
158
245
|
|
|
@@ -281,13 +368,13 @@ export default function addProperty(socket, baileys) {
|
|
|
281
368
|
videoMessage: preparedMedia.videoMessage,
|
|
282
369
|
};
|
|
283
370
|
} else if (document) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
371
|
+
if (!fileName) throw new Error("fileName requiered");
|
|
372
|
+
if (!mimetype) throw new Error("mimetype requiered");
|
|
373
|
+
const mediaInput = {
|
|
374
|
+
document: document,
|
|
375
|
+
fileName: fileName,
|
|
376
|
+
mimetype: mimetype
|
|
377
|
+
};
|
|
291
378
|
const preparedMedia = await prepareWAMessageMedia(mediaInput, {
|
|
292
379
|
upload: socket.waUploadToServer,
|
|
293
380
|
});
|