From 4a2bf47258ab7c7f85a002a7a4c6361f90a6385e Mon Sep 17 00:00:00 2001 From: NorySight <114584253+GrishMahat@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:18:13 +0545 Subject: [PATCH 1/2] Update economy.js --- src/schemas/economy.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/schemas/economy.js b/src/schemas/economy.js index 74111627..f584c681 100644 --- a/src/schemas/economy.js +++ b/src/schemas/economy.js @@ -1,15 +1,12 @@ -/** @format */ - import mongoose from 'mongoose'; -// Schema for user balances const balanceSchema = new mongoose.Schema({ userId: { type: String, required: true, unique: true, index: true }, balance: { type: Number, default: 0 }, bank: { type: Number, default: 0 }, + lastDaily: { type: Date, default: null }, lastWeekly: { type: Date, default: null }, lastHourly: { type: Date, default: null }, - lastDaily: { type: Date, default: null }, lastBeg: { type: Date, default: null }, lastcoin: { type: Date, default: null }, lastWork: { type: Date, default: null }, From 3045e2aee13d306087e10fe5b30d639c23c841af Mon Sep 17 00:00:00 2001 From: NorySight <114584253+GrishMahat@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:20:07 +0545 Subject: [PATCH 2/2] Create daliy.js --- src/commands/economy/daliy.js | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/commands/economy/daliy.js diff --git a/src/commands/economy/daliy.js b/src/commands/economy/daliy.js new file mode 100644 index 00000000..f396fb7a --- /dev/null +++ b/src/commands/economy/daliy.js @@ -0,0 +1,76 @@ +import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'; +import { Balance } from '../../schemas/economy.js'; + +export default { + data: new SlashCommandBuilder() + .setName("daily") + .setDescription("Claim your daily reward.") + .toJSON(), + userPermissions: [], + botPermissions: [], + cooldown: 5, + nwfwMode: false, + testMode: false, + devOnly: false, + + run: async (client, interaction) => { + try { + const userId = interaction.user.id; + const emoji = '🎁'; // Using a gift emoji for the daily reward + const minAmount = 1; // Minimum amount to be received + const maxAmount = 30; // Maximum amount to be received + const dailyCooldown = 24 * 60 * 60 * 1000; // 24 hours in milliseconds + + // Fetch the user's balance from the database + let userBalance = await Balance.findOne({ userId }); + + // If the user does not exist in the database, create a new entry + if (!userBalance) { + userBalance = new Balance({ userId }); + } + + // Check if the user has already claimed their daily reward + const now = Date.now(); + if (userBalance.lastDaily && (now - new Date(userBalance.lastDaily).getTime()) < dailyCooldown) { + const timeLeft = dailyCooldown - (now - new Date(userBalance.lastDaily).getTime()); + const hours = Math.floor(timeLeft / (1000 * 60 * 60)); + const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60)); + + const embed = new EmbedBuilder() + .setColor(0xFF0000) + .setTitle('Daily Reward') + .setDescription(`You have already claimed your daily reward. Please try again in ${hours} hours and ${minutes} minutes.`); + + return interaction.reply({ embeds: [embed], ephemeral: true }); + } + + // Generate a random amount for the daily reward + const amount = Math.floor(Math.random() * (maxAmount - minAmount + 1)) + minAmount; + + // Update the user's balance and last daily claim time + userBalance.balance += amount; + userBalance.lastDaily = new Date(); + await userBalance.save(); + + // Create an embed for the response + const embed = new EmbedBuilder() + .setColor(0x00FF00) + .setTitle('Daily Reward') + .setDescription(`${emoji} You have claimed your daily reward of ${amount} coins!`) + .addFields( + { name: 'New Balance', value: `${userBalance.balance} coins`, inline: true }, + ); + + // Reply with the embed + await interaction.reply({ embeds: [embed] }); + } catch (error) { + console.error('Error processing daily command:', error); + const embed = new EmbedBuilder() + .setColor(0xFF0000) + .setTitle('Error') + .setDescription('There was an error trying to process your daily reward.'); + + await interaction.reply({ embeds: [embed], ephemeral: true }); + } + }, +};