mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
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
This commit is contained in:
@@ -187,6 +187,7 @@ class ClientUser extends User {
|
|||||||
* @property {boolean} [afk] Whether the user is AFK
|
* @property {boolean} [afk] Whether the user is AFK
|
||||||
* @property {Object} [game] Game the user is playing
|
* @property {Object} [game] Game the user is playing
|
||||||
* @property {string} [game.name] Name of the game
|
* @property {string} [game.name] Name of the game
|
||||||
|
* @property {GameType|number} [game.type] Type of the game
|
||||||
* @property {string} [game.url] Twitch stream URL
|
* @property {string} [game.url] Twitch stream URL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -211,7 +212,7 @@ class ClientUser extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.status) {
|
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) {
|
if (this.bot) {
|
||||||
status = data.status;
|
status = data.status;
|
||||||
} else {
|
} else {
|
||||||
@@ -222,7 +223,12 @@ class ClientUser extends User {
|
|||||||
|
|
||||||
if (data.game) {
|
if (data.game) {
|
||||||
game = 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') {
|
} else if (typeof data.game !== 'undefined') {
|
||||||
game = null;
|
game = null;
|
||||||
}
|
}
|
||||||
@@ -266,15 +272,18 @@ class ClientUser extends User {
|
|||||||
/**
|
/**
|
||||||
* Sets the game the client user is playing.
|
* 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
|
* @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<ClientUser>}
|
* @returns {Promise<ClientUser>}
|
||||||
*/
|
*/
|
||||||
setGame(game, streamingURL) {
|
setGame(game, { url, type } = {}) {
|
||||||
if (!game) return this.setPresence({ game: null });
|
if (!game) return this.setPresence({ game: null });
|
||||||
return this.setPresence({
|
return this.setPresence({
|
||||||
game: {
|
game: {
|
||||||
name: game,
|
name: game,
|
||||||
url: streamingURL,
|
type,
|
||||||
|
url,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,15 +66,6 @@ class Game {
|
|||||||
this.url = data.url || null;
|
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
|
* Whether this game is equal to another game
|
||||||
* @param {Game} game The game to compare with
|
* @param {Game} game The game to compare with
|
||||||
|
|||||||
Reference in New Issue
Block a user