From 2ca74d6b63392c09a388c58f9b04945e884646c6 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Thu, 5 Dec 2019 13:13:42 +0100 Subject: [PATCH] feat(Activity): support for CUSTOM_STATUS activity type (#3353) * feat: support for custom status in activity * nit(typings): order properties --- src/structures/Presence.js | 22 ++++++++++++++++++++++ src/util/Constants.js | 2 ++ typings/index.d.ts | 6 +++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/structures/Presence.js b/src/structures/Presence.js index 8c7d22b0d..2eccf7cb2 100644 --- a/src/structures/Presence.js +++ b/src/structures/Presence.js @@ -3,6 +3,7 @@ const Util = require('../util/Util'); const ActivityFlags = require('../util/ActivityFlags'); const { ActivityTypes } = require('../util/Constants'); +const Emoji = require('./Emoji'); /** * Activity sent in a message. @@ -205,6 +206,18 @@ class Activity { * @type {Readonly} */ this.flags = new ActivityFlags(data.flags).freeze(); + + /** + * Emoji for a custom activity + * @type {?Emoji} + */ + this.emoji = data.emoji ? new Emoji(presence.client, data.emoji) : null; + + /** + * Creation date of the activity + * @type {number} + */ + this.createdTimestamp = new Date(data.created_at).getTime(); } /** @@ -221,6 +234,15 @@ class Activity { ); } + /** + * The time the activity was created at + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + /** * When concatenated with a string, this automatically returns the activities' name instead of the Activity object. * @returns {string} diff --git a/src/util/Constants.js b/src/util/Constants.js index da2d2e300..12ddfbf8f 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -411,6 +411,7 @@ exports.MessageTypes = [ * * STREAMING * * LISTENING * * WATCHING + * * CUSTOM_STATUS * @typedef {string} ActivityType */ exports.ActivityTypes = [ @@ -418,6 +419,7 @@ exports.ActivityTypes = [ 'STREAMING', 'LISTENING', 'WATCHING', + 'CUSTOM_STATUS', ]; exports.ChannelTypes = { diff --git a/typings/index.d.ts b/typings/index.d.ts index 20851d7a2..abab6b954 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -25,7 +25,10 @@ declare module 'discord.js' { constructor(presence: Presence, data?: object); public applicationID: Snowflake | null; public assets: RichPresenceAssets | null; + public readonly createdAt: Date; + public createdTimestamp: number; public details: string | null; + public emoji: Emoji | null; public name: string; public party: { id: string | null; @@ -1913,7 +1916,8 @@ declare module 'discord.js' { type ActivityType = 'PLAYING' | 'STREAMING' | 'LISTENING' - | 'WATCHING'; + | 'WATCHING' + | 'CUSTOM_STATUS'; type MessageFlagsString = 'CROSSPOSTED' | 'IS_CROSSPOST'