/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public static async Task <RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options, Action <GuildChannelProperties> func = null) { if (name == null) { throw new ArgumentNullException(paramName: nameof(name)); } var props = new GuildChannelProperties(); func?.Invoke(props); var args = new CreateGuildChannelParams(name, ChannelType.Category) { Position = props.Position, Overwrites = props.PermissionOverwrites.IsSpecified ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite { TargetId = overwrite.TargetId, TargetType = overwrite.TargetType, Allow = overwrite.Permissions.AllowValue.ToString(), Deny = overwrite.Permissions.DenyValue.ToString() }).ToArray() : Optional.Create <API.Overwrite[]>(), }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestCategoryChannel.Create(client, guild, model)); }
internal new static RestCategoryChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { var entity = new RestCategoryChannel(discord, guild, model.Id); entity.Update(model); return(entity); }
// Categories public static async Task<ICategoryChannel> GetCategoryAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) { // if no category id specified, return null if (!channel.CategoryId.HasValue) return null; // CategoryId will contain a value here var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false); return RestCategoryChannel.Create(client, model) as ICategoryChannel; }
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { return(model.Type switch { ChannelType.News => RestNewsChannel.Create(discord, guild, model), ChannelType.Text => RestTextChannel.Create(discord, guild, model), ChannelType.Voice => RestVoiceChannel.Create(discord, guild, model), ChannelType.Stage => RestStageChannel.Create(discord, guild, model), ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model), _ => new RestGuildChannel(discord, guild, model.Id), });
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public static async Task <RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options) { if (name == null) { throw new ArgumentNullException(paramName: nameof(name)); } var args = new CreateGuildChannelParams(name, ChannelType.Category); var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestCategoryChannel.Create(client, guild, model)); }
/// <exception cref="InvalidOperationException">Unexpected channel type.</exception> internal static RestChannel Create(BaseDiscordClient discord, Model model) { return(model.Type switch { ChannelType.News or ChannelType.Text or ChannelType.Voice or ChannelType.Stage or ChannelType.NewsThread or ChannelType.PrivateThread or ChannelType.PublicThread => RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model), ChannelType.DM or ChannelType.Group => CreatePrivate(discord, model) as RestChannel, ChannelType.Category => RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model), _ => new RestChannel(discord, model.Id), });
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { switch (model.Type) { case ChannelType.Text: return(RestTextChannel.Create(discord, guild, model)); case ChannelType.Voice: return(RestVoiceChannel.Create(discord, guild, model)); case ChannelType.Category: return(RestCategoryChannel.Create(discord, guild, model)); default: return(new RestGuildChannel(discord, guild, model.Id)); } }
internal static RestChannel Create(BaseDiscordClient discord, Model model) { switch (model.Type) { case ChannelType.Text: case ChannelType.Voice: return(RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model)); case ChannelType.DM: case ChannelType.Group: return(CreatePrivate(discord, model) as RestChannel); case ChannelType.Category: return(RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model)); default: return(new RestChannel(discord, model.Id)); } }
/// <summary> /// Converts an existing <see cref="RestCategoryChannel"/> to an abstracted <see cref="IRestCategoryChannel"/> value. /// </summary> /// <param name="restCategoryChannel">The existing <see cref="RestCategoryChannel"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restCategoryChannel"/>.</exception> /// <returns>An <see cref="IRestCategoryChannel"/> that abstracts <paramref name="restCategoryChannel"/>.</returns> public static IRestCategoryChannel Abstract(this RestCategoryChannel restCategoryChannel) => new RestCategoryChannelAbstraction(restCategoryChannel);
/// <summary> /// Constructs a new <see cref="RestCategoryChannelAbstraction"/> around an existing <see cref="Rest.RestCategoryChannel"/>. /// </summary> /// <param name="restCategoryChannel">The value to use for <see cref="Rest.RestCategoryChannel"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restCategoryChannel"/>.</exception> public RestCategoryChannelAbstraction(RestCategoryChannel restCategoryChannel) : base(restCategoryChannel) { }