Skip to content

Commit

Permalink
feat(Guild): add support for premium/boosting (#3332)
Browse files Browse the repository at this point in the history
Backports:
PR: #3316
Commit: c877580
  • Loading branch information
SpaceEEC committed Jun 13, 2019
1 parent e6a378b commit b892436
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/structures/Emoji.js
Expand Up @@ -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;
}

Expand Down
24 changes: 24 additions & 0 deletions src/structures/Guild.js
Expand Up @@ -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}
Expand Down
16 changes: 16 additions & 0 deletions src/structures/GuildMember.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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}
Expand Down
8 changes: 8 additions & 0 deletions src/util/Constants.js
Expand Up @@ -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 = [
Expand All @@ -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',
];

/**
Expand Down
7 changes: 7 additions & 0 deletions typings/index.d.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Snowflake, Presence>;
public region: string;
Expand Down Expand Up @@ -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<Snowflake, Role>;
public selfDeaf: boolean;
Expand Down Expand Up @@ -2058,6 +2063,8 @@ declare module 'discord.js' {

type PermissionResolvable = RecursiveArray<Permissions | PermissionString | number> | Permissions | PermissionString | number;

type PremiumTier = number;

type PresenceData = {
status?: PresenceStatus;
afk?: boolean;
Expand Down

0 comments on commit b892436

Please sign in to comment.