aboutsummaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/EvaluatedPermissions.js
diff options
context:
space:
mode:
authorAlee14 <alee14498@gmail.com>2017-03-26 15:18:10 -0400
committerAlee14 <alee14498@gmail.com>2017-03-26 15:18:10 -0400
commit29433e2f7dbd0e4a73d3c78ffe1005b922fb5982 (patch)
treeaa0ad3fe59468cbe452ee597e914839b68c01436 /node_modules/discord.js/src/structures/EvaluatedPermissions.js
parent878fefb4c4e1f12b804ae5c0def433fa873f4c8b (diff)
downloadAleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.gz
AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.bz2
AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.zip
Don't mind me i'm adding the discord.js files
Diffstat (limited to 'node_modules/discord.js/src/structures/EvaluatedPermissions.js')
-rw-r--r--node_modules/discord.js/src/structures/EvaluatedPermissions.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/structures/EvaluatedPermissions.js b/node_modules/discord.js/src/structures/EvaluatedPermissions.js
new file mode 100644
index 0000000..ae8a643
--- /dev/null
+++ b/node_modules/discord.js/src/structures/EvaluatedPermissions.js
@@ -0,0 +1,67 @@
+const Constants = require('../util/Constants');
+
+/**
+ * The final evaluated permissions for a member in a channel
+ */
+class EvaluatedPermissions {
+ constructor(member, raw) {
+ /**
+ * The member this permissions refer to
+ * @type {GuildMember}
+ */
+ this.member = member;
+
+ /**
+ * A number representing the packed permissions
+ * @type {number}
+ */
+ this.raw = raw;
+ }
+
+ /**
+ * 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) {
+ serializedPermissions[permissionName] = this.hasPermission(permissionName);
+ }
+ return serializedPermissions;
+ }
+
+ /**
+ * 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) {
+ permission = this.member.client.resolver.resolvePermission(permission);
+ if (!explicit && (this.raw & Constants.PermissionFlags.ADMINISTRATOR) > 0) return true;
+ return (this.raw & permission) > 0;
+ }
+
+ /**
+ * Checks whether the user has all specified permissions.
+ * @param {PermissionResolvable[]} permissions The permissions to check for
+ * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions
+ * @returns {boolean}
+ */
+ hasPermissions(permissions, explicit = false) {
+ return permissions.every(p => this.hasPermission(p, explicit));
+ }
+
+ /**
+ * Checks whether the user has all specified permissions, and lists any missing permissions.
+ * @param {PermissionResolvable[]} permissions The permissions to check for
+ * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions
+ * @returns {PermissionResolvable[]}
+ */
+ missingPermissions(permissions, explicit = false) {
+ return permissions.filter(p => !this.hasPermission(p, explicit));
+ }
+}
+
+module.exports = EvaluatedPermissions;