mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
137 lines
4.2 KiB
JavaScript
137 lines
4.2 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.');
|
|
});
|
|
const backupdb = new sqlite3.Database('backups.db', (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
db.serialize(() => {
|
|
db.run('CREATE TABLE IF NOT EXISTS gestion (id TEXT PRIMARY KEY, value TEXT)', (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
}
|
|
});
|
|
|
|
db.run('CREATE TABLE IF NOT EXISTS prevname (id TEXT PRIMARY KEY, value TEXT)', (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
}
|
|
});
|
|
db.run('CREATE TABLE IF NOT EXISTS soutiens (guildID TEXT PRIMARY KEY, message TEXT, roleID TEXT)', (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
}
|
|
});
|
|
|
|
backupdb.run(`CREATE TABLE IF NOT EXISTS backups (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
botId TEXT NOT NULL,
|
|
backupId TEXT NOT NULL,
|
|
createdAt TEXT NOT NULL
|
|
)`, (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
} else {
|
|
}
|
|
});
|
|
db.run(`
|
|
CREATE TABLE IF NOT EXISTS warnings (
|
|
guildId TEXT NOT NULL,
|
|
userId TEXT NOT NULL,
|
|
warningId INTEGER NOT NULL,
|
|
reason TEXT NOT NULL,
|
|
timestamp INTEGER NOT NULL,
|
|
PRIMARY KEY (guildId, userId, warningId)
|
|
);
|
|
`, (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
} else {
|
|
}
|
|
});
|
|
|
|
|
|
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 || Object.keys(permissionsData.permissions).length === 0) {
|
|
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();
|
|
}
|
|
});
|
|
} else {
|
|
console.log(`Les permissions existent déjà pour le bot ${client.user.tag}`);
|
|
resolve();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
client.snipes = new Map();
|
|
console.log(`Le bot ${client.user.tag} est en ligne
|
|
lien d'invite > https://discord.com/oauth2/authorize?client_id=${client.user.id}&scope=bot&permissions=8`);
|
|
|
|
|
|
//AntiCrash
|
|
process.on('unhandledRejection', (error) => {
|
|
console.log(' [antiCrash] :: Unhandled Rejection/Catch');
|
|
console.log(error);
|
|
});
|
|
|
|
process.on("uncaughtException", (error, origin) => {
|
|
console.log(' [antiCrash] :: Uncaught Exception/Catch');
|
|
console.log(error);
|
|
console.log('Information supplémentaire:', origin);
|
|
});
|
|
|
|
process.on('uncaughtExceptionMonitor', (error, origin) => {
|
|
console.log(' [antiCrash] :: Uncaught Exception Monitor/Catch');
|
|
console.log(error);
|
|
console.log('Information supplémentaire:', origin);
|
|
});
|
|
|
|
process.on('beforeExit', (code) => {
|
|
console.log(' [antiCrash] :: Before Exit');
|
|
console.log('Code de sortie:', code);
|
|
});
|
|
|
|
process.on('exit', (code) => {
|
|
console.log(' [antiCrash] :: Exit');
|
|
console.log('Code de sortie:', code);
|
|
});
|
|
|
|
},
|
|
}; |