From 1f01881bebfc6565ce74c11fe260bcdf15a98cca Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Wed, 18 May 2022 09:51:37 +0200 Subject: [PATCH] feature: Add DefaultArchiveDuration to ITextChannel (#2295) --- .../Entities/Channels/ITextChannel.cs | 11 +++++++++++ src/Discord.Net.Rest/API/Common/Channel.cs | 3 +++ .../Entities/Channels/RestTextChannel.cs | 9 ++++++++- .../Entities/Channels/SocketTextChannel.cs | 8 +++++++- .../MockedEntities/MockedTextChannel.cs | 2 ++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs index ae0fe674b..af4e5ec6a 100644 --- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs @@ -35,6 +35,17 @@ namespace Discord /// int SlowModeInterval { get; } + /// + /// Gets the default auto-archive duration for client-created threads in this channel. + /// + /// + /// The value of this property does not affect API thread creation, it will not respect this value. + /// + /// + /// The default auto-archive duration for thread creation in this channel. + /// + ThreadArchiveDuration DefaultArchiveDuration { get; } + /// /// Bulk-deletes multiple messages. /// diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index d565b269a..0eab65686 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -66,5 +66,8 @@ namespace Discord.API [JsonProperty("member_count")] public Optional MemberCount { get; set; } + + [JsonProperty("default_auto_archive_duration")] + public Optional AutoArchiveDuration { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index a73bda334..81f21bcd7 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -21,11 +21,12 @@ namespace Discord.Rest public virtual int SlowModeInterval { get; private set; } /// public ulong? CategoryId { get; private set; } - /// public string Mention => MentionUtils.MentionChannel(Id); /// public bool IsNsfw { get; private set; } + /// + public ThreadArchiveDuration DefaultArchiveDuration { get; private set; } internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) : base(discord, guild, id) @@ -46,6 +47,12 @@ namespace Discord.Rest if (model.SlowMode.IsSpecified) SlowModeInterval = model.SlowMode.Value; IsNsfw = model.Nsfw.GetValueOrDefault(); + + if (model.AutoArchiveDuration.IsSpecified) + DefaultArchiveDuration = model.AutoArchiveDuration.Value; + else + DefaultArchiveDuration = ThreadArchiveDuration.OneDay; + // 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 e8454ecf8..6aece7d78 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -40,7 +40,8 @@ namespace Discord.WebSocket private bool _nsfw; /// public bool IsNsfw => _nsfw; - + /// + public ThreadArchiveDuration DefaultArchiveDuration { get; private set; } /// public string Mention => MentionUtils.MentionChannel(Id); /// @@ -76,6 +77,11 @@ namespace Discord.WebSocket Topic = model.Topic.GetValueOrDefault(); SlowModeInterval = model.SlowMode.GetValueOrDefault(); // some guilds haven't been patched to include this yet? _nsfw = model.Nsfw.GetValueOrDefault(); + if (model.AutoArchiveDuration.IsSpecified) + DefaultArchiveDuration = model.AutoArchiveDuration.Value; + else + DefaultArchiveDuration = ThreadArchiveDuration.OneDay; + // 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 0dfcab7a5..ab1d3e534 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 ThreadArchiveDuration DefaultArchiveDuration => throw new NotImplementedException(); + public string Topic => throw new NotImplementedException(); public int SlowModeInterval => throw new NotImplementedException();