dibosockets 1.0.2 → 1.0.3
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/WAProto/WAProto.proto +4775 -5619
- package/lib/Defaults/baileys-version.json +3 -3
- package/lib/Defaults/index.js +106 -122
- package/lib/Socket/RHandler.js +530 -448
- package/lib/Socket/business.js +260 -266
- package/lib/Socket/chats.js +908 -1137
- package/lib/Socket/index.js +10 -43
- package/lib/Socket/messages-recv.js +1054 -1065
- package/lib/Socket/messages-send.js +903 -881
- package/lib/Socket/newsletter.js +303 -286
- package/lib/Socket/socket.js +654 -666
- package/lib/Store/make-in-memory-store.js +439 -439
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Utils/baileys-event-stream.js +63 -63
- package/lib/Utils/event-buffer.js +518 -518
- package/lib/Utils/generics.js +428 -432
- package/lib/Utils/index.js +36 -36
- package/lib/Utils/messages-media.js +887 -926
- package/lib/Utils/messages.js +1030 -1105
- package/lib/Utils/process-message.js +385 -404
- package/lib/Utils/use-multi-file-auth-state.js +125 -122
- package/lib/Utils/validate-connection.js +173 -229
- package/lib/WABinary/jid-utils.js +83 -85
- package/lib/index.js +86 -74
- package/package.json +2 -2
- package/lib/Api/Internet/growagarden.js +0 -28
- package/lib/Api/creator.json +0 -13
- package/lib/Api/downloader/tiktokdownload.js +0 -132
- package/lib/Api/index.js +0 -38
- package/lib/Api/nsfw/loli.js +0 -79
- package/lib/Api/stalker/githubstalk.js +0 -46
- package/lib/Api/stalker/stalkroblox.js +0 -94
- package/lib/Api/stalker/tiktokstalk.js +0 -68
- package/lib/Api/tools/ssweb.js +0 -38
- package/lib/Defaults/phonenumber_mcc.json +0 -223
- package/lib/Socket/communities.js +0 -441
- package/lib/Utils/async-iterable.js +0 -41
- package/lib/Utils/browser-utils.js +0 -35
- package/lib/Utils/message-retry-manager.js +0 -128
- package/lib/Utils/resolveJid.js +0 -52
|
@@ -1,122 +1,125 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useMultiFileAuthState = void 0;
|
|
4
|
-
const async_mutex_1 = require("async-mutex");
|
|
5
|
-
const promises_1 = require("fs/promises");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const WAProto_1 = require("../../WAProto");
|
|
8
|
-
const auth_utils_1 = require("./auth-utils");
|
|
9
|
-
const generics_1 = require("./generics");
|
|
10
|
-
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const auth_utils_1 = require("./auth-utils");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
10
|
+
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
11
|
+
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
12
|
+
// https://github.com/nodejs/node/issues/26338
|
|
13
|
+
// Use a Map to store mutexes for each file path
|
|
14
|
+
const fileLocks = new Map();
|
|
15
|
+
// Get or create a mutex for a specific file path
|
|
16
|
+
const getFileLock = (path) => {
|
|
17
|
+
let mutex = fileLocks.get(path);
|
|
18
|
+
if (!mutex) {
|
|
19
|
+
mutex = new async_mutex_1.Mutex();
|
|
20
|
+
fileLocks.set(path, mutex);
|
|
21
|
+
}
|
|
22
|
+
return mutex;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* stores the full authentication state in a single folder.
|
|
26
|
+
* Far more efficient than singlefileauthstate
|
|
27
|
+
*
|
|
28
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
29
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
30
|
+
* */
|
|
31
|
+
const useMultiFileAuthState = async (folder) => {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
const writeData = async (data, file) => {
|
|
34
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
|
+
const mutex = getFileLock(filePath);
|
|
36
|
+
return mutex.acquire().then(async (release) => {
|
|
37
|
+
try {
|
|
38
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
release();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const readData = async (file) => {
|
|
46
|
+
try {
|
|
47
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
48
|
+
const mutex = getFileLock(filePath);
|
|
49
|
+
return await mutex.acquire().then(async (release) => {
|
|
50
|
+
try {
|
|
51
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
52
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
release();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const removeData = async (file) => {
|
|
64
|
+
try {
|
|
65
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
66
|
+
const mutex = getFileLock(filePath);
|
|
67
|
+
return mutex.acquire().then(async (release) => {
|
|
68
|
+
try {
|
|
69
|
+
await (0, promises_1.unlink)(filePath);
|
|
70
|
+
}
|
|
71
|
+
catch (_a) {
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
release();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (_a) {
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
82
|
+
if (folderInfo) {
|
|
83
|
+
if (!folderInfo.isDirectory()) {
|
|
84
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
89
|
+
}
|
|
90
|
+
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
91
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
92
|
+
return {
|
|
93
|
+
state: {
|
|
94
|
+
creds,
|
|
95
|
+
keys: {
|
|
96
|
+
get: async (type, ids) => {
|
|
97
|
+
const data = {};
|
|
98
|
+
await Promise.all(ids.map(async (id) => {
|
|
99
|
+
let value = await readData(`${type}-${id}.json`);
|
|
100
|
+
if (type === 'app-state-sync-key' && value) {
|
|
101
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
102
|
+
}
|
|
103
|
+
data[id] = value;
|
|
104
|
+
}));
|
|
105
|
+
return data;
|
|
106
|
+
},
|
|
107
|
+
set: async (data) => {
|
|
108
|
+
const tasks = [];
|
|
109
|
+
for (const category in data) {
|
|
110
|
+
for (const id in data[category]) {
|
|
111
|
+
const value = data[category][id];
|
|
112
|
+
const file = `${category}-${id}.json`;
|
|
113
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await Promise.all(tasks);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
saveCreds: async () => {
|
|
121
|
+
return writeData(creds, 'creds.json');
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|