Added Pay and Daily

This commit is contained in:
2025-12-06 00:08:49 +05:30
parent cea52b0c6e
commit 24138988e6
5 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
import { createCommand } from "@lib/utils";
import { addUserBalance } from "@/modules/economy/economy.service";
import { createUser, getUserById, updateUserDaily } from "@/modules/users/users.service";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
export const daily = createCommand({
data: new SlashCommandBuilder()
.setName("daily")
.setDescription("Get rewarded with daily coins"),
execute: async (interaction) => {
const user = interaction.user;
// Ensure user exists in DB
let dbUser = await getUserById(user.id);
if (!dbUser) {
dbUser = await createUser(user.id);
}
const now = new Date();
const lastDaily = dbUser.lastDaily;
if (lastDaily) {
const diff = now.getTime() - lastDaily.getTime();
const oneDay = 24 * 60 * 60 * 1000;
if (diff < oneDay) {
const remaining = oneDay - diff;
const hours = Math.floor(remaining / (1000 * 60 * 60));
const minutes = Math.floor((remaining % (1000 * 60 * 60)) / (1000 * 60));
const embed = new EmbedBuilder()
.setTitle("Daily Reward")
.setDescription(`You have already claimed your daily reward.\nCome back in **${hours}h ${minutes}m**.`)
.setColor("Red");
await interaction.reply({ embeds: [embed], ephemeral: true });
return;
}
}
// Calculate streak
let streak = dbUser.dailyStreak;
if (lastDaily) {
const diff = now.getTime() - lastDaily.getTime();
const twoDays = 48 * 60 * 60 * 1000;
if (diff < twoDays) {
streak += 1;
} else {
streak = 1;
}
} else {
streak = 1;
}
const baseReward = 100;
const streakBonus = (streak - 1) * 10;
const totalReward = baseReward + streakBonus;
await updateUserDaily(user.id, now, streak);
await addUserBalance(user.id, totalReward);
const embed = new EmbedBuilder()
.setTitle("Daily Reward Claimed!")
.setDescription(`You received **${totalReward} coins**! 💰\n\n**Streak:** ${streak} days 🔥`)
.setColor("Green");
await interaction.reply({ embeds: [embed] });
}
});