mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
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:
@@ -53,10 +53,10 @@ class Role extends Base {
|
||||
this.position = data.position;
|
||||
|
||||
/**
|
||||
* The permissions bitfield of the role
|
||||
* @type {number}
|
||||
* The permissions of the role
|
||||
* @type {Permissions}
|
||||
*/
|
||||
this.permissions = data.permissions;
|
||||
this.permissions = new Permissions(data.permissions).freeze();
|
||||
|
||||
/**
|
||||
* Whether or not the role is managed by an external service
|
||||
@@ -139,7 +139,7 @@ class Role extends Base {
|
||||
* console.log(role.serialize());
|
||||
*/
|
||||
serialize() {
|
||||
return new Permissions(this.permissions).serialize();
|
||||
return this.permissions.serialize();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +159,7 @@ class Role extends Base {
|
||||
* }
|
||||
*/
|
||||
hasPermission(permission, explicit = false, checkAdmin) {
|
||||
return new Permissions(this.permissions).has(
|
||||
return this.permissions.has(
|
||||
permission, typeof checkAdmin !== 'undefined' ? checkAdmin : !explicit
|
||||
);
|
||||
}
|
||||
@@ -200,7 +200,7 @@ class Role extends Base {
|
||||
*/
|
||||
edit(data, reason) {
|
||||
if (data.permissions) data.permissions = Permissions.resolve(data.permissions);
|
||||
else data.permissions = this.permissions;
|
||||
else data.permissions = this.permissions.bitfield;
|
||||
return this.client.api.guilds[this.guild.id].roles[this.id].patch({
|
||||
data: {
|
||||
name: data.name || this.name,
|
||||
@@ -341,7 +341,7 @@ class Role extends Base {
|
||||
this.color === role.color &&
|
||||
this.hoist === role.hoist &&
|
||||
this.position === role.position &&
|
||||
this.permissions === role.permissions &&
|
||||
this.permissions.bitfield === role.permissions.bitfield &&
|
||||
this.managed === role.managed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user