mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +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 ClientUserSettings = require('./ClientUserSettings');
|
||||||
const ClientUserGuildSettings = require('./ClientUserGuildSettings');
|
const ClientUserGuildSettings = require('./ClientUserGuildSettings');
|
||||||
const Constants = require('../util/Constants');
|
const Constants = require('../util/Constants');
|
||||||
|
const util = require('util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the logged in client's Discord user.
|
* 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 {Object} [game] Game the user is playing
|
||||||
* @property {string} [game.name] Name of the game
|
* @property {string} [game.name] Name of the game
|
||||||
* @property {string} [game.url] Twitch stream URL
|
* @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) {
|
if (data.game) {
|
||||||
game = 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') {
|
} else if (typeof data.game !== 'undefined') {
|
||||||
game = null;
|
game = null;
|
||||||
}
|
}
|
||||||
@@ -243,8 +248,9 @@ 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 {?string} [streamingURL] Twitch stream URL
|
||||||
* @returns {Promise<ClientUser>}
|
* @returns {Promise<ClientUser>}
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
setGame(game, streamingURL) {
|
setGame(game, streamingURL) {
|
||||||
if (!game) return this.setPresence({ game: null });
|
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.
|
* Sets/removes the AFK flag for the client user.
|
||||||
* @param {boolean} afk Whether or not the user is AFK
|
* @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;
|
module.exports = ClientUser;
|
||||||
|
|||||||
@@ -1214,6 +1214,7 @@ class Guild {
|
|||||||
* @name Guild#defaultChannel
|
* @name Guild#defaultChannel
|
||||||
* @type {TextChannel}
|
* @type {TextChannel}
|
||||||
* @readonly
|
* @readonly
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Guild.prototype, 'defaultChannel', {
|
Object.defineProperty(Guild.prototype, 'defaultChannel', {
|
||||||
get: util.deprecate(function defaultChannel() {
|
get: util.deprecate(function defaultChannel() {
|
||||||
|
|||||||
@@ -350,6 +350,21 @@ exports.Events = {
|
|||||||
DEBUG: 'debug',
|
DEBUG: 'debug',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of an activity of a users presence, e.g. `PLAYING`. Here are the available types:
|
||||||
|
* * PLAYING
|
||||||
|
* * STREAMING
|
||||||
|
* * LISTENING
|
||||||
|
* * WATCHING
|
||||||
|
* @typedef {string} ActivityType
|
||||||
|
*/
|
||||||
|
exports.ActivityTypes = [
|
||||||
|
'PLAYING',
|
||||||
|
'STREAMING',
|
||||||
|
'LISTENING',
|
||||||
|
'WATCHING',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of a websocket message event, e.g. `MESSAGE_CREATE`. Here are the available events:
|
* The type of a websocket message event, e.g. `MESSAGE_CREATE`. Here are the available events:
|
||||||
* * READY
|
* * READY
|
||||||
|
|||||||
Reference in New Issue
Block a user