diff --git a/.dev.env b/.dev.env index d1b74b1..853096a 100644 --- a/.dev.env +++ b/.dev.env @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.3.1 +BOT_VER=0.3.0 DEV BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 diff --git a/.prod.env b/.prod.env index 0755c1e..c2d4d52 100644 --- a/.prod.env +++ b/.prod.env @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.3.1 +BOT_VER=0.3.0 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=1093810443589529631 diff --git a/.stage.env b/.stage.env index 4f70991..131fe37 100644 --- a/.stage.env +++ b/.stage.env @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.3.1 +BOT_VER=0.3.0 BETA BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=1147976642942214235 diff --git a/package-lock.json b/package-lock.json index ab404e8..6b5a430 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "card-drop", - "version": "0.3.1", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "card-drop", - "version": "0.3.1", + "version": "0.3.0", "license": "MIT", "dependencies": { "@discordjs/rest": "^2.0.0", diff --git a/package.json b/package.json index a70138f..64f40a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "card-drop", - "version": "0.3.1", + "version": "0.3.0", "main": "./dist/bot.js", "typings": "./dist", "scripts": { diff --git a/src/buttonEvents/Reroll.ts b/src/buttonEvents/Reroll.ts index 3b86e72..274c846 100644 --- a/src/buttonEvents/Reroll.ts +++ b/src/buttonEvents/Reroll.ts @@ -27,37 +27,45 @@ export default class Reroll extends ButtonEvent { return; } + let image: Buffer; + const imageFileName = randomCard.card.path.split("/").pop()!; + try { - let image: Buffer; - const imageFileName = randomCard.card.path.split("/").pop()!; - image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path)); + } catch { + await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`); + return; + } - await interaction.deferReply(); + await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); - const quantityClaimed = inventory ? inventory.Quantity : 0; + const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); + const quantityClaimed = inventory ? inventory.Quantity : 0; - const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); + const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); - const claimId = v4(); + const claimId = v4(); - const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); + const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); + try { await interaction.editReply({ embeds: [ embed ], files: [ attachment ], components: [ row ], }); - - CoreClient.ClaimId = claimId; - } catch (e) { console.error(e); - await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`); + if (e instanceof DiscordAPIError) { + await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`); + } else { + await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`); + } } + + CoreClient.ClaimId = claimId; } } \ No newline at end of file diff --git a/src/commands/drop.ts b/src/commands/drop.ts index 5a8ccd9..9c6646a 100644 --- a/src/commands/drop.ts +++ b/src/commands/drop.ts @@ -35,38 +35,45 @@ export default class Drop extends Command { return; } + let image: Buffer; + const imageFileName = randomCard.card.path.split("/").pop()!; + try { - let image: Buffer; - const imageFileName = randomCard.card.path.split("/").pop()!; - image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path)); + } catch { + await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`); + return; + } - await interaction.deferReply(); + await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); - const quantityClaimed = inventory ? inventory.Quantity : 0; + const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); + const quantityClaimed = inventory ? inventory.Quantity : 0; - const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); + const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); - const claimId = v4(); + const claimId = v4(); - const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); + const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); + try { await interaction.editReply({ embeds: [ embed ], files: [ attachment ], components: [ row ], }); - - CoreClient.ClaimId = claimId; - } catch (e) { console.error(e); - await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`); + if (e instanceof DiscordAPIError) { + await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`); + } else { + await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`); + } } + CoreClient.ClaimId = claimId; } } \ No newline at end of file