From cad041219061cdc6cf898d5eda0c056fa2b38ca0 Mon Sep 17 00:00:00 2001 From: Misha133 Date: Tue, 20 Sep 2022 20:38:41 +0300 Subject: [PATCH] Add `DefaultSlowModeInterval` and `DefaultSlowModeInterval` properties to forum channels --- .../Entities/Channels/IForumChannel.cs | 18 ++++++++++++++++++ src/Discord.Net.Rest/API/Common/Channel.cs | 3 +++ .../Entities/Channels/RestForumChannel.cs | 12 ++++++++++++ .../Entities/Channels/SocketForumChannel.cs | 12 ++++++++++++ 4 files changed, 45 insertions(+) diff --git a/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs b/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs index f4c6da2e2..fb6211615 100644 --- a/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IForumChannel.cs @@ -35,6 +35,24 @@ namespace Discord /// IReadOnlyCollection Tags { get; } + /// + /// Gets the current rate limit on creating posts in this forum channel. + /// + /// + /// An representing the time in seconds required before the user can send another + /// message; 0 if disabled. + /// + int ThreadCreationInterval { get; } + + /// + /// Gets the current default slow-mode delay for threads in this forum channel. + /// + /// + /// An representing the time in seconds required before the user can send another + /// message; 0 if disabled. + /// + int DefaultSlowModeInterval { get; } + /// /// Creates a new post (thread) within the forum. /// diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index 0bb0a152d..00a325b1b 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -76,5 +76,8 @@ namespace Discord.API [JsonProperty("default_auto_archive_duration")] public Optional AutoArchiveDuration { get; set; } + + [JsonProperty("default_thread_rate_limit_per_user")] + public Optional ThreadRateLimitPerUser { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs index aff8400aa..df42d0394 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs @@ -26,6 +26,12 @@ namespace Discord.Rest /// public IReadOnlyCollection Tags { get; private set; } + /// + public int ThreadCreationInterval { get; private set; } + + /// + public int DefaultSlowModeInterval { get; private set; } + /// public string Mention => MentionUtils.MentionChannel(Id); @@ -49,6 +55,12 @@ namespace Discord.Rest Topic = model.Topic.GetValueOrDefault(); DefaultAutoArchiveDuration = model.AutoArchiveDuration.GetValueOrDefault(ThreadArchiveDuration.OneDay); + if (model.ThreadRateLimitPerUser.IsSpecified) + DefaultSlowModeInterval = model.ThreadRateLimitPerUser.Value; + + if(model.SlowMode.IsSpecified) + ThreadCreationInterval = model.SlowMode.Value; + Tags = model.ForumTags.GetValueOrDefault(Array.Empty()).Select( x => new ForumTag(x.Id, x.Name, x.EmojiId.GetValueOrDefault(null), x.EmojiName.GetValueOrDefault()) ).ToImmutableArray(); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs index ea58ecdb5..4250a7057 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs @@ -27,6 +27,12 @@ namespace Discord.WebSocket /// public IReadOnlyCollection Tags { get; private set; } + /// + public int ThreadCreationInterval { get; private set; } + + /// + public int DefaultSlowModeInterval { get; private set; } + /// public string Mention => MentionUtils.MentionChannel(Id); @@ -46,6 +52,12 @@ namespace Discord.WebSocket Topic = model.Topic.GetValueOrDefault(); DefaultAutoArchiveDuration = model.AutoArchiveDuration.GetValueOrDefault(ThreadArchiveDuration.OneDay); + if (model.ThreadRateLimitPerUser.IsSpecified) + DefaultSlowModeInterval = model.ThreadRateLimitPerUser.Value; + + if (model.SlowMode.IsSpecified) + ThreadCreationInterval = model.SlowMode.Value; + Tags = model.ForumTags.GetValueOrDefault(Array.Empty()).Select( x => new ForumTag(x.Id, x.Name, x.EmojiId.GetValueOrDefault(null), x.EmojiName.GetValueOrDefault()) ).ToImmutableArray();