discord-self-lite 0.1.6 → 0.1.7
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/package.json +1 -1
- package/src/classes/Client.js +26 -0
- package/src/connection/rest/RestManager.js +78 -5
- package/src/index.js +1 -1
package/package.json
CHANGED
package/src/classes/Client.js
CHANGED
|
@@ -191,6 +191,32 @@ class Client extends EventEmitter {
|
|
|
191
191
|
return this.token;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Get rate limit status for debugging
|
|
196
|
+
* @param {string} endpoint - The API endpoint
|
|
197
|
+
* @param {string} method - The HTTP method (default: 'GET')
|
|
198
|
+
* @returns {object} Rate limit information
|
|
199
|
+
*/
|
|
200
|
+
getRateLimitStatus(endpoint, method = "GET") {
|
|
201
|
+
if (!this.rest) {
|
|
202
|
+
throw new Error("Client is not logged in");
|
|
203
|
+
}
|
|
204
|
+
return this.rest.getRateLimitStatus(endpoint, method);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Check if a route is currently rate limited
|
|
209
|
+
* @param {string} endpoint - The API endpoint
|
|
210
|
+
* @param {string} method - The HTTP method (default: 'GET')
|
|
211
|
+
* @returns {boolean} True if rate limited
|
|
212
|
+
*/
|
|
213
|
+
isRateLimited(endpoint, method = "GET") {
|
|
214
|
+
if (!this.rest) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
return this.rest.isRateLimited(endpoint, method);
|
|
218
|
+
}
|
|
219
|
+
|
|
194
220
|
/**
|
|
195
221
|
* Destroy the client and clean up resources
|
|
196
222
|
* @returns {void}
|
|
@@ -55,10 +55,20 @@ class RestManager {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// Check if we're globally rate limited before starting
|
|
59
|
+
if (this.globalRateLimit && Date.now() < this.globalRateLimit.reset) {
|
|
60
|
+
const delay = this.globalRateLimit.reset - Date.now();
|
|
61
|
+
console.log(
|
|
62
|
+
`⏳ Global rate limit active, waiting ${delay}ms before processing queue`,
|
|
63
|
+
);
|
|
64
|
+
setTimeout(() => this.processQueue(), delay);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
this.processingQueue = true;
|
|
59
69
|
|
|
60
70
|
while (this.requestQueue.length > 0) {
|
|
61
|
-
//
|
|
71
|
+
// Double-check global rate limit for each request
|
|
62
72
|
if (this.globalRateLimit && Date.now() < this.globalRateLimit.reset) {
|
|
63
73
|
const delay = this.globalRateLimit.reset - Date.now();
|
|
64
74
|
console.log(`⏳ Global rate limit active, waiting ${delay}ms`);
|
|
@@ -84,6 +94,14 @@ class RestManager {
|
|
|
84
94
|
`⏳ Route rate limit for ${routeKey} (${endpoint}), waiting ${delay}ms`,
|
|
85
95
|
);
|
|
86
96
|
await this.sleep(delay);
|
|
97
|
+
|
|
98
|
+
// After waiting, check if we still have remaining requests
|
|
99
|
+
const updatedRateLimit = this.rateLimits.get(routeKey);
|
|
100
|
+
if (updatedRateLimit && updatedRateLimit.remaining <= 0) {
|
|
101
|
+
// Still rate limited, put request back at front of queue
|
|
102
|
+
this.requestQueue.unshift(request);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
87
105
|
}
|
|
88
106
|
|
|
89
107
|
const result = await this.makeRequest(endpoint, options);
|
|
@@ -142,6 +160,14 @@ class RestManager {
|
|
|
142
160
|
|
|
143
161
|
if (isGlobal) {
|
|
144
162
|
this.globalRateLimit = { reset: Date.now() + retryAfter };
|
|
163
|
+
} else {
|
|
164
|
+
// Update route-specific rate limit for 429 responses
|
|
165
|
+
this.rateLimits.set(routeKey, {
|
|
166
|
+
remaining: 0,
|
|
167
|
+
reset: Date.now() + retryAfter,
|
|
168
|
+
limit: this.rateLimits.get(routeKey)?.limit || 5, // Default limit if unknown
|
|
169
|
+
updatedAt: Date.now(),
|
|
170
|
+
});
|
|
145
171
|
}
|
|
146
172
|
|
|
147
173
|
await this.sleep(retryAfter);
|
|
@@ -235,11 +261,58 @@ class RestManager {
|
|
|
235
261
|
}
|
|
236
262
|
|
|
237
263
|
/**
|
|
238
|
-
*
|
|
239
|
-
* @
|
|
264
|
+
* Check if a route is currently rate limited
|
|
265
|
+
* @param {string} endpoint - The API endpoint
|
|
266
|
+
* @param {string} method - The HTTP method
|
|
267
|
+
* @returns {boolean} True if rate limited
|
|
268
|
+
*/
|
|
269
|
+
isRateLimited(endpoint, method = "GET") {
|
|
270
|
+
// Check global rate limit
|
|
271
|
+
if (this.globalRateLimit && Date.now() < this.globalRateLimit.reset) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Check route-specific rate limit
|
|
276
|
+
const routeKey = this.getRouteKey(endpoint, method);
|
|
277
|
+
const rateLimit = this.rateLimits.get(routeKey);
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
rateLimit && rateLimit.remaining <= 0 && Date.now() < rateLimit.reset
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Get rate limit status for debugging
|
|
286
|
+
* @param {string} endpoint - The API endpoint
|
|
287
|
+
* @param {string} method - The HTTP method
|
|
288
|
+
* @returns {object} Rate limit information
|
|
240
289
|
*/
|
|
241
|
-
|
|
242
|
-
|
|
290
|
+
getRateLimitStatus(endpoint, method = "GET") {
|
|
291
|
+
const routeKey = this.getRouteKey(endpoint, method);
|
|
292
|
+
const rateLimit = this.rateLimits.get(routeKey);
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
routeKey,
|
|
296
|
+
endpoint,
|
|
297
|
+
method,
|
|
298
|
+
isGloballyLimited:
|
|
299
|
+
this.globalRateLimit && Date.now() < this.globalRateLimit.reset,
|
|
300
|
+
globalReset: this.globalRateLimit
|
|
301
|
+
? new Date(this.globalRateLimit.reset)
|
|
302
|
+
: null,
|
|
303
|
+
isRouteLimited:
|
|
304
|
+
rateLimit && rateLimit.remaining <= 0 && Date.now() < rateLimit.reset,
|
|
305
|
+
routeLimit: rateLimit
|
|
306
|
+
? {
|
|
307
|
+
remaining: rateLimit.remaining,
|
|
308
|
+
limit: rateLimit.limit,
|
|
309
|
+
reset: new Date(rateLimit.reset),
|
|
310
|
+
resetIn: Math.max(0, rateLimit.reset - Date.now()),
|
|
311
|
+
}
|
|
312
|
+
: null,
|
|
313
|
+
queueLength: this.requestQueue.length,
|
|
314
|
+
isProcessing: this.processingQueue,
|
|
315
|
+
};
|
|
243
316
|
}
|
|
244
317
|
|
|
245
318
|
/**
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* discord-self-lite - A lightweight Discord selfbot library
|
|
3
3
|
* @module discord-self-lite
|
|
4
|
-
* @version 0.1.
|
|
4
|
+
* @version 0.1.7
|
|
5
5
|
* @description A modern, lightweight Discord selfbot library with webhook support, built for Node.js 22+ with zero external dependencies (except ws for WebSocket connections).
|
|
6
6
|
*
|
|
7
7
|
* @example
|