diff --git a/fonctions/database.js b/fonctions/database.js new file mode 100644 index 0000000..4f42bc2 --- /dev/null +++ b/fonctions/database.js @@ -0,0 +1,50 @@ +const sqlite3 = require('sqlite3').verbose(); + +let db = new sqlite3.Database('./db.sqlite'); + +db.run(`CREATE TABLE IF NOT EXISTS config ( + guildId TEXT, + name TEXT, + value TEXT, + PRIMARY KEY (guildId, name) +)`); + +db.run(`CREATE TABLE IF NOT EXISTS users ( + guildId TEXT, + userId TEXT, + pocket INTEGER DEFAULT 0, + bank INTEGER DEFAULT 0, + reputation INTEGER DEFAULT 0, + buyer BOOLEAN DEFAULT FALSE, + owner BOOLEAN DEFAULT FALSE, + whitelist BOOLEAN DEFAULT FALSE, + blacklist BOOLEAN DEFAULT FALSE, + antiRob INTEGER DEFAULT 0, + lastRob INTEGER DEFAULT 0, + lastWork INTEGER DEFAULT 0, + lastDaily INTEGER DEFAULT 0, + job TEXT, + teamId TEXT, + teamRole TEXT, + embed TEXT, + PRIMARY KEY (guildId, userId) +)`); + +db.run(`CREATE TABLE IF NOT EXISTS teams ( + guildId TEXT, + id TEXT, + name TEXT, + description TEXT, + icon TEXT, + banner TEXT, + bank INTEGER DEFAULT 0, + level INTEGER DEFAULT 1, + padlock INTEGER DEFAULT 5, + soldiers INTEGER DEFAULT 0, + woundedSoldiers INTEGER DEFAULT 0, + campLevel INTEGER DEFAULT 1, + turrets INTEGER DEFAULT 0, + PRIMARY KEY (guildId, id) +)`); + +module.exports = db; \ No newline at end of file diff --git a/fonctions/embedColor.js b/fonctions/embedColor.js new file mode 100644 index 0000000..a2df899 --- /dev/null +++ b/fonctions/embedColor.js @@ -0,0 +1,37 @@ +const db = require('./database.js'); + +module.exports = async function embedColor(memberId, serverId) { + const user = await new Promise((resolve, reject) => { + db.get(`SELECT * FROM users WHERE guildId = ? AND userId = ?`, [serverId, memberId], (err, row) => { + if (err) reject(err); + resolve(row); + }); + }); + let embedColor = user.embed; + if (embedColor === 'random') { + const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'brown', 'black', 'white']; + embedColor = colors[Math.floor(Math.random() * colors.length)]; + } + if (!embedColor) { + embedColor = '#FFD700'; + } else if (embedColor === 'red') { + embedColor = '#FF0000'; + } else if (embedColor === 'orange') { + embedColor = '#FFA500'; + } else if (embedColor === 'yellow') { + embedColor = '#FFFF00'; + } else if (embedColor === 'green') { + embedColor = '#008000'; + } else if (embedColor === 'blue') { + embedColor = '#0000FF'; + } else if (embedColor === 'purple') { + embedColor = '#800080'; + } else if (embedColor === 'brown') { + embedColor = '#A52A2A'; + } else if (embedColor === 'black') { + embedColor = '#000000'; + } else if (embedColor === 'white') { + embedColor = '#FFFFFF'; + } + return embedColor; +} \ No newline at end of file diff --git a/fonctions/loadCommands.js b/fonctions/loadCommands.js new file mode 100644 index 0000000..8f930f5 --- /dev/null +++ b/fonctions/loadCommands.js @@ -0,0 +1,35 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function loadCommands(client, dir) { + let count = 0; + fs.readdirSync(path.join(__dirname, dir)).forEach((file) => { + const filePath = path.join(__dirname, dir, file); + if (fs.statSync(filePath).isDirectory()) { + count += loadCommands(client, path.join(dir, file)); + } else if (file.endsWith('.js') || file.endsWith('.ts')) { + try { + delete require.cache[require.resolve(filePath)]; + const command = require(filePath); + const fileName = file.replace(/\.js|\.ts/g, ''); + if (!command.name) command.name = fileName; + if (!command.category) { + const parentDir = path.basename(path.dirname(filePath)); + command.category = parentDir === 'commands' ? 'other' : parentDir; + } + if (!command.permission) command.permission = 0; + client.commands.set(fileName, command); + if (command.aliases) { + command.aliases.forEach((alias) => { + client.commands.set(alias, command); + }); + } + count++; + } catch (error) { + console.error(`Failed to load file: ${filePath}`); + console.error(error); + } + } + }); + return count; +} \ No newline at end of file diff --git a/fonctions/loadEvents.js b/fonctions/loadEvents.js new file mode 100644 index 0000000..d22c845 --- /dev/null +++ b/fonctions/loadEvents.js @@ -0,0 +1,22 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function loadEvents(client, dir) { + let count = 0; + fs.readdirSync(path.join(__dirname, dir)).forEach((file) => { + const filePath = path.join(__dirname, dir, file); + if (fs.statSync(filePath).isDirectory()) { + loadEvents(client, path.join(dir, file)); + } else if (file.endsWith('.js') || file.endsWith('.ts')) { + delete require.cache[require.resolve(filePath)]; + const event = require(filePath); + if (typeof event.execute === 'function') { + client.on(event.name, (...args) => event.execute(...args, client)); // Specify the type of 'args' as an array of any type + count++; + } else { + console.error(`Event ${event.name} does not have an execute method.`); + } + } + }); + return count; +} \ No newline at end of file