Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(ClientUser): deprecate ClientUser#setGame in favour of ClientUser#setActivity #2127

Merged
merged 3 commits into from Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/structures/ClientUser.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 });
Expand All @@ -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
Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions src/structures/Guild.js
Expand Up @@ -1214,6 +1214,7 @@ class Guild {
* @name Guild#defaultChannel
* @type {TextChannel}
* @readonly
* @deprecated
*/
Object.defineProperty(Guild.prototype, 'defaultChannel', {
get: util.deprecate(function defaultChannel() {
Expand Down
15 changes: 15 additions & 0 deletions src/util/Constants.js
Expand Up @@ -350,6 +350,21 @@ exports.Events = {
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:
* * READY
Expand Down