Make presences track users and guilds, emit them in presenceUpdate

This commit is contained in:
Amish Shah
2018-08-10 16:46:14 +01:00
parent fe8ece0192
commit 08eff66939
7 changed files with 32 additions and 13 deletions

View File

@@ -226,7 +226,7 @@ class Guild extends Base {
if (data.presences) {
for (const presence of data.presences) {
this.presences.add(presence);
this.presences.add(Object.assign(presence, { guild: this }));
}
}

View File

@@ -114,7 +114,7 @@ class GuildMember extends Base {
* @readonly
*/
get presence() {
return this.frozenPresence || this.guild.presences.get(this.id) || new Presence(this.client);
return this.guild.presences.get(this.id) || new Presence(this.client);
}
/**

View File

@@ -14,9 +14,27 @@ const { ActivityTypes, ActivityFlags } = require('../util/Constants');
class Presence {
constructor(client, data = {}) {
Object.defineProperty(this, 'client', { value: client });
this.userID = data.user.id;
this.guild = data.guild;
this.patch(data);
}
/**
* The user of this presence
* @type {User}
*/
get user() {
return this.client.users.get(this.userID);
}
/**
* The member of this presence
* @type {GuildMember}
*/
get member() {
return this.guild.members.get(this.userID);
}
patch(data) {
/**
* The status of the presence: