mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-12 08:14:34 +02:00
add : backup , antilick and event for antilink , wiki, and upgrade whitelist system with unique whitelist for guild
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
const Discord = require('discord.js');
|
||||
const backup = require('discord-backup');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const db = new sqlite3.Database('./backups.db');
|
||||
async function createBackup(botId, guild) {
|
||||
const backupData = await backup.create(guild, {
|
||||
maxMessagesPerChannel: 0,
|
||||
jsonBeautify: true
|
||||
});
|
||||
|
||||
const createdAt = new Date().toISOString();
|
||||
db.run(`INSERT INTO backups(botId, backupId, createdAt) VALUES(?, ?, ?)`, [botId, backupData.id, createdAt], function(err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
return backupData.id;
|
||||
}
|
||||
function listBackups(botId, color) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const db = new sqlite3.Database('./backups.db');
|
||||
db.all(`SELECT * FROM backups WHERE botId = ?`, [botId], (err, rows) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
let backupList = 'Liste des sauvegardes:\n';
|
||||
rows.forEach((row) => {
|
||||
backupList += `ID: ${row.backupId}, Créé le: ${row.createdAt}\n`;
|
||||
});
|
||||
|
||||
const embed = new Discord.EmbedBuilder()
|
||||
.setAuthor({name:'📰 Liste des backups'})
|
||||
.setDescription(`\`\`\`${backupList}\`\`\``)
|
||||
.setColor(color);
|
||||
|
||||
resolve(embed);
|
||||
}
|
||||
});
|
||||
db.close();
|
||||
});
|
||||
}
|
||||
async function loadBackup(botId, backupId, guild) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const db = new sqlite3.Database('./backups.db');
|
||||
db.get(`SELECT * FROM backups WHERE botId = ? AND backupId = ?`, [botId, backupId], async (err, row) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
if (!row) {
|
||||
console.log('Backup not found');
|
||||
reject(new Error('Backup not found'));
|
||||
}
|
||||
|
||||
try {
|
||||
await backup.load(backupId, guild);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function deleteBackup(botId, backupId) {
|
||||
const db = new sqlite3.Database('./backups.db');
|
||||
db.run(`DELETE FROM backups WHERE botId = ? AND backupId = ?`, [botId, backupId], function(err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
backup.remove(backupId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'backup',
|
||||
description: 'Crée, liste, charge ou supprime des backups du bot.',
|
||||
emote: '💾',
|
||||
utilisation: 'backup <paramètres>',
|
||||
category: 'gestion',
|
||||
async execute(message, args, client) {
|
||||
const botId = client.user.id;
|
||||
const author = message.author;
|
||||
const create = args[0] === "create";
|
||||
const list = args[0] === 'list';
|
||||
const load = args[0] === 'load';
|
||||
const del = args[0] === 'delete';
|
||||
|
||||
if (!args[0]) {
|
||||
const helpEmbed = new Discord.EmbedBuilder()
|
||||
.setTimestamp()
|
||||
.setFooter({text: `Backup Gestion | ${client.user.username}`})
|
||||
.addFields(
|
||||
{ name: 'Backup:', value: '\`backup create\` ・ Permet de créer une backup du serveur actuel\n\`backup delete\` ・ Permet de supprimer une backup\n\`backup list\` ・ Permet d\'afficher la liste de toutes les backup\n\`backup load\` ・ Permet de charger une backup sur un serveur' }
|
||||
);
|
||||
message.channel.send({ embeds: [helpEmbed] });
|
||||
} else if (create) {
|
||||
const messageCreate = await message.channel.send("\`🔃\`La backup est entrain de ce crée ......");
|
||||
const backupId = await createBackup(botId, message.guild);
|
||||
messageCreate.edit(`\`✅\`Backup correctement créé, faites \`backup load ${backupId}\` pour charger la backup`);
|
||||
} else if (list) {
|
||||
const color = '#00FFFF';
|
||||
listBackups(botId, color)
|
||||
.then(backupListEmbed => {
|
||||
message.channel.send({ embeds: [backupListEmbed] });
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
message.channel.send('Une erreur est survenue lors de la récupération de la liste des sauvegardes.');
|
||||
});
|
||||
} else if (load) {
|
||||
const backupId = args[1];
|
||||
if (!backupId) {
|
||||
return message.channel.send(`Vous devez spécifier une ID de backup valide !`);
|
||||
}
|
||||
await loadBackup(botId, backupId, message.guild).then(() => {
|
||||
const textChannel = message.guild.channels.cache.find(channel => channel.type === Discord.ChannelType.GuildText);
|
||||
if (textChannel) {
|
||||
textChannel.send(`@${message.author.username}, la backup a fini d'être chargée.`);
|
||||
} else {
|
||||
// Si aucun salon texte n'est trouvé, envoyer un message dans le salon actuel
|
||||
author.send(`@${message.author.username}, la backup a fini d'être chargée, mais aucun salon texte n'a été trouvé pour envoyer le message.`);
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error(`Failed to load backup: ${error}`);
|
||||
message.channel.send(`Une erreur est survenue lors du chargement de la backup: ${error.message}`);
|
||||
});
|
||||
} else if (del) {
|
||||
const backupId = args[1];
|
||||
if (!backupId) {
|
||||
return message.channel.send(`Veuillez spécifier l'ID de la backup que vous voulez supprimer`);
|
||||
}
|
||||
deleteBackup(botId, backupId);
|
||||
message.channel.send(`La backup ${backupId} a été supprimée avec succès`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user