Use new asset API
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const noblox = require("noblox.js");
|
||||
const { cookies, commands, gamePlaces } = require("../config/config.js");
|
||||
const { AssetType, getAssetInfo, validateMapAsset, getValidationMessage } = require("../common.js");
|
||||
const { getAssetInfo, buyModel, validateMapAsset, getValidationMessage } = require("../common.js");
|
||||
|
||||
/**
|
||||
* @param {import('discord.js').ChatInputCommandInteraction} interaction
|
||||
@ -25,52 +25,34 @@ 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: ${id}).`);
|
||||
await interaction.editReply(`🚫 This asset does not exist (id: \`${id}\`).`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 !== 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.`);
|
||||
return;
|
||||
}
|
||||
// 403 (Forbidden) means the asset isn't distributed
|
||||
if (assetInfo.status === 403 || !assetInfo.forSale) {
|
||||
await interaction.editReply(`🚫 This model (id: ${id}) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store). It is also possible that this is not a valid model.`);
|
||||
if (assetInfo.status === 403 || (assetInfo.forSale === false)) {
|
||||
await interaction.editReply(`🚫 This [model](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store).`);
|
||||
return;
|
||||
}
|
||||
if (assetInfo.typeId !== AssetType.Model) {
|
||||
await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`);
|
||||
if (!assetInfo.isModel) {
|
||||
await interaction.editReply(`🚫 This asset (id: \`${id}\` is not a model. Your map must be a model.`);
|
||||
return;
|
||||
}
|
||||
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](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`) is not free. Please change the price to be free.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Kick off the buy request
|
||||
let buyPromise;
|
||||
if (!alreadyOwned) {
|
||||
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"
|
||||
}
|
||||
})
|
||||
});
|
||||
buyPromise = buyModel(id);
|
||||
}
|
||||
|
||||
// Validate and send the validation result
|
||||
@ -85,8 +67,12 @@ async function execute(interaction) {
|
||||
}
|
||||
|
||||
// Make sure the buy request is done
|
||||
const res = await buyPromise;
|
||||
console.log(JSON.parse(res.body));
|
||||
const success = await buyPromise;
|
||||
if (!success) {
|
||||
await interaction.followUp(`🚫 Something went wrong when trying to buy the [model](<https://create.roblox.com/store/asset/${id}/>) (id: \`${id}\`).`);
|
||||
return;
|
||||
}
|
||||
|
||||
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]}>).
|
||||
|
Reference in New Issue
Block a user