amiudmodz 5.1.5 → 5.2.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.
|
@@ -704,6 +704,16 @@ const makeMessagesSocket = (config) => {
|
|
|
704
704
|
const { filter = false, quoted } = options;
|
|
705
705
|
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
706
706
|
const messageType = toxicHandler.detectType(content);
|
|
707
|
+
if (WABinary_1.isJidGroup(jid) && typeof content === 'object' && content) {
|
|
708
|
+
if (content.mentionAll || (Array.isArray(content.mentions) && content.mentions.includes('@all')) || options.mentionAll) {
|
|
709
|
+
try {
|
|
710
|
+
const metadata = await groupMetadata(jid);
|
|
711
|
+
content.mentions = metadata.participants.map(p => p.id);
|
|
712
|
+
} catch (err) {
|
|
713
|
+
logger.warn({ err, jid }, 'failed to fetch group metadata for mentionAll');
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
707
717
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
708
718
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
709
719
|
const { disappearingMessagesInChat } = content
|
|
@@ -442,16 +442,61 @@ const getHttpStream = async (url, options = {}) => {
|
|
|
442
442
|
return fetched.data;
|
|
443
443
|
};
|
|
444
444
|
exports.getHttpStream = getHttpStream;
|
|
445
|
-
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
445
|
+
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, isPtt, forceOpus } = {}) => {
|
|
446
446
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
447
447
|
media = undefined; // Help GC
|
|
448
448
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
449
|
+
|
|
450
|
+
let finalStream = stream;
|
|
451
|
+
let opusConverted = false;
|
|
452
|
+
let opusSpillPath;
|
|
453
|
+
if (mediaType === 'audio' && (isPtt === true || forceOpus === true)) {
|
|
454
|
+
try {
|
|
455
|
+
const audioTmpPath = await spillToDisk(stream);
|
|
456
|
+
try {
|
|
457
|
+
const ff = require('fluent-ffmpeg');
|
|
458
|
+
opusSpillPath = (0, path_1.join)(getTmpFilesDirectory(), `opus-${(0, generics_1.generateMessageID)()}`);
|
|
459
|
+
const opusWriteStream = (0, fs_1.createWriteStream)(opusSpillPath);
|
|
460
|
+
await new Promise((resolve, reject) => {
|
|
461
|
+
ff(audioTmpPath)
|
|
462
|
+
.noVideo()
|
|
463
|
+
.audioCodec('libopus')
|
|
464
|
+
.format('ogg')
|
|
465
|
+
.audioBitrate('48k')
|
|
466
|
+
.audioChannels(1)
|
|
467
|
+
.audioFrequency(48000)
|
|
468
|
+
.outputOptions([
|
|
469
|
+
'-vn',
|
|
470
|
+
'-b:a 64k',
|
|
471
|
+
'-ac 2',
|
|
472
|
+
'-ar 48000',
|
|
473
|
+
'-map_metadata', '-1',
|
|
474
|
+
'-application', 'voip'
|
|
475
|
+
])
|
|
476
|
+
.on('error', (err) => {
|
|
477
|
+
opusWriteStream.destroy();
|
|
478
|
+
reject(err);
|
|
479
|
+
})
|
|
480
|
+
.on('end', resolve)
|
|
481
|
+
.pipe(opusWriteStream);
|
|
482
|
+
});
|
|
483
|
+
finalStream = (0, fs_1.createReadStream)(opusSpillPath);
|
|
484
|
+
opusConverted = true;
|
|
485
|
+
}
|
|
486
|
+
finally {
|
|
487
|
+
await fs_1.promises.unlink(audioTmpPath).catch(() => { });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
const { stream: newStream } = await (0, exports.getStream)(media, opts);
|
|
492
|
+
finalStream = newStream;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
449
496
|
let bodyPath;
|
|
450
497
|
let didSaveToTmpPath = false;
|
|
451
498
|
let fileLength = 0;
|
|
452
499
|
const sha256 = Crypto.createHash('sha256');
|
|
453
|
-
|
|
454
|
-
|
|
455
500
|
const preparedPath = (0, path_1.join)(getTmpFilesDirectory(), `prepared-${mediaType}-${(0, generics_1.generateMessageID)()}`);
|
|
456
501
|
const preparedWriteStream = (0, fs_1.createWriteStream)(preparedPath);
|
|
457
502
|
|
|
@@ -465,7 +510,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
465
510
|
const writeStream = didSaveToTmpPath ? (0, fs_1.createWriteStream)(bodyPath) : undefined;
|
|
466
511
|
|
|
467
512
|
try {
|
|
468
|
-
for await (const chunk of
|
|
513
|
+
for await (const chunk of finalStream) {
|
|
469
514
|
fileLength += chunk.length;
|
|
470
515
|
sha256.update(chunk);
|
|
471
516
|
if (writeStream) {
|
|
@@ -477,13 +522,13 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
477
522
|
await (0, events_1.once)(preparedWriteStream, 'drain');
|
|
478
523
|
}
|
|
479
524
|
}
|
|
480
|
-
|
|
481
525
|
preparedWriteStream.end();
|
|
482
526
|
writeStream?.end();
|
|
483
|
-
|
|
484
527
|
const fileSha256 = sha256.digest();
|
|
485
528
|
logger === null || logger === void 0 ? void 0 : logger.debug('prepare stream data successfully');
|
|
486
|
-
|
|
529
|
+
if (opusSpillPath) {
|
|
530
|
+
await fs_1.promises.unlink(opusSpillPath).catch(() => { });
|
|
531
|
+
}
|
|
487
532
|
return {
|
|
488
533
|
mediaKey: undefined,
|
|
489
534
|
encWriteStream: (0, fs_1.createReadStream)(preparedPath),
|
|
@@ -492,16 +537,21 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
492
537
|
fileEncSha256: undefined,
|
|
493
538
|
bodyPath,
|
|
494
539
|
streamPath: preparedPath,
|
|
495
|
-
didSaveToTmpPath
|
|
540
|
+
didSaveToTmpPath,
|
|
541
|
+
opusConverted
|
|
496
542
|
};
|
|
497
543
|
}
|
|
498
544
|
catch (error) {
|
|
499
|
-
|
|
545
|
+
finalStream.destroy();
|
|
500
546
|
preparedWriteStream.destroy();
|
|
501
547
|
writeStream?.destroy();
|
|
548
|
+
if (opusSpillPath) {
|
|
549
|
+
await fs_1.promises.unlink(opusSpillPath).catch(() => { });
|
|
550
|
+
}
|
|
502
551
|
try {
|
|
503
552
|
await fs_1.promises.unlink(preparedPath);
|
|
504
|
-
}
|
|
553
|
+
}
|
|
554
|
+
catch { }
|
|
505
555
|
if (didSaveToTmpPath) {
|
|
506
556
|
try {
|
|
507
557
|
await fs_1.promises.unlink(bodyPath);
|
package/lib/Utils/messages.js
CHANGED
|
@@ -84,36 +84,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
84
84
|
...message,
|
|
85
85
|
...(message.annotations ? {
|
|
86
86
|
annotations: message.annotations
|
|
87
|
-
} : {
|
|
88
|
-
annotations: [
|
|
89
|
-
{
|
|
90
|
-
polygonVertices: [
|
|
91
|
-
{
|
|
92
|
-
x: 60.71664810180664,
|
|
93
|
-
y: -36.39784622192383
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
x: -16.710189819335938,
|
|
97
|
-
y: 49.263675689697266
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
x: -56.585853576660156,
|
|
101
|
-
y: 37.85963439941406
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
x: 20.840980529785156,
|
|
105
|
-
y: -47.80188751220703
|
|
106
|
-
}
|
|
107
|
-
],
|
|
108
|
-
newsletter: {
|
|
109
|
-
newsletterJid: "120363400725985615@newsletter",
|
|
110
|
-
serverMessageId: 0,
|
|
111
|
-
newsletterName: "z4ph",
|
|
112
|
-
contentType: "UPDATE",
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
}),
|
|
87
|
+
} : {}),
|
|
117
88
|
media: message[mediaType]
|
|
118
89
|
};
|
|
119
90
|
delete uploadData[mediaType];
|
|
@@ -9,6 +9,7 @@ const auth_utils_1 = require("./auth-utils");
|
|
|
9
9
|
const generics_1 = require("./generics");
|
|
10
10
|
const useMultiFileAuthState = async (folder) => {
|
|
11
11
|
const fileLocks = new Map();
|
|
12
|
+
const cache = new Map();
|
|
12
13
|
const getFileLock = (path) => {
|
|
13
14
|
let mutex = fileLocks.get(path);
|
|
14
15
|
if (!mutex) {
|
|
@@ -18,13 +19,13 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
18
19
|
return mutex;
|
|
19
20
|
};
|
|
20
21
|
const releaseFileLock = (path) => {
|
|
21
|
-
|
|
22
22
|
const mutex = fileLocks.get(path);
|
|
23
23
|
if (mutex && !mutex.isLocked()) {
|
|
24
24
|
fileLocks.delete(path);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
const writeData = async (data, file) => {
|
|
28
|
+
cache.set(file, data);
|
|
28
29
|
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
29
30
|
const tempPath = filePath + '.tmp';
|
|
30
31
|
const mutex = getFileLock(filePath);
|
|
@@ -44,13 +45,18 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
const readData = async (file) => {
|
|
48
|
+
if (cache.has(file)) {
|
|
49
|
+
return cache.get(file);
|
|
50
|
+
}
|
|
47
51
|
try {
|
|
48
52
|
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
49
53
|
const mutex = getFileLock(filePath);
|
|
50
54
|
return await mutex.acquire().then(async (release) => {
|
|
51
55
|
try {
|
|
52
56
|
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
53
|
-
|
|
57
|
+
const parsed = JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
58
|
+
cache.set(file, parsed);
|
|
59
|
+
return parsed;
|
|
54
60
|
}
|
|
55
61
|
finally {
|
|
56
62
|
release();
|
|
@@ -59,13 +65,12 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
67
|
catch (error) {
|
|
62
|
-
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
68
|
+
cache.set(file, null);
|
|
65
69
|
return null;
|
|
66
70
|
}
|
|
67
71
|
};
|
|
68
72
|
const removeData = async (file) => {
|
|
73
|
+
cache.set(file, null);
|
|
69
74
|
try {
|
|
70
75
|
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
71
76
|
const mutex = getFileLock(filePath);
|
|
@@ -5,11 +5,25 @@ const boom_1 = require("@hapi/boom");
|
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
|
6
6
|
const Utils_1 = require("../Utils")
|
|
7
7
|
|
|
8
|
+
const binaryNodeChildrenCache = new WeakMap();
|
|
8
9
|
const getBinaryNodeChildren = (node, childTag) => {
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
10
|
+
if (!node || typeof node !== 'object') {
|
|
11
|
+
return [];
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
let cached = binaryNodeChildrenCache.get(node);
|
|
14
|
+
if (!cached) {
|
|
15
|
+
cached = {};
|
|
16
|
+
binaryNodeChildrenCache.set(node, cached);
|
|
17
|
+
}
|
|
18
|
+
if (cached[childTag]) {
|
|
19
|
+
return cached[childTag];
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(node.content)) {
|
|
22
|
+
const filtered = node.content.filter(item => item.tag === childTag);
|
|
23
|
+
cached[childTag] = filtered;
|
|
24
|
+
return filtered;
|
|
25
|
+
}
|
|
26
|
+
return [];
|
|
13
27
|
}
|
|
14
28
|
exports.getBinaryNodeChildren = getBinaryNodeChildren;
|
|
15
29
|
const getAllBinaryNodeChildren = ({ content }) => {
|
|
@@ -19,10 +33,25 @@ const getAllBinaryNodeChildren = ({ content }) => {
|
|
|
19
33
|
return []
|
|
20
34
|
}
|
|
21
35
|
exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
|
|
36
|
+
const binaryNodeChildCache = new WeakMap();
|
|
22
37
|
const getBinaryNodeChild = (node, childTag) => {
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
38
|
+
if (!node || typeof node !== 'object') {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
let cached = binaryNodeChildCache.get(node);
|
|
42
|
+
if (!cached) {
|
|
43
|
+
cached = {};
|
|
44
|
+
binaryNodeChildCache.set(node, cached);
|
|
45
|
+
}
|
|
46
|
+
if (childTag in cached) {
|
|
47
|
+
return cached[childTag];
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(node.content)) {
|
|
50
|
+
const found = node.content.find(item => item.tag === childTag);
|
|
51
|
+
cached[childTag] = found;
|
|
52
|
+
return found;
|
|
25
53
|
}
|
|
54
|
+
return undefined;
|
|
26
55
|
}
|
|
27
56
|
exports.getBinaryNodeChild = getBinaryNodeChild;
|
|
28
57
|
const getBinaryNodeChildBuffer = (node, childTag) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amiudmodz",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "WhatsApp Baileys mod Powered by UDMODZ",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"udmodz",
|
|
9
9
|
"bot",
|
|
10
10
|
"whatsapp-api",
|
|
11
|
-
"whatsapp-web"
|
|
12
|
-
"badiys"
|
|
11
|
+
"whatsapp-web"
|
|
13
12
|
],
|
|
14
13
|
"main": "lib/index.js",
|
|
15
14
|
"types": "lib/index.d.ts",
|