Skip to content

Commit

Permalink
Move voice states to Guild collection (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanwashere authored and abalabahaha committed Nov 6, 2019
1 parent 9d6f4fe commit b930a97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Role = require("./Role");
const TextChannel = require("./TextChannel");
const NewsChannel = require("./NewsChannel");
const VoiceChannel = require("./VoiceChannel");
const VoiceState = require("./VoiceState");

/**
* Represents a guild
Expand All @@ -32,6 +33,7 @@ const VoiceChannel = require("./VoiceChannel");
* @prop {Boolean} unavailable Whether the guild is unavailable or not
* @prop {Boolean} large Whether the guild is "large" by "some Discord standard"
* @prop {Number} maxPresences The maximum number of people that can be online in a guild at once (returned from REST API only)
* @prop {Collection<VoiceState>} voiceStates Collection of voice states in the guild
* @prop {Collection<GuildChannel>} channels Collection of Channels in the guild
* @prop {Collection<Member>} members Collection of Members in the guild
* @prop {Number} memberCount Number of members in the guild
Expand All @@ -54,6 +56,7 @@ class Guild extends Base {
this.shard = client.shards.get(client.guildShardMap[this.id]);
this.unavailable = !!data.unavailable;
this.joinedAt = Date.parse(data.joined_at);
this.voiceStates = new Collection(VoiceState);
this.channels = new Collection(GuildChannel);
this.members = new Collection(Member);
this.memberCount = data.member_count;
Expand Down
18 changes: 15 additions & 3 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Member extends Base {
} else {
this.user = null;
}
this.voiceState = new VoiceState(data);
this.update(data);
}

Expand All @@ -66,8 +65,15 @@ class Member extends Base {
this.activities = data.activities;
this.premiumSince = data.premium_since !== undefined ? data.premium_since : this.premiumSince;

if(data.mute !== undefined) {
this.voiceState.update(data);
if("mute" in data) {
const state = this.guild.voiceStates.get(this.id);
if(data.channel_id === null && !data.mute && !data.deaf && !data.suppress && !data.self_deaf && !data.self_mute) {
this.guild.voiceStates.delete(this.id);
} else if(state) {
state.update(data);
} else if(data.channel_id || data.mute || data.deaf || data.suppress || data.self_mute || data.self_deaf) {
this.guild.voiceStates.update(data);
}
}

this.nick = data.nick !== undefined ? data.nick : this.nick || null;
Expand All @@ -76,6 +82,12 @@ class Member extends Base {
}
}

get voiceState() {
return this.guild.voiceStates.get(this.id) || new VoiceState({
id: this.id
});
}

get permission() {
if(this.id === this.guild.ownerID) {
return new Permission(Permissions.all);
Expand Down

0 comments on commit b930a97

Please sign in to comment.