diff --git a/commands/take.js b/commands/take.js index 4c0fdc1..69ca127 100644 --- a/commands/take.js +++ b/commands/take.js @@ -44,24 +44,33 @@ async function execute(interaction) { await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`); return; } - if (assetInfo.price !== 0) { + if (!assetInfo.isFree) { await interaction.editReply(`🚫 This model (id: ${id}) is not free. Please change the price to be free.`); return; } - // Make a "fake" product info object for the Noblox buy method - const productInfo = { - PriceInRobux: assetInfo.price, - ProductId: assetInfo.productId, - Creator: { - Id: assetInfo.creatorId - } - }; - // Kick off the buy request let buyPromise; if (!alreadyOwned) { - buyPromise = noblox.buy({product: productInfo, price: 0}); + const jar = noblox.options.jar; + const xcsrf = await noblox.getGeneralToken(jar); + buyPromise = noblox.http("https://apis.roblox.com/marketplace-fiat-service/v1/product/purchase", { + method: "POST", + resolveWithFullResponse: true, + jar, + headers: { + "X-CSRF-TOKEN": xcsrf, + "Content-Type": "application/json" + }, + body: JSON.stringify({ + expectedPrice: {currencyCode: "USD", quantity: {significand: 0, exponent: 0}}, + productKey: { + productNamespace: "PRODUCT_NAMESPACE_CREATOR_MARKETPLACE_ASSET", + productTargetId: `${id}`, + productType: "PRODUCT_TYPE_MODEL" + } + }) + }); } // Validate and send the validation result @@ -76,7 +85,8 @@ async function execute(interaction) { } // Make sure the buy request is done - await buyPromise; + const res = await buyPromise; + console.log(JSON.parse(res.body)); await interaction.followUp( ` Now that your [map (id: ${id})]() has been taken by the bot you can load it into the [${game} maptest place](<${gamePlaces[game]}>). diff --git a/common.js b/common.js index 9a1f53f..ae240d0 100644 --- a/common.js +++ b/common.js @@ -40,16 +40,26 @@ async function getAssetInfo(assetId) { const data = res.data.data; const assetInfo = data[0]; - + let isFree, forSale; + if (assetInfo.fiatProduct) { + const quantity = assetInfo.fiatProduct.purchasePrice.quantity; + isFree = quantity.significand === 0 && quantity.exponent === 0; + forSale = assetInfo.fiatProduct.published && assetInfo.fiatProduct.purchasable; + } + else { + isFree = assetInfo.product.price === 0; + forSale = assetInfo.product.isForSaleOrIsPublicDomain; + } + console.log(assetInfo); + return { status: res.status, id: assetId, name: assetInfo.asset.name, typeId: assetInfo.asset.typeId, creatorId: assetInfo.creator.id, - price: assetInfo.product.price, - productId: assetInfo.product.productId, - forSale: assetInfo.product.isForSaleOrIsPublicDomain + isFree: isFree, + forSale: forSale }; }