mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-08 15:18:44 +02:00
20 lines
577 B
JavaScript
20 lines
577 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);
|
|
},
|
|
);
|
|
});
|
|
|
|
const highestPermission = Math.max(...perms.map((perm) => perm.permission));
|
|
return highestPermission;
|
|
};
|