mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Reorganise Presence
This commit is contained in:
@@ -1,3 +1,51 @@
|
||||
/**
|
||||
* Represents a User's presence
|
||||
*/
|
||||
class Presence {
|
||||
constructor(data) {
|
||||
/**
|
||||
* The status of the presence:
|
||||
*
|
||||
* * **`online`** - user is online
|
||||
* * **`offline`** - user is offline
|
||||
* * **`idle`** - user is AFK
|
||||
* @type {string}
|
||||
*/
|
||||
this.status = data.status || 'offline';
|
||||
|
||||
if (data.game) {
|
||||
/**
|
||||
* The game that the user is playing, `null` if they aren't playing a game.
|
||||
* @type {Game}
|
||||
*/
|
||||
this.game = new Game(data.game);
|
||||
} else {
|
||||
this.game = null;
|
||||
}
|
||||
}
|
||||
|
||||
update(data) {
|
||||
this.status = data.status || this.status;
|
||||
if (data.game) {
|
||||
this.game = new Game(data.game);
|
||||
} else {
|
||||
this.game = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this presence is equal to another
|
||||
* @param {Presence} other the presence to compare
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equals(other) {
|
||||
return (
|
||||
this.status === other.status &&
|
||||
this.game ? this.game.equals(other.game) : !other.game
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Game that is part of a User's presence.
|
||||
*/
|
||||
@@ -8,11 +56,13 @@ class Game {
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = data.name;
|
||||
|
||||
/**
|
||||
* The type of the game status
|
||||
* @type {number}
|
||||
*/
|
||||
this.type = data.type;
|
||||
|
||||
/**
|
||||
* If the game is being streamed, a link to the stream
|
||||
* @type {string}
|
||||
@@ -43,52 +93,5 @@ class Game {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a User's presence
|
||||
*/
|
||||
class Presence {
|
||||
constructor(data) {
|
||||
/**
|
||||
* The status of the presence:
|
||||
*
|
||||
* * **`online`** - user is online
|
||||
* * **`offline`** - user is offline
|
||||
* * **`idle`** - user is AFK
|
||||
* @type {string}
|
||||
*/
|
||||
this.status = data.status || 'offline';
|
||||
if (data.game) {
|
||||
/**
|
||||
* The game that the user is playing, `null` if they aren't playing a game.
|
||||
* @type {Game}
|
||||
*/
|
||||
this.game = new Game(data.game);
|
||||
} else {
|
||||
this.game = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this presence is equal to another
|
||||
* @param {Presence} other the presence to compare
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equals(other) {
|
||||
return (
|
||||
this.status === other.status &&
|
||||
this.game ? this.game.equals(other.game) : !other.game
|
||||
);
|
||||
}
|
||||
|
||||
update(data) {
|
||||
this.status = data.status || this.status;
|
||||
if (data.game) {
|
||||
this.game = new Game(data.game);
|
||||
} else {
|
||||
this.game = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.Presence = Presence;
|
||||
exports.Game = Game;
|
||||
|
||||
Reference in New Issue
Block a user