forked from syntaxbullet/AuroraBot-discord
35 lines
1.7 KiB
TypeScript
35 lines
1.7 KiB
TypeScript
|
|
import { createCommand } from "@shared/lib/utils";
|
|
import { SlashCommandBuilder } from "discord.js";
|
|
import { economyService } from "@shared/modules/economy/economy.service";
|
|
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
|
|
import { UserError } from "@/lib/errors";
|
|
|
|
export const daily = createCommand({
|
|
data: new SlashCommandBuilder()
|
|
.setName("daily")
|
|
.setDescription("Claim your daily reward"),
|
|
execute: async (interaction) => {
|
|
try {
|
|
const result = await economyService.claimDaily(interaction.user.id);
|
|
|
|
const embed = createSuccessEmbed(`You claimed ** ${result.amount}** Astral Units!${result.isWeekly ? `\n🎉 **Weekly Bonus!** +${result.weeklyBonus} extra!` : ''}`, "💰 Daily Reward Claimed!")
|
|
.addFields(
|
|
{ name: "Streak", value: `🔥 ${result.streak} days`, inline: true },
|
|
{ name: "Weekly Progress", value: `${"🟩".repeat(result.streak % 7 || 7)}${"⬜".repeat(7 - (result.streak % 7 || 7))} (${result.streak % 7 || 7}/7)`, inline: true },
|
|
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R> `, inline: true }
|
|
)
|
|
.setColor("Gold");
|
|
|
|
await interaction.reply({ embeds: [embed] });
|
|
|
|
} catch (error: any) {
|
|
if (error instanceof UserError) {
|
|
await interaction.reply({ embeds: [createErrorEmbed(error.message)], ephemeral: true });
|
|
} else {
|
|
console.error("Error claiming daily:", error);
|
|
await interaction.reply({ embeds: [createErrorEmbed("An unexpected error occurred.")], ephemeral: true });
|
|
}
|
|
}
|
|
}
|
|
}); |