using DSharpPlus;
using DSharpPlus.Entities;
namespace X10D.DSharpPlus;
///
/// Extension methods for .
///
public static class DiscordChannelExtensions
{
///
/// Gets the category of this channel.
///
/// The channel whose category to retrieve.
///
/// The category of , or itself if it is already a category;
/// if this channel is not defined in a category.
///
/// is .
public static DiscordChannel? GetCategory(this DiscordChannel channel)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(channel);
#else
if (channel is null)
{
throw new ArgumentNullException(nameof(channel));
}
#endif
while (true)
{
if (channel.IsCategory)
{
return channel;
}
if (channel.Parent is not { } parent)
{
return null;
}
channel = parent;
}
}
///
/// Normalizes a so that the internal client is assured to be a specified value.
///
/// The to normalize.
/// The target client.
///
/// A whose public values will match , but whose internal client
/// is .
///
///
/// is
/// -or-
/// is
///
public static async Task NormalizeClientAsync(this DiscordChannel channel, DiscordClient client)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(channel);
ArgumentNullException.ThrowIfNull(client);
#else
if (channel is null)
{
throw new ArgumentNullException(nameof(channel));
}
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
#endif
return await client.GetChannelAsync(channel.Id);
}
}