mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
feat: Presence#clientStatus (#2997)
* feat: Presence#clientStatus * fix Presence#equals check * fix typings * vlad changes * presence consistency docs * fix docs * fix big docs fail
This commit is contained in:
@@ -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<Presence>}
|
||||
* @example
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
19
typings/index.d.ts
vendored
19
typings/index.d.ts
vendored
@@ -270,7 +270,7 @@ declare module 'discord.js' {
|
||||
public setAFK(afk: boolean): Promise<Presence>;
|
||||
public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise<ClientUser>;
|
||||
public setPresence(data: PresenceData): Promise<Presence>;
|
||||
public setStatus(status: PresenceStatus, shardID?: number | number[]): Promise<Presence>;
|
||||
public setStatus(status: PresenceStatusData, shardID?: number | number[]): Promise<Presence>;
|
||||
public setUsername(username: string): Promise<ClientUser>;
|
||||
}
|
||||
|
||||
@@ -820,7 +820,8 @@ declare module 'discord.js' {
|
||||
constructor(client: Client, data?: object);
|
||||
public activity: Activity;
|
||||
public flags: Readonly<ActivityFlags>;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user