mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Presence): add clientStatus (#3056)
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
14
typings/index.d.ts
vendored
14
typings/index.d.ts
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user