types(ClientPresence): add type declarations and docs (#6450)

This commit is contained in:
Rodry
2021-08-17 21:49:36 +01:00
committed by GitHub
parent 76cf52cd0d
commit 6cac03a394
3 changed files with 35 additions and 11 deletions

View File

@@ -4,6 +4,10 @@ const { Presence } = require('./Presence');
const { TypeError } = require('../errors');
const { ActivityTypes, Opcodes } = require('../util/Constants');
/**
* Represents the client's presence.
* @extends {Presence}
*/
class ClientPresence extends Presence {
/**
* @param {Client} client The instantiating client
@@ -13,6 +17,11 @@ class ClientPresence extends Presence {
super(client, Object.assign(data, { status: data.status ?? 'online', user: { id: null } }));
}
/**
* Sets the client's presence
* @param {PresenceData} presence The data to set the presence to
* @returns {ClientPresence}
*/
set(presence) {
const packet = this._parse(presence);
this._patch(packet);
@@ -28,6 +37,12 @@ class ClientPresence extends Presence {
return this;
}
/**
* Parses presence data into a packet ready to be sent to Discord
* @param {PresenceData} presence The data to parse
* @returns {APIPresence}
* @private
*/
_parse({ status, since, afk, activities }) {
const data = {
activities: [],

View File

@@ -33,8 +33,8 @@ class ClientUser extends User {
}
/**
* ClientUser's presence
* @type {Presence}
* Represents the client user's presence
* @type {ClientPresence}
* @readonly
*/
get presence() {
@@ -109,7 +109,7 @@ class ClientUser extends User {
/**
* Sets the full presence of the client user.
* @param {PresenceData} data Data for the presence
* @returns {Presence}
* @returns {ClientPresence}
* @example
* // Set the client user's presence
* client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
@@ -131,7 +131,7 @@ class ClientUser extends User {
* Sets the status of the client user.
* @param {PresenceStatusData} status Status to change to
* @param {number|number[]} [shardId] Shard id(s) to have the activity set on
* @returns {Presence}
* @returns {ClientPresence}
* @example
* // Set the client user's status
* client.user.setStatus('idle');
@@ -153,7 +153,7 @@ class ClientUser extends User {
* Sets the activity the client user is playing.
* @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity
* @param {ActivityOptions} [options] Options for setting the activity
* @returns {Presence}
* @returns {ClientPresence}
* @example
* // Set the client user's activity
* client.user.setActivity('discord.js', { type: 'WATCHING' });
@@ -169,7 +169,7 @@ class ClientUser extends User {
* Sets/removes the AFK flag for the client user.
* @param {boolean} afk Whether or not the user is AFK
* @param {number|number[]} [shardId] Shard Id(s) to have the AFK flag set on
* @returns {Presence}
* @returns {ClientPresence}
*/
setAFK(afk, shardId) {
return this.setPresence({ afk, shardId });