From f878bd4d5de582acb26b5714b42ee99584a121f5 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 17:45:36 +0200 Subject: [PATCH 01/23] feat(Role): role tags --- src/managers/GuildMemberRoleManager.js | 9 ++++++ src/managers/RoleManager.js | 18 ++++++++++++ src/structures/Role.js | 38 ++++++++++++++++++++++++++ typings/index.d.ts | 12 ++++++++ 4 files changed, 77 insertions(+) diff --git a/src/managers/GuildMemberRoleManager.js b/src/managers/GuildMemberRoleManager.js index 9fc6248f8a64..9fd8fce98787 100644 --- a/src/managers/GuildMemberRoleManager.js +++ b/src/managers/GuildMemberRoleManager.js @@ -72,6 +72,15 @@ class GuildMemberRoleManager { return this._roles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this._roles.first()); } + /** + * The premium subscriber role of the guild, if present on the member + * @type {?Role} + * @readonly + */ + get premiumSubscriberRole() { + return this.cache.find(role => role.premiumSubscriberRole); + } + /** * Adds a role (or multiple roles) to the member. * @param {RoleResolvable|RoleResolvable[]|Collection} roleOrRoles The role or roles to add diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 7c5bf51ac6b5..58209bdaaee4 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -132,6 +132,24 @@ class RoleManager extends BaseManager { return this.cache.get(this.guild.id); } + /** + * The premium subscriber role of the guild, if any + * @type {?Role} + * @readonly + */ + get premiumSubscriberRole() { + return this.cache.find(role => role.premiumSubscriberRole); + } + + /** + * The role associated with the client user of the guild, if any + * @rype {Role} + * @readonly + */ + get myRole() { + return this.cache.find(role => role.myRole); + } + /** * The role with the highest position in the cache * @type {Role} diff --git a/src/structures/Role.js b/src/structures/Role.js index bba198ecfd52..12930acc5799 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -82,6 +82,44 @@ class Role extends Base { * @type {boolean} */ this.deleted = false; + + /** + * The tags this role has + * @type {?Object} + * @property {?Snowflake} botID The id of the bot this role belongs to + * @property {?Snowflake} integrationID The id of the integration this role belongs to + * @property {?boolean} premiumSubcriberRole Whether this is the guilds premium subscription role + */ + this.tags = data.tags ? {} : null; + if (data.tags) { + if (Reflect.has(data.tags, 'bot_id')) { + this.tags.botID = data.tags.bot_id; + } + if (Reflect.has(data.tags, 'integration_id')) { + this.tags.integrationID = data.tags.integration_id; + } + if (Reflect.has(data.tags, 'premium_subscriber')) { + this.tags.premiumSubscriberRole = true; + } + } + } + + /** + * Whether this role is the guilds premium subscription role + * @type {boolean} + * @readonly + */ + get isPremiumSubscriberRole() { + return this.tags && this.tags.premiumSubscriberRole; + } + + /** + * Whether this role is the role associated with the logged in bot user + * @type {boolean} + * @readonly + */ + get isMyRole() { + return this.tags && this.tags.botID === this.client.user.id; } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index e0ada93fa043..45c57250adb6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1241,6 +1241,8 @@ declare module 'discord.js' { public readonly hexColor: string; public hoist: boolean; public id: Snowflake; + public readonly isMyRole: boolean; + public readonly isPremiumSubscriberRole: boolean; public managed: boolean; public readonly members: Collection; public mentionable: boolean; @@ -1248,6 +1250,7 @@ declare module 'discord.js' { public permissions: Readonly; public readonly position: number; public rawPosition: number; + public tags?: RoleTagData; public comparePositionTo(role: Role): number; public delete(reason?: string): Promise; public edit(data: RoleData, reason?: string): Promise; @@ -1899,6 +1902,7 @@ declare module 'discord.js' { public readonly hoist: Role | null; public readonly color: Role | null; public readonly highest: Role; + public readonly premiumSubscriberRole?: Role; public member: GuildMember; public guild: Guild; @@ -1955,6 +1959,8 @@ declare module 'discord.js' { public readonly everyone: Role; public readonly highest: Role; public guild: Guild; + public readonly myRole?: Role; + public readonly premiumSubscriberRole?: Role; public create(options?: { data?: RoleData; reason?: string }): Promise; public fetch(id: Snowflake, cache?: boolean): Promise; @@ -2962,6 +2968,12 @@ declare module 'discord.js' { type RoleResolvable = Role | string; + interface RoleTagData { + botID?: Snowflake; + integrationID?: Snowflake; + premiumSubcriberRole?: boolean; + } + type ShardingManagerMode = 'process' | 'worker'; type Snowflake = string; From 9aaa93ce1adca55bb3494320b971a71178b9b77c Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 18:11:26 +0200 Subject: [PATCH 02/23] fix(RoleManager): fix js docs and mark nullable --- src/managers/RoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 58209bdaaee4..c4d19a1f369a 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -143,7 +143,7 @@ class RoleManager extends BaseManager { /** * The role associated with the client user of the guild, if any - * @rype {Role} + * @type {?Role} * @readonly */ get myRole() { From 15d3d7fbcb51633d44ad3813b0bff16da513101b Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 18:15:06 +0200 Subject: [PATCH 03/23] fix(Role): typings tags are be null, not undefined --- 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 45c57250adb6..c1213edc870d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1250,7 +1250,7 @@ declare module 'discord.js' { public permissions: Readonly; public readonly position: number; public rawPosition: number; - public tags?: RoleTagData; + public tags: RoleTagData | null; public comparePositionTo(role: Role): number; public delete(reason?: string): Promise; public edit(data: RoleData, reason?: string): Promise; From ab7cb31782a5956e574070e3431780ed07eec1ab Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 18:33:33 +0200 Subject: [PATCH 04/23] fix(Role): getters should actually return a bool --- src/structures/Role.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 12930acc5799..3cee047ce846 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -110,7 +110,7 @@ class Role extends Base { * @readonly */ get isPremiumSubscriberRole() { - return this.tags && this.tags.premiumSubscriberRole; + return this.tags ? this.tags.premiumSubscriberRole : false; } /** @@ -119,7 +119,7 @@ class Role extends Base { * @readonly */ get isMyRole() { - return this.tags && this.tags.botID === this.client.user.id; + return this.tags ? this.tags.botID === this.client.user.id : false; } /** From 72c2d01ff50d67ade0df2b402ec5de8e9c23b05d Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 18:36:08 +0200 Subject: [PATCH 05/23] fix(RoleManager): typo --- src/managers/RoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index c4d19a1f369a..75fefcdbc3d5 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -147,7 +147,7 @@ class RoleManager extends BaseManager { * @readonly */ get myRole() { - return this.cache.find(role => role.myRole); + return this.cache.find(role => role.isMyRole); } /** From 830c45cda0232977254ff2758be3b7184d90aea5 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 21:25:30 +0200 Subject: [PATCH 06/23] fix(Role): should always return a boolean --- src/structures/Role.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 3cee047ce846..31b446846ed6 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -110,7 +110,7 @@ class Role extends Base { * @readonly */ get isPremiumSubscriberRole() { - return this.tags ? this.tags.premiumSubscriberRole : false; + return Boolean(this.tags && this.tags.premiumSubscriberRole); } /** @@ -119,7 +119,7 @@ class Role extends Base { * @readonly */ get isMyRole() { - return this.tags ? this.tags.botID === this.client.user.id : false; + return Boolean(this.tags && this.tags.botID === this.client.user.id); } /** From 54c7c3237e588f513390acf23208af4acc7e3225 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 21:44:32 +0200 Subject: [PATCH 07/23] fix(Gmrm): getter should return null --- src/managers/GuildMemberRoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/GuildMemberRoleManager.js b/src/managers/GuildMemberRoleManager.js index 9fd8fce98787..6014b493c7d8 100644 --- a/src/managers/GuildMemberRoleManager.js +++ b/src/managers/GuildMemberRoleManager.js @@ -78,7 +78,7 @@ class GuildMemberRoleManager { * @readonly */ get premiumSubscriberRole() { - return this.cache.find(role => role.premiumSubscriberRole); + return this.cache.find(role => role.premiumSubscriberRole) || null; } /** From ac63b6268b8b101374049a8712aac5b08e7bd06d Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 21:45:01 +0200 Subject: [PATCH 08/23] fix(RoleManager): getters should return null --- src/managers/RoleManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 75fefcdbc3d5..77cf6137e27c 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -138,7 +138,7 @@ class RoleManager extends BaseManager { * @readonly */ get premiumSubscriberRole() { - return this.cache.find(role => role.premiumSubscriberRole); + return this.cache.find(role => role.premiumSubscriberRole) || null; } /** @@ -147,7 +147,7 @@ class RoleManager extends BaseManager { * @readonly */ get myRole() { - return this.cache.find(role => role.isMyRole); + return this.cache.find(role => role.isMyRole) || null; } /** From 190b101f5b35f75e656843ada515773037411523 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 22:13:29 +0200 Subject: [PATCH 09/23] fix: typing getters should return null --- typings/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index c1213edc870d..ebd15b21582e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1902,7 +1902,7 @@ declare module 'discord.js' { public readonly hoist: Role | null; public readonly color: Role | null; public readonly highest: Role; - public readonly premiumSubscriberRole?: Role; + public readonly premiumSubscriberRole: Role | null; public member: GuildMember; public guild: Guild; @@ -1959,8 +1959,8 @@ declare module 'discord.js' { public readonly everyone: Role; public readonly highest: Role; public guild: Guild; - public readonly myRole?: Role; - public readonly premiumSubscriberRole?: Role; + public readonly myRole: Role | null; + public readonly premiumSubscriberRole: Role | null; public create(options?: { data?: RoleData; reason?: string }): Promise; public fetch(id: Snowflake, cache?: boolean): Promise; From 240780f8706796390c88effeabcfda13a3274f7c Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 22:32:52 +0200 Subject: [PATCH 10/23] fix(Role): docs grammar and consistency --- src/structures/Role.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 31b446846ed6..2bb062e8730f 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -88,7 +88,7 @@ class Role extends Base { * @type {?Object} * @property {?Snowflake} botID The id of the bot this role belongs to * @property {?Snowflake} integrationID The id of the integration this role belongs to - * @property {?boolean} premiumSubcriberRole Whether this is the guilds premium subscription role + * @property {?boolean} premiumSubcriberRole Whether this is the guild's premium subscription role */ this.tags = data.tags ? {} : null; if (data.tags) { @@ -105,7 +105,7 @@ class Role extends Base { } /** - * Whether this role is the guilds premium subscription role + * Whether this role is the guild's premium subscription role * @type {boolean} * @readonly */ @@ -114,7 +114,7 @@ class Role extends Base { } /** - * Whether this role is the role associated with the logged in bot user + * Whether this role is the role associated with the client user * @type {boolean} * @readonly */ From de4b61afd04e700794531fdf03bce405508d518c Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 22:39:23 +0200 Subject: [PATCH 11/23] chore: prefer in operator over Reflect#has --- src/structures/Role.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 2bb062e8730f..69dfc3437c85 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -92,13 +92,13 @@ class Role extends Base { */ this.tags = data.tags ? {} : null; if (data.tags) { - if (Reflect.has(data.tags, 'bot_id')) { + if ('bot_id' in data.tags) { this.tags.botID = data.tags.bot_id; } - if (Reflect.has(data.tags, 'integration_id')) { + if ('integration_id' in data.tags) { this.tags.integrationID = data.tags.integration_id; } - if (Reflect.has(data.tags, 'premium_subscriber')) { + if ('premium_subscriber' in data.tags) { this.tags.premiumSubscriberRole = true; } } From c619796a4b8e99ec805e030f753d189489a67b3c Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 23:17:25 +0200 Subject: [PATCH 12/23] feat(GmRm): botRole getter --- src/managers/GuildMemberRoleManager.js | 11 +++++++++++ typings/index.d.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/managers/GuildMemberRoleManager.js b/src/managers/GuildMemberRoleManager.js index 6014b493c7d8..e20d8b667023 100644 --- a/src/managers/GuildMemberRoleManager.js +++ b/src/managers/GuildMemberRoleManager.js @@ -81,6 +81,17 @@ class GuildMemberRoleManager { return this.cache.find(role => role.premiumSubscriberRole) || null; } + /** + * The managed role this member created when joining the guild, if any + * Only ever available on bots + * @type {?Role} + * @readonly + */ + get botRole() { + if (!this.member.user.bot) return null; + return this.cache.find(role => role.tags && role.tags.bot_id === this.id) || null; + } + /** * Adds a role (or multiple roles) to the member. * @param {RoleResolvable|RoleResolvable[]|Collection} roleOrRoles The role or roles to add diff --git a/typings/index.d.ts b/typings/index.d.ts index ebd15b21582e..6a06cb446bf6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1903,6 +1903,7 @@ declare module 'discord.js' { public readonly color: Role | null; public readonly highest: Role; public readonly premiumSubscriberRole: Role | null; + public readonly botRole: Role | null; public member: GuildMember; public guild: Guild; From d6631e32ea98dcc0e1d12d410430fdade190ad40 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sat, 11 Jul 2020 23:44:29 +0200 Subject: [PATCH 13/23] fix(GmRm): use the actual properties --- src/managers/GuildMemberRoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/GuildMemberRoleManager.js b/src/managers/GuildMemberRoleManager.js index e20d8b667023..3f8d7f65a400 100644 --- a/src/managers/GuildMemberRoleManager.js +++ b/src/managers/GuildMemberRoleManager.js @@ -89,7 +89,7 @@ class GuildMemberRoleManager { */ get botRole() { if (!this.member.user.bot) return null; - return this.cache.find(role => role.tags && role.tags.bot_id === this.id) || null; + return this.cache.find(role => role.tags && role.tags.botID === this.member.user.id) || null; } /** From 42abed52fe0cfdf50a1ada2e3075139c8b134ef4 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 12 Jul 2020 00:27:31 +0200 Subject: [PATCH 14/23] feat(RoleManager): rem myRole in pref o botRoleFor --- src/managers/RoleManager.js | 21 ++++++++++++--------- typings/index.d.ts | 3 +-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 77cf6137e27c..55c8ccd48587 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -123,6 +123,18 @@ class RoleManager extends BaseManager { }); } + /** + * Gets the managed role a user created when joining the guild, if any + * Only ever available for bots + * @param {UserResolvable} user The user to access the bot role for + * @returns {?Role} + */ + botRoleFor(user) { + user = this.client.users.resolve(user); + if (!user || !user.bot) return null; + return this.cache.find(r => r.tags && r.tags.botID === user.id) || null; + } + /** * The `@everyone` role of the guild * @type {Role} @@ -141,15 +153,6 @@ class RoleManager extends BaseManager { return this.cache.find(role => role.premiumSubscriberRole) || null; } - /** - * The role associated with the client user of the guild, if any - * @type {?Role} - * @readonly - */ - get myRole() { - return this.cache.find(role => role.isMyRole) || null; - } - /** * The role with the highest position in the cache * @type {Role} diff --git a/typings/index.d.ts b/typings/index.d.ts index 6a06cb446bf6..6ccd04229afc 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1960,9 +1960,8 @@ declare module 'discord.js' { public readonly everyone: Role; public readonly highest: Role; public guild: Guild; - public readonly myRole: Role | null; public readonly premiumSubscriberRole: Role | null; - + public botRoleFor(user: UserResolvable): Role | null; public create(options?: { data?: RoleData; reason?: string }): Promise; public fetch(id: Snowflake, cache?: boolean): Promise; public fetch(id?: Snowflake, cache?: boolean): Promise; From a95bbba9a38ba99eca5b7987f6c39ceae6f70cea Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 12 Jul 2020 00:28:45 +0200 Subject: [PATCH 15/23] fix(Role): remove obsolete is- getters --- src/structures/Role.js | 18 ------------------ typings/index.d.ts | 2 -- 2 files changed, 20 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 69dfc3437c85..61c32ef3f62d 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -104,24 +104,6 @@ class Role extends Base { } } - /** - * Whether this role is the guild's premium subscription role - * @type {boolean} - * @readonly - */ - get isPremiumSubscriberRole() { - return Boolean(this.tags && this.tags.premiumSubscriberRole); - } - - /** - * Whether this role is the role associated with the client user - * @type {boolean} - * @readonly - */ - get isMyRole() { - return Boolean(this.tags && this.tags.botID === this.client.user.id); - } - /** * The timestamp the role was created at * @type {number} diff --git a/typings/index.d.ts b/typings/index.d.ts index 6ccd04229afc..d4eb07b2f4dd 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1241,8 +1241,6 @@ declare module 'discord.js' { public readonly hexColor: string; public hoist: boolean; public id: Snowflake; - public readonly isMyRole: boolean; - public readonly isPremiumSubscriberRole: boolean; public managed: boolean; public readonly members: Collection; public mentionable: boolean; From 8db00f682a2270240cb42259b8c43b2465974dd5 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 12 Jul 2020 00:37:36 +0200 Subject: [PATCH 16/23] fix: checking tags after getter removal --- src/managers/GuildMemberRoleManager.js | 2 +- src/managers/RoleManager.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/GuildMemberRoleManager.js b/src/managers/GuildMemberRoleManager.js index 3f8d7f65a400..6082700492fc 100644 --- a/src/managers/GuildMemberRoleManager.js +++ b/src/managers/GuildMemberRoleManager.js @@ -78,7 +78,7 @@ class GuildMemberRoleManager { * @readonly */ get premiumSubscriberRole() { - return this.cache.find(role => role.premiumSubscriberRole) || null; + return this.cache.find(role => role.tags && role.tags.premiumSubscriberRole) || null; } /** diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 55c8ccd48587..eb9a575b533a 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -150,7 +150,7 @@ class RoleManager extends BaseManager { * @readonly */ get premiumSubscriberRole() { - return this.cache.find(role => role.premiumSubscriberRole) || null; + return this.cache.find(role => role.tags && role.tags.premiumSubscriberRole) || null; } /** From d4bc55e89d3a58bb05a5fcd72b3238fc328402f6 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 12 Jul 2020 00:42:32 +0200 Subject: [PATCH 17/23] chore: identifier naming consistency --- src/managers/RoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index eb9a575b533a..5f37580dde8a 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -132,7 +132,7 @@ class RoleManager extends BaseManager { botRoleFor(user) { user = this.client.users.resolve(user); if (!user || !user.bot) return null; - return this.cache.find(r => r.tags && r.tags.botID === user.id) || null; + return this.cache.find(role => role.tags && role.tags.botID === user.id) || null; } /** From 3e6091de80fd02e9d3a379e578e37018d48f7b9d Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 12 Jul 2020 00:56:10 +0200 Subject: [PATCH 18/23] chore: prefer explicit true type over boolean --- src/structures/Role.js | 2 +- typings/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 61c32ef3f62d..24a9cc7fcdd0 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -88,7 +88,7 @@ class Role extends Base { * @type {?Object} * @property {?Snowflake} botID The id of the bot this role belongs to * @property {?Snowflake} integrationID The id of the integration this role belongs to - * @property {?boolean} premiumSubcriberRole Whether this is the guild's premium subscription role + * @property {?true} premiumSubcriberRole Whether this is the guild's premium subscription role */ this.tags = data.tags ? {} : null; if (data.tags) { diff --git a/typings/index.d.ts b/typings/index.d.ts index d4eb07b2f4dd..1905792a221d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2969,7 +2969,7 @@ declare module 'discord.js' { interface RoleTagData { botID?: Snowflake; integrationID?: Snowflake; - premiumSubcriberRole?: boolean; + premiumSubcriberRole?: true; } type ShardingManagerMode = 'process' | 'worker'; From f0b6741bf7c29ddfe3bea9d85deb46a44e9acd25 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 12 Jul 2020 00:58:41 +0200 Subject: [PATCH 19/23] fix: typo --- src/structures/Role.js | 2 +- typings/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 24a9cc7fcdd0..1bc588e90de5 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -88,7 +88,7 @@ class Role extends Base { * @type {?Object} * @property {?Snowflake} botID The id of the bot this role belongs to * @property {?Snowflake} integrationID The id of the integration this role belongs to - * @property {?true} premiumSubcriberRole Whether this is the guild's premium subscription role + * @property {?true} premiumSubscriberRole Whether this is the guild's premium subscription role */ this.tags = data.tags ? {} : null; if (data.tags) { diff --git a/typings/index.d.ts b/typings/index.d.ts index 1905792a221d..3cd20aeb53d7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2969,7 +2969,7 @@ declare module 'discord.js' { interface RoleTagData { botID?: Snowflake; integrationID?: Snowflake; - premiumSubcriberRole?: true; + premiumSubscriberRole?: true; } type ShardingManagerMode = 'process' | 'worker'; From 1cd58081fb0ab55f98c401bca286dd8d0e0e6e15 Mon Sep 17 00:00:00 2001 From: Jan <66554238+Vaporox@users.noreply.github.com> Date: Sun, 12 Jul 2020 23:39:04 +0200 Subject: [PATCH 20/23] feat(Integration): Add Integration#roles getter (#1) --- src/structures/Integration.js | 10 ++++++++++ typings/index.d.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/structures/Integration.js b/src/structures/Integration.js index 49a0227af848..efe684555323 100644 --- a/src/structures/Integration.js +++ b/src/structures/Integration.js @@ -78,6 +78,16 @@ class Integration extends Base { this._patch(data); } + /** + * All roles that are managed by this integration + * @type {Collection} + * @readonly + */ + get roles() { + const roles = this.guild.roles.cache; + return roles.filter(role => role.tags && role.tags.integrationID === this.id); + } + _patch(data) { /** * The behavior of expiring subscribers diff --git a/typings/index.d.ts b/typings/index.d.ts index 3cd20aeb53d7..c849dd0fe3a4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -868,6 +868,7 @@ declare module 'discord.js' { public id: Snowflake; public name: string; public role: Role; + public readonly roles: Collection; public syncedAt: number; public syncing: boolean; public type: string; @@ -1478,7 +1479,7 @@ declare module 'discord.js' { public readonly createdTimestamp: number; public discriminator: string; public readonly defaultAvatarURL: string; - public readonly dmChannel: DMChannel; + public readonly dmChannel: DMChannel | null; public flags?: Readonly; public id: Snowflake; public lastMessageID: Snowflake | null; From 066eaa0d6104eb00ee880ed8f42c07400e5069a0 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 30 Aug 2020 23:11:43 +0200 Subject: [PATCH 21/23] fix(RoleManager): remove bot check r:partials --- src/managers/RoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 5f37580dde8a..324b979f7f64 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -131,7 +131,7 @@ class RoleManager extends BaseManager { */ botRoleFor(user) { user = this.client.users.resolve(user); - if (!user || !user.bot) return null; + if (!user) return null; return this.cache.find(role => role.tags && role.tags.botID === user.id) || null; } From b1fe25c7fa0e91959cabac110a5418a24eb00890 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 30 Aug 2020 23:36:19 +0200 Subject: [PATCH 22/23] feat(RoleManager): robustness against uncached u --- src/managers/RoleManager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 324b979f7f64..2c967d2f1703 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -130,9 +130,9 @@ class RoleManager extends BaseManager { * @returns {?Role} */ botRoleFor(user) { - user = this.client.users.resolve(user); - if (!user) return null; - return this.cache.find(role => role.tags && role.tags.botID === user.id) || null; + const userID = this.client.users.resolveID(user); + if (!userID) return null; + return this.cache.find(role => role.tags && role.tags.botID === userID) || null; } /** From 258d6a589d02486bcb42eca2f0e0897f654ffa08 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Wed, 25 Nov 2020 23:04:19 +0100 Subject: [PATCH 23/23] docs: possibly undefined --- src/structures/Role.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index a534fe78aaf5..d14db3639386 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -86,9 +86,9 @@ class Role extends Base { /** * The tags this role has * @type {?Object} - * @property {?Snowflake} botID The id of the bot this role belongs to - * @property {?Snowflake} integrationID The id of the integration this role belongs to - * @property {?true} premiumSubscriberRole Whether this is the guild's premium subscription role + * @property {Snowflake} [botID] The id of the bot this role belongs to + * @property {Snowflake} [integrationID] The id of the integration this role belongs to + * @property {true} [premiumSubscriberRole] Whether this is the guild's premium subscription role */ this.tags = data.tags ? {} : null; if (data.tags) {