Use non-rate-limited API and improve some stuff
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const noblox = require("noblox.js");
|
||||
const { cookies, commands } = require("../config/config.js");
|
||||
const { AssetType, getAssetInfo } = require("../common.js");
|
||||
|
||||
async function execute(interaction) {
|
||||
const game = interaction.options.getString("game");
|
||||
@ -18,28 +19,37 @@ async function execute(interaction) {
|
||||
await interaction.reply({content: msg, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
let info;
|
||||
// Validate that this is a model
|
||||
try {
|
||||
info = await noblox.getProductInfo(id);
|
||||
if (info.AssetTypeId != 10) {
|
||||
await interaction.reply({content: `(id: ${id}) is not a valid model ID.`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
// Roblox only lets you call the product info API like once per 30 seconds for some reason...
|
||||
if (error.message.startsWith("429")) {
|
||||
await interaction.reply({content: `The maptest bot is being rate-limited by Roblox, please wait a minute before doing this command again.`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
console.log(error);
|
||||
await interaction.reply({content: `There is a problem with this asset ID (id: ${id}).`, ephemeral: true});
|
||||
const assetInfo = await getAssetInfo(id);
|
||||
if (assetInfo.status === 404) {
|
||||
await interaction.reply({content: `This asset may not exist or is not a model (id: ${id}). Your map must be a model.`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
// 403 (Forbidden) means the asset isn't distributed
|
||||
if (assetInfo.status === 403 || !assetInfo.forSale) {
|
||||
await interaction.reply({content: `This model (id: ${id}) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store).`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
if (assetInfo.typeId !== AssetType.Model) {
|
||||
await interaction.reply({content: `This asset (id: ${id}) is not a model. Your map must be a model.`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
if (assetInfo.price !== 0) {
|
||||
await interaction.reply({content: `This model (id: ${id}) is not free. Please change the price to be free.`, ephemeral: true});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await noblox.buy({product: info, price: 0});
|
||||
await interaction.reply(
|
||||
// Make a "fake" product info object for the Noblox buy method
|
||||
const productInfo = {
|
||||
PriceInRobux: assetInfo.price,
|
||||
ProductId: assetInfo.productId,
|
||||
Creator: {
|
||||
Id: assetInfo.creatorId
|
||||
}
|
||||
}
|
||||
|
||||
await noblox.buy({product: productInfo, price: 0});
|
||||
await interaction.reply(
|
||||
`
|
||||
Now that your map (id: ${id}) has been taken by the ${game} maptest bot you can load it into the ${game} maptest place. To load your map, join the game and say
|
||||
\`\`\`
|
||||
@ -47,16 +57,7 @@ Now that your map (id: ${id}) has been taken by the ${game} maptest bot you can
|
||||
\`\`\`Read what it says. If your map successfully loaded type !rtv and then choose your map.
|
||||
If it did not load successfully, you can expand the chat to view the full error message by clicking and dragging on the edge of the chat.
|
||||
`
|
||||
);
|
||||
} catch (error) {
|
||||
if (error.message == "You already own this item.") {
|
||||
await interaction.reply({content: "The bot has already taken this model!", ephemeral: true});
|
||||
} else {
|
||||
await interaction.reply({content: `An error occured trying to take the model (id: ${id}). Make sure it is uncopylocked!`, ephemeral: true});
|
||||
console.log(`Could not take asset ID ${id}: `);
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Reference in New Issue
Block a user