| @@ -37,6 +37,23 @@ namespace Discord.Rest | |||||
| _ => new RestChannel(discord, model.Id), | _ => 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), | |||||
| }; | |||||
| } | |||||
| /// <exception cref="InvalidOperationException">Unexpected channel type.</exception> | /// <exception cref="InvalidOperationException">Unexpected channel type.</exception> | ||||
| internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Model model) | internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Model model) | ||||
| { | { | ||||
| @@ -47,13 +47,20 @@ namespace Discord.Rest | |||||
| internal override void Update(Model model) | internal override void Update(Model model) | ||||
| { | { | ||||
| Name = model.Name.Value; | Name = model.Name.Value; | ||||
| Position = model.Position.Value; | |||||
| var overwrites = model.PermissionOverwrites.Value; | |||||
| var newOverwrites = ImmutableArray.CreateBuilder<Overwrite>(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<Overwrite>(overwrites.Length); | |||||
| for (int i = 0; i < overwrites.Length; i++) | |||||
| newOverwrites.Add(overwrites[i].ToEntity()); | |||||
| _overwrites = newOverwrites.ToImmutable(); | |||||
| } | |||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -38,8 +38,12 @@ namespace Discord.Rest | |||||
| { | { | ||||
| base.Update(model); | base.Update(model); | ||||
| CategoryId = model.CategoryId; | 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; | |||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -52,15 +52,6 @@ namespace Discord.Rest | |||||
| internal override async Task UpdateAsync(DiscordRestClient client, Model model) | internal override async Task UpdateAsync(DiscordRestClient client, Model model) | ||||
| { | { | ||||
| await base.UpdateAsync(client, model).ConfigureAwait(false); | 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); | |||||
| } | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -27,14 +27,14 @@ namespace Discord.Rest | |||||
| { | { | ||||
| } | } | ||||
| internal static async Task<RestCommandBaseData> CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) | |||||
| internal static async Task<RestCommandBaseData> CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) | |||||
| { | { | ||||
| var entity = new RestCommandBaseData(client, model); | var entity = new RestCommandBaseData(client, model); | ||||
| await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | ||||
| return entity; | 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; | Name = model.Name; | ||||
| if (model.Resolved.IsSpecified && ResolvableData == null) | if (model.Resolved.IsSpecified && ResolvableData == null) | ||||
| @@ -19,7 +19,7 @@ namespace Discord.Rest | |||||
| internal readonly Dictionary<ulong, RestMessage> Messages | internal readonly Dictionary<ulong, RestMessage> Messages | ||||
| = new Dictionary<ulong, RestMessage>(); | = new Dictionary<ulong, RestMessage>(); | ||||
| 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; | var resolved = model.Resolved.Value; | ||||
| @@ -35,11 +35,13 @@ namespace Discord.Rest | |||||
| if (resolved.Channels.IsSpecified) | 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) | 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); | Channels.Add(ulong.Parse(channelModel.Key), restChannel); | ||||
| } | } | ||||
| @@ -49,6 +51,8 @@ namespace Discord.Rest | |||||
| { | { | ||||
| foreach (var member in resolved.Members.Value) | 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); | var restMember = RestGuildUser.Create(discord, guild, member.Value); | ||||
| GuildMembers.Add(ulong.Parse(member.Key), restMember); | GuildMembers.Add(ulong.Parse(member.Key), restMember); | ||||
| @@ -28,7 +28,7 @@ namespace Discord.Rest | |||||
| internal RestMessageCommandData(DiscordRestClient client, Model model) | internal RestMessageCommandData(DiscordRestClient client, Model model) | ||||
| : base(client, model) { } | : base(client, model) { } | ||||
| internal new static async Task<RestMessageCommandData> CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) | |||||
| internal new static async Task<RestMessageCommandData> CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) | |||||
| { | { | ||||
| var entity = new RestMessageCommandData(client, model); | var entity = new RestMessageCommandData(client, model); | ||||
| await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | ||||
| @@ -26,7 +26,7 @@ namespace Discord.Rest | |||||
| internal RestUserCommandData(DiscordRestClient client, Model model) | internal RestUserCommandData(DiscordRestClient client, Model model) | ||||
| : base(client, model) { } | : base(client, model) { } | ||||
| internal new static async Task<RestUserCommandData> CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) | |||||
| internal new static async Task<RestUserCommandData> CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) | |||||
| { | { | ||||
| var entity = new RestUserCommandData(client, model); | var entity = new RestUserCommandData(client, model); | ||||
| await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | ||||
| @@ -14,13 +14,13 @@ namespace Discord.Rest | |||||
| internal RestSlashCommandData(DiscordRestClient client, Model model) | internal RestSlashCommandData(DiscordRestClient client, Model model) | ||||
| : base(client, model) { } | : base(client, model) { } | ||||
| internal static new async Task<RestSlashCommandData> CreateAsync(DiscordRestClient client, Model model, IGuild guild, IRestMessageChannel channel) | |||||
| internal static new async Task<RestSlashCommandData> CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) | |||||
| { | { | ||||
| var entity = new RestSlashCommandData(client, model); | var entity = new RestSlashCommandData(client, model); | ||||
| await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | ||||
| return entity; | 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); | await base.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); | ||||