From e4e6135a21fe7d4fe25c2b0442d885bbc892ad8d Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Sat, 26 Oct 2024 19:42:52 +0100 Subject: [PATCH] economy: forgot to add the streak to schema, and adjust shop logic with categories and type --- commands/economy/daily.js | 9 ++++++++- commands/economy/shop.js | 4 +++- models/ShopItem.js | 2 ++ models/UserEconomy.js | 1 + utils/seedShopItems.js | 23 +++++++++++++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/commands/economy/daily.js b/commands/economy/daily.js index 02eeb0c..896f175 100644 --- a/commands/economy/daily.js +++ b/commands/economy/daily.js @@ -22,10 +22,12 @@ module.exports = { userEconomy = await UserEconomy.create({ userId: user.id, guildId: guild.id, + streak: 0, // Initialize streak }); } const now = new Date(); + if (userEconomy.lastDaily && now - userEconomy.lastDaily < oneDay) { const remainingTime = new Date(userEconomy.lastDaily.getTime() + oneDay) - now; @@ -49,8 +51,13 @@ module.exports = { return; } - let reward = dailyBaseReward + userEconomy.streak * streakBonus; + if (userEconomy.lastDaily && now - userEconomy.lastDaily >= oneDay) { + userEconomy.streak = 0; + } + userEconomy.streak += 1; + + let reward = dailyBaseReward + userEconomy.streak * streakBonus; userEconomy.lastDaily = now; userEconomy.balance += reward; diff --git a/commands/economy/shop.js b/commands/economy/shop.js index 3ba06dd..c1ce528 100644 --- a/commands/economy/shop.js +++ b/commands/economy/shop.js @@ -31,7 +31,9 @@ module.exports = { const price = Math.floor(item.price * discount); const discountText = discount < 1 ? " (Discounted!)" : ""; - return `${item.name} - **${price}** coins${discountText} - Rarity: ${item.rarity}`; + return `${item.name} - **${price}** coins${discountText} - Rarity: ${ + item.rarity + } - Type: ${item.type} - Category: ${item.category || "N/A"}`; }); const shopEmbed = new EmbedBuilder() diff --git a/models/ShopItem.js b/models/ShopItem.js index 71a29ec..ecb1085 100644 --- a/models/ShopItem.js +++ b/models/ShopItem.js @@ -11,6 +11,8 @@ const shopItemSchema = new mongoose.Schema({ enum: ["Common", "Rare", "Epic", "Legendary"], default: "Common", }, + type: { type: String, required: true }, + category: { type: String }, }); module.exports = mongoose.model("ShopItem", shopItemSchema); diff --git a/models/UserEconomy.js b/models/UserEconomy.js index d269140..1ad5fcf 100644 --- a/models/UserEconomy.js +++ b/models/UserEconomy.js @@ -6,6 +6,7 @@ const userEconomySchema = new mongoose.Schema({ balance: { type: Number, default: 200 }, lastDaily: { type: Date, default: null }, lastWork: { type: Date, default: null }, + streak: { type: Number, default: 0 }, }); module.exports = mongoose.model("UserEconomy", userEconomySchema); diff --git a/utils/seedShopItems.js b/utils/seedShopItems.js index 930f346..7aac6c9 100644 --- a/utils/seedShopItems.js +++ b/utils/seedShopItems.js @@ -2,6 +2,7 @@ const ShopItem = require("../models/ShopItem"); async function seedShopItems(guildId) { const items = [ + // Valorant Skins { itemId: "prime_vandal", name: "Prime Vandal", @@ -9,6 +10,8 @@ async function seedShopItems(guildId) { description: "A futuristic skin for the Vandal with a sleek design and special effects.", rarity: "Rare", + type: "Skin", + category: "Valorant", }, { itemId: "reaver_vandal", @@ -17,6 +20,8 @@ async function seedShopItems(guildId) { description: "One of the most popular Vandal skins with a haunting aesthetic and special animations.", rarity: "Epic", + type: "Skin", + category: "Valorant", }, { itemId: "sovereign_ghost", @@ -25,6 +30,8 @@ async function seedShopItems(guildId) { description: "Golden elegance for the Ghost pistol with unique sound effects.", rarity: "Common", + type: "Skin", + category: "Valorant", }, { itemId: "araxys_operator", @@ -33,6 +40,8 @@ async function seedShopItems(guildId) { description: "A top-tier sniper skin with alien-like animations and sound effects.", rarity: "Legendary", + type: "Skin", + category: "Valorant", }, { itemId: "glitchpop_bulldog", @@ -41,7 +50,11 @@ async function seedShopItems(guildId) { description: "A flashy skin for the Bulldog with vibrant colors and cyberpunk vibe.", rarity: "Rare", + type: "Skin", + category: "Valorant", }, + + // CS2 Skins { itemId: "dragon_lore_awp", name: "AWP Dragon Lore", @@ -49,6 +62,8 @@ async function seedShopItems(guildId) { description: "A legendary skin for the AWP with dragon designs, a rare and coveted item.", rarity: "Legendary", + type: "Skin", + category: "CS2", }, { itemId: "ak47_redline", @@ -57,6 +72,8 @@ async function seedShopItems(guildId) { description: "A simple yet iconic AK-47 skin with red and black color scheme.", rarity: "Common", + type: "Skin", + category: "CS2", }, { itemId: "m4a4_howl", @@ -65,6 +82,8 @@ async function seedShopItems(guildId) { description: "A rare and valuable skin for the M4A4 with a striking wolf design.", rarity: "Epic", + type: "Skin", + category: "CS2", }, { itemId: "desert_eagle_kumicho_dragon", @@ -73,6 +92,8 @@ async function seedShopItems(guildId) { description: "A Desert Eagle skin with an intricate dragon design and a metallic finish.", rarity: "Rare", + type: "Skin", + category: "CS2", }, { itemId: "usp_kill_confirmed", @@ -81,6 +102,8 @@ async function seedShopItems(guildId) { description: "A detailed skin for the USP-S with a unique comic-style design.", rarity: "Epic", + type: "Skin", + category: "CS2", }, ];