From a64ab6025b4da17fcfea1876d54fdd032d5361dd Mon Sep 17 00:00:00 2001 From: Nathan Solomon Date: Tue, 27 Nov 2018 16:16:32 -0600 Subject: [PATCH] Resolve Issue #1188 (Allow Users to specify position when creating a new channel) (#1196) * Added ability to specify position when creating a channel * Adjusted categories to include guildproperties and allow specifying position when creating channel categories * fixed unimplemented methods (for CreateCategoryChannelAsync) and added appropriate documentation --- src/Discord.Net.Core/Entities/Guilds/IGuild.cs | 3 ++- .../API/Rest/CreateGuildChannelParams.cs | 2 ++ .../Entities/Guilds/GuildHelper.cs | 15 ++++++++++++--- src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs | 9 +++++---- .../Entities/Guilds/SocketGuild.cs | 9 +++++---- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index a7206bd599..3b35796b94 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -474,12 +474,13 @@ public interface IGuild : IDeletable, ISnowflakeEntity /// Creates a new channel category in this guild. /// /// The new name for the category. + /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// category channel. /// - Task CreateCategoryAsync(string name, RequestOptions options = null); + Task CreateCategoryAsync(string name, Action func = null, RequestOptions options = null); /// /// Gets a collection of all the voice regions this guild can access. diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs index 05cdf4b8af..a102bd38dc 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs @@ -12,6 +12,8 @@ internal class CreateGuildChannelParams public ChannelType Type { get; } [JsonProperty("parent_id")] public Optional CategoryId { get; set; } + [JsonProperty("position")] + public Optional Position { get; set; } //Text channels [JsonProperty("topic")] diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index c31fa89f27..affa746850 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -163,6 +163,7 @@ public static async Task GetBanAsync(IGuild guild, BaseDiscordClient cl CategoryId = props.CategoryId, Topic = props.Topic, IsNsfw = props.IsNsfw, + Position = props.Position }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestTextChannel.Create(client, guild, model); @@ -180,18 +181,26 @@ public static async Task GetBanAsync(IGuild guild, BaseDiscordClient cl { CategoryId = props.CategoryId, Bitrate = props.Bitrate, - UserLimit = props.UserLimit + UserLimit = props.UserLimit, + Position = props.Position }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestVoiceChannel.Create(client, guild, model); } /// is null. public static async Task CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, - string name, RequestOptions options) + string name, RequestOptions options, Action func = null) { if (name == null) throw new ArgumentNullException(paramName: nameof(name)); - var args = new CreateGuildChannelParams(name, ChannelType.Category); + var props = new GuildChannelProperties(); + func?.Invoke(props); + + var args = new CreateGuildChannelParams(name, ChannelType.Category) + { + Position = props.Position + }; + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestCategoryChannel.Create(client, guild, model); } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index bd70bf96b2..a847998b54 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -441,13 +441,14 @@ public Task CreateVoiceChannelAsync(string name, Action /// The name of the new channel. + /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. /// is null. /// /// The created category channel. /// - public Task CreateCategoryChannelAsync(string name, RequestOptions options = null) - => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); + public Task CreateCategoryChannelAsync(string name, Action func = null, RequestOptions options = null) + => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); /// /// Gets a collection of all the voice regions this guild can access. @@ -776,8 +777,8 @@ async Task IGuild.CreateTextChannelAsync(string name, Action IGuild.CreateVoiceChannelAsync(string name, Action func, RequestOptions options) => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); /// - async Task IGuild.CreateCategoryAsync(string name, RequestOptions options) - => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateCategoryAsync(string name, Action func, RequestOptions options) + => await CreateCategoryChannelAsync(name, func, options).ConfigureAwait(false); /// async Task> IGuild.GetVoiceRegionsAsync(RequestOptions options) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 412f3acffe..4e41246797 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -561,14 +561,15 @@ public Task CreateVoiceChannelAsync(string name, Action /// The new name for the category. + /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. /// is null. /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// category channel. /// - public Task CreateCategoryChannelAsync(string name, RequestOptions options = null) - => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); + public Task CreateCategoryChannelAsync(string name, Action func = null, RequestOptions options = null) + => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { @@ -1069,8 +1070,8 @@ async Task IGuild.CreateTextChannelAsync(string name, Action IGuild.CreateVoiceChannelAsync(string name, Action func, RequestOptions options) => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); /// - async Task IGuild.CreateCategoryAsync(string name, RequestOptions options) - => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateCategoryAsync(string name, Action func, RequestOptions options) + => await CreateCategoryChannelAsync(name, func, options).ConfigureAwait(false); /// async Task> IGuild.GetVoiceRegionsAsync(RequestOptions options)