Skip to content

Commit

Permalink
Convert CategoryChannel.channels to getter (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanwashere authored and abalabahaha committed Nov 23, 2019
1 parent 3f87066 commit 0e9791c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
12 changes: 3 additions & 9 deletions lib/gateway/Shard.js
Expand Up @@ -886,12 +886,10 @@ class Shard extends EventEmitter {
}
this.client.channelGuildMap[packet.d.id] = packet.d.guild_id;
if(packet.d.parent_id) {
const parentChannel = guild.channels.get(packet.d.parent_id);
if(!parentChannel) {
if(!guild.channels.has(packet.d.parent_id)) {
this.emit("debug", `Missing category channel ${packet.d.parent_id} in CHANNEL_CREATE`);
break;
}
parentChannel.channels.add(channel);
}
this.emit("channelCreate", channel);
} else if(packet.d.type === 3) {
Expand Down Expand Up @@ -959,18 +957,14 @@ class Shard extends EventEmitter {

if(packet.d.parent_id) {
if(packet.d.parent_id !== channel.parentID) {
const oldParentChannel = guild.channels.get(channel.parentID);
if(!oldParentChannel) {
if(!guild.channels.has(channel.parentID)) {
break;
}
oldParentChannel.channels.remove(channel);
}
const parentChannel = guild.channels.get(packet.d.parent_id);
if(!parentChannel) {
if(!guild.channels.has(packet.d.parent_id)) {
this.emit("debug", `Missing category channel ${packet.d.parent_id} in UPDATE`);
break;
}
parentChannel.channels.add(channel);
}
/**
* Fired when a channel is updated
Expand Down
14 changes: 6 additions & 8 deletions lib/structures/CategoryChannel.js
Expand Up @@ -18,18 +18,16 @@ const GuildChannel = require("./GuildChannel");
* @prop {Collection<GuildChannel>} channels A collection of guild channels that are part of this category
*/
class CategoryChannel extends GuildChannel {
constructor(data, guild) {
super(data, guild);
this.channels = new Collection(GuildChannel);
if(guild) {
for(const channel of guild.channels.values()) {
get channels() {
const channels = new Collection(GuildChannel);
if(this.guild && this.guild.channels) {
for(const channel of this.guild.channels.values()) {
if(channel.parentID === this.id) {
this.channels.add(channel);
channels.add(channel);
}
}
}

this.update(data);
return channels;
}

toJSON() {
Expand Down
3 changes: 0 additions & 3 deletions lib/structures/Guild.js
Expand Up @@ -81,9 +81,6 @@ class Guild extends Base {
} else {
channel = this.channels.add(channel, this);
}
if(channel.parentID && this.channels.get(channel.parentID)) {
this.channels.get(channel.parentID).channels.add(channel);
}
client.channelGuildMap[channel.id] = this.id;
}
}
Expand Down

0 comments on commit 0e9791c

Please sign in to comment.