mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
const db = new sqlite3.Database('myDatabase.db');
|
|
|
|
module.exports = {
|
|
name: 'clearwl',
|
|
aliases: ['clearwhitelist'],
|
|
description: 'Supprimer tout la whitelist',
|
|
emote: '👑',
|
|
utilisation: 'clearwl',
|
|
category: 'buyer',
|
|
|
|
async execute(message, args, client) {
|
|
const botId = message.client.user.id;
|
|
const guildId = message.guild.id;
|
|
|
|
let data = await getWhitelistData(db, botId, guildId);
|
|
|
|
if (data.whitelist[guildId]) {
|
|
delete data.whitelist[guildId];
|
|
await updateWhitelist(db, botId, data);
|
|
message.reply("Toutes la whitelist a été supprimée pour cette guilde.");
|
|
} else {
|
|
message.reply("Il n'y avait pas de liste blanche à supprimer pour cette guilde.");
|
|
}
|
|
},
|
|
};
|
|
|
|
async function getWhitelistData(db, botId, guildId) {
|
|
return new Promise((resolve, reject) => {
|
|
db.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
const data = row ? JSON.parse(row.value) : {};
|
|
data.whitelist = data.whitelist || {};
|
|
data.whitelist[guildId] = data.whitelist[guildId] || {};
|
|
resolve(data);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
async function updateWhitelist(db, botId, data) {
|
|
return new Promise((resolve, reject) => {
|
|
const updatedData = JSON.stringify(data);
|
|
db.run('UPDATE gestion SET value = ? WHERE id = ?', [updatedData, botId], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
} |