Skip to content

Commit bcbe6eb

Browse files
committed
[1.2.0] Fix ratelimiting issues, automerge deps with Renovate
1 parent 683708c commit bcbe6eb

File tree

6 files changed

+459
-403
lines changed

6 files changed

+459
-403
lines changed

index.d.ts

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* SOFTWARE.
2121
*/
2222

23-
import { HttpMethod, DataLike } from '@augu/orchid';
23+
import { HttpMethod, DataLike, Response } from '@augu/orchid';
24+
import { Collection } from '@augu/collections';
2425
import { EventBus } from '@augu/utils';
2526
import { Agent } from 'undici';
2627

@@ -219,8 +220,19 @@ declare namespace Rest {
219220
data?: D;
220221
}
221222

223+
/**
224+
* Represents a file to send on Discord
225+
*/
222226
export interface MessageFile {
227+
/**
228+
* The name of the file
229+
* @default 'file.png'
230+
*/
223231
name?: string;
232+
233+
/**
234+
* The file contents to send
235+
*/
224236
file: Buffer;
225237
}
226238

@@ -272,43 +284,70 @@ declare namespace Rest {
272284
public lastDispatchAt: number;
273285

274286
/**
275-
* If the rest client has been ratelimited or not
287+
* Represents the current cancellation token list
276288
*/
277-
public ratelimited: boolean;
289+
public clsToken: CancellationTokens;
278290

279291
/**
280-
* How many requests we can make
292+
* List of routes for ratelimiting purposes
281293
*/
282-
public remaining: number;
294+
public routes: Collection<string, RouteBucket>;
295+
296+
/**
297+
* List of options available
298+
*/
299+
public options: Pick<RestClientOptions, 'baseUrl'> & { token: string | null; agent: Agent | null; };
283300

284301
/**
285-
* The reset time
302+
* The rest client to create requests to Discord
303+
* @param options Any additional options to create this RestClient
286304
*/
287-
public resetTime: number;
305+
constructor(options: RestClientOptions);
306+
307+
public get ping(): number;
308+
public dispatch<D extends DataLike | unknown = unknown, TReturn = unknown>(options: RequestDispatchOptions<D>): Promise<TReturn>;
309+
}
288310

311+
/**
312+
* Represents a ratelimit buckets for specific routes
313+
*/
314+
export class RouteBucket {
289315
/**
290-
* The limit of requests
316+
* The global ratelimit promise
291317
*/
292-
public limit: number;
318+
public static globalRatelimit: Promise<void> | null;
293319

294320
/**
295-
* Represents the current cancellation token list
321+
* The route this [`RouteBucket`] belongs to
296322
*/
297-
public clsToken: CancellationTokens;
323+
public readonly route: string;
298324

299325
/**
300-
* List of options available
326+
* The reset time for ratelimiting purposes
301327
*/
302-
public options: Pick<RestClientOptions, 'baseUrl'> & { token: string | null; agent: Agent | null; };
328+
public resetTime: number;
303329

304330
/**
305-
* The rest client to create requests to Discord
306-
* @param options Any additional options to create this RestClient
331+
* The remaining times before we reach a 429 status
307332
*/
308-
constructor(options: RestClientOptions);
333+
public remaining: number;
309334

310-
public get ping(): number;
311-
public dispatch<D extends DataLike | unknown = unknown, TReturn = unknown>(options: RequestDispatchOptions<D>): Promise<TReturn>;
335+
/**
336+
* If this [`RouteBucket`] has been ratelimited or not
337+
*/
338+
public get ratelimited(): boolean;
339+
340+
/**
341+
* Returns the offset given by Discord's server date and our server date
342+
* @param serverDate The date in milliseconds Discord has gaven us
343+
*/
344+
public getOffset(serverDate: string): number;
345+
346+
/**
347+
* Handles the ratelimiting for this [`RouteBucket`]
348+
* @param res The orchid response
349+
*/
350+
public handle(res: Response): Promise<void>;
312351
}
313352
}
314353

0 commit comments

Comments
 (0)