From b8924369ea036509602a516b9a1ed4dcda202b1e Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 13 Jun 2019 19:03:36 +0200 Subject: [PATCH] feat(Guild): add support for premium/boosting (#3332) Backports: PR: #3316 Commit: c87758086b81fda632a2f678ed46c4ab2ae8673f --- src/structures/Emoji.js | 7 +++++++ src/structures/Guild.js | 24 ++++++++++++++++++++++++ src/structures/GuildMember.js | 16 ++++++++++++++++ src/util/Constants.js | 8 ++++++++ typings/index.d.ts | 7 +++++++ 5 files changed, 62 insertions(+) diff --git a/src/structures/Emoji.js b/src/structures/Emoji.js index ef332fe68..39bb5f5e1 100644 --- a/src/structures/Emoji.js +++ b/src/structures/Emoji.js @@ -62,6 +62,13 @@ class Emoji { */ this.animated = data.animated; + /** + * Whether this emoji is available + * @type {boolean} + * @name Emoji#available + */ + if (typeof data.available !== 'undefined') this.available = data.available; + this._roles = data.roles; } diff --git a/src/structures/Guild.js b/src/structures/Guild.js index b3084d5ac..2fe5c64fb 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -184,6 +184,30 @@ class Guild { this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] || data.default_message_notifications; + /** + * The type of premium tier: + * * 0: NONE + * * 1: TIER_1 + * * 2: TIER_2 + * * 3: TIER_3 + * @typedef {number} PremiumTier + */ + + /** + * The premium tier on this guild + * @type {PremiumTier} + */ + this.premiumTier = data.premium_tier; + + /** + * The total number of users currently boosting this server + * @type {?number} + * @name Guild#premiumSubscriptionCount + */ + if (typeof data.premium_subscription_count !== 'undefined') { + this.premiumSubscriptionCount = data.premium_subscription_count; + } + /** * The hash of the guild banner * @type {?string} diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index e10f11d6c..54702d439 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -37,6 +37,12 @@ class GuildMember { */ this.joinedTimestamp = null; + /** + * The timestamp of when the member used their Nitro boost on the guild, if it was used + * @type {?number} + */ + this.premiumSinceTimestamp = null; + this._roles = []; if (data) this.setup(data); @@ -109,6 +115,7 @@ class GuildMember { this.nickname = data.nick || null; if (data.joined_at) this.joinedTimestamp = new Date(data.joined_at).getTime(); + if (data.premium_since) this.premiumSinceTimestamp = new Date(data.premium_since).getTime(); this.user = data.user; this._roles = data.roles; @@ -123,6 +130,15 @@ class GuildMember { return this.joinedTimestamp ? new Date(this.joinedTimestamp) : null; } + /** + * The time of when the member used their Nitro boost on the guild, if it was used + * @type {?Date} + * @readonly + */ + get premiumSince() { + return this.premiumSinceTimestamp ? new Date(this.premiumSinceTimestamp) : null; + } + /** * The presence of this member * @type {Presence} diff --git a/src/util/Constants.js b/src/util/Constants.js index 3787818b6..231622ecd 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -480,6 +480,10 @@ exports.WSEvents = { * * CHANNEL_ICON_CHANGE * * PINS_ADD * * GUILD_MEMBER_JOIN + * * USER_PREMIUM_GUILD_SUBSCRIPTION + * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 + * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 + * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 * @typedef {string} MessageType */ exports.MessageTypes = [ @@ -491,6 +495,10 @@ exports.MessageTypes = [ 'CHANNEL_ICON_CHANGE', 'PINS_ADD', 'GUILD_MEMBER_JOIN', + 'USER_PREMIUM_GUILD_SUBSCRIPTION', + 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1', + 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2', + 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3', ]; /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 8e48a99dd..2cd2be09b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -403,6 +403,7 @@ declare module 'discord.js' { export class Emoji { constructor(guild: Guild, data: object); public animated: boolean; + public available: boolean; public readonly client: Client; public readonly createdAt: Date; public readonly createdTimestamp: number; @@ -516,6 +517,8 @@ declare module 'discord.js' { public readonly nameAcronym: string; public readonly owner: GuildMember; public ownerID: string; + public premiumSubscriptionCount: number | null; + public premiumTier: PremiumTier; public readonly position: number; public presences: Collection; public region: string; @@ -665,6 +668,8 @@ declare module 'discord.js' { public nickname: string; public readonly manageable: boolean; public readonly permissions: Permissions; + public readonly premiumSince: Date | null; + public premiumSinceTimestamp: number | null; public readonly presence: Presence; public readonly roles: Collection; public selfDeaf: boolean; @@ -2058,6 +2063,8 @@ declare module 'discord.js' { type PermissionResolvable = RecursiveArray | Permissions | PermissionString | number; + type PremiumTier = number; + type PresenceData = { status?: PresenceStatus; afk?: boolean;