Skip to content

Commit

Permalink
feature(ClientUser): deprecate ClientUser#setGame in favour of Client…
Browse files Browse the repository at this point in the history
…User#setActivity (#2127)

* feature(ClientUser): backported ClientUser#setPresence

* fix ternary

* deprecation stuff
  • Loading branch information
Lewdcario authored and Gawdl3y committed Nov 30, 2017
1 parent e40c3f8 commit cd06684
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
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',
};

This comment has been minimized.

Copy link
@d4rckh

d4rckh Jan 15, 2018

???


/**
* 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

3 comments on commit cd06684

@ibrahimcaj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bot.user.setPresence({
status: "online",
activity: {
name: "dabs. | " + bot.guilds.size + " servers.",
type: 'WATCHING',
url: "https://www.twitch.tv/"
}
})
It doesen't want to work.

@iCrawl
Copy link
Member

@iCrawl iCrawl commented on cd06684 Jan 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a question, please ask it in the Discord server instead of commenting on commit.

@ibrahimcaj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.

Please sign in to comment.