Skip to content

Commit

Permalink
Allow presence updating to allow null games (#1186)
Browse files Browse the repository at this point in the history
* Adding resetGame functionallity

`setGame` method would allways result in an Object passed to `setPresence`.
Passing { game: null } (supported by discords WebSocket gateway to reset the current Game) to `setPresence` would still result in a Game Object sent to the endpoint.
Explicitly setting `game` to null should overwrite the `game` object provided by `localPresence` or `client.presence`.
This was neither supported by `setGame` or `setPresence`.

* Missing semicolons to resetGame and setPresence

* Fixing trailing spaces, commas and semicolons

* Moving resetGame functionality into setGame method

Minification of if statement in setPresence.
Removing resetGame method and adding a case for `game === null` to setGame method

* Adding missing space in setGame method

* Fix docs
  • Loading branch information
JoschuaSchneider authored and amishshah committed Feb 22, 2017
1 parent f068010 commit 5c2086b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/structures/ClientUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class ClientUser extends User {
if (game.url) game.type = 1;
}

if (data.game === null) game = null;

if (typeof data.afk !== 'undefined') afk = data.afk;
afk = Boolean(afk);

Expand Down Expand Up @@ -224,11 +226,12 @@ class ClientUser extends User {

/**
* Sets the game the client user is playing.
* @param {string} game Game being played
* @param {?string} game Game being played
* @param {string} [streamingURL] Twitch stream URL
* @returns {Promise<ClientUser>}
*/
setGame(game, streamingURL) {
if (game === null) return this.setPresence({ game });
return this.setPresence({ game: {
name: game,
url: streamingURL,
Expand Down

0 comments on commit 5c2086b

Please sign in to comment.