2022-10-23 18:23:11 -04:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Discord.Guild} guild
|
|
|
|
|
* @returns {Promise<Boolean>}
|
|
|
|
|
*/
|
|
|
|
|
function checkRole(bot, guild, userId) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const user = guild.members.cache.get(userId);
|
|
|
|
|
|
|
|
|
|
// return (role != undefined && user.roles.cache.has(role.id)); // || user.id == guild.ownerId || bot.inDebugMode
|
|
|
|
|
|
|
|
|
|
// Maybe implement this later, useless for now
|
|
|
|
|
bot.mongoconnection.then((client) => {
|
|
|
|
|
// const role = client.db(message.guild.id).collection("admin-roles");
|
|
|
|
|
const a = new Array();
|
|
|
|
|
client.db(guild.id).collection("SETUP").findOne({_id: "roles"}).then((doc) => {
|
|
|
|
|
const comRoles = doc.commands;
|
|
|
|
|
const role = guild.roles.cache.find((role) => { return (role.name == "Selmer Bot Commands"); });
|
|
|
|
|
const hasPreAdminRole = (role != undefined && user.roles.cache.has(role.id) || user.id == guild.ownerId);
|
|
|
|
|
|
|
|
|
|
if (!comRoles) {
|
|
|
|
|
resolve(hasPreAdminRole);
|
|
|
|
|
} else {
|
|
|
|
|
const hasRoles = [];
|
|
|
|
|
Promise.all(comRoles.map((val) => {
|
|
|
|
|
if (user.roles.cache.has(val)) {
|
|
|
|
|
hasRoles.push(true);
|
|
|
|
|
}
|
|
|
|
|
})).then(() => {
|
|
|
|
|
resolve(hasRoles.length > 0 || hasPreAdminRole);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-14 20:40:58 +03:00
|
|
|
});
|
2022-10-23 18:23:11 -04:00
|
|
|
});
|
2022-05-14 20:40:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-09 20:30:31 +03:00
|
|
|
module.exports = { checkRole }
|