From 0e9791ce2c488d1023dc5ff6c4455a559b4260ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=80=8C=E3=83=8D=E3=82=B3=E3=80=8D?= Date: Sat, 23 Nov 2019 06:06:43 +0200 Subject: [PATCH] Convert CategoryChannel.channels to getter (#566) --- lib/gateway/Shard.js | 12 +++--------- lib/structures/CategoryChannel.js | 14 ++++++-------- lib/structures/Guild.js | 3 --- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index db3d101e0..d3ff34056 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -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) { @@ -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 diff --git a/lib/structures/CategoryChannel.js b/lib/structures/CategoryChannel.js index 258bc2808..3011eb536 100644 --- a/lib/structures/CategoryChannel.js +++ b/lib/structures/CategoryChannel.js @@ -18,18 +18,16 @@ const GuildChannel = require("./GuildChannel"); * @prop {Collection} 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() { diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index fffc98c7a..0d065ded2 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -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; } }