Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change category.channels to getter #566

Merged
merged 3 commits into from Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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