From 2d7fd61abb37cff1774de0f147b44880fe9378b3 Mon Sep 17 00:00:00 2001 From: Carter Penterman Date: Mon, 26 Aug 2024 21:38:17 -0500 Subject: [PATCH] Improve error messages a bit for new API --- commands/submit.js | 10 +++++----- commands/take.js | 13 ++++++++----- common.js | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/commands/submit.js b/commands/submit.js index 4dbdfc6..0319970 100644 --- a/commands/submit.js +++ b/commands/submit.js @@ -53,7 +53,7 @@ async function execute(interaction) { try { // Check that the bot owns this model if (!(await noblox.getOwnership(await getCurrentUser(), id, "Asset"))) { - const msg = `🚫 The ${game} maptest bot's inventory does not contain this asset (\`${id}\`). You must use the /take command first.`; + const msg = `🚫 The ${game} maptest bot's inventory does not contain this asset (id: \`${id}\`). You must use the /take command first.`; await interaction.editReply(msg); return; } @@ -61,13 +61,13 @@ async function execute(interaction) { if (error.message !== "400 The specified Asset does not exist!") { throw error; } - await interaction.editReply(`🚫 This asset does not exist (\`${id}\`).`); + await interaction.editReply(`🚫 This asset does not exist (id: \`${id}\`).`); return; } const assetInfo = await getAssetInfo(id); if (!assetInfo.isModel) { - await interaction.editReply(`🚫 This asset (\`${id}\`) is not a model. Your map must be a model.`); + await interaction.editReply(`🚫 This asset (id: \`${id}\`) is not a model. Your map must be a model.`); return; } @@ -87,7 +87,7 @@ async function execute(interaction) { for (let lineStr of lines) { const line = getSubmissionLine(lineStr); if (id === line.modelId) { - await interaction.editReply(`🚫 This map (id: ${id}) was already submitted on .`); + await interaction.editReply(`🚫 This map (id: \`${id}\`) was already submitted on .`); return; } } @@ -112,7 +112,7 @@ async function execute(interaction) { csvString += createSubmissionLine(id, unixTimestamp, userId, await robloxUsernameFromId(userId), validation.displayName, validation.creator); fs.writeFileSync(fname, csvString); - await interaction.followUp(`Map (id: ${id}) successfully submitted.`); + await interaction.followUp(`Map (id: \`${id}\`) successfully submitted.`); } module.exports = { diff --git a/commands/take.js b/commands/take.js index ddc0f52..db322d7 100644 --- a/commands/take.js +++ b/commands/take.js @@ -31,17 +31,20 @@ async function execute(interaction) { // Validate that this is a model const assetInfo = await getAssetInfo(id); - if (assetInfo.status !== 403 && (assetInfo.status < 200 || assetInfo.status >= 300)) { - await interaction.editReply(`🚫 This asset may not exist or is not a model (id: \`${id}\`). Your map must be a model.`); + if (assetInfo.status === 404) { + await interaction.editReply(`🚫 This [model]() (id: \`${id}\`) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store). Alternatively, the provided ID may not actually be a model.`); return; } - // 403 (Forbidden) means the asset isn't distributed - if (assetInfo.status === 403 || (assetInfo.forSale === false)) { + if (assetInfo.status < 200 || assetInfo.status >= 300) { + await interaction.editReply(`🚫 Something unexpected went wrong trying to retrive info about the model (id: \`${id}\`).`); + return; + } + if (assetInfo.forSale === false) { await interaction.editReply(`🚫 This [model]() (id: \`${id}\`) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store).`); return; } if (!assetInfo.isModel) { - await interaction.editReply(`🚫 This asset (id: \`${id}\` is not a model. Your map must be a model.`); + await interaction.editReply(`🚫 This asset (id: \`${id}\`) is not a model. Your map must be a model.`); return; } if (!assetInfo.isFree) { diff --git a/common.js b/common.js index 8d5c4df..48389e1 100644 --- a/common.js +++ b/common.js @@ -41,7 +41,7 @@ async function getAssetInfo(assetId) { if (res.statusCode < 200 || res.statusCode >= 300) { return { - status: res.status, + status: res.statusCode, isModel: false }; }