diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs index 00b99a1cb..83c6d8bfb 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs @@ -37,6 +37,23 @@ namespace Discord.Rest _ => new RestChannel(discord, model.Id), }; } + internal static RestChannel Create(BaseDiscordClient discord, Model model, IGuild guild) + { + return model.Type switch + { + ChannelType.News or + ChannelType.Text or + ChannelType.Voice or + ChannelType.Stage or + ChannelType.NewsThread or + ChannelType.PrivateThread or + ChannelType.PublicThread + => RestGuildChannel.Create(discord, guild, model), + ChannelType.DM or ChannelType.Group => CreatePrivate(discord, model) as RestChannel, + ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), + _ => new RestChannel(discord, model.Id), + }; + } /// Unexpected channel type. internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Model model) { diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 70267bf73..bc9d4110a 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -47,13 +47,20 @@ namespace Discord.Rest internal override void Update(Model model) { Name = model.Name.Value; - Position = model.Position.Value; - var overwrites = model.PermissionOverwrites.Value; - var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); - for (int i = 0; i < overwrites.Length; i++) - newOverwrites.Add(overwrites[i].ToEntity()); - _overwrites = newOverwrites.ToImmutable(); + if (model.Position.IsSpecified) + { + Position = model.Position.Value; + } + + if (model.PermissionOverwrites.IsSpecified) + { + var overwrites = model.PermissionOverwrites.Value; + var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); + for (int i = 0; i < overwrites.Length; i++) + newOverwrites.Add(overwrites[i].ToEntity()); + _overwrites = newOverwrites.ToImmutable(); + } } /// diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs index b8ee8fc93..d687b6c3c 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs @@ -38,8 +38,12 @@ namespace Discord.Rest { base.Update(model); CategoryId = model.CategoryId; - Bitrate = model.Bitrate.Value; - UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; + + if(model.Bitrate.IsSpecified) + Bitrate = model.Bitrate.Value; + + if(model.UserLimit.IsSpecified) + UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; } /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs index 845cd861b..a9efb6de1 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs @@ -52,15 +52,6 @@ namespace Discord.Rest internal override async Task UpdateAsync(DiscordRestClient client, Model model) { await base.UpdateAsync(client, model).ConfigureAwait(false); - - var data = model.Data.IsSpecified - ? (DataModel)model.Data.Value - : null; - - if(Data == null) - { - Data = await RestCommandBaseData.CreateAsync(client, data, Guild, Channel).ConfigureAwait(false); - } } /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs index 2310cb4b0..4227c802a 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs @@ -27,14 +27,14 @@ namespace Discord.Rest { } - internal static async Task CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) + internal static async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) { var entity = new RestCommandBaseData(client, model); await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); return entity; } - internal virtual async Task UpdateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) + internal virtual async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) { Name = model.Name; if (model.Resolved.IsSpecified && ResolvableData == null) diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs index 9f206c7f1..710207ef9 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs @@ -19,7 +19,7 @@ namespace Discord.Rest internal readonly Dictionary Messages = new Dictionary(); - internal async Task PopulateAsync(DiscordRestClient discord, IGuild guild, IRestMessageChannel channel, T model) + internal async Task PopulateAsync(DiscordRestClient discord, RestGuild guild, IRestMessageChannel channel, T model) { var resolved = model.Resolved.Value; @@ -35,11 +35,13 @@ namespace Discord.Rest if (resolved.Channels.IsSpecified) { - //var channels = await guild.GetChannelsAsync().ConfigureAwait(false); + var channels = await guild.GetChannelsAsync().ConfigureAwait(false); foreach (var channelModel in resolved.Channels.Value) { - var restChannel = RestChannel.Create(discord, channelModel.Value); + var restChannel = channels.FirstOrDefault(x => x.Id == channelModel.Value.Id); + + restChannel.Update(channelModel.Value); Channels.Add(ulong.Parse(channelModel.Key), restChannel); } @@ -49,6 +51,8 @@ namespace Discord.Rest { foreach (var member in resolved.Members.Value) { + // pull the adjacent user model + member.Value.User = resolved.Users.Value.FirstOrDefault(x => x.Key == member.Key).Value; var restMember = RestGuildUser.Create(discord, guild, member.Value); GuildMembers.Add(ulong.Parse(member.Key), restMember); diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs index ee528bc65..8eadab617 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs @@ -28,7 +28,7 @@ namespace Discord.Rest internal RestMessageCommandData(DiscordRestClient client, Model model) : base(client, model) { } - internal new static async Task CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) + internal new static async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) { var entity = new RestMessageCommandData(client, model); await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs index 5ceec6bca..7563eecc7 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs @@ -26,7 +26,7 @@ namespace Discord.Rest internal RestUserCommandData(DiscordRestClient client, Model model) : base(client, model) { } - internal new static async Task CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) + internal new static async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) { var entity = new RestUserCommandData(client, model); await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs index 667aabd8f..f967cc628 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs @@ -14,13 +14,13 @@ namespace Discord.Rest internal RestSlashCommandData(DiscordRestClient client, Model model) : base(client, model) { } - internal static new async Task CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) + internal static new async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) { var entity = new RestSlashCommandData(client, model); await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); return entity; } - internal override async Task UpdateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) + internal override async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) { await base.UpdateAsync(client, model, guild, channel).ConfigureAwait(false);