From 5d87398f9fc57915d5447842b4788f0c80642de0 Mon Sep 17 00:00:00 2001 From: tig Date: Thu, 23 Sep 2021 20:41:18 +0900 Subject: [PATCH] fix(xxxable): follow more properly with discord behavior (#6551) Co-authored-by: SpaceEEC --- src/structures/GuildChannel.js | 6 +---- src/structures/Message.js | 40 +++++++++++++++++++++++----------- src/structures/VoiceChannel.js | 11 +--------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index 49e24a823..f8bbe3e54 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -497,11 +497,7 @@ class GuildChannel extends Channel { * @readonly */ get deletable() { - return ( - this.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) && - this.guild.rulesChannelId !== this.id && - this.guild.publicUpdatesChannelId !== this.id - ); + return this.manageable && this.guild.rulesChannelId !== this.id && this.guild.publicUpdatesChannelId !== this.id; } /** diff --git a/src/structures/Message.js b/src/structures/Message.js index 5f7507597..c8174e6b0 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -548,7 +548,7 @@ class Message extends Base { * @readonly */ get editable() { - return this.author.id === this.client.user.id; + return Boolean(this.author.id === this.client.user.id && !this.deleted && (!this.guild || this.channel?.viewable)); } /** @@ -557,10 +557,19 @@ class Message extends Base { * @readonly */ get deletable() { + if (this.deleted) { + return false; + } + if (!this.guild) { + return this.author.id === this.client.user.id; + } + // DMChannel does not have viewable property, so check viewable after proved that message is on a guild. + if (!this.channel?.viewable) { + return false; + } return Boolean( - !this.deleted && - (this.author.id === this.client.user.id || - this.channel.permissionsFor?.(this.client.user)?.has(Permissions.FLAGS.MANAGE_MESSAGES)), + this.author.id === this.client.user.id || + this.channel.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_MESSAGES, false), ); } @@ -572,7 +581,10 @@ class Message extends Base { get pinnable() { return Boolean( !this.system && - (!this.guild || this.channel.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_MESSAGES, false)), + !this.deleted && + (!this.guild || + (this.channel?.viewable && + this.channel.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_MESSAGES, false))), ); } @@ -595,14 +607,16 @@ class Message extends Base { * @readonly */ get crosspostable() { - return ( - this.channel.type === 'GUILD_NEWS' && - !this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) && - this.type === 'DEFAULT' && - this.channel.viewable && - this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.SEND_MESSAGES) && - (this.author.id === this.client.user.id || - this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES)) + const bitfield = + Permissions.FLAGS.SEND_MESSAGES | + (this.author.id === this.client.user.id ? Permissions.defaultBit : Permissions.FLAGS.MANAGE_MESSAGES); + return Boolean( + this.channel?.type === 'GUILD_NEWS' && + !this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) && + this.type === 'DEFAULT' && + this.channel.viewable && + this.channel.permissionsFor(this.client.user)?.has(bitfield, false) && + !this.deleted, ); } diff --git a/src/structures/VoiceChannel.js b/src/structures/VoiceChannel.js index 9076278bc..64cc6c50c 100644 --- a/src/structures/VoiceChannel.js +++ b/src/structures/VoiceChannel.js @@ -8,15 +8,6 @@ const Permissions = require('../util/Permissions'); * @extends {BaseGuildVoiceChannel} */ class VoiceChannel extends BaseGuildVoiceChannel { - /** - * Whether the channel is deletable by the client user - * @type {boolean} - * @readonly - */ - get deletable() { - return super.deletable && this.permissionsFor(this.client.user).has(Permissions.FLAGS.CONNECT, false); - } - /** * Whether the channel is editable by the client user * @type {boolean} @@ -24,7 +15,7 @@ class VoiceChannel extends BaseGuildVoiceChannel { * @deprecated Use {@link VoiceChannel#manageable} instead */ get editable() { - return this.manageable && this.permissionsFor(this.client.user).has(Permissions.FLAGS.CONNECT, false); + return this.manageable; } /**