From b9ca2b8d5c184a71c340914b35fc37cdff74762e Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Sun, 27 Oct 2024 18:46:27 +0800 Subject: [PATCH] Add getting ThreadChannel/s in IGuild --- src/Kook.Net.Core/Entities/Guilds/IGuild.cs | 17 +++++++ .../Entities/Guilds/RestGuild.cs | 45 +++++++++++++++++++ .../Entities/Guilds/SocketGuild.cs | 20 +++++++++ 3 files changed, 82 insertions(+) diff --git a/src/Kook.Net.Core/Entities/Guilds/IGuild.cs b/src/Kook.Net.Core/Entities/Guilds/IGuild.cs index e9dddd87..e629ad04 100644 --- a/src/Kook.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Kook.Net.Core/Entities/Guilds/IGuild.cs @@ -321,6 +321,23 @@ public interface IGuild : IEntity /// Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null); + /// + /// 获取此服务器中的所有帖子频道。 + /// + /// 指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。 + /// 发送请求时要使用的选项。 + /// 一个表示异步获取操作的任务。任务的结果包含此服务器的所有帖子频道。 + Task> GetThreadChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null); + + /// + /// 获取此服务器内的指定帖子频道。 + /// + /// 要获取的频道的 ID。 + /// 指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。 + /// 发送请求时要使用的选项。 + /// 一个表示异步获取操作的任务。任务的结果包含与指定的 关联的频道;如果未找到,则返回 null + Task GetThreadChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null); + /// /// 获取此服务器中所有具有语音聊天能力的频道。 /// diff --git a/src/Kook.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Kook.Net.Rest/Entities/Guilds/RestGuild.cs index 54416c07..08cf3352 100644 --- a/src/Kook.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Kook.Net.Rest/Entities/Guilds/RestGuild.cs @@ -109,6 +109,11 @@ public class RestGuild : RestEntity, IGuild, IUpdateable /// public IReadOnlyCollection TextChannels => Channels.OfType().ToImmutableArray(); + /// + /// 获取此服务器中的所有帖子频道。 + /// + public IReadOnlyCollection ThreadChannels => Channels.OfType().ToImmutableArray(); + /// /// 获取此服务器中所有具有语音聊天能力的频道。 /// @@ -442,6 +447,20 @@ public Task GetChannelAsync(ulong id, RequestOptions? options return channel as RestTextChannel; } + /// + /// 获取此服务器内的指定帖子频道。 + /// + /// 要获取的频道的 ID。 + /// 发送请求时要使用的选项。 + /// 一个表示异步获取操作的任务。任务的结果包含与指定的 关联的频道;如果未找到,则返回 null + public async Task GetThreadChannelAsync(ulong id, RequestOptions? options = null) + { + RestGuildChannel channel = await GuildHelper + .GetChannelAsync(this, Kook, id, options) + .ConfigureAwait(false); + return channel as RestThreadChannel; + } + /// /// 获取此服务器中所有具有文字聊天能力的频道。 /// @@ -459,6 +478,19 @@ public async Task> GetTextChannelsAsync(Req return [..channels.OfType()]; } + /// + /// 获取此服务器中的所有帖子频道。 + /// + /// 发送请求时要使用的选项。 + /// 一个表示异步获取操作的任务。任务的结果包含此服务器的所有帖子频道。 + public async Task> GetThreadChannelsAsync(RequestOptions? options = null) + { + IReadOnlyCollection channels = await GuildHelper + .GetChannelsAsync(this, Kook, options) + .ConfigureAwait(false); + return [..channels.OfType()]; + } + /// /// 获取此服务器内指定具有语音聊天能力的频道。 /// @@ -725,12 +757,25 @@ async Task> IGuild.GetTextChannelsAsync(CacheM ? await GetTextChannelsAsync(options).ConfigureAwait(false) : TextChannels; + /// + async Task> IGuild.GetThreadChannelsAsync(CacheMode mode, + RequestOptions? options) => + mode == CacheMode.AllowDownload + ? await GetThreadChannelsAsync(options).ConfigureAwait(false) + : ThreadChannels; + /// async Task IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions? options) => mode == CacheMode.AllowDownload ? await GetTextChannelAsync(id, options).ConfigureAwait(false) : TextChannels.FirstOrDefault(x => x.Id == id); + /// + async Task IGuild.GetThreadChannelAsync(ulong id, CacheMode mode, RequestOptions? options) => + mode == CacheMode.AllowDownload + ? await GetThreadChannelAsync(id, options).ConfigureAwait(false) + : ThreadChannels.FirstOrDefault(x => x.Id == id); + /// async Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions? options) => diff --git a/src/Kook.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Kook.Net.WebSocket/Entities/Guilds/SocketGuild.cs index a6af6b73..ed0c9a5c 100644 --- a/src/Kook.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Kook.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -189,6 +189,11 @@ Kook.CurrentUser is not null /// public IReadOnlyCollection CategoryChannels => [..Channels.OfType()]; + /// + /// 获取此服务器中的所有帖子频道。 + /// + public IReadOnlyCollection ThreadChannels => [..Channels.OfType()]; + /// /// 获取此服务器的所有频道。 /// @@ -509,6 +514,13 @@ public Task RemoveBanAsync(ulong userId, RequestOptions? options = null) => /// public SocketTextChannel? GetTextChannel(ulong id) => GetChannel(id) as SocketTextChannel; + /// + /// 获取此服务器中的所有帖子频道。 + /// + /// 要获取的频道的 ID。 + /// 与指定的 关联的频道;如果未找到,则返回 null + public SocketThreadChannel? GetThreadChannel(ulong id) => GetChannel(id) as SocketThreadChannel; + /// /// 获取此服务器内指定具有语音聊天能力的频道。 /// @@ -959,6 +971,14 @@ Task> IGuild.GetTextChannelsAsync(CacheMode mo Task IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions? options) => Task.FromResult(GetTextChannel(id)); + /// + Task> IGuild.GetThreadChannelsAsync(CacheMode mode, RequestOptions? options) => + Task.FromResult>(ThreadChannels); + + /// + Task IGuild.GetThreadChannelAsync(ulong id, CacheMode mode, RequestOptions? options) => + Task.FromResult(GetThreadChannel(id)); + /// Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions? options) => Task.FromResult>(VoiceChannels);