change: prettier code

This commit is contained in:
Skillz4Killz
2021-10-07 15:06:03 +00:00
committed by GitHub Action
parent a9e5ce01c9
commit 3878115640
3 changed files with 27 additions and 25 deletions
+12 -18
View File
@@ -19,14 +19,11 @@ export async function createBot(options: CreateBotOptions) {
applicationId: options.applicationId || options.botId, applicationId: options.applicationId || options.botId,
token: `Bot ${options.token}`, token: `Bot ${options.token}`,
events: { dispatchRequirements: dispatchRequirements, ...options.events }, events: { dispatchRequirements: dispatchRequirements, ...options.events },
intents: options.intents.reduce( intents: options.intents.reduce((bits, next) => (bits |= DiscordGatewayIntents[next]), 0),
(bits, next) => (bits |= DiscordGatewayIntents[next]), botGatewayData: options.botGatewayData || (await getGatewayBot()),
0
),
botGatewayData: options.botGatewayData || await getGatewayBot(),
isReady: false, 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({ const bot = await createBot({
@@ -34,14 +31,14 @@ const bot = await createBot({
botId: 0n, botId: 0n,
events: createEventHandlers(), events: createEventHandlers(),
intents: [], intents: [],
}) });
export function createEventHandlers(options?: Partial<EventHandlers>) { export function createEventHandlers(options?: Partial<EventHandlers>) {
return { return {
debug: () => undefined, debug: () => undefined,
// PROVIDED OPTIONS OVERRIDE EVERYTHING ABOVE // PROVIDED OPTIONS OVERRIDE EVERYTHING ABOVE
...options ...options,
} };
} }
export interface CreateRestManagerOptions { export interface CreateRestManagerOptions {
@@ -58,7 +55,7 @@ export interface CreateRestManagerOptions {
processRequest?: typeof processRequest; processRequest?: typeof processRequest;
createRequestBody?: typeof createRequestBody; createRequestBody?: typeof createRequestBody;
runMethod?: typeof runMethod; runMethod?: typeof runMethod;
simplifyUrl?: typeof simplifyUrl simplifyUrl?: typeof simplifyUrl;
} }
export function createRestManager(options: CreateRestManagerOptions) { export function createRestManager(options: CreateRestManagerOptions) {
@@ -88,7 +85,7 @@ export function createRestManager(options: CreateRestManagerOptions) {
createRequestBody: options.createRequestBody || createRequestBody, createRequestBody: options.createRequestBody || createRequestBody,
runMethod: options.runMethod || runMethod, runMethod: options.runMethod || runMethod,
simplifyUrl: options.simplifyUrl || simplifyUrl, simplifyUrl: options.simplifyUrl || simplifyUrl,
} };
} }
export async function startBot(bot: Bot) { export async function startBot(bot: Bot) {
@@ -96,12 +93,11 @@ export async function startBot(bot: Bot) {
bot.rest = createRestManager({ token: bot.token }); bot.rest = createRestManager({ token: bot.token });
// START WS // START WS
bot.gateway = createGatewayManager() bot.gateway = createGatewayManager();
} }
export function stopBot(bot: Bot) { export function stopBot(bot: Bot) {
// STOP REST // STOP REST
// STOP WS // STOP WS
} }
@@ -122,13 +118,11 @@ export type CreatedBot = UnPromise<ReturnType<typeof createBot>>;
export type Bot = CreatedBot & { export type Bot = CreatedBot & {
rest: RestManager; rest: RestManager;
gateway: GatewayManager; gateway: GatewayManager;
} };
export type RestManager = ReturnType<typeof createRestManager>; export type RestManager = ReturnType<typeof createRestManager>;
export interface GatewayManager { export interface GatewayManager {}
}
export interface EventHandlers { export interface EventHandlers {
debug: (text: string) => unknown; debug: (text: string) => unknown;
+6 -2
View File
@@ -34,7 +34,9 @@ export async function processQueue(rest: RestManager, id: string) {
} }
// IF A BUCKET EXISTS, CHECK THE BUCKET'S RATE LIMITS // 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 // THIS BUCKET IS STILL RATELIMITED, RE-ADD TO QUEUE
if (bucketResetIn) continue; if (bucketResetIn) continue;
@@ -71,7 +73,9 @@ export async function processQueue(rest: RestManager, id: string) {
} }
if (response.status < 200 || response.status >= 400) { 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"; let error = "REQUEST_UNKNOWN_ERROR";
switch (response.status) { switch (response.status) {
+5 -1
View File
@@ -9,7 +9,11 @@ export async function runMethod<T = any>(
retryCount = 0, retryCount = 0,
bucketId?: string bucketId?: string
): Promise<T> { ): Promise<T> {
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:"); const errorStack = new Error("Location:");
// @ts-ignore Breaks deno deploy. Luca said add tsignore until it's fixed // @ts-ignore Breaks deno deploy. Luca said add tsignore until it's fixed