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; };