From 6e448907ee9d51bc2148565807824c845980dbf1 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Mon, 20 Jun 2022 20:55:40 -0400 Subject: [PATCH] deno fmt --- src/endpoints/gets/apiRoll.ts | 30 +++++++++------- src/solver/rollQueue.ts | 66 +++++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/endpoints/gets/apiRoll.ts b/src/endpoints/gets/apiRoll.ts index 37658ea..3991836 100644 --- a/src/endpoints/gets/apiRoll.ts +++ b/src/endpoints/gets/apiRoll.ts @@ -10,10 +10,10 @@ import { Status, STATUS_TEXT, } from '../../../deps.ts'; -import { RollModifiers, QueuedRoll } from '../../mod.d.ts'; +import { QueuedRoll, RollModifiers } from '../../mod.d.ts'; import { queueRoll } from '../../solver/rollQueue.ts'; -const apiWarning = `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>`; +const apiWarning = `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>`; export const apiRoll = async (requestEvent: Deno.RequestEvent, query: Map, apiUserid: BigInt) => { // Make sure query contains all the needed parts @@ -97,13 +97,15 @@ export const apiRoll = async (requestEvent: Deno.RequestEvent, query: Map { - apiRoll: true, - api: { requestEvent, channelId: BigInt(query.get('channel') || '0'), userId: BigInt(query.get('user') || '')}, - rollCmd, - modifiers, - originalCommand, - }); + await queueRoll( + { + apiRoll: true, + api: { requestEvent, channelId: BigInt(query.get('channel') || '0'), userId: BigInt(query.get('user') || '') }, + rollCmd, + modifiers, + originalCommand, + }, + ); } catch (err) { // Handle any errors we missed log(LT.ERROR, `Unhandled Error: ${JSON.stringify(err)}`); @@ -111,10 +113,12 @@ export const apiRoll = async (requestEvent: Deno.RequestEvent, query: Map { rollWorker.terminate(); currentWorkers--; if (rq.apiRoll) { - rq.api.requestEvent.respondWith(new Response( - 'Roll took too long to process, try breaking roll down into simpler parts', - { status: Status.RequestTimeout, statusText: STATUS_TEXT.get(Status.RequestTimeout) } - )); + rq.api.requestEvent.respondWith( + new Response( + 'Roll took too long to process, try breaking roll down into simpler parts', + { status: Status.RequestTimeout, statusText: STATUS_TEXT.get(Status.RequestTimeout) }, + ), + ); } else { rq.dd.m.edit({ embeds: [ @@ -74,10 +76,12 @@ const handleRollWorker = async (rq: QueuedRoll) => { // If there was an error, report it to the user in hopes that they can determine what they did wrong if (returnmsg.error) { if (rq.apiRoll) { - rq.api.requestEvent.respondWith(new Response( - returnmsg.errorMsg, - { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) } - )); + rq.api.requestEvent.respondWith( + new Response( + returnmsg.errorMsg, + { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) }, + ), + ); } else { rq.dd.m.edit({ embeds: [pubEmbedDetails.embed] }); } @@ -95,13 +99,15 @@ const handleRollWorker = async (rq: QueuedRoll) => { if (rq.apiRoll) { n = await sendMessage(rq.api.channelId, { content: rq.modifiers.apiWarn, - embeds: [pubEmbedDetails.embed] + embeds: [pubEmbedDetails.embed], }).catch(() => { apiErroredOut = true; - rq.api.requestEvent.respondWith(new Response( - 'Message failed to send.', - { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) } - )); + rq.api.requestEvent.respondWith( + new Response( + 'Message failed to send.', + { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) }, + ), + ); }); } else { // Send the public embed to correct channel @@ -142,13 +148,15 @@ const handleRollWorker = async (rq: QueuedRoll) => { if (rq.apiRoll) { n = await sendMessage(rq.api.channelId, { content: rq.modifiers.apiWarn, - embeds: rq.modifiers.count ? [pubEmbedDetails.embed, countEmbed] : [pubEmbedDetails.embed] + embeds: rq.modifiers.count ? [pubEmbedDetails.embed, countEmbed] : [pubEmbedDetails.embed], }).catch(() => { apiErroredOut = true; - rq.api.requestEvent.respondWith(new Response( - 'Message failed to send.', - { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) } - )); + rq.api.requestEvent.respondWith( + new Response( + 'Message failed to send.', + { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) }, + ), + ); }); } else { n = await rq.dd.m.edit({ @@ -165,21 +173,25 @@ const handleRollWorker = async (rq: QueuedRoll) => { } if (!apiErroredOut) { - rq.api.requestEvent.respondWith(new Response( - JSON.stringify( - rq.modifiers.count ? { counts: countEmbed, details: pubEmbedDetails } : { details: pubEmbedDetails } + rq.api.requestEvent.respondWith( + new Response( + JSON.stringify( + rq.modifiers.count ? { counts: countEmbed, details: pubEmbedDetails } : { details: pubEmbedDetails }, + ), + { status: Status.OK, statusText: STATUS_TEXT.get(Status.OK) }, ), - { status: Status.OK, statusText: STATUS_TEXT.get(Status.OK) } - )); + ); } } } catch (e) { log(LT.ERROR, `Unddandled Error: ${JSON.stringify(e)}`); if (rq.apiRoll && !apiErroredOut) { - rq.api.requestEvent.respondWith(new Response( - JSON.stringify(e), - { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) } - )); + rq.api.requestEvent.respondWith( + new Response( + JSON.stringify(e), + { status: Status.InternalServerError, statusText: STATUS_TEXT.get(Status.InternalServerError) }, + ), + ); } } });