mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
25 lines
667 B
JavaScript
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;
|
|
};
|