economy: never made the discounted price deductable

This commit is contained in:
Ayden Jahola 2024-10-26 20:10:21 +01:00
parent 81544d3f65
commit 45fdb3537f
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -60,9 +60,9 @@ module.exports = {
} }
const discount = Math.random() < discountChance ? 0.8 : 1; const discount = Math.random() < discountChance ? 0.8 : 1;
const price = Math.floor(item.price * discount); const discountedPrice = Math.floor(item.price * discount);
if (userEconomy.balance < price) { if (userEconomy.balance < discountedPrice) {
const insufficientFundsEmbed = new EmbedBuilder() const insufficientFundsEmbed = new EmbedBuilder()
.setColor("#ff0000") .setColor("#ff0000")
.setTitle("💸 Insufficient Funds") .setTitle("💸 Insufficient Funds")
@ -75,7 +75,11 @@ module.exports = {
value: `${userEconomy.balance} coins`, value: `${userEconomy.balance} coins`,
inline: true, inline: true,
}, },
{ name: "Item Price", value: `${price} coins`, inline: true } {
name: "Item Price",
value: `${discountedPrice} coins`,
inline: true,
}
) )
.setTimestamp() .setTimestamp()
.setFooter({ .setFooter({
@ -90,7 +94,7 @@ module.exports = {
return; return;
} }
userEconomy.balance -= price; userEconomy.balance -= discountedPrice;
await userEconomy.save(); await userEconomy.save();
const userInventory = await UserInventory.findOne({ const userInventory = await UserInventory.findOne({
@ -113,7 +117,9 @@ module.exports = {
const successEmbed = new EmbedBuilder() const successEmbed = new EmbedBuilder()
.setColor("#00ff00") .setColor("#00ff00")
.setTitle("🎉 Purchase Successful") .setTitle("🎉 Purchase Successful")
.setDescription(`You bought **${item.name}** for **${price}** coins!`) .setDescription(
`You bought **${item.name}** for **${discountedPrice}** coins!`
)
.setTimestamp() .setTimestamp()
.setFooter({ .setFooter({
text: `Requested by ${user.username}`, text: `Requested by ${user.username}`,