From d5ba7d25aa818882f0e0360f8ec9efb15028d116 Mon Sep 17 00:00:00 2001 From: Misha133 <61027276+Misha-133@users.noreply.github.com> Date: Sat, 15 Apr 2023 04:36:07 +0300 Subject: [PATCH] initial commit (#2666) --- .../API/Common/Interaction.cs | 3 +++ .../Entities/Interactions/RestInteraction.cs | 23 +++++++++++++++---- .../Entities/Interaction/SocketInteraction.cs | 4 ++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Rest/API/Common/Interaction.cs b/src/Discord.Net.Rest/API/Common/Interaction.cs index 1ca08a0f..7ac81432 100644 --- a/src/Discord.Net.Rest/API/Common/Interaction.cs +++ b/src/Discord.Net.Rest/API/Common/Interaction.cs @@ -23,6 +23,9 @@ namespace Discord.API [JsonProperty("channel_id")] public Optional ChannelId { get; set; } + [JsonProperty("channel")] + public Optional Channel { get; set; } + [JsonProperty("member")] public Optional Member { get; set; } diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs index 1caa4613..70445f80 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs @@ -135,8 +135,8 @@ namespace Discord.Rest internal virtual async Task UpdateAsync(DiscordRestClient discord, Model model, bool doApiCall) { - ChannelId = model.ChannelId.IsSpecified - ? model.ChannelId.Value + ChannelId = model.Channel.IsSpecified + ? model.Channel.Value.Id : null; GuildId = model.GuildId.IsSpecified @@ -186,8 +186,23 @@ namespace Discord.Rest Channel = (IRestMessageChannel)await discord.GetChannelAsync(ChannelId.Value); else { - Channel = null; - + if (model.Channel.IsSpecified) + { + Channel = model.Channel.Value.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.Channel.Value) as IRestMessageChannel, + ChannelType.DM => RestDMChannel.Create(discord, model.Channel.Value), + ChannelType.Group => RestGroupChannel.Create(discord, model.Channel.Value), + _ => null + }; + } _getChannel = async (opt, ul) => { if (Guild is null) diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs index 8a2ee004..c7c1e268 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs @@ -116,8 +116,8 @@ namespace Discord.WebSocket internal virtual void Update(Model model) { - ChannelId = model.ChannelId.IsSpecified - ? model.ChannelId.Value + ChannelId = model.Channel.IsSpecified + ? model.Channel.Value.Id : null; GuildId = model.GuildId.IsSpecified