mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 15:07:26 +02:00
66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
const { Events } = require('discord.js');
|
|
const permissions = require('../../permissions.json');
|
|
|
|
module.exports = {
|
|
name: Events.ClientReady,
|
|
async execute(client) {
|
|
const db = new sqlite3.Database('myDatabase.db', (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
console.log('Connected to the SQLite database.');
|
|
});
|
|
|
|
// Wrap the serialize operations in a promise to use async/await
|
|
await new Promise((resolve, reject) => {
|
|
db.serialize(() => {
|
|
// Create the table if it doesn't exist
|
|
db.run('CREATE TABLE IF NOT EXISTS gestion (id TEXT PRIMARY KEY, value TEXT)', (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
console.log('Table gestion created or already exists.');
|
|
}
|
|
});
|
|
|
|
// Now that the table is guaranteed to exist, proceed with other operations
|
|
db.get('SELECT value FROM gestion WHERE id = ?', [client.user.id], (err, row) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
let permissionsData = row ? JSON.parse(row.value) : {};
|
|
|
|
if (!permissionsData.permissions) {
|
|
permissionsData.permissions = {};
|
|
}
|
|
|
|
permissionsData.permissions = permissions;
|
|
const permissionsJson = JSON.stringify(permissionsData);
|
|
|
|
db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [client.user.id, permissionsJson], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
console.log(`Les permissions ont été chargées pour le bot ${client.user.tag}`);
|
|
resolve(); // Resolve the promise once all operations are complete
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
console.log(`Le bot ${client.user.tag} est en ligne`);
|
|
process.on('uncaughtException', (error) => {
|
|
console.error('Uncaught Exception:', error);
|
|
});
|
|
|
|
process.on('unhandledRejection', (reason, promise) => {
|
|
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
});
|
|
},
|
|
}; |