Skip to content

Commit

Permalink
feat(ThreadChannel): add permission checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Dec 22, 2021
1 parent eb57f31 commit 0c64dde
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,12 @@ class ThreadChannel extends Channel {
* @readonly
*/
get manageable() {
return this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_THREADS, false);
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
// This flag allows managing even if timed out
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
if (!permissions.has(Permissions.FLAGS.MANAGE_THREADS, false)) return false;
return this.guild.me.communicationDisabledUntilTimestamp < Date.now();
}

/**
Expand All @@ -460,11 +465,16 @@ class ThreadChannel extends Channel {
* @readonly
*/
get sendable() {
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
// This flag allows sending even if timed out
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;

return (
(!(this.archived && this.locked && !this.manageable) &&
(this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) &&
this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.SEND_MESSAGES_IN_THREADS, false)) ??
false
!(this.archived && this.locked && !this.manageable) &&
(this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) &&
permissions.has(Permissions.FLAGS.SEND_MESSAGES_IN_THREADS, false) &&
this.guild.me.communicationDisabledUntilTimestamp < Date.now()
);
}

Expand Down

0 comments on commit 0c64dde

Please sign in to comment.