Files
bot-discord-coins/fonctions/getPermissionLevel.js
T
2024-07-08 22:39:14 +02:00

25 lines
667 B
JavaScript

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);
},
);
});
let highestPermission;
if (perms.length === 0) {
highestPermission = 0
} else {
highestPermission = Math.max(...perms.map((perm) => perm.permission));
}
return highestPermission;
};