feat: allow channels from uncached guilds to be returned from fetch (#6034)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
ckohen
2021-07-06 05:04:26 -07:00
committed by GitHub
parent 2e078e4488
commit 755c180659
9 changed files with 79 additions and 34 deletions

View File

@@ -127,7 +127,7 @@ class Channel extends Base {
return ThreadChannelTypes.includes(this.type);
}
static create(client, data, guild) {
static create(client, data, guild, allowUnknownGuild) {
if (!CategoryChannel) CategoryChannel = require('./CategoryChannel');
if (!DMChannel) DMChannel = require('./DMChannel');
if (!NewsChannel) NewsChannel = require('./NewsChannel');
@@ -148,41 +148,41 @@ class Channel extends Base {
} else {
if (!guild) guild = client.guilds.cache.get(data.guild_id);
if (guild) {
if (guild || allowUnknownGuild) {
switch (data.type) {
case ChannelTypes.TEXT: {
channel = new TextChannel(guild, data);
channel = new TextChannel(guild, data, client);
break;
}
case ChannelTypes.VOICE: {
channel = new VoiceChannel(guild, data);
channel = new VoiceChannel(guild, data, client);
break;
}
case ChannelTypes.CATEGORY: {
channel = new CategoryChannel(guild, data);
channel = new CategoryChannel(guild, data, client);
break;
}
case ChannelTypes.NEWS: {
channel = new NewsChannel(guild, data);
channel = new NewsChannel(guild, data, client);
break;
}
case ChannelTypes.STORE: {
channel = new StoreChannel(guild, data);
channel = new StoreChannel(guild, data, client);
break;
}
case ChannelTypes.STAGE: {
channel = new StageChannel(guild, data);
channel = new StageChannel(guild, data, client);
break;
}
case ChannelTypes.NEWS_THREAD:
case ChannelTypes.PUBLIC_THREAD:
case ChannelTypes.PRIVATE_THREAD: {
channel = new ThreadChannel(guild, data);
channel.parent?.threads.cache.set(channel.id, channel);
channel = new ThreadChannel(guild, data, client);
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
}
}
if (channel) guild.channels?.cache.set(channel.id, channel);
if (channel && !allowUnknownGuild) guild.channels?.cache.set(channel.id, channel);
}
}
return channel;

View File

@@ -24,9 +24,10 @@ class GuildChannel extends Channel {
/**
* @param {Guild} guild The guild the guild channel is part of
* @param {APIChannel} data The data for the guild channel
* @param {Client} [client] A safety parameter for the client that instantiated this
*/
constructor(guild, data) {
super(guild.client, data, false);
constructor(guild, data, client) {
super(guild?.client ?? client, data, false);
/**
* The guild the channel is in
@@ -34,6 +35,12 @@ class GuildChannel extends Channel {
*/
this.guild = guild;
/**
* The id of the guild the channel is in
* @type {Snowflake}
*/
this.guildId = guild?.id ?? data.guild_id;
this.parentId = this.parentId ?? null;
/**
* A manager of permission overwrites that belong to this channel
@@ -63,6 +70,10 @@ class GuildChannel extends Channel {
this.rawPosition = data.position;
}
if ('guild_id' in data) {
this.guildId = data.guild_id;
}
if ('parent_id' in data) {
/**
* The id of the category parent of this channel

View File

@@ -8,11 +8,12 @@ const GuildChannel = require('./GuildChannel');
*/
class StoreChannel extends GuildChannel {
/**
* @param {*} guild The guild the store channel is part of
* @param {*} data The data for the store channel
* @param {Guild} guild The guild the store channel is part of
* @param {APIChannel} data The data for the store channel
* @param {Client} [client] A safety parameter for the client that instantiated this
*/
constructor(guild, data) {
super(guild, data);
constructor(guild, data, client) {
super(guild, data, client);
/**
* If the guild considers this channel NSFW

View File

@@ -17,9 +17,10 @@ class TextChannel extends GuildChannel {
/**
* @param {Guild} guild The guild the text channel is part of
* @param {APIChannel} data The data for the text channel
* @param {Client} [client] A safety parameter for the client that instantiated this
*/
constructor(guild, data) {
super(guild, data);
constructor(guild, data, client) {
super(guild, data, client);
/**
* A manager of the messages sent to this channel
* @type {MessageManager}

View File

@@ -15,9 +15,10 @@ class ThreadChannel extends Channel {
/**
* @param {Guild} guild The guild the thread channel is part of
* @param {APIChannel} data The data for the thread channel
* @param {Client} [client] A safety parameter for the client that instantiated this
*/
constructor(guild, data) {
super(guild.client, data, false);
constructor(guild, data, client) {
super(guild?.client ?? client, data, false);
/**
* The guild the thread is in
@@ -25,6 +26,12 @@ class ThreadChannel extends Channel {
*/
this.guild = guild;
/**
* The id of the guild the channel is in
* @type {Snowflake}
*/
this.guildId = guild?.id ?? data.guild_id;
/**
* A manager of the messages sent to this thread
* @type {MessageManager}
@@ -50,6 +57,10 @@ class ThreadChannel extends Channel {
*/
this.name = data.name;
if ('guild_id' in data) {
this.guildId = data.guild_id;
}
if ('parent_id' in data) {
/**
* The id of the parent channel of this thread