mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-03 23:36:35 +02:00
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
let buyer = 0;
|
|
|
|
module.exports = function addBaseInDB(client) {
|
|
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
|
|
|
|
client.guilds.cache.forEach(guild => {
|
|
db.run('INSERT OR IGNORE INTO prefix (serverID) VALUES (?)', [guild.id], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
client.guilds.cache.forEach(guild => {
|
|
guild.members.cache.forEach(member => {
|
|
if (member.user.bot) return;
|
|
if (member.id === '671763971803447298') {
|
|
buyer = 1;
|
|
} else {
|
|
buyer = 0;
|
|
};
|
|
db.run('INSERT OR IGNORE INTO users (serverID, userID, buyer) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE serverID = ? AND userID = ?)', [guild.id, member.id, buyer, guild.id, member.id], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
client.commands.forEach(command => {
|
|
client.guilds.cache.forEach(guild => {
|
|
db.run('INSERT OR IGNORE INTO commands (command, permission, serverID) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM commands WHERE command = ? AND serverID = ?)', [command.name, command.permission, guild.id, command.name, guild.id], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
db.close((err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
} |