Skip to content

Commit

Permalink
fix(xxxable): follow more properly with discord behavior (#6551)
Browse files Browse the repository at this point in the history
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
  • Loading branch information
tignear and SpaceEEC committed Sep 23, 2021
1 parent 6033506 commit 5d87398
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
6 changes: 1 addition & 5 deletions src/structures/GuildChannel.js
Expand Up @@ -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;
}

/**
Expand Down
40 changes: 27 additions & 13 deletions src/structures/Message.js
Expand Up @@ -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));
}

/**
Expand All @@ -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),
);
}

Expand All @@ -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))),
);
}

Expand All @@ -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,
);
}

Expand Down
11 changes: 1 addition & 10 deletions src/structures/VoiceChannel.js
Expand Up @@ -8,23 +8,14 @@ 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}
* @readonly
* @deprecated Use {@link VoiceChannel#manageable} instead
*/
get editable() {
return this.manageable && this.permissionsFor(this.client.user).has(Permissions.FLAGS.CONNECT, false);
return this.manageable;
}

/**
Expand Down

0 comments on commit 5d87398

Please sign in to comment.