Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Interaction channel field support #2666

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/API/Common/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ internal class Interaction
[JsonProperty("channel_id")]
public Optional<ulong> ChannelId { get; set; }

[JsonProperty("channel")]
public Optional<Channel> Channel { get; set; }

[JsonProperty("member")]
public Optional<GuildMember> Member { get; set; }

Expand Down
23 changes: 19 additions & 4 deletions src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ internal static async Task<RestInteraction> CreateAsync(DiscordRestClient client

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
Expand Down Expand Up @@ -186,8 +186,23 @@ internal virtual async Task UpdateAsync(DiscordRestClient discord, Model model,
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ internal static SocketInteraction Create(DiscordSocketClient client, Model model

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
Expand Down