Document EvaluatedPermissions

This commit is contained in:
Amish Shah
2016-09-01 13:08:49 +01:00
parent 28ad224207
commit a725147f17
2 changed files with 25 additions and 2 deletions

View File

@@ -1,11 +1,28 @@
const Constants = require('../util/Constants');
/**
* The final evaluated permissions for a member in a channel
*/
class EvaluatedPermissions {
constructor(member, permissions) {
/**
* The member this permissions refer to
* @type {GuildMember}
*/
this.member = member;
/**
* A number representing the packed permissions.
* @private
* @type {Number}
*/
this.permissions = permissions;
}
/**
* Get an object mapping permission name, e.g. `READ_MESSAGES` to a boolean - whether the user
* can perform this or not.
* @returns {Object<String, Boolean>}
*/
serialize() {
const serializedPermissions = {};
for (const permissionName in Constants.PermissionFlags) {
@@ -15,7 +32,13 @@ class EvaluatedPermissions {
return serializedPermissions;
}
hasPermission(permission, explicit) {
/**
* Checks whether a user has a certain permission, e.g. `READ_MESSAGES`.
* @param {any} permission the permission to check for
* @param {any} [explicit=false] whether the user should explicitly have the permission.
* @returns {Boolean}
*/
hasPermission(permission, explicit = false) {
if (permission instanceof String || typeof permission === 'string') {
permission = Constants.PermissionFlags[permission];
}