mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-12 23:59:20 +02:00
add debut confession system and corrige commande logs
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const db = new sqlite3.Database('myDatabase.db');
|
||||
const { ActionRowBuilder, ButtonStyle, EmbedBuilder, ButtonBuilder} = require('discord.js');
|
||||
module.exports = {
|
||||
name: 'confession',
|
||||
description: 'Configure les paramètres pour le salon de confession.',
|
||||
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;
|
||||
}
|
||||
|
||||
// Vérifier si le salon existe
|
||||
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.');
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ module.exports = {
|
||||
|
||||
const filter = i => i.customId.startsWith('logsselect_') && i.user.id === message.author.id;
|
||||
const filter2 = m => m.author.id === message.author.id;
|
||||
const collector = logmessage.createMessageComponentCollector({ filter:filter, max: 1, time: 150000 });
|
||||
const collector = logmessage.createMessageComponentCollector({ filter:filter, time: 150000 });
|
||||
|
||||
collector.on('collect', async i => {
|
||||
await i.deferReply();
|
||||
|
||||
Reference in New Issue
Block a user