amiudmodz 5.1.6 → 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
@@ -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
- return JSON.parse(data, generics_1.BufferJSON.reviver);
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
- if (error.code === 'ENOENT') {
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 (Array.isArray(node?.content)) {
10
- return node.content.filter(item => item.tag === childTag)
10
+ if (!node || typeof node !== 'object') {
11
+ return [];
11
12
  }
12
- return []
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 (Array.isArray(node?.content)) {
24
- return node?.content.find(item => item.tag === childTag)
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.1.6",
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",