backport: Permissions improvements

This commit is contained in:
Lewdcario
2018-07-17 21:49:21 -05:00
parent 0702a0fcda
commit 524a15df0b
9 changed files with 120 additions and 45 deletions

View File

@@ -140,6 +140,28 @@ class GuildChannel extends Channel {
};
}
/**
* Replaces the permission overwrites for a channel
* @param {Object} [options] Options
* @param {Array<PermissionOverwrites|PermissionOverwriteOptions>} [options.overwrites] Permission overwrites
* @param {string} [options.reason] Reason for updating the channel overwrites
* @returns {Promise<GuildChannel>}
* @example
* channel.replacePermissionOverwrites({
* overwrites: [
* {
* id: message.author.id,
* denied: ['VIEW_CHANNEL'],
* },
* ],
* reason: 'Needed to change permissions'
* });
*/
replacePermissionOverwrites({ overwrites, reason } = {}) {
return this.edit({ permissionOverwrites: overwrites, reason })
.then(() => this);
}
/**
* An object mapping permission flags to `true` (enabled), `false` (disabled), or `null` (not set).
* ```js
@@ -215,6 +237,21 @@ class GuildChannel extends Channel {
return this.client.rest.methods.setChannelOverwrite(this, payload, reason).then(() => this);
}
/**
* Locks in the permission overwrites from the parent channel.
* @returns {Promise<GuildChannel>}
*/
lockPermissions() {
if (!this.parent) return Promise.reject(new TypeError('Could not find a parent to this guild channel.'));
const permissionOverwrites = this.parent.permissionOverwrites.map(overwrite => ({
deny: overwrite.deny.bitfield,
allow: overwrite.allow.bitfield,
id: overwrite.id,
type: overwrite.type,
}));
return this.edit({ permissionOverwrites });
}
/**
* The data for a guild channel.
* @typedef {Object} ChannelData