From c0b107a6f9d6140016e289560d4fbbb0abbc89b9 Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 11:38:16 -0700 Subject: [PATCH 1/8] feat(Threads): update permissions and fix getters --- src/structures/ThreadChannel.js | 21 ++++++++------------- src/util/Permissions.js | 10 ++++++---- typings/index.d.ts | 7 ++++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js index b098c15322de..0fe618e4966c 100644 --- a/src/structures/ThreadChannel.js +++ b/src/structures/ThreadChannel.js @@ -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 + ); } /** @@ -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, ) ); } @@ -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); } /** @@ -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( + this.isThread() ? Permissions.FLAGS.SEND_MESSAGES_IN_THREADS : Permissions.FLAGS.SEND_MESSAGES, ) ); } diff --git a/src/util/Permissions.js b/src/util/Permissions.js index 5ce6cc1ace95..1fd3352d663b 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -91,9 +91,10 @@ class Permissions extends BitField { * * `USE_APPLICATION_COMMANDS` * * `REQUEST_TO_SPEAK` * * `MANAGE_THREADS` - * * `USE_PUBLIC_THREADS` - * * `USE_PRIVATE_THREADS` + * * `CREATE_PUBLIC_THREADS` + * * `CREATE_PRIVATE_THREADS` * * `USE_EXTERNAL_STICKERS` (use stickers from different guilds) + * * `SEND_MESSAGES_IN_THREADS` * @type {Object} * @see {@link https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags} */ @@ -132,9 +133,10 @@ Permissions.FLAGS = { USE_APPLICATION_COMMANDS: 1n << 31n, REQUEST_TO_SPEAK: 1n << 32n, MANAGE_THREADS: 1n << 34n, - USE_PUBLIC_THREADS: 1n << 35n, - USE_PRIVATE_THREADS: 1n << 36n, + CREATE_PUBLIC_THREADS: 1n << 35n, + CREATE_PRIVATE_THREADS: 1n << 36n, USE_EXTERNAL_STICKERS: 1n << 37n, + SEND_MESSAGES_IN_THREADS: 1n << 38n, }; /** diff --git a/typings/index.d.ts b/typings/index.d.ts index ab686cb62202..db5f06c0fc03 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4329,9 +4329,10 @@ export type PermissionString = | 'USE_APPLICATION_COMMANDS' | 'REQUEST_TO_SPEAK' | 'MANAGE_THREADS' - | 'USE_PUBLIC_THREADS' - | 'USE_PRIVATE_THREADS' - | 'USE_EXTERNAL_STICKERS'; + | 'CREATE_PUBLIC_THREADS' + | 'CREATE_PRIVATE_THREADS' + | 'USE_EXTERNAL_STICKERS' + | 'SEND_MESSAGES_IN_THREADS'; export type RecursiveArray = ReadonlyArray>; From 450350d97b616aab1cb5a7de90f6f7d4d956adf6 Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 11:45:00 -0700 Subject: [PATCH 2/8] chore: change back names for now --- src/util/Permissions.js | 8 ++++---- typings/index.d.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/Permissions.js b/src/util/Permissions.js index 1fd3352d663b..7166b6fcd9ba 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -91,8 +91,8 @@ class Permissions extends BitField { * * `USE_APPLICATION_COMMANDS` * * `REQUEST_TO_SPEAK` * * `MANAGE_THREADS` - * * `CREATE_PUBLIC_THREADS` - * * `CREATE_PRIVATE_THREADS` + * * `USE_PUBLIC_THREADS` (create threads) + * * `USE_PRIVATE_THREADS` (create private threads) * * `USE_EXTERNAL_STICKERS` (use stickers from different guilds) * * `SEND_MESSAGES_IN_THREADS` * @type {Object} @@ -133,8 +133,8 @@ Permissions.FLAGS = { USE_APPLICATION_COMMANDS: 1n << 31n, REQUEST_TO_SPEAK: 1n << 32n, MANAGE_THREADS: 1n << 34n, - CREATE_PUBLIC_THREADS: 1n << 35n, - CREATE_PRIVATE_THREADS: 1n << 36n, + USE_PUBLIC_THREADS: 1n << 35n, + USE_PRIVATE_THREADS: 1n << 36n, USE_EXTERNAL_STICKERS: 1n << 37n, SEND_MESSAGES_IN_THREADS: 1n << 38n, }; diff --git a/typings/index.d.ts b/typings/index.d.ts index db5f06c0fc03..a75ed59e0744 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4329,8 +4329,8 @@ export type PermissionString = | 'USE_APPLICATION_COMMANDS' | 'REQUEST_TO_SPEAK' | 'MANAGE_THREADS' - | 'CREATE_PUBLIC_THREADS' - | 'CREATE_PRIVATE_THREADS' + | 'USE_PUBLIC_THREADS' + | 'USE_PRIVATE_THREADS' | 'USE_EXTERNAL_STICKERS' | 'SEND_MESSAGES_IN_THREADS'; From 3567ca645cb4a12ead141432590ab1d77824a4d7 Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 11:59:03 -0700 Subject: [PATCH 3/8] fix: apparently checkAdmin for channel permissions is actually bad https://canary.discord.com/channels/222078108977594368/682166281826598932/877264062512246874 --- src/structures/ThreadChannel.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js index 0fe618e4966c..5486f5610a11 100644 --- a/src/structures/ThreadChannel.js +++ b/src/structures/ThreadChannel.js @@ -404,6 +404,7 @@ 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, ) ); } @@ -414,7 +415,7 @@ class ThreadChannel extends Channel { * @readonly */ get manageable() { - return this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_THREADS); + return this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_THREADS, false); } /** @@ -428,6 +429,7 @@ class ThreadChannel extends Channel { (this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) && this.permissionsFor(this.client.user)?.has( this.isThread() ? Permissions.FLAGS.SEND_MESSAGES_IN_THREADS : Permissions.FLAGS.SEND_MESSAGES, + false, ) ); } From 8b396ca6f73bae24a46aaacfd59f24eb289ab3a0 Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 12:03:00 -0700 Subject: [PATCH 4/8] chore: add TODO comment --- src/util/Permissions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/Permissions.js b/src/util/Permissions.js index 7166b6fcd9ba..32375c12f6ba 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -133,6 +133,7 @@ Permissions.FLAGS = { USE_APPLICATION_COMMANDS: 1n << 31n, REQUEST_TO_SPEAK: 1n << 32n, MANAGE_THREADS: 1n << 34n, + // TODO: Rename USE_*_THREADS to CREATE_*_THREADS in v14 USE_PUBLIC_THREADS: 1n << 35n, USE_PRIVATE_THREADS: 1n << 36n, USE_EXTERNAL_STICKERS: 1n << 37n, From 62db20395fbc6bcf1bc9d1d92f9cc00f2dcce991 Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 12:59:43 -0700 Subject: [PATCH 5/8] chore: remove pointless isThread check --- src/structures/ThreadChannel.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js index 5486f5610a11..999f99ace332 100644 --- a/src/structures/ThreadChannel.js +++ b/src/structures/ThreadChannel.js @@ -427,10 +427,7 @@ class ThreadChannel extends Channel { return ( !(this.archived && this.locked && !this.manageable) && (this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) && - this.permissionsFor(this.client.user)?.has( - this.isThread() ? Permissions.FLAGS.SEND_MESSAGES_IN_THREADS : Permissions.FLAGS.SEND_MESSAGES, - false, - ) + this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.SEND_MESSAGES_IN_THREADS, false) ); } From 790bfc8d964d92cf00b0b4f8ccdb50a9ba3a4923 Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 13:03:49 -0700 Subject: [PATCH 6/8] fix: sendable should return false instead of undefined --- src/structures/ThreadChannel.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js index 999f99ace332..9f8098550b89 100644 --- a/src/structures/ThreadChannel.js +++ b/src/structures/ThreadChannel.js @@ -425,9 +425,10 @@ class ThreadChannel extends Channel { */ get sendable() { 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) + (!(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 ); } From c9898ed028709c6cb1857c528e2d7af9e24b9b9d Mon Sep 17 00:00:00 2001 From: Advaith Date: Tue, 17 Aug 2021 14:13:42 -0700 Subject: [PATCH 7/8] feat: add new names --- src/util/Permissions.js | 10 +++++++--- typings/index.d.ts | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/util/Permissions.js b/src/util/Permissions.js index 32375c12f6ba..5360205414fc 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -91,8 +91,10 @@ class Permissions extends BitField { * * `USE_APPLICATION_COMMANDS` * * `REQUEST_TO_SPEAK` * * `MANAGE_THREADS` - * * `USE_PUBLIC_THREADS` (create threads) - * * `USE_PRIVATE_THREADS` (create private threads) + * * `USE_PUBLIC_THREADS` (deprecated) + * * `CREATE_PUBLIC_THREADS` + * * `USE_PRIVATE_THREADS` (deprecated) + * * `CREATE_PRIVATE_THREADS` * * `USE_EXTERNAL_STICKERS` (use stickers from different guilds) * * `SEND_MESSAGES_IN_THREADS` * @type {Object} @@ -133,9 +135,11 @@ Permissions.FLAGS = { USE_APPLICATION_COMMANDS: 1n << 31n, REQUEST_TO_SPEAK: 1n << 32n, MANAGE_THREADS: 1n << 34n, - // TODO: Rename USE_*_THREADS to CREATE_*_THREADS in v14 + // TODO: Remove deprecated USE_*_THREADS flags in v14 USE_PUBLIC_THREADS: 1n << 35n, + CREATE_PUBLIC_THREADS: 1n << 35n, USE_PRIVATE_THREADS: 1n << 36n, + CREATE_PRIVATE_THREADS: 1n << 36n, USE_EXTERNAL_STICKERS: 1n << 37n, SEND_MESSAGES_IN_THREADS: 1n << 38n, }; diff --git a/typings/index.d.ts b/typings/index.d.ts index a75ed59e0744..26dc39165e87 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4330,7 +4330,9 @@ export type PermissionString = | 'REQUEST_TO_SPEAK' | 'MANAGE_THREADS' | 'USE_PUBLIC_THREADS' + | 'CREATE_PUBLIC_THREADS' | 'USE_PRIVATE_THREADS' + | 'CREATE_PRIVATE_THREADS' | 'USE_EXTERNAL_STICKERS' | 'SEND_MESSAGES_IN_THREADS'; From 717c4c91b9d0938ad9d52e6996a578beaa841389 Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 29 Sep 2021 16:21:31 -0700 Subject: [PATCH 8/8] fix: typings merge issue --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index f0be3f18e754..576f5c0f1999 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4538,7 +4538,7 @@ export type PermissionString = | 'USE_PRIVATE_THREADS' | 'CREATE_PRIVATE_THREADS' | 'USE_EXTERNAL_STICKERS' - | 'SEND_MESSAGES_IN_THREADS'; + | 'SEND_MESSAGES_IN_THREADS' | 'START_EMBEDDED_ACTIVITIES'; export type RecursiveArray = ReadonlyArray>;