diff --git a/commands/gestion/clear.js b/commands/gestion/clear.js index 0aaef74..4526a4e 100644 --- a/commands/gestion/clear.js +++ b/commands/gestion/clear.js @@ -14,7 +14,7 @@ module.exports = { return message.reply('Vous devez entrer un nombre entre 1 et 99'); } await message.reply('🗑️ Clear en cours...'); - await message.channel.bulkDelete(amount, true).catch((err) => { + await message.channel.bulkDelete(amount + 1, true).catch((err) => { message.reply('Une erreur est survenue lors du clear'); }); }, diff --git a/commands/utils/gif.js b/commands/utils/gif.js new file mode 100644 index 0000000..adba5a1 --- /dev/null +++ b/commands/utils/gif.js @@ -0,0 +1,36 @@ +const Discord = require("discord.js") +const giphy = require("giphy-api")("eW1dIGt8WPveUcxEZgXAFtEmuZ8MTxmy"); + +module.exports = { + name: 'gif', + usage: 'gif [terme de recherche]', + description: 'Recherche un gif basé sur le terme de recherche fourni.', + emote: '🎮', + category: 'utils', + async execute(message, args, client) { + + + if (args.length === 0) { + message.channel.send("Indiquez une recherche"); + return; + } + if (args.length === 1) { + term = args.toString(); + } else { + term = args.join(" "); + } + giphy.search(term).then(function (res) { + + let id = res.data[0].id; + let msgurl = `https://media.giphy.com/media/${id}/giphy.gif`; + + const embed = new Discord.EmbedBuilder() + .setTitle(`Résultat pour \`${term}\``) + .setImage(msgurl) + .setFooter({text: `${client.user.username}`}) + message.channel.send({ embeds: [embed] }); + }); + + message.delete(); + }, + }; \ No newline at end of file diff --git a/commands/utils/help.js b/commands/utils/help.js index 2b86e2b..39dc048 100644 --- a/commands/utils/help.js +++ b/commands/utils/help.js @@ -1,6 +1,6 @@ const { EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } = require("discord.js") -const db = require('quick.db'); -const GestionDb = new db.table("gestion"); +const sqlite3 = require('sqlite3').verbose(); +const db = new sqlite3.Database('myDatabase.db'); module.exports = { name: 'help', @@ -11,22 +11,42 @@ module.exports = { utilisation: 'help [commande]', async execute(message, args, client) { - const botId = client.user.id; - const botInfo = GestionDb.get(botId); - const permissions = botInfo.permissions; + const botId = client.user.id; const guildId = message.guild.id; - const defaultprefix = "+"; - let mainPrefix = await GestionDb.get(`${botId}.prefix`); - let serverPrefix = await GestionDb.get(`${botId}.${guildId}.prefix`); - const prefix = serverPrefix !== undefined ? serverPrefix : mainPrefix !== undefined ? mainPrefix : defaultprefix; + let data = await new Promise((resolve, reject) => { + db.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => { + if (err) { + console.error(err.message); + reject(err); + } + resolve(row ? JSON.parse(row.value) : {}); + }); + }); + const permissions = data.permissions || {}; + const defaultPrefix = "+"; + let mainPrefix = data.prefixes && data.prefixes.main ? data.prefixes.main : defaultPrefix; + let serverPrefix = data.prefixes && data.prefixes[guildId]; + const prefix = serverPrefix !== undefined ? serverPrefix : mainPrefix; if (args[0]) { const command = client.commands.get(args[0]); if (!command) { return message.reply(`Je n'ai pas trouvé de commande nommée "${args[0]}".`); } - + const commandPerm = await permissions[command.name]; - + + let customAliases = []; + if (data.alias && data.alias[command.name]) { + customAliases = Object.keys(data.alias[command.name]); + } + + const allAliases = [...(command.aliases || []), ...customAliases]; + + let aliasesField = { name: 'Alias', value: 'Aucun', inline: true }; + if (allAliases.length > 0) { + aliasesField.value = allAliases.map(alias => `\`${alias}\``).join(', '); + } + const embed_command = new EmbedBuilder() .setColor('#0099ff') .setTitle(`Aide pour la commande ${command.emote ? ` ${command.emote}` : '🔧'} ${command.name}`) @@ -34,16 +54,15 @@ module.exports = { .addFields( { name: 'Utilisation', value: `\`${prefix}${command.utilisation ? `${command.utilisation}` : ''}\``, inline: true }, { name: 'Catégorie', value: command.category || 'Non spécifiée', inline: true }, - { name: 'Alias', value: command.aliases ? command.aliases.map(alias => `\`${alias}\``).join(', ') : 'Aucun', inline: true }, - { name: 'Permissions', value: `Perm level: ${commandPerm}` || 'Indéfini', inline: true }, + aliasesField, + { name: 'Permissions', value: commandPerm === 11 ? 'buyer' : commandPerm === 10 ? 'owner' : `Perm level: ${commandPerm}`, inline: true }, ) .setTimestamp() - .setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})}) - - return message.reply({ embeds: [embed_command] }); + .setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})}) + + return message.reply({ embeds: [embed_command] }); } - const categories = { antiraid: [], botcontrol: [], diff --git a/loaders/loadCommands.js b/loaders/loadCommands.js index 691e4d6..f36fa95 100644 --- a/loaders/loadCommands.js +++ b/loaders/loadCommands.js @@ -81,9 +81,10 @@ module.exports = (client) => { const permissions = data.permissions || {}; const defaultPrefix = "+"; - let mainPrefix = data.prefix || defaultPrefix; - let serverPrefix = data.permissions && data.permissions[guildId] && data.permissions[guildId].prefix || mainPrefix; + let mainPrefix = data.prefixes && data.prefixes.main ? data.prefixes.main : defaultPrefix; + let serverPrefix = data.prefixes && data.prefixes[guildId]; const prefix = serverPrefix !== undefined ? serverPrefix : mainPrefix; + if (!message.content.startsWith(prefix) || message.author.bot) return; diff --git a/package-lock.json b/package-lock.json index 0bf7f05..584c282 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "discord.js": "^14.14.1", "discordjs-button-pagination": "^3.0.1", "dotenv": "^16.4.4", + "giphy-api": "^2.0.2", "ms": "^2.1.3", "quick.db": "^7.1.3", "sqlite": "^5.1.1", @@ -811,6 +812,11 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/giphy-api": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/giphy-api/-/giphy-api-2.0.2.tgz", + "integrity": "sha512-vZaLQhgMF0mDQSNpqooe4Zqoe2dWGqVYhh7Ar6I41BRtcZtfupr9avT23IIPScKBYfb3qAfiKQRQyKgLi8Lcxw==" + }, "node_modules/github-from-package": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", diff --git a/package.json b/package.json index df0cd0f..f4f8b76 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "discord.js": "^14.14.1", "discordjs-button-pagination": "^3.0.1", "dotenv": "^16.4.4", + "giphy-api": "^2.0.2", "ms": "^2.1.3", "quick.db": "^7.1.3", "sqlite": "^5.1.1",