Permissions Cleanup (#1643)

* fix Permissions.add/remove, by completely changing what they do

* permissions cleanup

Removes overwrite._denied and overwrite._allowed in favor of overwrite.denied.bitfield and overwrite.allowed.bitfield

uses the modified Permissions.add and Permissions.remove to clean up existing code

fixes GuildMember.missingPermissions

changes Permissions add/remove to reverse loops for speed, changes resolve to allow the number 0 as a valid permission.

* Revert createChannel overwrite.allow / overwrite.deny for arrays of {allow:bitfield, deny:bitfield}

Documentation should be improved here, although I would need advice. I believe a overwrite object typedef is needed, to show the structure of the object, and also include that collections may be used for this, rather than arrays.

* api router fix for overwritePermissions

* add Permissions.freeze, and change all returned Permissions to immutable instances

* Make Permissions a permission resolveable

change role.permissions to be an instance of Permissions

* Make permissions.add/remove return a new instance if the instance is frozen

* Fix invalid error

* Update GuildChannel.js

* Update Guild.js

* fix bad merge
This commit is contained in:
bdistin
2017-09-09 15:07:39 -05:00
committed by Crawl
parent b3e5f6271c
commit 98582cd1b7
6 changed files with 74 additions and 82 deletions

View File

@@ -249,13 +249,8 @@ class GuildMember extends Base {
* @readonly
*/
get permissions() {
if (this.user.id === this.guild.ownerID) return new Permissions(Permissions.ALL);
let permissions = 0;
const roles = this.roles;
for (const role of roles.values()) permissions |= role.permissions;
return new Permissions(permissions);
if (this.user.id === this.guild.ownerID) return new Permissions(Permissions.ALL).freeze();
return new Permissions(this.roles.map(role => role.permissions)).freeze();
}
/**
@@ -321,7 +316,7 @@ class GuildMember extends Base {
* @returns {PermissionResolvable[]}
*/
missingPermissions(permissions, explicit = false) {
return permissions.missing(permissions, explicit);
return this.permissions.missing(permissions, explicit);
}
/**