mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-18 21:38:32 +02:00
creation de tout le systeme de permission du bot !
This commit is contained in:
@@ -55,4 +55,11 @@ db.run(`CREATE TABLE IF NOT EXISTS teams (
|
||||
PRIMARY KEY (guildId, id)
|
||||
)`);
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS rolePermission (
|
||||
guildId TEXT,
|
||||
roleId TEXT,
|
||||
permission INTEGER,
|
||||
PRIMARY KEY (guildId, permission)
|
||||
)`);
|
||||
|
||||
module.exports = db;
|
||||
@@ -0,0 +1,15 @@
|
||||
const db = require('./database.js');
|
||||
|
||||
module.exports = async function getPermissionLevel(serverId, user) {
|
||||
const roles = user.roles.cache.map(role => role.id);
|
||||
|
||||
const perms = await new Promise((resolve, reject) => {
|
||||
db.all(`SELECT * FROM rolePermission WHERE guildId = ? AND roleId IN (${roles.map(() => '?').join(',')})`, [serverId, ...roles], (err, rows) => {
|
||||
if (err) reject(err);
|
||||
resolve(rows);
|
||||
});
|
||||
});
|
||||
|
||||
const highestPermission = Math.max(...perms.map(perm => perm.permission));
|
||||
return highestPermission;
|
||||
}
|
||||
Reference in New Issue
Block a user