Fix: Don't rely on Guild for id (#2911)

This commit is contained in:
Quin Lynch
2024-04-15 15:22:06 -03:00
committed by GitHub
parent 69fb1eb0a6
commit 397a887719
9 changed files with 30 additions and 28 deletions

View File

@@ -13,13 +13,13 @@ namespace Discord.Rest
public class RestCategoryChannel : RestGuildChannel, ICategoryChannel public class RestCategoryChannel : RestGuildChannel, ICategoryChannel
{ {
#region RestCategoryChannel #region RestCategoryChannel
internal RestCategoryChannel(BaseDiscordClient discord, IGuild guild, ulong id) internal RestCategoryChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId)
: base(discord, guild, id) : base(discord, guild, id, guildId)
{ {
} }
internal new static RestCategoryChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestCategoryChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestCategoryChannel(discord, guild, model.Id); var entity = new RestCategoryChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -47,15 +47,15 @@ namespace Discord.Rest
/// <inheritdoc/> /// <inheritdoc/>
public string Mention => MentionUtils.MentionChannel(Id); public string Mention => MentionUtils.MentionChannel(Id);
internal RestForumChannel(BaseDiscordClient client, IGuild guild, ulong id) internal RestForumChannel(BaseDiscordClient client, IGuild guild, ulong id, ulong guildId)
: base(client, guild, id) : base(client, guild, id, guildId)
{ {
} }
internal new static RestForumChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestForumChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestForumChannel(discord, guild, model.Id); var entity = new RestForumChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -23,16 +23,18 @@ namespace Discord.Rest
public string Name { get; private set; } public string Name { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public int Position { get; private set; } public int Position { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public ulong GuildId => Guild.Id; public ulong GuildId { get; }
/// <inheritdoc /> /// <inheritdoc />
public ChannelFlags Flags { get; private set; } public ChannelFlags Flags { get; private set; }
internal RestGuildChannel(BaseDiscordClient discord, IGuild guild, ulong id) internal RestGuildChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId)
: base(discord, id) : base(discord, id)
{ {
Guild = guild; Guild = guild;
GuildId = guildId;
} }
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
@@ -46,7 +48,7 @@ namespace Discord.Rest
ChannelType.Forum => RestForumChannel.Create(discord, guild, model), ChannelType.Forum => RestForumChannel.Create(discord, guild, model),
ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), ChannelType.Category => RestCategoryChannel.Create(discord, guild, model),
ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model), ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model),
_ => new RestGuildChannel(discord, guild, model.Id), _ => new RestGuildChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value),
}; };
} }
internal override void Update(Model model) internal override void Update(Model model)

View File

@@ -4,15 +4,15 @@ namespace Discord.Rest;
public class RestMediaChannel : RestForumChannel, IMediaChannel public class RestMediaChannel : RestForumChannel, IMediaChannel
{ {
internal RestMediaChannel(BaseDiscordClient client, IGuild guild, ulong id) internal RestMediaChannel(BaseDiscordClient client, IGuild guild, ulong id, ulong guildId)
: base(client, guild, id) : base(client, guild, id, guildId)
{ {
} }
internal new static RestMediaChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestMediaChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestMediaChannel(discord, guild, model.Id); var entity = new RestMediaChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -15,13 +15,13 @@ namespace Discord.Rest
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestNewsChannel : RestTextChannel, INewsChannel public class RestNewsChannel : RestTextChannel, INewsChannel
{ {
internal RestNewsChannel(BaseDiscordClient discord, IGuild guild, ulong id) internal RestNewsChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId)
: base(discord, guild, id) : base(discord, guild, id, guildId)
{ {
} }
internal new static RestNewsChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestNewsChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestNewsChannel(discord, guild, model.Id); var entity = new RestNewsChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -15,7 +15,7 @@ namespace Discord.Rest
/// <remarks> /// <remarks>
/// This field is always true for stage channels. /// This field is always true for stage channels.
/// </remarks> /// </remarks>
/// ///
[Obsolete("This property is no longer used because Discord enabled text-in-voice and text-in-stage for all channels.")] [Obsolete("This property is no longer used because Discord enabled text-in-voice and text-in-stage for all channels.")]
public override bool IsTextInVoice public override bool IsTextInVoice
=> true; => true;
@@ -28,12 +28,12 @@ namespace Discord.Rest
/// <inheritdoc/> /// <inheritdoc/>
public bool IsLive { get; private set; } public bool IsLive { get; private set; }
internal RestStageChannel(BaseDiscordClient discord, IGuild guild, ulong id) internal RestStageChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId)
: base(discord, guild, id) { } : base(discord, guild, id, guildId) { }
internal new static RestStageChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestStageChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestStageChannel(discord, guild, model.Id); var entity = new RestStageChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -30,13 +30,13 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public int DefaultSlowModeInterval { get; private set; } public int DefaultSlowModeInterval { get; private set; }
internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId)
: base(discord, guild, id) : base(discord, guild, id, guildId)
{ {
} }
internal new static RestTextChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestTextChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestTextChannel(discord, guild, model.Id); var entity = new RestTextChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -51,15 +51,15 @@ namespace Discord.Rest
/// </summary> /// </summary>
public ulong ParentChannelId { get; private set; } public ulong ParentChannelId { get; private set; }
internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id, DateTimeOffset? createdAt) internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId, DateTimeOffset? createdAt)
: base(discord, guild, id) : base(discord, guild, id, guildId)
{ {
CreatedAt = createdAt ?? new DateTimeOffset(2022, 1, 9, 0, 0, 0, TimeSpan.Zero); CreatedAt = createdAt ?? new DateTimeOffset(2022, 1, 9, 0, 0, 0, TimeSpan.Zero);
} }
internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestThreadChannel(discord, guild, model.Id, model.ThreadMetadata.GetValueOrDefault()?.CreatedAt.GetValueOrDefault()); var entity = new RestThreadChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value, model.ThreadMetadata.GetValueOrDefault()?.CreatedAt.GetValueOrDefault());
entity.Update(model); entity.Update(model);
return entity; return entity;
} }

View File

@@ -31,13 +31,13 @@ namespace Discord.Rest
/// <inheritdoc/> /// <inheritdoc/>
public VideoQualityMode VideoQualityMode { get; private set; } public VideoQualityMode VideoQualityMode { get; private set; }
internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id) internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id, ulong guildId)
: base(discord, guild, id) : base(discord, guild, id, guildId)
{ {
} }
internal new static RestVoiceChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestVoiceChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestVoiceChannel(discord, guild, model.Id); var entity = new RestVoiceChannel(discord, guild, model.Id, guild?.Id ?? model.GuildId.Value);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }