Skip to content

Commit

Permalink
Add getting ThreadChannel/s in IGuild
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Oct 27, 2024
1 parent 230223d commit b9ca2b8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Kook.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,23 @@ public interface IGuild : IEntity<ulong>
/// </remarks>
Task<ITextChannel?> GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null);

/// <summary>
/// 获取此服务器中的所有帖子频道。
/// </summary>
/// <param name="mode"> 指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。 </param>
/// <param name="options"> 发送请求时要使用的选项。 </param>
/// <returns> 一个表示异步获取操作的任务。任务的结果包含此服务器的所有帖子频道。 </returns>
Task<IReadOnlyCollection<IThreadChannel>> GetThreadChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null);

/// <summary>
/// 获取此服务器内的指定帖子频道。
/// </summary>
/// <param name="id"> 要获取的频道的 ID。 </param>
/// <param name="mode"> 指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。 </param>
/// <param name="options"> 发送请求时要使用的选项。 </param>
/// <returns> 一个表示异步获取操作的任务。任务的结果包含与指定的 <paramref name="id"/> 关联的频道;如果未找到,则返回 <c>null</c>。 </returns>
Task<IThreadChannel?> GetThreadChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null);

/// <summary>
/// 获取此服务器中所有具有语音聊天能力的频道。
/// </summary>
Expand Down
45 changes: 45 additions & 0 deletions src/Kook.Net.Rest/Entities/Guilds/RestGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public class RestGuild : RestEntity<ulong>, IGuild, IUpdateable
/// </remarks>
public IReadOnlyCollection<RestTextChannel> TextChannels => Channels.OfType<RestTextChannel>().ToImmutableArray();

/// <summary>
/// 获取此服务器中的所有帖子频道。
/// </summary>
public IReadOnlyCollection<RestThreadChannel> ThreadChannels => Channels.OfType<RestThreadChannel>().ToImmutableArray();

/// <summary>
/// 获取此服务器中所有具有语音聊天能力的频道。
/// </summary>
Expand Down Expand Up @@ -442,6 +447,20 @@ public Task<RestGuildChannel> GetChannelAsync(ulong id, RequestOptions? options
return channel as RestTextChannel;
}

/// <summary>
/// 获取此服务器内的指定帖子频道。
/// </summary>
/// <param name="id"> 要获取的频道的 ID。 </param>
/// <param name="options"> 发送请求时要使用的选项。 </param>
/// <returns> 一个表示异步获取操作的任务。任务的结果包含与指定的 <paramref name="id"/> 关联的频道;如果未找到,则返回 <c>null</c>。 </returns>
public async Task<RestThreadChannel?> GetThreadChannelAsync(ulong id, RequestOptions? options = null)
{
RestGuildChannel channel = await GuildHelper
.GetChannelAsync(this, Kook, id, options)
.ConfigureAwait(false);
return channel as RestThreadChannel;
}

/// <summary>
/// 获取此服务器中所有具有文字聊天能力的频道。
/// </summary>
Expand All @@ -459,6 +478,19 @@ public async Task<IReadOnlyCollection<RestTextChannel>> GetTextChannelsAsync(Req
return [..channels.OfType<RestTextChannel>()];
}

/// <summary>
/// 获取此服务器中的所有帖子频道。
/// </summary>
/// <param name="options"> 发送请求时要使用的选项。 </param>
/// <returns> 一个表示异步获取操作的任务。任务的结果包含此服务器的所有帖子频道。 </returns>
public async Task<IReadOnlyCollection<RestThreadChannel>> GetThreadChannelsAsync(RequestOptions? options = null)
{
IReadOnlyCollection<RestGuildChannel> channels = await GuildHelper
.GetChannelsAsync(this, Kook, options)
.ConfigureAwait(false);
return [..channels.OfType<RestThreadChannel>()];
}

/// <summary>
/// 获取此服务器内指定具有语音聊天能力的频道。
/// </summary>
Expand Down Expand Up @@ -725,12 +757,25 @@ async Task<IReadOnlyCollection<ITextChannel>> IGuild.GetTextChannelsAsync(CacheM
? await GetTextChannelsAsync(options).ConfigureAwait(false)
: TextChannels;

/// <inheritdoc />
async Task<IReadOnlyCollection<IThreadChannel>> IGuild.GetThreadChannelsAsync(CacheMode mode,
RequestOptions? options) =>
mode == CacheMode.AllowDownload
? await GetThreadChannelsAsync(options).ConfigureAwait(false)
: ThreadChannels;

/// <inheritdoc />
async Task<ITextChannel?> IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions? options) =>
mode == CacheMode.AllowDownload
? await GetTextChannelAsync(id, options).ConfigureAwait(false)
: TextChannels.FirstOrDefault(x => x.Id == id);

/// <inheritdoc />
async Task<IThreadChannel?> IGuild.GetThreadChannelAsync(ulong id, CacheMode mode, RequestOptions? options) =>
mode == CacheMode.AllowDownload
? await GetThreadChannelAsync(id, options).ConfigureAwait(false)
: ThreadChannels.FirstOrDefault(x => x.Id == id);

/// <inheritdoc />
async Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode,
RequestOptions? options) =>
Expand Down
20 changes: 20 additions & 0 deletions src/Kook.Net.WebSocket/Entities/Guilds/SocketGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ Kook.CurrentUser is not null
/// </summary>
public IReadOnlyCollection<SocketCategoryChannel> CategoryChannels => [..Channels.OfType<SocketCategoryChannel>()];

/// <summary>
/// 获取此服务器中的所有帖子频道。
/// </summary>
public IReadOnlyCollection<SocketThreadChannel> ThreadChannels => [..Channels.OfType<SocketThreadChannel>()];

/// <summary>
/// 获取此服务器的所有频道。
/// </summary>
Expand Down Expand Up @@ -509,6 +514,13 @@ public Task RemoveBanAsync(ulong userId, RequestOptions? options = null) =>
/// </remarks>
public SocketTextChannel? GetTextChannel(ulong id) => GetChannel(id) as SocketTextChannel;

/// <summary>
/// 获取此服务器中的所有帖子频道。
/// </summary>
/// <param name="id"> 要获取的频道的 ID。 </param>
/// <returns> 与指定的 <paramref name="id"/> 关联的频道;如果未找到,则返回 <c>null</c>。 </returns>
public SocketThreadChannel? GetThreadChannel(ulong id) => GetChannel(id) as SocketThreadChannel;

/// <summary>
/// 获取此服务器内指定具有语音聊天能力的频道。
/// </summary>
Expand Down Expand Up @@ -959,6 +971,14 @@ Task<IReadOnlyCollection<ITextChannel>> IGuild.GetTextChannelsAsync(CacheMode mo
Task<ITextChannel?> IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions? options) =>
Task.FromResult<ITextChannel?>(GetTextChannel(id));

/// <inheritdoc />
Task<IReadOnlyCollection<IThreadChannel>> IGuild.GetThreadChannelsAsync(CacheMode mode, RequestOptions? options) =>
Task.FromResult<IReadOnlyCollection<IThreadChannel>>(ThreadChannels);

/// <inheritdoc />
Task<IThreadChannel?> IGuild.GetThreadChannelAsync(ulong id, CacheMode mode, RequestOptions? options) =>
Task.FromResult<IThreadChannel?>(GetThreadChannel(id));

/// <inheritdoc />
Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions? options) =>
Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels);
Expand Down

0 comments on commit b9ca2b8

Please sign in to comment.