mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
feature(ClientUser): deprecate ClientUser#setGame in favour of ClientUser#setActivity (#2127)
* feature(ClientUser): backported ClientUser#setPresence * fix ternary * deprecation stuff
This commit is contained in:
committed by
Schuyler Cebulskie
parent
e40c3f8cd0
commit
cd066849ad
@@ -3,6 +3,7 @@ const Collection = require('../util/Collection');
|
||||
const ClientUserSettings = require('./ClientUserSettings');
|
||||
const ClientUserGuildSettings = require('./ClientUserGuildSettings');
|
||||
const Constants = require('../util/Constants');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
* Represents the logged in client's Discord user.
|
||||
@@ -165,6 +166,7 @@ class ClientUser extends User {
|
||||
* @property {Object} [game] Game the user is playing
|
||||
* @property {string} [game.name] Name of the game
|
||||
* @property {string} [game.url] Twitch stream URL
|
||||
* @property {?ActivityType|number} [game.type] Type of the activity
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -199,7 +201,10 @@ class ClientUser extends User {
|
||||
|
||||
if (data.game) {
|
||||
game = data.game;
|
||||
game.type = game.url ? 1 : 0;
|
||||
game.type = game.url && typeof game.type === 'undefined' ? 1 : game.type || 0;
|
||||
if (typeof game.type === 'string') {
|
||||
game.type = Constants.ActivityTypes.indexOf(game.type.toUpperCase());
|
||||
}
|
||||
} else if (typeof data.game !== 'undefined') {
|
||||
game = null;
|
||||
}
|
||||
@@ -243,8 +248,9 @@ 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 {?string} [streamingURL] Twitch stream URL
|
||||
* @returns {Promise<ClientUser>}
|
||||
* @deprecated
|
||||
*/
|
||||
setGame(game, streamingURL) {
|
||||
if (!game) return this.setPresence({ game: null });
|
||||
@@ -256,6 +262,21 @@ class ClientUser extends User {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the activity the client user is playing.
|
||||
* @param {?string} name Activity being played
|
||||
* @param {Object} [options] Options for setting the activity
|
||||
* @param {string} [options.url] Twitch stream URL
|
||||
* @param {ActivityType|number} [options.type] Type of the activity
|
||||
* @returns {Promise<Presence>}
|
||||
*/
|
||||
setActivity(name, { url, type } = {}) {
|
||||
if (!name) return this.setPresence({ activity: null });
|
||||
return this.setPresence({
|
||||
game: { name, type, url },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/removes the AFK flag for the client user.
|
||||
* @param {boolean} afk Whether or not the user is AFK
|
||||
@@ -352,4 +373,7 @@ class ClientUser extends User {
|
||||
}
|
||||
}
|
||||
|
||||
ClientUser.prototype.setGame =
|
||||
util.deprecate(ClientUser.prototype.setGame, 'ClientUser#setGame: use ClientUser#setActivity instead');
|
||||
|
||||
module.exports = ClientUser;
|
||||
|
||||
@@ -1214,6 +1214,7 @@ class Guild {
|
||||
* @name Guild#defaultChannel
|
||||
* @type {TextChannel}
|
||||
* @readonly
|
||||
* @deprecated
|
||||
*/
|
||||
Object.defineProperty(Guild.prototype, 'defaultChannel', {
|
||||
get: util.deprecate(function defaultChannel() {
|
||||
|
||||
Reference in New Issue
Block a user