Log errors to a channel and also fix/improve error handling

This commit is contained in:
2024-04-25 12:33:55 -05:00
parent 1a1019b37b
commit 9cb8c24e58
7 changed files with 95 additions and 52 deletions

@ -10,35 +10,45 @@ async function execute(interaction) {
const game = interaction.options.getString("game", true);
const cookie = cookies[game];
if (cookie === undefined) {
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
await interaction.editReply("🚫 Invalid game specified!");
return;
}
const id = interaction.options.getInteger("asset_id", true);
await noblox.setCookie(cookie);
// Check that the bot doesn't already own this asset
if (await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset")) {
const msg = `The ${game} maptest bot already has this model (id: ${id})`;
await interaction.reply({content: msg, ephemeral: true});
try {
// Check that the bot doesn't already own this asset
if (await noblox.getOwnership(await noblox.getCurrentUser("UserID"), id, "Asset")) {
const msg = `🚫 The ${game} maptest bot already has this model (id: ${id})`;
await interaction.editReply(msg);
return;
}
} catch (error) {
if (error.message !== "400 The specified Asset does not exist!") {
throw error;
}
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 === 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});
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.reply({content: `This model (id: ${id}) is off sale. Please configure it to be on sale (Configure -> Distribute on Creator Store).`, ephemeral: true});
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.`);
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});
await interaction.editReply(`🚫 This asset (id: ${id}) is not a model. Your map must be a model.`);
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});
await interaction.editReply(`🚫 This model (id: ${id}) is not free. Please change the price to be free.`);
return;
}
@ -50,9 +60,6 @@ async function execute(interaction) {
Id: assetInfo.creatorId
}
};
// Show "Bot is thinking..."
await interaction.deferReply();
// Kick off the buy request
const buyPromise = noblox.buy({product: productInfo, price: 0});