nice
This commit is contained in:
parent
ea478cb6dd
commit
f5f16b9c6c
121
commands/utility/delier-rygainland.js
Normal file
121
commands/utility/delier-rygainland.js
Normal file
@ -0,0 +1,121 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const { getUserLink, deleteUserLink } = require('../../database.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('delier-rygainland')
|
||||
.setDescription('Délier votre compte Discord de votre compte Palworld'),
|
||||
|
||||
async execute(interaction) {
|
||||
try {
|
||||
const existingLink = await getUserLink(interaction.user.id);
|
||||
|
||||
if (!existingLink) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFF9900)
|
||||
.setTitle('⚠️ Aucune liaison trouvée')
|
||||
.setDescription('Votre compte Discord n\'est pas lié à un compte Palworld.')
|
||||
.addFields(
|
||||
{ name: '💡 Pour vous lier', value: 'Utilisez la commande `/lier-rygainland`' }
|
||||
)
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Afficher un embed de confirmation avec boutons
|
||||
const confirmEmbed = new EmbedBuilder()
|
||||
.setColor(0xFF6600)
|
||||
.setTitle('⚠️ Confirmation de déliaison')
|
||||
.setDescription('Êtes-vous sûr de vouloir délier votre compte ?')
|
||||
.addFields(
|
||||
{ name: '👤 Discord', value: `${interaction.user.tag}`, inline: false },
|
||||
{ name: '🎮 Palworld', value: `**${existingLink.palworld_username}**`, inline: true },
|
||||
{ name: '🆔 Steam ID', value: `\`${existingLink.steam_id}\``, inline: true },
|
||||
{ name: '🎯 Player ID', value: `\`${existingLink.player_id || 'N/A'}\``, inline: false }
|
||||
)
|
||||
.setFooter({ text: 'Cette action est irréversible' })
|
||||
.setTimestamp();
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('confirm_unlink')
|
||||
.setLabel('✅ Confirmer la déliaison')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('cancel_unlink')
|
||||
.setLabel('❌ Annuler')
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
);
|
||||
|
||||
const response = await interaction.reply({
|
||||
embeds: [confirmEmbed],
|
||||
components: [row],
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
// Attendre la réponse de l'utilisateur (60 secondes)
|
||||
const collectorFilter = i => i.user.id === interaction.user.id;
|
||||
|
||||
try {
|
||||
const confirmation = await response.awaitMessageComponent({
|
||||
filter: collectorFilter,
|
||||
time: 60000
|
||||
});
|
||||
|
||||
if (confirmation.customId === 'confirm_unlink') {
|
||||
// Supprimer la liaison
|
||||
await deleteUserLink(interaction.user.id);
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
.setColor(0x00FF00)
|
||||
.setTitle('✅ Déliaison réussie')
|
||||
.setDescription('Votre compte Discord a été délié avec succès de votre compte Palworld.')
|
||||
.addFields(
|
||||
{ name: '🎮 Compte Palworld délié', value: `**${existingLink.palworld_username}**` },
|
||||
{ name: '💡 Pour vous lier à nouveau', value: 'Utilisez la commande `/lier-rygainland`' }
|
||||
)
|
||||
.setTimestamp();
|
||||
|
||||
await confirmation.update({
|
||||
embeds: [successEmbed],
|
||||
components: []
|
||||
});
|
||||
|
||||
} else if (confirmation.customId === 'cancel_unlink') {
|
||||
const cancelEmbed = new EmbedBuilder()
|
||||
.setColor(0x808080)
|
||||
.setTitle('❌ Déliaison annulée')
|
||||
.setDescription('Votre compte reste lié.')
|
||||
.setTimestamp();
|
||||
|
||||
await confirmation.update({
|
||||
embeds: [cancelEmbed],
|
||||
components: []
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
// Timeout ou erreur
|
||||
const timeoutEmbed = new EmbedBuilder()
|
||||
.setColor(0x808080)
|
||||
.setTitle('⏱️ Temps écoulé')
|
||||
.setDescription('La demande de déliaison a expiré. Votre compte reste lié.')
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [timeoutEmbed],
|
||||
components: []
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la déliaison:', error);
|
||||
await interaction.reply({
|
||||
content: '❌ Une erreur est survenue lors de la déliaison.',
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -10,10 +10,27 @@ module.exports = {
|
||||
try {
|
||||
const existingLink = await getUserLink(interaction.user.id);
|
||||
if (existingLink) {
|
||||
return interaction.reply({
|
||||
content: `Vous êtes déjà lié au compte Palworld: **${existingLink.palworld_username}** (Steam ID: ${existingLink.steam_id})`,
|
||||
ephemeral: true
|
||||
});
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x0099FF)
|
||||
.setTitle('🔗 Votre compte est déjà lié')
|
||||
.setDescription('Votre compte Discord est déjà associé à un compte Palworld.')
|
||||
.addFields(
|
||||
{ name: '👤 Discord', value: `${interaction.user.tag}`, inline: false },
|
||||
{ name: '🎮 Palworld', value: `**${existingLink.palworld_username}**`, inline: true },
|
||||
{ name: '🆔 Steam ID', value: `\`${existingLink.steam_id}\``, inline: true },
|
||||
{ name: '🎯 Player ID', value: `\`${existingLink.player_id || 'N/A'}\``, inline: false },
|
||||
{ name: '📅 Lié le', value: new Date(existingLink.linked_at).toLocaleDateString('fr-FR', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}), inline: false }
|
||||
)
|
||||
.setFooter({ text: 'Contactez un administrateur pour modifier votre liaison' })
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
const code = await generateLinkCode(interaction.user.id);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user