diff --git a/src/artigen/managers/handler/workerComplete.ts b/src/artigen/managers/handler/workerComplete.ts index 7ce8de5..9579fab 100644 --- a/src/artigen/managers/handler/workerComplete.ts +++ b/src/artigen/managers/handler/workerComplete.ts @@ -25,6 +25,7 @@ import stdResp from 'endpoints/stdResponses.ts'; import { InteractionValueSeparator } from 'events/interactionCreate.ts'; import utils from 'utils/utils.ts'; +import { STATUS_CODE, STATUS_TEXT } from '@std/http/status'; const getUserIdForEmbed = (rollRequest: QueuedRoll): bigint => { if (rollRequest.apiRoll) return rollRequest.api.userId; @@ -60,10 +61,11 @@ export const onWorkerComplete = async (workerMessage: MessageEvent, const gmEmbeds: Embed[] = [gmEmbedDetails.embed]; const pubAttachments: FileContent[] = pubEmbedDetails.hasAttachment ? [pubEmbedDetails.attachment] : []; const gmAttachments: FileContent[] = gmEmbedDetails.hasAttachment ? [gmEmbedDetails.attachment] : []; + let countEmbed, rollDistEmbed; // Handle adding count embed to correct list if (rollRequest.modifiers.count) { - const countEmbed = generateCountDetailsEmbed(returnMsg.counts); + countEmbed = generateCountDetailsEmbed(returnMsg.counts); if (rollRequest.modifiers.gmRoll) { gmEmbeds.push(countEmbed.embed); gmRespCharCount += countEmbed.charCount; @@ -75,7 +77,7 @@ export const onWorkerComplete = async (workerMessage: MessageEvent, // Handle adding rollDist embed to correct list if (rollRequest.modifiers.rollDist) { - const rollDistEmbed = generateRollDistsEmbed(returnMsg.rollDistributions); + rollDistEmbed = generateRollDistsEmbed(returnMsg.rollDistributions); if (rollRequest.modifiers.gmRoll) { gmEmbeds.push(rollDistEmbed.embed); rollDistEmbed.hasAttachment && gmAttachments.push(rollDistEmbed.attachment); @@ -248,20 +250,33 @@ Please click on "<@${botId}> *Click to see attachment*" above this message to se .execute(queries.insertRollLogCmd(1, 0), [rollRequest.originalCommand, returnMsg.errorCode, newMsg ? newMsg.id : null]) .catch((e) => utils.commonLoggers.dbError('rollQueue.ts:155', 'insert into', e)); + const headers = new Headers(); + headers.append('Content-Type', 'text/json'); apiResolve && apiResolve( - stdResp.OK( - JSON.stringify( - rollRequest.modifiers.count - ? { - counts: returnMsg.counts, - details: pubEmbedDetails, - } - : { - details: pubEmbedDetails, + new Response( + JSON.stringify({ + discordEmbeds: { + rollResponse: pubEmbedDetails, + countsResponse: countEmbed ?? null, + rollDistResponse: rollDistEmbed ?? null, + }, + rawData: { + roll: { + raw: returnMsg.line1, + results: returnMsg.line2, + details: returnMsg.line3, }, - ), - ), + counts: rollRequest.modifiers.count ? returnMsg.counts : null, + rollDistributions: returnMsg.rollDistributions.entries().toArray(), + }, + }), + { + status: STATUS_CODE.OK, + statusText: STATUS_TEXT[STATUS_CODE.OK], + headers, + } + ) ); } } catch (e) { @@ -272,13 +287,12 @@ Please click on "<@${botId}> *Click to see attachment*" above this message to se ( await generateRollEmbed( rollRequest.dd.authorId, - { + { error: true, - errorMsg: - `Something weird went wrong, likely the requested roll is too complex and caused the response to be too large for Discord. Try breaking the request down into smaller messages and try again.\n\nIf this error continues to come up, please \`${config.prefix}report\` this to my developer.`, + errorMsg: `Something weird went wrong, likely the requested roll is too complex and caused the response to be too large for Discord. Try breaking the request down into smaller messages and try again.\n\nIf this error continues to come up, please \`${config.prefix}report\` this to my developer.`, errorCode: 'UnhandledWorkerComplete', }, - {}, + {} ) ).embed, ], diff --git a/src/endpoints/gets/apiRoll.ts b/src/endpoints/gets/apiRoll.ts index 7ec6f9b..83cde97 100644 --- a/src/endpoints/gets/apiRoll.ts +++ b/src/endpoints/gets/apiRoll.ts @@ -119,7 +119,7 @@ export const apiRoll = async (query: Map, apiUserid: bigint): Pr const [name, rawSides] = shape.split(':').filter((x) => x); if (!name || !rawSides) { return stdResp.BadRequest( - 'cd specified with invalid pattern. Must be in format of `name:[side1,side2,...,sideN]`. If multiple custom dice shapes are needed, use a `;` to separate the list', + 'cd specified with invalid pattern. Must be in format of `name:[side1,side2,...,sideN]`. If multiple custom dice shapes are needed, use a `;` to separate the list' ); } @@ -181,9 +181,13 @@ export const apiRoll = async (query: Map, apiUserid: bigint): Pr } } else { // Alert API user that they messed up - return stdResp.Forbidden( - `Verify you are a member of the guild you are sending this roll to. If you are, the ${config.name} may not have that registered, please send a message in the guild so ${config.name} can register this. This registration is temporary, so if you see this error again, just poke your server again.`, - ); + return stdResp.Forbidden(`Verify you are a member of the guild you are sending this roll to. + +If you are, ${config.name} may not have that guild actively cached. + +Please send a message in the guild so ${config.name} can cache this guild. ${config.name}'s cache will clear out inactive guilds after some time, so if you see this error again, just poke the guild again. + +If you still see this error after "poking" your guild, please verify the channel allows API Rolls (${config.prefix}api status).`); } } else { // Alert API user that they shouldn't be doing this