add debut confession system and corrige commande logs

This commit is contained in:
VALOU3336
2024-02-27 13:39:39 +01:00
parent 2f2a7995d7
commit 74df746b53
3 changed files with 161 additions and 2 deletions
+83
View File
@@ -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.');
}
}
+1 -1
View File
@@ -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();
+77 -1
View File
@@ -1,4 +1,4 @@
const {Events} = require("discord.js")
const {Events , ModalBuilder, TextInputStyle, ActionRowBuilder, TextInputBuilder , EmbedBuilder} = require("discord.js")
const db = require('quick.db');
const PrevnameDb = new db.table("prevname");
const sqlite3 = require('sqlite3').verbose();
@@ -7,6 +7,15 @@ module.exports = {
name: Events.InteractionCreate,
async execute(interaction, client) {
const botId = client.user.id;
let data = await new Promise((resolve, reject) => {
db2.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
if (err) {
console.error(err.message);
reject(err);
}
resolve(row ? JSON.parse(row.value).owners || {} : {});
});
});
let owners = await new Promise((resolve, reject) => {
db2.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
if (err) {
@@ -37,6 +46,73 @@ module.exports = {
await PrevnameDb.delete(userId)
await interaction.reply({ content: "Vos prevname on etait correctement supprimer.", ephemeral: true });
} else if (interaction.customId.startsWith('addconfession_')) {
let data = await new Promise((resolve, reject) => {
db2.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
if (err) {
console.error(err.message);
reject(err);
}
resolve(row ? JSON.parse(row.value).owners || {} : {});
});
});
const guildId= interaction.customId.split('_')[1];
const userId = interaction.user.id;
let Modal = new ModalBuilder()
.setCustomId('confession')
.setTitle(`${client.user.username} - Confession`);
let question1 = new TextInputBuilder()
.setCustomId('messageconfession')
.setLabel("Quel est votre confession")
.setRequired(true)
.setPlaceholder('Indiquez la description ici')
.setStyle(TextInputStyle.Paragraph);
let question2 = new TextInputBuilder()
.setCustomId('status')
.setLabel("Vous voulez reste anonyme")
.setRequired(true)
.setPlaceholder('Indiquez par oui ou non')
.setStyle(TextInputStyle.Short);
let actionRow1 = new ActionRowBuilder().addComponents(question1);
let actionRow2 = new ActionRowBuilder().addComponents(question2);
Modal.addComponents(actionRow1, actionRow2);
await interaction.showModal(Modal);
let reponse = await interaction.awaitModalSubmit({time: 300000})
let ConfessionMessageToSend = reponse.fields.getTextInputValue('messageconfession')
let ConfidentielAuthor = reponse.fields.getTextInputValue('status')
let isConfidential = !ConfidentielAuthor.toLowerCase().startsWith('n');
data.guildId = data.guildId || {};
data.guildId.confession = data.guildId.confession || {};
console.log(guildId);
console.log(data.guildId.confession.channel);
const channelId = data.confession.channel[guildId];
const embed = new EmbedBuilder()
.setTitle('**Nouvelle Confession**')
.setDescription(ConfessionMessageToSend)
.setFooter({text: `${client.user.username} - ${interaction.guild.name}`})
.setColor('#0099ff');
if (!isConfidential) {
embed.setAuthor({ name: interaction.user.username, iconURL: interaction.user.displayAvatarURL() })
} else {
embed.setAuthor({ name: 'Confidentiel' });
}
if (channelId) {
const channel = interaction.guild.channels.cache.get(channelId);
console.log(channelId);
channel.send({ embeds: [embed] });
} else {
console.error(`Le salon avec l'ID ${channelId} n'a pas été trouvé.`);
}
}
},
};