From b070fe6edfea63005b00455f5f05caeb17dd6e72 Mon Sep 17 00:00:00 2001 From: VALOU3336 Date: Sat, 24 Feb 2024 20:18:39 +0100 Subject: [PATCH] quel que petit truc mdr --- commands/botcontrol/dnd.js | 12 +++++++++ commands/botcontrol/idle.js | 12 +++++++++ commands/botcontrol/invisible.js | 12 +++++++++ commands/botcontrol/online.js | 12 +++++++++ commands/fonction.js | 1 - commands/gestion/dm.js | 4 --- commands/gestion/greetlist.js | 36 ++++++++++++++++++++++++-- commands/gestion/massiverole.js | 16 +++--------- commands/gestion/perm.js | 1 - commands/gestion/renew.js | 5 ---- commands/gestion/suggest.js | 43 +++++++++++++++++++++++++++++++ commands/gestion/unmassiverole.js | 8 ------ events/gestion/buttongestion.js | 16 ++++++++++++ events/gestion/messageCreate.js | 32 +++++++++++++++++++++++ events/gestion/messageDelete.js | 4 ++- 15 files changed, 179 insertions(+), 35 deletions(-) create mode 100644 commands/botcontrol/dnd.js create mode 100644 commands/botcontrol/idle.js create mode 100644 commands/botcontrol/invisible.js create mode 100644 commands/botcontrol/online.js create mode 100644 commands/gestion/suggest.js create mode 100644 events/gestion/buttongestion.js create mode 100644 events/gestion/messageCreate.js diff --git a/commands/botcontrol/dnd.js b/commands/botcontrol/dnd.js new file mode 100644 index 0000000..da63401 --- /dev/null +++ b/commands/botcontrol/dnd.js @@ -0,0 +1,12 @@ +module.exports = { + name: 'dnd', + description: 'Changer le status du bot en dnd', + emote: '🔕', + utilisation: 'dnd', + category: 'botcontrol', + async execute(message, args, client) { + + client.user.setStatus('dnd'); + message.channel.send(`Le bot est maintenant en de pas deranger`); + }, +}; \ No newline at end of file diff --git a/commands/botcontrol/idle.js b/commands/botcontrol/idle.js new file mode 100644 index 0000000..caa117d --- /dev/null +++ b/commands/botcontrol/idle.js @@ -0,0 +1,12 @@ +module.exports = { + name: 'idle', + description: 'Changer le status du bot en idle', + emote: '🔄', + utilisation: 'idle', + category: 'botcontrol', + + async execute(message, args, client) { + client.user.setStatus('idle'); + message.channel.send(`Le bot est maintenant en mode idle`); + }, +}; \ No newline at end of file diff --git a/commands/botcontrol/invisible.js b/commands/botcontrol/invisible.js new file mode 100644 index 0000000..be44165 --- /dev/null +++ b/commands/botcontrol/invisible.js @@ -0,0 +1,12 @@ +module.exports = { + name: 'invisible', + description: 'Changer le status du bot en invisible', + emote: '🕶️', + utilisation: 'invisible', + category: 'botcontrol', + + async execute(message, args, client) { + client.user.setStatus('invisible'); + message.channel.send(`Le bot est maintenant invisible`); + }, + }; \ No newline at end of file diff --git a/commands/botcontrol/online.js b/commands/botcontrol/online.js new file mode 100644 index 0000000..da68404 --- /dev/null +++ b/commands/botcontrol/online.js @@ -0,0 +1,12 @@ +module.exports = { + name: 'online', + description: 'Changer le status du bot en online', + emote: '🟢', + utilisation: 'online', + category: 'botcontrol', + + async execute(message, args, client) { + client.user.setStatus('online'); + message.channel.send(`Le bot est maintenant en ligne`); + }, + }; \ No newline at end of file diff --git a/commands/fonction.js b/commands/fonction.js index 63504db..5466333 100644 --- a/commands/fonction.js +++ b/commands/fonction.js @@ -16,7 +16,6 @@ async function getPermissionLevel(member, client) { for (let i = 1; i <= 9; i++) { const roleIds = await GestionDb.get(`${botId}.${member.guild.id}.p${i}`); if (roleIds) { - // Si roleIds n'est pas un tableau, le convertir en tableau if (!Array.isArray(roleIds)) { roleIds = [roleIds]; } diff --git a/commands/gestion/dm.js b/commands/gestion/dm.js index 6b8b065..bc6b4fc 100644 --- a/commands/gestion/dm.js +++ b/commands/gestion/dm.js @@ -5,21 +5,17 @@ module.exports = { emote: '📧', utilisation: 'dm <@utilisateur> ', category: 'gestion', - async execute(message, args) { - // Vérifie si un utilisateur a été mentionné const user = message.mentions.users.first(); if (!user) { return message.reply('Veuillez mentionner un utilisateur à qui envoyer un message privé.'); } - // Vérifie si un message a été spécifié const dmMessage = args.slice(1).join(' '); if (!dmMessage) { return message.reply('Veuillez spécifier un message à envoyer.'); } - // Envoie le message privé à l'utilisateur try { await user.send(dmMessage); message.reply(`Message envoyé à ${user.tag} : "${dmMessage}"`); diff --git a/commands/gestion/greetlist.js b/commands/gestion/greetlist.js index 59d5359..e0ca31f 100644 --- a/commands/gestion/greetlist.js +++ b/commands/gestion/greetlist.js @@ -1,4 +1,4 @@ -const { EmbedBuilder } = require('discord.js'); +const { EmbedBuilder, ButtonBuilder , ActionRowBuilder, ButtonStyle } = require('discord.js'); const db = require('quick.db'); const GestionDb = new db.table('gestion'); @@ -27,7 +27,39 @@ module.exports = { .setTitle(`Salons avec un greet ${guildGreetings.length}/5`) .setDescription(`${greetingChannels}`) .setColor('#0099ff'); - message.channel.send({ embeds: [embed] }); + const greet = new ButtonBuilder() + .setCustomId(`greet_${guildId}`) + .setLabel('↪️ greet') + .setStyle(ButtonStyle.Primary) + const row = new ActionRowBuilder() + .addComponents(greet); + const sentMessage = await message.channel.send({ embeds: [embed], components: [row] }); + const greetfilter = i => i.customId.startsWith('greet_') && i.user.id === message.author.id; + const collector = sentMessage.createMessageComponentCollector({ filter: greetfilter, time: 15000 }); + collector.on('collect', async (interaction) => { + const member = interaction.member; + const guild = interaction.guild; + const welcomeMessage = `Bienvenue <@${member.id}> sur le serveur ${guild.name} !`; + const messagePromises = []; + for (const greeting of guildGreetings) { + try { + const channel = await guild.channels.fetch(greeting.channelId); + if (channel && channel.type === 0) { + messagePromises.push( + channel.send(welcomeMessage) + .then(message => { + setTimeout(() => message.delete(), 1000); + }) + ); + } + } catch (error) { + } + } + try { + await Promise.all(messagePromises); + } catch (error) { + } + }); } }, }; \ No newline at end of file diff --git a/commands/gestion/massiverole.js b/commands/gestion/massiverole.js index 7cb9acd..c1379ae 100644 --- a/commands/gestion/massiverole.js +++ b/commands/gestion/massiverole.js @@ -9,7 +9,6 @@ module.exports = { category: 'gestion', async execute(message, args) { - // Vérifie si un rôle a été mentionné const role = message.mentions.roles.first(); if (!role) { return message.reply('Veuillez mentionner un rôle.'); @@ -24,7 +23,6 @@ module.exports = { .setTitle('Attribution de rôle') .addFields(fields); - // Crée un menu déroulant avec les options const selectMenu = new StringSelectMenuBuilder() .setCustomId('massiverole_select') .setPlaceholder('Sélectionnez le type de membres') @@ -34,13 +32,10 @@ module.exports = { { label: '🤖 Bot', value: 'bot' }, { label: '🚀 Lancer', value: 'launch' }, ]); - // Crée une action de ligne avec le menu déroulant const row = new ActionRowBuilder() .addComponents(selectMenu); const sentMessage = await message.channel.send({ embeds: [embed], components: [row] }); - - // Crée un collecteur d'interactions pour le menu déroulant const filter = i => i.customId === 'massiverole_select' && i.user.id === message.author.id; const collector = sentMessage.createMessageComponentCollector({ filter, time: 15000 }) collector.on('collect', async (interaction) => { @@ -57,22 +52,18 @@ module.exports = { name2 = '🤖 Bot'; } - // Trouvez l'index du champ 'Type de membres' et mettez à jour sa valeur const memberTypeFieldIndex = fields.findIndex(field => field.name === 'Type de membres'); if (memberTypeFieldIndex !== -1) { fields[memberTypeFieldIndex].value = name2; } - - // Recréez l'embed avec les champs mis à jour + const updatedEmbed = new EmbedBuilder() .setTitle('Attribution de rôle') .addFields(fields); - - // Mettre à jour l'embed dans le message + await interaction.update({ embeds: [updatedEmbed] }); } - - // Si l'option "Lancer" est sélectionnée, attribuez le rôle + if (interaction.values[0] === 'launch') { await assignRole(interaction, role, memberType, message); } @@ -83,7 +74,6 @@ module.exports = { async function assignRole(interaction, role, memberType, message) { let count = 0; - // Récupère tous les membres pour s'assurer que le cache est complet const members = await interaction.guild.members.fetch(); if (memberType === 'human') { diff --git a/commands/gestion/perm.js b/commands/gestion/perm.js index c2cd0a6..b8f51a2 100644 --- a/commands/gestion/perm.js +++ b/commands/gestion/perm.js @@ -20,7 +20,6 @@ module.exports = { let roleIds = await GestionDb.get(`${botId}.${message.guild.id}.p${i}`); let roles = 'Aucun rôle défini'; if (roleIds) { - // Si roleIds n'est pas un tableau, le convertir en tableau if (!Array.isArray(roleIds)) { roleIds = [roleIds]; } diff --git a/commands/gestion/renew.js b/commands/gestion/renew.js index 869b9b5..983719f 100644 --- a/commands/gestion/renew.js +++ b/commands/gestion/renew.js @@ -11,20 +11,15 @@ module.exports = { const guild = message.guild; const channel = message.mentions.channels.first() || message.channel; const botMember = guild.members.cache.get(client.user.id); - // Check if the bot has the 'MANAGE_CHANNELS' permission if (!botMember.permissions.has(PermissionsBitField.Flags.ManageChannels)) { return message.reply("Je n'ai pas la permission de gére les salon"); } - // Check if the channel is deletable if (channel.deletable) { - // Clone the channel const newChannel = await channel.clone(); - // Delete the old channel await channel.delete(); - // Send a message in the new channel newChannel.send(`${message.author}, ce salon a été renouvelé.`); } else { return message.reply("Je ne peux pas supprimer ce salon."); diff --git a/commands/gestion/suggest.js b/commands/gestion/suggest.js new file mode 100644 index 0000000..138a98f --- /dev/null +++ b/commands/gestion/suggest.js @@ -0,0 +1,43 @@ +const db = require('quick.db'); +const GestionDb = new db.table("gestion"); + +module.exports = { + name: 'suggest', + description: 'configure le salon de suggestion', + emote: '🛡️', + utilisation: 'suggest #channel', + category: 'gestion', + async execute(message, args, client) { + const botid = client.user.id; + const guildId = message.guild.id; + const currentSuggestChannelId = GestionDb.get(`${botid}.${guildId}.suggestchannel`); + + const mentionedChannel = message.mentions.channels.first(); + if (mentionedChannel) { + if (mentionedChannel.id === currentSuggestChannelId) { + GestionDb.delete(`${botid}.${guildId}.suggestchannel`); + message.channel.send(`Le salon de suggestion a été supprimé.`); + } else { + GestionDb.set(`${botid}.${guildId}.suggestchannel`, mentionedChannel.id); + message.channel.send(`Le salon de suggestion a été configuré à <#${mentionedChannel.id}>`); + } + return; + } + + if (args[0]) { + const channel = message.guild.channels.cache.get(args[0]); + if (channel) { + if (channel.id === currentSuggestChannelId) { + GestionDb.delete(`${botid}.${guildId}.suggestchannel`); + message.channel.send(`Le salon de suggestion a été supprimé.`); + } else { + GestionDb.set(`${botid}.${guildId}.suggestchannel`, args[0]); + message.channel.send(`Le salon de suggestion a été configuré à <#${args[0]}>`); + } + return; + } + } + + message.channel.send("Veuillez mentionner un salon ou fournir un ID de salon valide."); + }, +}; \ No newline at end of file diff --git a/commands/gestion/unmassiverole.js b/commands/gestion/unmassiverole.js index 059d22d..3dee137 100644 --- a/commands/gestion/unmassiverole.js +++ b/commands/gestion/unmassiverole.js @@ -34,14 +34,12 @@ module.exports = { { label: '🤖 Bot', value: 'bot' }, { label: '🚀 Lancer', value: 'launch' }, ]); - // Crée une action de ligne avec le menu déroulant const row = new ActionRowBuilder() .addComponents(selectMenu); const sentMessage = await message.channel.send({ embeds: [embed], components: [row] }); - // Crée un collecteur d'interactions pour le menu déroulant const filter = i => i.customId === 'unmassiverole_select' && i.user.id === message.author.id; const collector = sentMessage.createMessageComponentCollector({ filter, time: 15000 }); collector.on('collect', async (interaction) => { @@ -57,23 +55,18 @@ module.exports = { if (interaction.values[0] === 'bot') { name2 = '🤖 Bot'; } - - // Trouvez l'index du champ 'Type de membres' et mettez à jour sa valeur const memberTypeFieldIndex = fields.findIndex(field => field.name === 'Type de membres'); if (memberTypeFieldIndex !== -1) { fields[memberTypeFieldIndex].value = name2; } - // Recréez l'embed avec les champs mis à jour const updatedEmbed = new EmbedBuilder() .setTitle('Retrait de rôle') .addFields(fields); - // Mettre à jour l'embed dans le message await interaction.update({ embeds: [updatedEmbed] }); } - // Si l'option "Lancer" est sélectionnée, retirez le rôle if (interaction.values[0] === 'launch') { await removeRole(interaction, role, memberType, message); } @@ -84,7 +77,6 @@ module.exports = { async function removeRole(interaction, role, memberType, message) { let count = 0; - // Récupère tous les membres pour s'assurer que le cache est complet const members = await interaction.guild.members.fetch(); if (memberType === 'human') { diff --git a/events/gestion/buttongestion.js b/events/gestion/buttongestion.js new file mode 100644 index 0000000..d5d0873 --- /dev/null +++ b/events/gestion/buttongestion.js @@ -0,0 +1,16 @@ +const {Events} = require("discord.js") +module.exports = { + name: Events.InteractionCreate, + async execute(interaction) { + if (!interaction.isButton()) return; + if (interaction.customId.startsWith('deletesuggestion_')) { + const userId = interaction.customId.split('_')[1]; + if (interaction.user.id !== userId) { + await interaction.reply({ content: "vous n'avez pas la permission de suprimer cette suggestion.", ephemeral: true }); + return; + } + + await interaction.message.delete(); + } + }, +}; \ No newline at end of file diff --git a/events/gestion/messageCreate.js b/events/gestion/messageCreate.js new file mode 100644 index 0000000..82faf76 --- /dev/null +++ b/events/gestion/messageCreate.js @@ -0,0 +1,32 @@ +const { ActionRowBuilder, ButtonBuilder,ButtonStyle , EmbedBuilder } = require('discord.js'); +const db = require('quick.db'); +const GestionDb = new db.table('gestion') +const {Events} = require("discord.js") +module.exports = { + name: Events.MessageCreate, + async execute(message) { + const botid = message.client.user.id; + const suggestChannelId = GestionDb.get(`${botid}.${message.guild.id}.suggestchannel`); + if (message.channel.id === suggestChannelId && !message.author.bot) { + await message.delete(); + + const embed = new EmbedBuilder() + .setAuthor({ name: message.author.tag, iconURL: message.author.displayAvatarURL() }) + .setDescription(message.content || 'Aucun contenu fourni') + .setFooter({ text: `${message.guild.name} | ${message.client.user.username}`, }) + .setColor('#409CED'); + + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(`deletesuggestion_${message.author.id}`) + .setLabel('Supprimer') + .setStyle(ButtonStyle.Danger) + ); + + const suggestionmesssage = await message.channel.send({ embeds: [embed], components: [row] }); + suggestionmesssage.react('👎') + suggestionmesssage.react('👍') + } + }, +}; \ No newline at end of file diff --git a/events/gestion/messageDelete.js b/events/gestion/messageDelete.js index 238a99c..1ab3888 100644 --- a/events/gestion/messageDelete.js +++ b/events/gestion/messageDelete.js @@ -1,5 +1,7 @@ +const {Events} = require("discord.js") + module.exports = { - name: 'messageDelete', + name: Events.MessageDelete, once: false, async execute(message, client) { if (message.author.bot) return;