AeThex-Bot-Master/aethex-bot/commands/daily.js
sirpiglr ca07d17417 Add new commands and improve bot functionality
Introduce several new slash commands including ban, kick, timeout, and userinfo. Enhance existing commands like config and rank with new features and configurations. Add new listeners for welcome and goodbye messages. Implement XP tracking for user leveling and integrate it with role rewards. Update documentation to reflect these changes.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 1be8d824-5029-4875-bed8-0bd1d810892d
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/SQxsvtx
Replit-Helium-Checkpoint-Created: true
2025-12-08 04:09:56 +00:00

110 lines
3.5 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const DAILY_XP = 50;
const STREAK_BONUS = 10;
const MAX_STREAK_BONUS = 100;
module.exports = {
data: new SlashCommandBuilder()
.setName('daily')
.setDescription('Claim your daily XP bonus'),
async execute(interaction, supabase, client) {
if (!supabase) {
return interaction.reply({ content: 'Database not configured.', ephemeral: true });
}
await interaction.deferReply();
try {
const { data: link } = await supabase
.from('discord_links')
.select('user_id')
.eq('discord_id', interaction.user.id)
.single();
if (!link) {
return interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(0xff6b6b)
.setDescription('You need to link your account first! Use `/verify` to get started.')
]
});
}
const { data: profile } = await supabase
.from('user_profiles')
.select('xp, daily_streak, last_daily')
.eq('id', link.user_id)
.single();
const now = new Date();
const lastDaily = profile?.last_daily ? new Date(profile.last_daily) : null;
const currentXp = profile?.xp || 0;
let streak = profile?.daily_streak || 0;
if (lastDaily) {
const hoursSince = (now - lastDaily) / (1000 * 60 * 60);
if (hoursSince < 20) {
const nextClaim = new Date(lastDaily.getTime() + 20 * 60 * 60 * 1000);
return interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(0xfbbf24)
.setTitle('Already Claimed!')
.setDescription(`You've already claimed your daily XP.\nNext claim: <t:${Math.floor(nextClaim.getTime() / 1000)}:R>`)
.addFields({ name: 'Current Streak', value: `🔥 ${streak} days` })
]
});
}
if (hoursSince > 48) {
streak = 0;
}
}
streak += 1;
const streakBonus = Math.min(streak * STREAK_BONUS, MAX_STREAK_BONUS);
const totalXp = DAILY_XP + streakBonus;
const newXp = currentXp + totalXp;
await supabase
.from('user_profiles')
.update({
xp: newXp,
daily_streak: streak,
last_daily: now.toISOString()
})
.eq('id', link.user_id);
const newLevel = Math.floor(Math.sqrt(newXp / 100));
const oldLevel = Math.floor(Math.sqrt(currentXp / 100));
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Daily Reward Claimed!')
.setDescription(`You received **+${totalXp} XP**!`)
.addFields(
{ name: 'Base XP', value: `+${DAILY_XP}`, inline: true },
{ name: 'Streak Bonus', value: `+${streakBonus}`, inline: true },
{ name: 'Current Streak', value: `🔥 ${streak} days`, inline: true },
{ name: 'Total XP', value: newXp.toLocaleString(), inline: true },
{ name: 'Level', value: `${newLevel}`, inline: true }
)
.setFooter({ text: 'Come back tomorrow to keep your streak!' })
.setTimestamp();
if (newLevel > oldLevel) {
embed.addFields({ name: '🎉 Level Up!', value: `You reached level ${newLevel}!` });
}
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error('Daily error:', error);
await interaction.editReply({ content: 'Failed to claim daily reward.' });
}
},
};