mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 04:52:22 +00:00
Reorganise Presence
This commit is contained in:
parent
c8761d72de
commit
f2cd48d94b
1 changed files with 50 additions and 47 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue