From 75e264da5744b7258d92865856f5f238947c1f47 Mon Sep 17 00:00:00 2001 From: Isabella Date: Sat, 2 Feb 2019 13:29:47 -0600 Subject: [PATCH] feat: Presence#clientStatus (#2997) * feat: Presence#clientStatus * fix Presence#equals check * fix typings * vlad changes * presence consistency docs * fix docs * fix big docs fail --- src/structures/ClientUser.js | 6 ++--- src/structures/Presence.js | 45 ++++++++++++++++++++++++++++-------- typings/index.d.ts | 19 +++++++++++---- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 79d7ad0e1..3ec32e9dd 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -80,7 +80,7 @@ class ClientUser extends Structures.get('User') { /** * Data resembling a raw Discord presence. * @typedef {Object} PresenceData - * @property {PresenceStatus} [status] Status of the user + * @property {PresenceStatusData} [status] Status of the user * @property {boolean} [afk] Whether the user is AFK * @property {Object} [activity] Activity the user is playing * @property {Object|string} [activity.application] An application object or application id @@ -111,12 +111,12 @@ class ClientUser extends Structures.get('User') { * * `idle` * * `invisible` * * `dnd` (do not disturb) - * @typedef {string} PresenceStatus + * @typedef {string} PresenceStatusData */ /** * Sets the status of the client user. - * @param {PresenceStatus} status Status to change to + * @param {PresenceStatusData} status Status to change to * @param {?number|number[]} [shardID] Shard ID(s) to have the activity set on * @returns {Promise} * @example diff --git a/src/structures/Presence.js b/src/structures/Presence.js index 122b461d5..baacab138 100644 --- a/src/structures/Presence.js +++ b/src/structures/Presence.js @@ -11,14 +11,34 @@ const { ActivityTypes } = require('../util/Constants'); * @property {number} [type] Type of activity sent */ +/** + * 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. */ class Presence { constructor(client, data = {}) { Object.defineProperty(this, 'client', { value: client }); + /** + * The user ID of this presence + * @type {Snowflake} + */ this.userID = data.user.id; + + /** + * The guild of this presence + * @type {?Guild} + */ this.guild = data.guild; + this.patch(data); } @@ -40,23 +60,27 @@ class Presence { patch(data) { /** - * 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 || this.status || 'offline'; const activity = data.game || data.activity; /** - * The activity of the presence + * The activity of this presence * @type {?Activity} */ this.activity = activity ? new Activity(this, activity) : null; + /** + * The devices this presence is on + * @type {?object} + * @property {PresenceStatus} web + * @property {PresenceStatus} mobile + * @property {PresenceStatus} desktop + */ + this.clientStatus = data.client_status || null; + return this; } @@ -75,7 +99,10 @@ class Presence { return this === presence || ( presence && this.status === presence.status && - this.activity ? this.activity.equals(presence.activity) : !presence.activity + this.activity ? this.activity.equals(presence.activity) : !presence.activity && + 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 b167be1f6..4910e3545 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -270,7 +270,7 @@ declare module 'discord.js' { public setAFK(afk: boolean): Promise; public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise; public setPresence(data: PresenceData): Promise; - public setStatus(status: PresenceStatus, shardID?: number | number[]): Promise; + public setStatus(status: PresenceStatusData, shardID?: number | number[]): Promise; public setUsername(username: string): Promise; } @@ -820,7 +820,8 @@ declare module 'discord.js' { constructor(client: Client, data?: object); public activity: Activity; public flags: Readonly; - public status: 'online' | 'offline' | 'idle' | 'dnd'; + public status: PresenceStatus; + public clientStatus: ClientPresenceStatusData; public readonly user: User; public readonly member?: GuildMember; public equals(presence: Presence): boolean; @@ -1994,7 +1995,7 @@ declare module 'discord.js' { }; type PresenceData = { - status?: PresenceStatus; + status?: PresenceStatusData; afk?: boolean; activity?: { name?: string; @@ -2006,7 +2007,17 @@ declare module 'discord.js' { type PresenceResolvable = Presence | UserResolvable | Snowflake; - type PresenceStatus = 'online' | 'idle' | 'invisible' | 'dnd'; + type ClientPresenceStatus = 'online' | 'idle' | 'dnd'; + + type ClientPresenceStatusData = { + web?: ClientPresenceStatus, + mobile?: ClientPresenceStatus, + desktop?: ClientPresenceStatus + }; + + type PresenceStatus = ClientPresenceStatus | 'offline'; + + type PresenceStatusData = ClientPresenceStatus | 'invisible'; type RateLimitData = { timeout: number;