From f9c8530a89b1b2c43ea9442b19b79aabb312ad11 Mon Sep 17 00:00:00 2001 From: Misha133 <61027276+Misha-133@users.noreply.github.com> Date: Fri, 31 Mar 2023 14:22:00 +0300 Subject: [PATCH] [Feature] Default thread ratelimit in guild text channels (#2622) * initial commit * mocked bruh --- .../Entities/Channels/ForumChannelProperties.cs | 15 --------------- .../Entities/Channels/ITextChannel.cs | 9 +++++++++ .../Entities/Channels/TextChannelProperties.cs | 14 ++++++++++++++ .../API/Rest/ModifyForumChannelParams.cs | 3 --- .../API/Rest/ModifyTextChannelParams.cs | 5 +++++ .../Entities/Channels/ChannelHelper.cs | 1 + .../Entities/Channels/RestTextChannel.cs | 4 ++++ .../Entities/Channels/SocketTextChannel.cs | 4 ++++ .../MockedEntities/MockedTextChannel.cs | 2 ++ .../MockedEntities/MockedVoiceChannel.cs | 2 ++ 10 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Channels/ForumChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/ForumChannelProperties.cs index 26b985b8..1704dc32 100644 --- a/src/Discord.Net.Core/Entities/Channels/ForumChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/ForumChannelProperties.cs @@ -28,21 +28,6 @@ public class ForumChannelProperties : TextChannelProperties /// Thrown if the value does not fall within [0, 21600]. public Optional ThreadCreationInterval { get; set; } - - /// - /// Gets or sets the default slow-mode for threads in this channel. - /// - /// - /// Setting this value to anything above zero will require each user to wait X seconds before - /// sending another message; setting this value to 0 will disable slow-mode for child threads. - /// - /// Users with or - /// will be exempt from slow-mode. - /// - /// - /// Thrown if the value does not fall within [0, 21600]. - public Optional DefaultSlowModeInterval { get; set; } - /// /// Gets or sets a collection of tags inside of this forum channel. /// diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs index e27317b0..ae02229b 100644 --- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs @@ -35,6 +35,15 @@ namespace Discord /// int SlowModeInterval { get; } + /// + /// Gets the current default slow-mode delay for threads in this channel. + /// + /// + /// An representing the time in seconds required before the user can send another + /// message; 0 if disabled. + /// + int DefaultSlowModeInterval { get; } + /// /// Gets the default auto-archive duration for client-created threads in this channel. /// diff --git a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs index acd69f48..2dc5cfd2 100644 --- a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs @@ -45,5 +45,19 @@ namespace Discord /// public Optional AutoArchiveDuration { get; set; } + /// + /// Gets or sets the default slow-mode for threads in this channel. + /// + /// + /// Setting this value to anything above zero will require each user to wait X seconds before + /// sending another message; setting this value to 0 will disable slow-mode for child threads. + /// + /// Users with or + /// will be exempt from slow-mode. + /// + /// + /// Thrown if the value does not fall within [0, 21600]. + public Optional DefaultSlowModeInterval { get; set; } + } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyForumChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyForumChannelParams.cs index ba5da8a3..4162709b 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyForumChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyForumChannelParams.cs @@ -9,9 +9,6 @@ internal class ModifyForumChannelParams : ModifyTextChannelParams [JsonProperty("available_tags")] public Optional Tags { get; set; } - [JsonProperty("default_thread_rate_limit_per_user")] - public Optional DefaultSlowModeInterval { get; set; } - [JsonProperty("rate_limit_per_user")] public Optional ThreadCreationInterval { get; set; } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs index 409d90c3..6952b1a9 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs @@ -7,9 +7,14 @@ namespace Discord.API.Rest { [JsonProperty("topic")] public Optional Topic { get; set; } + [JsonProperty("nsfw")] public Optional IsNsfw { get; set; } + [JsonProperty("rate_limit_per_user")] public Optional SlowModeInterval { get; set; } + + [JsonProperty("default_thread_rate_limit_per_user")] + public Optional DefaultSlowModeInterval { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 3e1d0a60..f04cb3d3 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -65,6 +65,7 @@ namespace Discord.Rest Deny = overwrite.Permissions.DenyValue.ToString() }).ToArray() : Optional.Create(), + DefaultSlowModeInterval = args.DefaultSlowModeInterval }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index 1d1e6df9..14f531de 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -27,6 +27,8 @@ namespace Discord.Rest public bool IsNsfw { get; private set; } /// public ThreadArchiveDuration DefaultArchiveDuration { get; private set; } + /// + public int DefaultSlowModeInterval { get; private set; } internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) : base(discord, guild, id) @@ -52,6 +54,8 @@ namespace Discord.Rest DefaultArchiveDuration = model.AutoArchiveDuration.Value; else DefaultArchiveDuration = ThreadArchiveDuration.OneDay; + + DefaultSlowModeInterval = model.ThreadRateLimitPerUser.GetValueOrDefault(0); // basic value at channel creation. Shouldn't be called since guild text channels always have this property } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 13f4e669..7f7ebc2b 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -25,6 +25,8 @@ namespace Discord.WebSocket public virtual int SlowModeInterval { get; private set; } /// public ulong? CategoryId { get; private set; } + /// + public int DefaultSlowModeInterval { get; private set; } /// /// Gets the parent (category) of this channel in the guild's channel list. /// @@ -81,6 +83,8 @@ namespace Discord.WebSocket DefaultArchiveDuration = model.AutoArchiveDuration.Value; else DefaultArchiveDuration = ThreadArchiveDuration.OneDay; + + DefaultSlowModeInterval = model.ThreadRateLimitPerUser.GetValueOrDefault(0); // basic value at channel creation. Shouldn't be called since guild text channels always have this property } diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs index 873e8df7..a9abe2e8 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs @@ -10,6 +10,8 @@ namespace Discord { public bool IsNsfw => throw new NotImplementedException(); + public int DefaultSlowModeInterval => throw new NotImplementedException(); + public ThreadArchiveDuration DefaultArchiveDuration => throw new NotImplementedException(); public string Topic => throw new NotImplementedException(); diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs index 30328877..2c2becf8 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs @@ -9,6 +9,8 @@ namespace Discord { internal sealed class MockedVoiceChannel : IVoiceChannel { + public int DefaultSlowModeInterval => throw new NotImplementedException(); + public int Bitrate => throw new NotImplementedException(); public int? UserLimit => throw new NotImplementedException();