mirror of
https://github.com/danbulant/discord.js
synced 2026-05-24 20:42:27 +00:00
Document EvaluatedPermissions
This commit is contained in:
parent
28ad224207
commit
a725147f17
2 changed files with 25 additions and 2 deletions
File diff suppressed because one or more lines are too long
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue