mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-03 23:36:35 +02:00
add prefix
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
require('dotenv').config();
|
||||
|
||||
function getServerPrefix(serverID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
|
||||
db.get('SELECT prefix FROM prefix WHERE serverID = ?', [serverID], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
}
|
||||
if (row) {
|
||||
resolve(row.prefix);
|
||||
} else {
|
||||
resolve(process.env.DEFAULT_PREFIX);
|
||||
}
|
||||
});
|
||||
|
||||
db.close((err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = getServerPrefix;
|
||||
@@ -0,0 +1,52 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
require('dotenv').config();
|
||||
|
||||
module.exports = function initDB() {
|
||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Connected to the db.db database.');
|
||||
});
|
||||
|
||||
db.run(`PRAGMA foreign_keys = ON;`, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Foreign key constraint enabled');
|
||||
});
|
||||
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS prefix(
|
||||
prefix TEXT NOT NULL DEFAULT '${process.env.DEFAULT_PREFIX}',
|
||||
serverID TEXT NOT NULL UNIQUE
|
||||
)`, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Created prefix table');
|
||||
});
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS users(
|
||||
serverID TEXT NOT NULL,
|
||||
userID TEXT NOT NULL,
|
||||
coins INTEGER NOT NULL DEFAULT 0,
|
||||
bank INTEGER NOT NULL DEFAULT 0,
|
||||
xp INTEGER NOT NULL DEFAULT 0,
|
||||
levels INTEGER NOT NULL DEFAULT 0,
|
||||
messages INTEGER NOT NULL DEFAULT 0
|
||||
)`, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Created users table');
|
||||
});
|
||||
|
||||
|
||||
db.close((err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Close the database connection.');
|
||||
});
|
||||
};
|
||||
+1
-1
@@ -12,4 +12,4 @@ module.exports = function run(token) {
|
||||
console.log(`${loadCommands(client, 'commands')} commands loaded`);
|
||||
|
||||
client.login(token);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user