Initial fix

This commit is contained in:
Carter Penterman 2024-08-21 16:55:26 -05:00
parent 50e9abe5d2
commit 41affeae6e
2 changed files with 36 additions and 16 deletions

View File

@ -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.`); await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`);
return; 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.`); await interaction.editReply(`🚫 This model (id: ${id}) is not free. Please change the price to be free.`);
return; 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 // Kick off the buy request
let buyPromise; let buyPromise;
if (!alreadyOwned) { 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 // Validate and send the validation result
@ -76,7 +85,8 @@ async function execute(interaction) {
} }
// Make sure the buy request is done // Make sure the buy request is done
await buyPromise; const res = await buyPromise;
console.log(JSON.parse(res.body));
await interaction.followUp( await interaction.followUp(
` `
Now that your [map (id: ${id})](<https://create.roblox.com/store/asset/${id}/>) has been taken by the bot you can load it into the [${game} maptest place](<${gamePlaces[game]}>). Now that your [map (id: ${id})](<https://create.roblox.com/store/asset/${id}/>) has been taken by the bot you can load it into the [${game} maptest place](<${gamePlaces[game]}>).

View File

@ -40,6 +40,17 @@ async function getAssetInfo(assetId) {
const data = res.data.data; const data = res.data.data;
const assetInfo = data[0]; 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 { return {
status: res.status, status: res.status,
@ -47,9 +58,8 @@ async function getAssetInfo(assetId) {
name: assetInfo.asset.name, name: assetInfo.asset.name,
typeId: assetInfo.asset.typeId, typeId: assetInfo.asset.typeId,
creatorId: assetInfo.creator.id, creatorId: assetInfo.creator.id,
price: assetInfo.product.price, isFree: isFree,
productId: assetInfo.product.productId, forSale: forSale
forSale: assetInfo.product.isForSaleOrIsPublicDomain
}; };
} }