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:
Schuyler Cebulskie
2016-09-04 05:08:09 -04:00
committed by Amish Shah
parent 5a9c42061f
commit 0b908f5bce
95 changed files with 946 additions and 1526 deletions

View File

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