@realvare/based 2.5.7 → 2.5.71
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/README.MD +1237 -1544
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Socket/messages-send.js +1410 -1410
- package/lib/Types/Message.d.ts +413 -413
- package/lib/Utils/rate-limiter.js +95 -95
- package/package.json +1 -1
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* RateLimiter class for controlling message sending frequency
|
|
5
|
-
* to prevent ban detection by simulating human-like behavior
|
|
6
|
-
*/
|
|
7
|
-
class RateLimiter {
|
|
8
|
-
constructor(limitPerSecond = 1) {
|
|
9
|
-
this.limitPerSecond = limitPerSecond;
|
|
10
|
-
this.interval = 1000 / limitPerSecond; // milliseconds between messages
|
|
11
|
-
this.queue = [];
|
|
12
|
-
this.processing = false;
|
|
13
|
-
this.lastSendTime = 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Add a task to the rate limiting queue
|
|
18
|
-
* @param {Function} task - Async function to execute
|
|
19
|
-
* @returns {Promise} - Promise that resolves when task is complete
|
|
20
|
-
*/
|
|
21
|
-
async add(task) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
this.queue.push({ task, resolve, reject });
|
|
24
|
-
if (!this.processing) {
|
|
25
|
-
this.process();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Process the queue with rate limiting
|
|
32
|
-
*/
|
|
33
|
-
async process() {
|
|
34
|
-
if (this.processing || this.queue.length === 0) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.processing = true;
|
|
39
|
-
|
|
40
|
-
while (this.queue.length > 0) {
|
|
41
|
-
const { task, resolve, reject } = this.queue.shift();
|
|
42
|
-
const now = Date.now();
|
|
43
|
-
const timeSinceLastSend = now - this.lastSendTime;
|
|
44
|
-
|
|
45
|
-
// Wait if we need to respect the rate limit
|
|
46
|
-
if (timeSinceLastSend < this.interval) {
|
|
47
|
-
const waitTime = this.interval - timeSinceLastSend;
|
|
48
|
-
await new Promise(r => setTimeout(r, waitTime));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const result = await task();
|
|
53
|
-
this.lastSendTime = Date.now();
|
|
54
|
-
resolve(result);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
reject(error);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Add small random delay to simulate human behavior (0-500ms)
|
|
60
|
-
const randomDelay = Math.random() * 500;
|
|
61
|
-
await new Promise(r => setTimeout(r, randomDelay));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.processing = false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Update the rate limit
|
|
69
|
-
* @param {number} newLimit - New messages per second limit
|
|
70
|
-
*/
|
|
71
|
-
setLimit(newLimit) {
|
|
72
|
-
this.limitPerSecond = newLimit;
|
|
73
|
-
this.interval = 1000 / newLimit;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get current queue length
|
|
78
|
-
* @returns {number} - Number of pending tasks
|
|
79
|
-
*/
|
|
80
|
-
getQueueLength() {
|
|
81
|
-
return this.queue.length;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Clear all pending tasks
|
|
86
|
-
*/
|
|
87
|
-
clear() {
|
|
88
|
-
this.queue.forEach(({ reject }) => {
|
|
89
|
-
reject(new Error('Rate limiter cleared'));
|
|
90
|
-
});
|
|
91
|
-
this.queue = [];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = RateLimiter;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RateLimiter class for controlling message sending frequency
|
|
5
|
+
* to prevent ban detection by simulating human-like behavior
|
|
6
|
+
*/
|
|
7
|
+
class RateLimiter {
|
|
8
|
+
constructor(limitPerSecond = 1) {
|
|
9
|
+
this.limitPerSecond = limitPerSecond;
|
|
10
|
+
this.interval = 1000 / limitPerSecond; // milliseconds between messages
|
|
11
|
+
this.queue = [];
|
|
12
|
+
this.processing = false;
|
|
13
|
+
this.lastSendTime = 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Add a task to the rate limiting queue
|
|
18
|
+
* @param {Function} task - Async function to execute
|
|
19
|
+
* @returns {Promise} - Promise that resolves when task is complete
|
|
20
|
+
*/
|
|
21
|
+
async add(task) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
this.queue.push({ task, resolve, reject });
|
|
24
|
+
if (!this.processing) {
|
|
25
|
+
this.process();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Process the queue with rate limiting
|
|
32
|
+
*/
|
|
33
|
+
async process() {
|
|
34
|
+
if (this.processing || this.queue.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.processing = true;
|
|
39
|
+
|
|
40
|
+
while (this.queue.length > 0) {
|
|
41
|
+
const { task, resolve, reject } = this.queue.shift();
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
const timeSinceLastSend = now - this.lastSendTime;
|
|
44
|
+
|
|
45
|
+
// Wait if we need to respect the rate limit
|
|
46
|
+
if (timeSinceLastSend < this.interval) {
|
|
47
|
+
const waitTime = this.interval - timeSinceLastSend;
|
|
48
|
+
await new Promise(r => setTimeout(r, waitTime));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const result = await task();
|
|
53
|
+
this.lastSendTime = Date.now();
|
|
54
|
+
resolve(result);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
reject(error);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Add small random delay to simulate human behavior (0-500ms)
|
|
60
|
+
const randomDelay = Math.random() * 500;
|
|
61
|
+
await new Promise(r => setTimeout(r, randomDelay));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.processing = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Update the rate limit
|
|
69
|
+
* @param {number} newLimit - New messages per second limit
|
|
70
|
+
*/
|
|
71
|
+
setLimit(newLimit) {
|
|
72
|
+
this.limitPerSecond = newLimit;
|
|
73
|
+
this.interval = 1000 / newLimit;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get current queue length
|
|
78
|
+
* @returns {number} - Number of pending tasks
|
|
79
|
+
*/
|
|
80
|
+
getQueueLength() {
|
|
81
|
+
return this.queue.length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Clear all pending tasks
|
|
86
|
+
*/
|
|
87
|
+
clear() {
|
|
88
|
+
this.queue.forEach(({ reject }) => {
|
|
89
|
+
reject(new Error('Rate limiter cleared'));
|
|
90
|
+
});
|
|
91
|
+
this.queue = [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = RateLimiter;
|