creation de tout le systeme de permission du bot !

This commit is contained in:
arthur
2024-06-21 16:15:11 +02:00
parent 8860e85bea
commit 89bdff6b35
5 changed files with 130 additions and 2 deletions
+7
View File
@@ -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;
+15
View File
@@ -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;
}