Files
gestion/commands/gestion/setconfession.js
T
VALOU3336 9bd39c69ca grand commit que tutur attend ( marche pas le raidmode en dev)
sinon il y a pleins de truc comme les anti raid , des coorectif ect
2024-04-22 18:30:33 +02:00

85 lines
3.2 KiB
JavaScript

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('myDatabase.db');
const { ActionRowBuilder, ButtonStyle, EmbedBuilder, ButtonBuilder} = require('discord.js');
module.exports = {
name: 'setconfession',
description: 'Configure les paramètres pour le salon de confession.',
category: 'gestion',
emote: '🙏',
utilisation: 'confession [channel|send] [channelID|#channel]',
async execute(message, args) {
const guildId = message.guild.id;
if (!args.length) return message.reply('Veuillez spécifier une sous-commande: channel ou send.');
const subCommand = args[0].toLowerCase();
if (subCommand === 'channel') {
await setConfessionChannel(guildId,message, args.slice(1).join(' '));
} else if (subCommand === 'send') {
await sendConfessionEmbed(message, args.slice(1).join(' '));
} else {
message.reply('Sous-commande invalide. Veuillez utiliser "channel" ou "send".');
}
},
};
async function setConfessionChannel(guildId, message, channelInput) {
let data = await new Promise((resolve, reject) => {
db.get('SELECT value FROM gestion WHERE id = ?', [message.client.user.id], (err, row) => {
if (err) {
console.error(err.message);
reject(err);
}
resolve(row ? JSON.parse(row.value) : {});
});
});
let channelId;
if (channelInput.startsWith('<#') && channelInput.endsWith('>')) {
channelId = channelInput.slice(2, -1);
} else {
channelId = channelInput;
}
const channel = message.guild.channels.cache.get(channelId);
if (!channel) {
return message.reply('Le salon spécifié n\'existe pas ou l\'ID est incorrect.');
}
data.confession = data.confession || {};
data.confession.channel = data.confession.channel || {};
data.confession.channel[guildId] = channelId;
try {
await db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [message.client.user.id, JSON.stringify(data)]);
message.reply(`Le salon de confession a été défini sur <#${channelId}>.`);
} catch (err) {
message.reply('Une erreur est survenue lors de la définition du salon de confession.');
}
}
async function sendConfessionEmbed(message, channelInput) {
let channelId;
if (channelInput.startsWith('<#') && channelInput.endsWith('>')) {
channelId = channelInput.slice(2, -1);
} else {
channelId = channelInput;
}
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Ajoutez votre confession')
.setDescription('Cliquez sur le bouton pour ajouter votre confession.');
const button = new ButtonBuilder()
.setCustomId(`addconfession_${message.guild.id}`)
.setLabel('Ajouter une confession')
.setStyle(ButtonStyle.Primary);
const row = new ActionRowBuilder().addComponents(button);
try {
await message.guild.channels.cache.get(channelId).send({ embeds: [embed], components: [row] });
message.reply('L\'embed avec le bouton a été envoyé.');
} catch (err) {
message.reply('Une erreur est survenue lors de l\'envoi de l\'embed.');
}
}