forked from syntaxbullet/AuroraBot-discord
feat: Introduce new modules for class, inventory, leveling, and quests with expanded schema, refactor user service, and add verification scripts.
This commit is contained in:
@@ -1,68 +1,42 @@
|
||||
import { createCommand } from "@lib/utils";
|
||||
import { addUserBalance } from "@/modules/economy/economy.service";
|
||||
import { createUser, getUserById, updateUserDaily } from "@/modules/users/users.service";
|
||||
import { createCommand } from "@/lib/utils";
|
||||
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
|
||||
import { economyService } from "@/modules/economy/economy.service";
|
||||
|
||||
export const daily = createCommand({
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("daily")
|
||||
.setDescription("Get rewarded with daily coins"),
|
||||
.setDescription("Claim your daily reward"),
|
||||
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);
|
||||
}
|
||||
await interaction.deferReply();
|
||||
|
||||
const now = new Date();
|
||||
const lastDaily = dbUser.lastDaily;
|
||||
try {
|
||||
const result = await economyService.claimDaily(interaction.user.id);
|
||||
|
||||
if (lastDaily) {
|
||||
const diff = now.getTime() - lastDaily.getTime();
|
||||
const oneDay = 24 * 60 * 60 * 1000;
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("💰 Daily Reward Claimed!")
|
||||
.setDescription(`You claimed **${result.amount}** coins!`)
|
||||
.addFields(
|
||||
{ name: "Current Streak", value: `🔥 ${result.streak} days`, inline: true },
|
||||
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R>`, inline: true }
|
||||
)
|
||||
.setColor("Gold")
|
||||
.setTimestamp();
|
||||
|
||||
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));
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
} catch (error: any) {
|
||||
if (error.message.includes("Daily already claimed")) {
|
||||
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 });
|
||||
.setTitle("⏳ Cooldown")
|
||||
.setDescription(error.message)
|
||||
.setColor("Orange");
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(error);
|
||||
await interaction.editReply({ content: "❌ An error occurred while claiming your daily reward." });
|
||||
}
|
||||
|
||||
// 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] });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user