|
20 | 20 | * SOFTWARE.
|
21 | 21 | */
|
22 | 22 |
|
23 |
| -import { HttpMethod, DataLike } from '@augu/orchid'; |
| 23 | +import { HttpMethod, DataLike, Response } from '@augu/orchid'; |
| 24 | +import { Collection } from '@augu/collections'; |
24 | 25 | import { EventBus } from '@augu/utils';
|
25 | 26 | import { Agent } from 'undici';
|
26 | 27 |
|
@@ -219,8 +220,19 @@ declare namespace Rest {
|
219 | 220 | data?: D;
|
220 | 221 | }
|
221 | 222 |
|
| 223 | + /** |
| 224 | + * Represents a file to send on Discord |
| 225 | + */ |
222 | 226 | export interface MessageFile {
|
| 227 | + /** |
| 228 | + * The name of the file |
| 229 | + * @default 'file.png' |
| 230 | + */ |
223 | 231 | name?: string;
|
| 232 | + |
| 233 | + /** |
| 234 | + * The file contents to send |
| 235 | + */ |
224 | 236 | file: Buffer;
|
225 | 237 | }
|
226 | 238 |
|
@@ -272,43 +284,70 @@ declare namespace Rest {
|
272 | 284 | public lastDispatchAt: number;
|
273 | 285 |
|
274 | 286 | /**
|
275 |
| - * If the rest client has been ratelimited or not |
| 287 | + * Represents the current cancellation token list |
276 | 288 | */
|
277 |
| - public ratelimited: boolean; |
| 289 | + public clsToken: CancellationTokens; |
278 | 290 |
|
279 | 291 | /**
|
280 |
| - * How many requests we can make |
| 292 | + * List of routes for ratelimiting purposes |
281 | 293 | */
|
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; }; |
283 | 300 |
|
284 | 301 | /**
|
285 |
| - * The reset time |
| 302 | + * The rest client to create requests to Discord |
| 303 | + * @param options Any additional options to create this RestClient |
286 | 304 | */
|
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 | + } |
288 | 310 |
|
| 311 | + /** |
| 312 | + * Represents a ratelimit buckets for specific routes |
| 313 | + */ |
| 314 | + export class RouteBucket { |
289 | 315 | /**
|
290 |
| - * The limit of requests |
| 316 | + * The global ratelimit promise |
291 | 317 | */
|
292 |
| - public limit: number; |
| 318 | + public static globalRatelimit: Promise<void> | null; |
293 | 319 |
|
294 | 320 | /**
|
295 |
| - * Represents the current cancellation token list |
| 321 | + * The route this [`RouteBucket`] belongs to |
296 | 322 | */
|
297 |
| - public clsToken: CancellationTokens; |
| 323 | + public readonly route: string; |
298 | 324 |
|
299 | 325 | /**
|
300 |
| - * List of options available |
| 326 | + * The reset time for ratelimiting purposes |
301 | 327 | */
|
302 |
| - public options: Pick<RestClientOptions, 'baseUrl'> & { token: string | null; agent: Agent | null; }; |
| 328 | + public resetTime: number; |
303 | 329 |
|
304 | 330 | /**
|
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 |
307 | 332 | */
|
308 |
| - constructor(options: RestClientOptions); |
| 333 | + public remaining: number; |
309 | 334 |
|
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>; |
312 | 351 | }
|
313 | 352 | }
|
314 | 353 |
|
|
0 commit comments