Introduces a new server mode configuration system (Federation/Standalone) with associated command changes, dynamic status rotation for the bot, and adds new commands and features. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: b08e6ba5-7498-4b9f-b1c9-7dc11b362ddd Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/R9PkDi8 Replit-Helium-Checkpoint-Created: true
98 lines
3.1 KiB
JavaScript
98 lines
3.1 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
|
const { getServerMode, getEmbedColor, EMBED_COLORS } = require('../utils/modeHelper');
|
|
const { updateStandaloneXp, getStandaloneXp } = require('../utils/standaloneXp');
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('gift')
|
|
.setDescription('Gift XP to another user')
|
|
.addUserOption(option =>
|
|
option.setName('user')
|
|
.setDescription('User to gift XP to')
|
|
.setRequired(true)
|
|
)
|
|
.addIntegerOption(option =>
|
|
option.setName('amount')
|
|
.setDescription('Amount of XP to gift')
|
|
.setRequired(true)
|
|
.setMinValue(1)
|
|
.setMaxValue(1000)
|
|
),
|
|
|
|
async execute(interaction, supabase, client) {
|
|
const recipient = interaction.options.getUser('user');
|
|
const amount = interaction.options.getInteger('amount');
|
|
const sender = interaction.user;
|
|
const mode = await getServerMode(supabase, interaction.guildId);
|
|
const guildId = interaction.guildId;
|
|
|
|
if (recipient.id === sender.id) {
|
|
return interaction.reply({ content: "You can't gift XP to yourself!", ephemeral: true });
|
|
}
|
|
|
|
if (recipient.bot) {
|
|
return interaction.reply({ content: "You can't gift XP to bots!", ephemeral: true });
|
|
}
|
|
|
|
if (!supabase) {
|
|
return interaction.reply({ content: 'Gift system unavailable.', ephemeral: true });
|
|
}
|
|
|
|
try {
|
|
let senderXp = 0;
|
|
|
|
if (mode === 'standalone') {
|
|
const senderData = await getStandaloneXp(supabase, sender.id, guildId);
|
|
senderXp = senderData?.xp || 0;
|
|
} else {
|
|
const { data } = await supabase
|
|
.from('user_profiles')
|
|
.select('xp')
|
|
.eq('discord_id', sender.id)
|
|
.maybeSingle();
|
|
senderXp = data?.xp || 0;
|
|
}
|
|
|
|
if (senderXp < amount) {
|
|
return interaction.reply({
|
|
content: `You don't have enough XP! You have ${senderXp} XP.`,
|
|
ephemeral: true
|
|
});
|
|
}
|
|
|
|
if (mode === 'standalone') {
|
|
await updateStandaloneXp(supabase, sender.id, guildId, -amount, sender.username);
|
|
await updateStandaloneXp(supabase, recipient.id, guildId, amount, recipient.username);
|
|
} else {
|
|
await supabase
|
|
.from('user_profiles')
|
|
.update({ xp: senderXp - amount })
|
|
.eq('discord_id', sender.id);
|
|
|
|
const { data: recipientData } = await supabase
|
|
.from('user_profiles')
|
|
.select('xp')
|
|
.eq('discord_id', recipient.id)
|
|
.maybeSingle();
|
|
|
|
if (recipientData) {
|
|
await supabase
|
|
.from('user_profiles')
|
|
.update({ xp: (recipientData.xp || 0) + amount })
|
|
.eq('discord_id', recipient.id);
|
|
}
|
|
}
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(EMBED_COLORS.success)
|
|
.setTitle('🎁 Gift Sent!')
|
|
.setDescription(`${sender} gifted **${amount} XP** to ${recipient}!`)
|
|
.setThumbnail(recipient.displayAvatarURL({ size: 128 }))
|
|
.setTimestamp();
|
|
|
|
await interaction.reply({ embeds: [embed] });
|
|
} catch (e) {
|
|
await interaction.reply({ content: 'Failed to send gift.', ephemeral: true });
|
|
}
|
|
},
|
|
};
|