From e677543c30274216104beaab36fbeb2637e6bf5a Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 17 Aug 2017 18:27:32 +0200 Subject: [PATCH] Allow to set the new game types via ClientUser#setPresence and ClientUser#setGame (#1782) * Allow to set the new game types via ClientUser#setPresence and setGame * Accept string version of types, fix options parameter, remove Presence#streaming * One line if statement, don't reuse data.game when game is already reassigned and fix error message * Removed redundant if statement --- src/structures/ClientUser.js | 19 ++++++++++++++----- src/structures/Presence.js | 9 --------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 1190feb3c..6363d23a9 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -187,6 +187,7 @@ class ClientUser extends User { * @property {boolean} [afk] Whether the user is AFK * @property {Object} [game] Game the user is playing * @property {string} [game.name] Name of the game + * @property {GameType|number} [game.type] Type of the game * @property {string} [game.url] Twitch stream URL */ @@ -211,7 +212,7 @@ class ClientUser extends User { } if (data.status) { - if (typeof data.status !== 'string') throw new TypeError('STATUS_TYPE'); + if (typeof data.status !== 'string') throw new TypeError('INVALID_TYPE', 'status', 'string'); if (this.bot) { status = data.status; } else { @@ -222,7 +223,12 @@ class ClientUser extends User { if (data.game) { game = data.game; - if (game.url) game.type = 1; + if (typeof game.type === 'string') { + game.type = Constants.GameTypes.indexOf(game.type); + if (game.type === -1) throw new TypeError('INVALID_TYPE', 'type', 'GameType'); + } else if (typeof game.type !== 'number') { + game.type = game.url ? 1 : 0; + } } else if (typeof data.game !== 'undefined') { game = null; } @@ -266,15 +272,18 @@ class ClientUser extends User { /** * Sets the game the client user is playing. * @param {?string} game Game being played - * @param {string} [streamingURL] Twitch stream URL + * @param {Object} [options] Options for setting the game + * @param {string} [options.url] Twitch stream URL + * @param {GameType|number} [options.type] Type of the game * @returns {Promise} */ - setGame(game, streamingURL) { + setGame(game, { url, type } = {}) { if (!game) return this.setPresence({ game: null }); return this.setPresence({ game: { name: game, - url: streamingURL, + type, + url, }, }); } diff --git a/src/structures/Presence.js b/src/structures/Presence.js index 2306e9a81..0284260fd 100644 --- a/src/structures/Presence.js +++ b/src/structures/Presence.js @@ -66,15 +66,6 @@ class Game { this.url = data.url || null; } - /** - * Whether or not the game is being streamed - * @type {boolean} - * @readonly - */ - get streaming() { - return this.type === Constants.GameTypes[1]; - } - /** * Whether this game is equal to another game * @param {Game} game The game to compare with