mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
Cleanup Part 2: Electric Boogaloo (Reloaded) (#594)
* Cleanup Part 2: Electric Boogaloo (Reloaded) * Moar cleanup * Tweak NOT_A_PERMISSION error
This commit is contained in:
committed by
Amish Shah
parent
5a9c42061f
commit
0b908f5bce
@@ -28,31 +28,18 @@ class EvaluatedPermissions {
|
||||
for (const permissionName in Constants.PermissionFlags) {
|
||||
serializedPermissions[permissionName] = this.hasPermission(permissionName);
|
||||
}
|
||||
|
||||
return serializedPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a user has a certain permission, e.g. `READ_MESSAGES`.
|
||||
* @param {string} permission the permission to check for
|
||||
* @param {boolean} [explicit=false] whether the user should explicitly have the permission.
|
||||
* Checks whether the user has a certain permission, e.g. `READ_MESSAGES`.
|
||||
* @param {PermissionResolvable} permission The permission to check for
|
||||
* @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permission
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasPermission(permission, explicit = false) {
|
||||
if (typeof permission === 'string') {
|
||||
permission = Constants.PermissionFlags[permission];
|
||||
}
|
||||
|
||||
if (!permission) {
|
||||
throw Constants.Errors.NOT_A_PERMISSION;
|
||||
}
|
||||
|
||||
if (!explicit) {
|
||||
if ((this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
permission = this.member.client.resolver.resolvePermission(permission);
|
||||
if (!explicit && (this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) return true;
|
||||
return (this.permissions & permission) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user