From 5d020cf11feb8fb7211309d62cd80b40ed090883 Mon Sep 17 00:00:00 2001 From: Misha133 Date: Wed, 21 Sep 2022 21:50:57 +0300 Subject: [PATCH] Add default reaction emoji property --- .../Entities/Channels/IForumChannel.cs | 9 +++++++++ src/Discord.Net.Rest/API/Common/Channel.cs | 3 +++ .../API/Common/ForumReactionEmoji.cs | 12 ++++++++++++ .../Entities/Channels/RestForumChannel.cs | 13 +++++++++++++ .../Entities/Channels/SocketForumChannel.cs | 13 +++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 src/Discord.Net.Rest/API/Common/ForumReactionEmoji.cs diff --git a/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs b/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs index e6c055779..3b244b1a9 100644 --- a/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs @@ -53,6 +53,15 @@ namespace Discord /// int DefaultSlowModeInterval { get; } + /// + /// Gets the emoji to show in the add reaction button on a thread in a forum channel + /// + /// + /// If the emoji is only the will be populated. + /// Use to get the emoji. + /// + IEmote DefaultReactionEmoji { get; } + /// /// Modifies this forum channel. /// diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index 2cd3b13a9..2c43cc492 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -82,5 +82,8 @@ namespace Discord.API [JsonProperty("flags")] public Optional Flags { get; set; } + + [JsonProperty("default_reaction_emoji")] + public Optional DefaultReactionEmoji { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/ForumReactionEmoji.cs b/src/Discord.Net.Rest/API/Common/ForumReactionEmoji.cs new file mode 100644 index 000000000..ba8d78eeb --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ForumReactionEmoji.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Discord.API; + +public class ForumReactionEmoji +{ + [JsonProperty("emoji_id")] + public Optional EmojiId { get; set; } + + [JsonProperty("emoji_name")] + public Optional EmojiName { get; set; } +} diff --git a/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs index d4c82abb8..b8af7bc9f 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs @@ -35,6 +35,9 @@ namespace Discord.Rest /// public ulong? CategoryId { get; private set; } + /// + public IEmote DefaultReactionEmoji { get; private set; } + /// public string Mention => MentionUtils.MentionChannel(Id); @@ -67,6 +70,16 @@ namespace Discord.Rest Tags = model.ForumTags.GetValueOrDefault(Array.Empty()).Select( x => new ForumTag(x.Id, x.Name, x.EmojiId.GetValueOrDefault(null), x.EmojiName.GetValueOrDefault(), x.Moderated) ).ToImmutableArray(); + + if (model.DefaultReactionEmoji.IsSpecified) + { + if (model.DefaultReactionEmoji.Value.EmojiId.IsSpecified && model.DefaultReactionEmoji.Value.EmojiId.Value != 0) + DefaultReactionEmoji = new Emote(model.DefaultReactionEmoji.Value.EmojiId.Value, null, false); + else if (model.DefaultReactionEmoji.Value.EmojiName.IsSpecified) + DefaultReactionEmoji = new Emoji(model.DefaultReactionEmoji.Value.EmojiName.Value); + else + DefaultReactionEmoji = null; + } } /// diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs index 2b5f24f2d..09745abf8 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs @@ -39,6 +39,9 @@ namespace Discord.WebSocket /// public ulong? CategoryId { get; private set; } + /// + public IEmote DefaultReactionEmoji { get; private set; } + /// /// Gets the parent (category) of this channel in the guild's channel list. /// @@ -73,6 +76,16 @@ namespace Discord.WebSocket Tags = model.ForumTags.GetValueOrDefault(Array.Empty()).Select( x => new ForumTag(x.Id, x.Name, x.EmojiId.GetValueOrDefault(null), x.EmojiName.GetValueOrDefault(), x.Moderated) ).ToImmutableArray(); + + if (model.DefaultReactionEmoji.IsSpecified) + { + if (model.DefaultReactionEmoji.Value.EmojiId.IsSpecified && model.DefaultReactionEmoji.Value.EmojiId.Value != 0) + DefaultReactionEmoji = new Emote(model.DefaultReactionEmoji.Value.EmojiId.Value, null, false); + else if (model.DefaultReactionEmoji.Value.EmojiName.IsSpecified) + DefaultReactionEmoji = new Emoji(model.DefaultReactionEmoji.Value.EmojiName.Value); + else + DefaultReactionEmoji = null; + } } ///