diff --git a/src/structures/Presence.js b/src/structures/Presence.js index 6e64bc080..47cf0a719 100644 --- a/src/structures/Presence.js +++ b/src/structures/Presence.js @@ -1,5 +1,15 @@ const { ActivityFlags, Endpoints } = require('../util/Constants'); +/** + * The status of this presence: + * + * * **`online`** - user is online + * * **`idle`** - user is AFK + * * **`offline`** - user is offline or invisible + * * **`dnd`** - user is in Do Not Disturb + * @typedef {string} PresenceStatus + */ + /** * Represents a user's presence. */ @@ -8,13 +18,8 @@ class Presence { Object.defineProperty(this, 'client', { value: client }); /** - * The status of the presence: - * - * * **`online`** - user is online - * * **`offline`** - user is offline or invisible - * * **`idle`** - user is AFK - * * **`dnd`** - user is in Do not Disturb - * @type {string} + * The status of this presence: + * @type {PresenceStatus} */ this.status = data.status || 'offline'; @@ -23,11 +28,21 @@ class Presence { * @type {?Game} */ this.game = data.game ? new Game(data.game, this) : null; + + /** + * The devices this presence is on + * @type {?object} + * @property {PresenceStatus} web + * @property {PresenceStatus} mobile + * @property {PresenceStatus} desktop + */ + this.clientStatus = data.client_status || null; } update(data) { this.status = data.status || this.status; this.game = data.game ? new Game(data.game, this) : null; + this.clientStatus = data.client_status || null; } /** @@ -39,7 +54,10 @@ class Presence { return this === presence || ( presence && this.status === presence.status && - this.game ? this.game.equals(presence.game) : !presence.game + (this.game ? this.game.equals(presence.game) : !presence.game) && + this.clientStatus.web === presence.clientStatus.web && + this.clientStatus.mobile === presence.clientStatus.mobile && + this.clientStatus.desktop === presence.clientStatus.desktop ); } } diff --git a/typings/index.d.ts b/typings/index.d.ts index 467ee6bb9..d1adde4b4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -968,7 +968,8 @@ declare module 'discord.js' { constructor(data: object, client: Client); public readonly client: Client; public game: Game; - public status: 'online' | 'offline' | 'idle' | 'dnd'; + public status: PresenceStatusData; + public clientStatus: ClientPresenceStatusData; public equals(presence: Presence): boolean; } @@ -2033,7 +2034,16 @@ declare module 'discord.js' { } | null; }; - type PresenceStatus = 'online' | 'idle' | 'invisible' | 'dnd'; + type ClientPresenceStatus = 'online' | 'idle' | 'dnd'; + + type PresenceStatus = ClientPresenceStatus | 'invisible' ; + type PresenceStatusData = ClientPresenceStatus | 'offline'; + + type ClientPresenceStatusData = { + web?: ClientPresenceStatus; + mobile?: ClientPresenceStatus; + desktop?: ClientPresenceStatus; + }; type RateLimitInfo = { requestLimit: number;