Add setStatus function

This commit is contained in:
Hyper-Coder
2016-08-22 15:48:19 -04:00
committed by Amish Shah
parent dd40b870d5
commit 8fed1b1d80

View File

@@ -64,6 +64,7 @@ class ClientUser extends User {
setPassword(password) {
return this.client.rest.methods.updateCurrentUser({ password });
}
/**
* Set the avatar of the logged in Client.
* @param {Base64Resolvable} avatar the new avatar
@@ -78,6 +79,43 @@ class ClientUser extends User {
return this.client.rest.methods.updateCurrentUser({ avatar });
}
/**
* Set the playing status of the logged in client.
* @param {String} status
* @param {String} game
* @returns {Promise<ClientUser>}
* @example
* // set status
* client.user.setStatus('status', 'game')
* .then(user => console.log('Changed status!'))
* .catch(console.log);
*/
setStatus(status, game) {
if (status === "online" || status === "here" || status === "available") {
this.idleStatus = null;
} else if (status === "idle" || status === "away") {
this.idleStatus = Date.now();
} 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
}
});
this.status = this.idleStatus ? "idle" : "online";
this.game = this.userGame;
return Promise.resolve();
}
edit(data) {
return this.client.rest.methods.updateCurrentUser(data);
}