minor fixes to ClientUser.setStatus

This commit is contained in:
Amish Shah
2016-08-22 21:00:03 +01:00
parent 8fed1b1d80
commit fb2392a1ed
2 changed files with 36 additions and 26 deletions

File diff suppressed because one or more lines are too long

View File

@@ -80,10 +80,10 @@ class ClientUser extends User {
} }
/** /**
* Set the playing status of the logged in client. * Set the status and playing game of the logged in client.
* @param {String} status * @param {String} [status] the status, can be `online` or `idle`.
* @param {String} game * @param {String|Object} [game] the game that is being played
* @returns {Promise<ClientUser>} * @returns {Promise<ClientUser, Error>}
* @example * @example
* // set status * // set status
* client.user.setStatus('status', 'game') * client.user.setStatus('status', 'game')
@@ -91,29 +91,39 @@ class ClientUser extends User {
* .catch(console.log); * .catch(console.log);
*/ */
setStatus(status, game) { setStatus(status, game) {
if (status === "online" || status === "here" || status === "available") { return new Promise(resolve => {
this.idleStatus = null; if (status === 'online' || status === 'here' || status === 'available') {
} else if (status === "idle" || status === "away") { this.idleStatus = null;
this.idleStatus = Date.now(); } else if (status === 'idle' || status === 'away') {
} else { this.idleStatus = Date.now();
this.idleStatus = this.idleStatus || null; } else {
} this.idleStatus = this.idleStatus || null;
if (typeof game === "string" && !game.length) game = null;
this.userGame = game === null ? null : !game ? this.userGame || null : typeof game === "string" ? {name: game} : game;
this.client.ws.send({
op: 3,
d: {
idle_since: this.idleStatus,
game: this.userGame
} }
if (typeof game === 'string' && !game.length) game = null;
if (game === null) {
this.userGame = null;
} else if (!game) {
this.userGame = this.userGame || null;
} else if (typeof game === 'string') {
this.userGame = { name: game };
} else {
this.userGame = game;
}
this.client.ws.send({
op: 3,
d: {
idle_since: this.idleStatus,
game: this.userGame,
},
});
this.status = this.idleStatus ? 'idle' : 'online';
this.game = this.userGame;
resolve(this);
}); });
this.status = this.idleStatus ? "idle" : "online";
this.game = this.userGame;
return Promise.resolve();
} }
edit(data) { edit(data) {