add alias systeme create , remove and list

This commit is contained in:
VALOU3336
2024-02-26 10:23:23 +01:00
parent e2290b0b7f
commit 91b20034d1
7 changed files with 259 additions and 5 deletions
+121
View File
@@ -0,0 +1,121 @@
const { EmbedBuilder } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('myDatabase.db');
module.exports = {
name: 'alias',
description: 'Gérer les alias des commandes',
aliases: ['alias'],
category: 'botcontrol',
emote: '📝',
utilisation: '+alias <add|remove|list>',
async execute(message, args, client) {
const botId = message.client.user.id;
const subCommand = args[0];
if (!subCommand) {
return message.reply('Veuillez spécifier une sous-commande: add, remove, list.');
}
switch (subCommand) {
case 'add':
const commandName = args[1];
const newAlias = args[2];
if (!commandName || !newAlias) {
return message.reply('Veuillez spécifier la commande et le nouvel alias.');
}
const command = client.commands.get(commandName);
if (!command) {
return message.reply(`La commande ${commandName} n'existe pas.`);
}
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) : {});
});
});
if (!data.alias) {
data.alias = {};
}
for (const cmd in data.alias) {
if (data.alias[cmd][newAlias]) {
return message.reply('Cet alias est déjà utilisé pour une autre commande.');
}
}
if (!data.alias[commandName]) {
data.alias[commandName] = {};
}
data.alias[commandName][newAlias] = true;
db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [botId, JSON.stringify(data)], (err) => {
if (err) {
console.error(err.message);
return message.reply('Une erreur est survenue lors de l\'ajout de l\'alias.');
}
message.reply(`Alias ajouté pour la commande ${commandName}: ${newAlias}`);
});
break;
case 'remove':
const commandName2 = args[1];
const aliasToRemove = args[2];
if (!commandName2 || !aliasToRemove) {
return message.reply('Veuillez spécifier la commande et l\'alias à supprimer.');
}
let data2 = 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) : {});
});
});
if (!data2.alias || !data2.alias[commandName2] || !data2.alias[commandName2][aliasToRemove]) {
return message.reply('Alias non trouvé pour cette commande.');
}
delete data2.alias[commandName2][aliasToRemove];
db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [botId, JSON.stringify(data2)], (err) => {
if (err) {
console.error(err.message);
return message.reply('Une erreur est survenue lors de la suppression de l\'alias.');
}
message.reply(`Alias ${aliasToRemove} supprimé de la commande ${commandName2}.`);
});
break;
case 'list':
let data3 = 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) : {});
});
});
let aliasesList = '';
for (const command in data3.alias) {
aliasesList += `**${command}**: ${Object.keys(data3.alias[command]).join(', ')}\n`;
}
const embed = new EmbedBuilder()
.setTitle('Liste des alias')
.setDescription(aliasesList || 'Aucun alias défini.')
.setFooter({ text: 'Gestion des alias', iconURL: client.user.displayAvatarURL({dynamic: true})});
message.channel.send({ embeds: [embed] });
break;
default:
return message.reply('Sous-commande invalide. Veuillez utiliser add, remove, ou list.');
}
},
};
+47
View File
@@ -0,0 +1,47 @@
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: 'botconfig',
description: 'Affiche la configuration du bot',
aliases: ['botconfig'],
category: 'gestion',
emote: '🤖',
utilisation: '+botconfig',
async execute(message, args, client) {
const bot = client.user;
const presenceStatus = bot.presence.status;
let presenceEmoji = '';
switch (presenceStatus) {
case 'online':
presenceEmoji = '🟢';
break;
case 'idle':
presenceEmoji = '🟡';
break;
case 'dnd':
presenceEmoji = '🔴';
break;
case 'invisible':
presenceEmoji = '⚪';
break;
default:
presenceEmoji = '⚪';
break;
}
const embed = new EmbedBuilder()
.setTitle('Configuration du bot')
.addFields(
{ name: 'Nom du bot', value: bot.username || 'Inconnu' },
{ name: 'ID du bot', value: bot.id || 'Inconnu'},
{ name: ' ', value: `[URL du profil](${bot.displayAvatarURL({ dynamic: true })})`},
{ name: 'Présence', value: `${presenceEmoji}`},
{ name: 'Statut', value: bot.presence.activities[0] && bot.presence.activities[0].state ? bot.presence.activities[0].state : 'Aucun statut'}
)
.setThumbnail(bot.displayAvatarURL({ dynamic: true }))
.setFooter({ text: 'Informations sur le bot', iconURL: bot.displayAvatarURL({dynamic: true})});
message.channel.send({ embeds: [embed] });
},
};
+34
View File
@@ -0,0 +1,34 @@
const weather = require('weather');
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: 'weather',
description: 'Affiche les informations météorologiques d\'une ville',
async execute(message, args) {
if (!args.length) {
return message.channel.send('Veuillez fournir une ville.');
}
const city = args.join(' ');
const woeid = await weather.find({ search: city, degreeType: 'C' });
if (!woeid || woeid.length === 0) {
return message.channel.send('Ville non trouvée.');
}
const weatherData = await weather.get({ search: woeid[0].title, degreeType: 'C' });
const embed = new EmbedBuilder()
.setTitle(`🌤️ Météo pour ${weatherData.location.name}`)
.setDescription(`Température: ${weatherData.current.temperature}°C`)
.addFields(
{ name: '🌦️ Conditions', value: weatherData.current.skytext, inline: true },
{ name: '💨 Vent', value: weatherData.current.winddisplay, inline: true },
{ name: '💧 Humidité', value: weatherData.current.humidity, inline: true }
)
.setFooter('Informations météorologiques fournies par Weather.com');
message.channel.send({ embeds: [embed] });
},
};
+5
View File
@@ -30,6 +30,11 @@ module.exports = {
await interaction.reply({ content: "vous n'avez pas la permission de suprimer cette suggestion.", ephemeral: true });
return;
}
if (!PrevnameDb.has(userId)) {
await interaction.reply({ content: "Vous n'avez aucun prevname à supprimer.", ephemeral: true });
return;
}
await PrevnameDb.delete(userId)
await interaction.reply({ content: "Vos prevname on etait correctement supprimer.", ephemeral: true });
}
+22 -3
View File
@@ -88,11 +88,30 @@ module.exports = (client) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const commandNameOrAlias = args.shift().toLowerCase();
let commandName = commandNameOrAlias;
//if (!client.commands.has(commandName)) return;
for (const cmd in data.alias) {
if (data.alias[cmd][commandNameOrAlias]) {
commandName = cmd;
break;
}
}
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) {
for (const cmd in data.alias) {
if (data.alias[cmd][commandNameOrAlias]) {
commandName = cmd;
command = client.commands.get(commandName);
break;
}
}
}
if (!command) {
return;
}
if (command) {
const permissionLevel = await getPermissionLevel(message.member, client, guildId);
+28 -1
View File
@@ -18,7 +18,8 @@
"ms": "^2.1.3",
"quick.db": "^7.1.3",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
"sqlite3": "^5.1.7",
"weather": "^1.0.4"
}
},
"node_modules/@discordjs/builders": {
@@ -440,6 +441,12 @@
"node": ">=10"
}
},
"node_modules/centra": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/centra/-/centra-2.6.0.tgz",
"integrity": "sha512-dgh+YleemrT8u85QL11Z6tYhegAs3MMxsaWAq/oXeAmYJ7VxL3SI9TZtnfaEvNDMAPolj25FXIb3S+HCI4wQaQ==",
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."
},
"node_modules/chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
@@ -1363,6 +1370,18 @@
"node": ">=0.10.0"
}
},
"node_modules/phin": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/phin/-/phin-3.7.0.tgz",
"integrity": "sha512-DqnVNrpYhKGBZppNKprD+UJylMeEKOZxHgPB+ZP6mGzf3uA2uox4Ep9tUm+rUc8WLIdHT3HcAE4X8fhwQA9JKg==",
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
"dependencies": {
"centra": "^2.6.0"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/prebuild-install": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.1.tgz",
@@ -1824,6 +1843,14 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"node_modules/weather": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/weather/-/weather-1.0.4.tgz",
"integrity": "sha512-6K4jGKz0Hr5Lsc0UgencI2218kSJsiPahW0VJ/PzblEA0uTNv4AgNyebQUW8vqy2y+Pm3VHMTCkTCrnSe8PeKQ==",
"dependencies": {
"phin": "^3.4.0"
}
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+2 -1
View File
@@ -26,6 +26,7 @@
"ms": "^2.1.3",
"quick.db": "^7.1.3",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
"sqlite3": "^5.1.7",
"weather": "^1.0.4"
}
}