Add more types of whitelisting, plus support for subcommands
All checks were successful
CI / CI (push) Successful in 1m24s

This commit is contained in:
SileNce5k 2025-05-04 03:58:11 +02:00
parent 99d6fc2401
commit b2c6c705c3
Signed by: SileNce
GPG key ID: B0A142BB4291B204
4 changed files with 63 additions and 9 deletions

22
util/isWhitelisted.js Normal file
View file

@ -0,0 +1,22 @@
// type: 0 for both, 1 for guild, 2 for userId, 3 for either.
function isWhitelisted(command, whitelist, guildId, userId, type=0){
const isGuildWhitelisted = Boolean(whitelist.guild.get(guildId)?.includes(command))
if(type === whitelistTypes.GUILD_ONLY) return isGuildWhitelisted;
if(type === whitelistTypes.BOTH && !isGuildWhitelisted) return false;
if(type === whitelistTypes.EITHER && isGuildWhitelisted) return true;
const isUserWhitelisted = Boolean(whitelist.user.get(userId)?.includes(command))
if(type === whitelistTypes.USER_ONLY) return isUserWhitelisted;
if(type === whitelistTypes.BOTH && isGuildWhitelisted && isUserWhitelisted) return true;
if(type === whitelistTypes.EITHER && (isGuildWhitelisted || isUserWhitelisted)) return true;
return false;
}
const whitelistTypes = {
BOTH: 0,
GUILD_ONLY: 1,
USER_ONLY: 2,
EITHER: 3
}
module.exports = {isWhitelisted, whitelistTypes}