diff --git a/src/bot.ts b/src/bot.ts index 12222b8f1..f740aa0f9 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -18,15 +18,12 @@ export async function createBot(options: CreateBotOptions) { id: options.botId, applicationId: options.applicationId || options.botId, token: `Bot ${options.token}`, - events: {dispatchRequirements: dispatchRequirements, ...options.events}, - intents: options.intents.reduce( - (bits, next) => (bits |= DiscordGatewayIntents[next]), - 0 - ), - botGatewayData: options.botGatewayData || await getGatewayBot(), + events: { dispatchRequirements: dispatchRequirements, ...options.events }, + intents: options.intents.reduce((bits, next) => (bits |= DiscordGatewayIntents[next]), 0), + botGatewayData: options.botGatewayData || (await getGatewayBot()), isReady: false, - rest: createRestManager(options.rest ? { token: options.token, ...options.rest} : { token: options.token}) - } + rest: createRestManager(options.rest ? { token: options.token, ...options.rest } : { token: options.token }), + }; } const bot = await createBot({ @@ -34,14 +31,14 @@ const bot = await createBot({ botId: 0n, events: createEventHandlers(), intents: [], -}) +}); export function createEventHandlers(options?: Partial) { return { debug: () => undefined, // PROVIDED OPTIONS OVERRIDE EVERYTHING ABOVE - ...options - } + ...options, + }; } export interface CreateRestManagerOptions { @@ -58,7 +55,7 @@ export interface CreateRestManagerOptions { processRequest?: typeof processRequest; createRequestBody?: typeof createRequestBody; runMethod?: typeof runMethod; - simplifyUrl?: typeof simplifyUrl + simplifyUrl?: typeof simplifyUrl; } export function createRestManager(options: CreateRestManagerOptions) { @@ -88,7 +85,7 @@ export function createRestManager(options: CreateRestManagerOptions) { createRequestBody: options.createRequestBody || createRequestBody, runMethod: options.runMethod || runMethod, simplifyUrl: options.simplifyUrl || simplifyUrl, - } + }; } export async function startBot(bot: Bot) { @@ -96,13 +93,12 @@ export async function startBot(bot: Bot) { bot.rest = createRestManager({ token: bot.token }); // START WS - bot.gateway = createGatewayManager() + bot.gateway = createGatewayManager(); } export function stopBot(bot: Bot) { - // STOP REST - - // STOP WS + // STOP REST + // STOP WS } export interface CreateBotOptions { @@ -122,14 +118,12 @@ export type CreatedBot = UnPromise>; export type Bot = CreatedBot & { rest: RestManager; gateway: GatewayManager; -} +}; export type RestManager = ReturnType; -export interface GatewayManager { - -} +export interface GatewayManager {} export interface EventHandlers { debug: (text: string) => unknown; -} \ No newline at end of file +} diff --git a/src/rest/process_queue.ts b/src/rest/process_queue.ts index e6e4a190e..d0e153540 100644 --- a/src/rest/process_queue.ts +++ b/src/rest/process_queue.ts @@ -34,7 +34,9 @@ export async function processQueue(rest: RestManager, id: string) { } // IF A BUCKET EXISTS, CHECK THE BUCKET'S RATE LIMITS - const bucketResetIn = queuedRequest.payload.bucketId ? rest.checkRateLimits(rest, queuedRequest.payload.bucketId) : false; + const bucketResetIn = queuedRequest.payload.bucketId + ? rest.checkRateLimits(rest, queuedRequest.payload.bucketId) + : false; // THIS BUCKET IS STILL RATELIMITED, RE-ADD TO QUEUE if (bucketResetIn) continue; @@ -71,7 +73,9 @@ export async function processQueue(rest: RestManager, id: string) { } if (response.status < 200 || response.status >= 400) { - rest.debug(`[REST - httpError] Payload: ${JSON.stringify(queuedRequest.payload)} | Response: ${JSON.stringify(response)}`); + rest.debug( + `[REST - httpError] Payload: ${JSON.stringify(queuedRequest.payload)} | Response: ${JSON.stringify(response)}` + ); let error = "REQUEST_UNKNOWN_ERROR"; switch (response.status) { diff --git a/src/rest/run_method.ts b/src/rest/run_method.ts index 0ea2485e8..0d796b2c0 100644 --- a/src/rest/run_method.ts +++ b/src/rest/run_method.ts @@ -9,7 +9,11 @@ export async function runMethod( retryCount = 0, bucketId?: string ): Promise { - rest.debug(`[REST - RequestCreate] Method: ${method} | URL: ${url} | Retry Count: ${retryCount} | Bucket ID: ${bucketId} | Body: ${JSON.stringify(body)}`) + rest.debug( + `[REST - RequestCreate] Method: ${method} | URL: ${url} | Retry Count: ${retryCount} | Bucket ID: ${bucketId} | Body: ${JSON.stringify( + body + )}` + ); const errorStack = new Error("Location:"); // @ts-ignore Breaks deno deploy. Luca said add tsignore until it's fixed