39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
```typescript
|
|
import { createCommand } from "@/lib/utils";
|
|
import { SlashCommandBuilder, EmbedBuilder, MessageFlags } from "discord.js";
|
|
import { economyService } from "@/modules/economy/economy.service";
|
|
import { createSuccessEmbed, createErrorEmbed } 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 = new EmbedBuilder()
|
|
.setTitle("💰 Daily Reward Claimed!")
|
|
.setDescription(`You claimed ** ${ result.amount }** Astral Units!`)
|
|
.addFields(
|
|
{ name: "Streak", value: `🔥 ${ result.streak } days`, inline: true },
|
|
{ name: "Next Reward", value: `< t:${ Math.floor(result.nextReadyAt.getTime() / 1000) }: R > `, inline: true }
|
|
)
|
|
.setColor("Gold")
|
|
.setTimestamp();
|
|
|
|
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 });
|
|
}
|
|
}
|
|
}
|
|
});
|
|
```
|