Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Threads): update permissions and fix getters #6466

Merged
merged 9 commits into from
Oct 2, 2021
21 changes: 8 additions & 13 deletions src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ class ThreadChannel extends Channel {
* @readonly
*/
get editable() {
return (this.ownerId === this.client.user.id && (this.type !== 'private_thread' || this.joined)) || this.manageable;
return (
(this.ownerId === this.client.user.id && (this.type !== 'GUILD_PRIVATE_THREAD' || this.joined)) || this.manageable
);
}

/**
Expand All @@ -402,7 +404,6 @@ class ThreadChannel extends Channel {
!this.joined &&
this.permissionsFor(this.client.user)?.has(
this.type === 'GUILD_PRIVATE_THREAD' ? Permissions.FLAGS.MANAGE_THREADS : Permissions.FLAGS.VIEW_CHANNEL,
false,
)
);
}
Expand All @@ -413,7 +414,7 @@ class ThreadChannel extends Channel {
* @readonly
*/
get manageable() {
return this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_THREADS, false);
return this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_THREADS);
}

/**
Expand All @@ -423,16 +424,10 @@ class ThreadChannel extends Channel {
*/
get sendable() {
return (
!this.archived &&
(this.type !== 'private_thread' || this.joined || this.manageable) &&
this.permissionsFor(this.client.user)?.any(
[
Permissions.FLAGS.SEND_MESSAGES,
this.type === 'GUILD_PRIVATE_THREAD'
? Permissions.FLAGS.USE_PRIVATE_THREADS
: Permissions.FLAGS.USE_PUBLIC_THREADS,
],
false,
!(this.archived && this.locked && !this.manageable) &&
(this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) &&
this.permissionsFor(this.client.user)?.has(
advaith1 marked this conversation as resolved.
Show resolved Hide resolved
this.isThread() ? Permissions.FLAGS.SEND_MESSAGES_IN_THREADS : Permissions.FLAGS.SEND_MESSAGES,
advaith1 marked this conversation as resolved.
Show resolved Hide resolved
)
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/util/Permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ class Permissions extends BitField {
* * `USE_APPLICATION_COMMANDS`
* * `REQUEST_TO_SPEAK`
* * `MANAGE_THREADS`
* * `USE_PUBLIC_THREADS`
* * `USE_PRIVATE_THREADS`
* * `USE_PUBLIC_THREADS` (create threads)
* * `USE_PRIVATE_THREADS` (create private threads)
advaith1 marked this conversation as resolved.
Show resolved Hide resolved
advaith1 marked this conversation as resolved.
Show resolved Hide resolved
* * `USE_EXTERNAL_STICKERS` (use stickers from different guilds)
* * `SEND_MESSAGES_IN_THREADS`
* @type {Object<string, bigint>}
* @see {@link https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags}
*/
Expand Down Expand Up @@ -135,6 +136,7 @@ Permissions.FLAGS = {
USE_PUBLIC_THREADS: 1n << 35n,
USE_PRIVATE_THREADS: 1n << 36n,
advaith1 marked this conversation as resolved.
Show resolved Hide resolved
USE_EXTERNAL_STICKERS: 1n << 37n,
SEND_MESSAGES_IN_THREADS: 1n << 38n,
};

/**
Expand Down
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4331,7 +4331,8 @@ export type PermissionString =
| 'MANAGE_THREADS'
| 'USE_PUBLIC_THREADS'
| 'USE_PRIVATE_THREADS'
advaith1 marked this conversation as resolved.
Show resolved Hide resolved
| 'USE_EXTERNAL_STICKERS';
| 'USE_EXTERNAL_STICKERS'
| 'SEND_MESSAGES_IN_THREADS';

export type RecursiveArray<T> = ReadonlyArray<T | RecursiveArray<T>>;

Expand Down