amiudmodz 5.1.6 → 5.2.1
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
|
package/lib/Utils/generics.js
CHANGED
|
@@ -57,7 +57,7 @@ exports.BufferJSON = {
|
|
|
57
57
|
return value;
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
const getKeyAuthor = (key, meId = 'me') =>
|
|
60
|
+
const getKeyAuthor = (key, meId = 'me') => key ? (key.fromMe ? meId : (key.participant || key.remoteJid || '')) : '';
|
|
61
61
|
exports.getKeyAuthor = getKeyAuthor;
|
|
62
62
|
const writeRandomPadMax16 = (msg) => {
|
|
63
63
|
const pad = (0, crypto_1.randomBytes)(1);
|
|
@@ -99,7 +99,7 @@ exports.encodeBigEndian = encodeBigEndian;
|
|
|
99
99
|
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
100
100
|
exports.toNumber = toNumber;
|
|
101
101
|
/** unix timestamp of a date in seconds */
|
|
102
|
-
const unixTimestampSeconds = (date
|
|
102
|
+
const unixTimestampSeconds = (date) => date ? Math.floor(date.getTime() / 1000) : Math.floor(Date.now() / 1000);
|
|
103
103
|
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
104
104
|
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
105
105
|
let timeout;
|
|
@@ -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) => {
|
|
@@ -10,28 +10,54 @@ const jidEncode = (user, server, device, agent) => {
|
|
|
10
10
|
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
|
11
11
|
};
|
|
12
12
|
exports.jidEncode = jidEncode;
|
|
13
|
+
const jidDecodeCache = new Map();
|
|
13
14
|
const jidDecode = (jid) => {
|
|
14
|
-
|
|
15
|
+
if (typeof jid !== 'string') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const cached = jidDecodeCache.get(jid);
|
|
19
|
+
if (cached !== undefined) {
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
const sepIdx = jid.indexOf('@');
|
|
15
23
|
if (sepIdx < 0) {
|
|
24
|
+
jidDecodeCache.set(jid, undefined);
|
|
16
25
|
return undefined;
|
|
17
26
|
}
|
|
18
27
|
const server = jid.slice(sepIdx + 1);
|
|
19
28
|
const userCombined = jid.slice(0, sepIdx);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
|
|
30
|
+
let user = userCombined;
|
|
31
|
+
let device;
|
|
32
|
+
const colonIdx = userCombined.indexOf(':');
|
|
33
|
+
if (colonIdx >= 0) {
|
|
34
|
+
const userAgent = userCombined.slice(0, colonIdx);
|
|
35
|
+
device = userCombined.slice(colonIdx + 1);
|
|
36
|
+
const underscoreIdx = userAgent.indexOf('_');
|
|
37
|
+
user = underscoreIdx >= 0 ? userAgent.slice(0, underscoreIdx) : userAgent;
|
|
38
|
+
} else {
|
|
39
|
+
const underscoreIdx = userCombined.indexOf('_');
|
|
40
|
+
user = underscoreIdx >= 0 ? userCombined.slice(0, underscoreIdx) : userCombined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const decoded = {
|
|
23
44
|
server,
|
|
24
45
|
user,
|
|
25
|
-
|
|
26
46
|
domainType: (server === 'lid' || server === 'hosted.lid') ? 1 : 0,
|
|
27
47
|
device: device ? +device : undefined
|
|
28
48
|
};
|
|
49
|
+
jidDecodeCache.set(jid, decoded);
|
|
50
|
+
return decoded;
|
|
29
51
|
};
|
|
30
52
|
exports.jidDecode = jidDecode;
|
|
31
53
|
/** is the jid a user */
|
|
32
54
|
const areJidsSameUser = (jid1, jid2) => {
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
if (jid1 === jid2) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const decoded1 = jidDecode(jid1);
|
|
59
|
+
const decoded2 = jidDecode(jid2);
|
|
60
|
+
return (decoded1?.user === decoded2?.user);
|
|
35
61
|
};
|
|
36
62
|
exports.areJidsSameUser = areJidsSameUser;
|
|
37
63
|
/** is the jid a user */
|
|
@@ -52,12 +78,23 @@ exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
|
52
78
|
/** is the jid the newsletter */
|
|
53
79
|
const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
|
|
54
80
|
exports.isJidNewsLetter = isJidNewsLetter;
|
|
81
|
+
const jidNormalizedUserCache = new Map();
|
|
55
82
|
const jidNormalizedUser = (jid) => {
|
|
56
|
-
|
|
83
|
+
if (typeof jid !== 'string') {
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
const cached = jidNormalizedUserCache.get(jid);
|
|
87
|
+
if (cached !== undefined) {
|
|
88
|
+
return cached;
|
|
89
|
+
}
|
|
90
|
+
const result = jidDecode(jid);
|
|
57
91
|
if (!result) {
|
|
92
|
+
jidNormalizedUserCache.set(jid, '');
|
|
58
93
|
return '';
|
|
59
94
|
}
|
|
60
95
|
const { user, server } = result;
|
|
61
|
-
|
|
96
|
+
const normalized = jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
97
|
+
jidNormalizedUserCache.set(jid, normalized);
|
|
98
|
+
return normalized;
|
|
62
99
|
};
|
|
63
100
|
exports.jidNormalizedUser = jidNormalizedUser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amiudmodz",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
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",
|