Files
discord.js/src/structures/Presence.js
2017-08-17 20:04:01 +02:00

86 lines
1.8 KiB
JavaScript

const Constants = require('../util/Constants');
/**
* Represents a user's presence.
*/
class Presence {
constructor(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}
*/
this.status = data.status || 'offline';
/**
* The game that the user is playing
* @type {?Game}
*/
this.game = data.game ? new Game(data.game) : null;
}
update(data) {
this.status = data.status || this.status;
this.game = data.game ? new Game(data.game) : null;
}
/**
* Whether this presence is equal to another
* @param {Presence} presence The presence to compare with
* @returns {boolean}
*/
equals(presence) {
return this === presence || (
presence &&
this.status === presence.status &&
this.game ? this.game.equals(presence.game) : !presence.game
);
}
}
/**
* Represents a game that is part of a user's presence.
*/
class Game {
constructor(data) {
/**
* The name of the game being played
* @type {string}
*/
this.name = data.name;
/**
* The type of the game status
* @type {GameType}
*/
this.type = Constants.GameTypes[data.type];
/**
* If the game is being streamed, a link to the stream
* @type {?string}
*/
this.url = data.url || null;
}
/**
* Whether this game is equal to another game.
* @param {Game} game The game to compare with
* @returns {boolean}
*/
equals(game) {
return this === game || (
game &&
this.name === game.name &&
this.type === game.type &&
this.url === game.url
);
}
}
exports.Presence = Presence;
exports.Game = Game;