Skip to content

Commit a2a0c05

Browse files
authored
feat(Presence): add clientStatus (#3056)
1 parent 5272cec commit a2a0c05

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/structures/Presence.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const { ActivityFlags, Endpoints } = require('../util/Constants');
22

3+
/**
4+
* The status of this presence:
5+
*
6+
* * **`online`** - user is online
7+
* * **`idle`** - user is AFK
8+
* * **`offline`** - user is offline or invisible
9+
* * **`dnd`** - user is in Do Not Disturb
10+
* @typedef {string} PresenceStatus
11+
*/
12+
313
/**
414
* Represents a user's presence.
515
*/
@@ -8,13 +18,8 @@ class Presence {
818
Object.defineProperty(this, 'client', { value: client });
919

1020
/**
11-
* The status of the presence:
12-
*
13-
* * **`online`** - user is online
14-
* * **`offline`** - user is offline or invisible
15-
* * **`idle`** - user is AFK
16-
* * **`dnd`** - user is in Do not Disturb
17-
* @type {string}
21+
* The status of this presence:
22+
* @type {PresenceStatus}
1823
*/
1924
this.status = data.status || 'offline';
2025

@@ -23,11 +28,21 @@ class Presence {
2328
* @type {?Game}
2429
*/
2530
this.game = data.game ? new Game(data.game, this) : null;
31+
32+
/**
33+
* The devices this presence is on
34+
* @type {?object}
35+
* @property {PresenceStatus} web
36+
* @property {PresenceStatus} mobile
37+
* @property {PresenceStatus} desktop
38+
*/
39+
this.clientStatus = data.client_status || null;
2640
}
2741

2842
update(data) {
2943
this.status = data.status || this.status;
3044
this.game = data.game ? new Game(data.game, this) : null;
45+
this.clientStatus = data.client_status || null;
3146
}
3247

3348
/**
@@ -39,7 +54,10 @@ class Presence {
3954
return this === presence || (
4055
presence &&
4156
this.status === presence.status &&
42-
this.game ? this.game.equals(presence.game) : !presence.game
57+
(this.game ? this.game.equals(presence.game) : !presence.game) &&
58+
this.clientStatus.web === presence.clientStatus.web &&
59+
this.clientStatus.mobile === presence.clientStatus.mobile &&
60+
this.clientStatus.desktop === presence.clientStatus.desktop
4361
);
4462
}
4563
}

typings/index.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ declare module 'discord.js' {
968968
constructor(data: object, client: Client);
969969
public readonly client: Client;
970970
public game: Game;
971-
public status: 'online' | 'offline' | 'idle' | 'dnd';
971+
public status: PresenceStatusData;
972+
public clientStatus: ClientPresenceStatusData;
972973
public equals(presence: Presence): boolean;
973974
}
974975

@@ -2033,7 +2034,16 @@ declare module 'discord.js' {
20332034
} | null;
20342035
};
20352036

2036-
type PresenceStatus = 'online' | 'idle' | 'invisible' | 'dnd';
2037+
type ClientPresenceStatus = 'online' | 'idle' | 'dnd';
2038+
2039+
type PresenceStatus = ClientPresenceStatus | 'invisible' ;
2040+
type PresenceStatusData = ClientPresenceStatus | 'offline';
2041+
2042+
type ClientPresenceStatusData = {
2043+
web?: ClientPresenceStatus;
2044+
mobile?: ClientPresenceStatus;
2045+
desktop?: ClientPresenceStatus;
2046+
};
20372047

20382048
type RateLimitInfo = {
20392049
requestLimit: number;

0 commit comments

Comments
 (0)