Skip to content

Commit

Permalink
Add activities and clientStatus support (#449)
Browse files Browse the repository at this point in the history
* Add client_status from PRESENCE_UPDATE to Member class
- Status for all three clients is always present, defaults to "offline"

* Add "dnd" to as supported status in documentation

* Add member activities to Member class
- Raw data, for now

* Add clientStatus and activities to old presence in presenceUpdate event

* Remove redundant object, add undefined check
  • Loading branch information
Brayzure authored and abalabahaha committed Feb 9, 2019
1 parent 22d1648 commit 97da098
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ class Shard extends EventEmitter {
if(member) {
oldPresence = {
game: member.game,
status: member.status
status: member.status,
clientStatus: member.clientStatus,
activities: member.activities
};
}
if((!member && packet.d.user.username) || oldPresence) {
Expand Down
9 changes: 8 additions & 1 deletion lib/structures/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ const VoiceState = require("./VoiceState");
* @prop {String} mention A string that mentions the member
* @prop {Guild} guild The guild the member is in
* @prop {Number} joinedAt Timestamp of when the member joined the guild
* @prop {String} status The member's status. Either "online", "idle", or "offline"
* @prop {String} status The member's status. Either "online", "idle", "dnd", or "offline"
* @prop {Object?} game The active game the member is playing
* @prop {String} game.name The name of the active game
* @prop {Object} clientStatus The member's per-client status
* @prop {String} clientStatus.web The member's status on web. Either "online", "idle", "dnd", or "offline". Will be "online" for bots
* @prop {String} clientStatus.desktop The member's status on desktop. Either "online", "idle", "dnd", or "offline". Will be "offline" for bots
* @prop {String} clientStatus.mobile The member's status on mobile. Either "online", "idle", "dnd", or "offline". Will be "offline" for bots
* @prop {Object[]} activities The member's current activities
* @prop {Number} game.type The type of the active game (0 is default, 1 is Twitch, 2 is YouTube)
* @prop {String?} game.url The url of the active game
* @prop {VoiceState} voiceState The voice state of the member
Expand Down Expand Up @@ -56,6 +61,8 @@ class Member extends Base {
this.status = data.status !== undefined ? data.status : this.status || "offline";
this.game = data.game !== undefined ? data.game : this.game || null;
this.joinedAt = data.joined_at !== undefined ? Date.parse(data.joined_at) : this.joinedAt;
this.clientStatus = data.client_status !== undefined ? Object.assign({ web: "offline", desktop: "offline", mobile: "offline" }, data.client_status) : this.clientStatus;
this.activities = data.activities;

if(data.mute !== undefined) {
this.voiceState.update(data);
Expand Down

0 comments on commit 97da098

Please sign in to comment.