diff --git a/src/Discord.Net.Core/Entities/Channels/BulkGuildChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/BulkGuildChannelProperties.cs deleted file mode 100644 index 2358b2e2e..000000000 --- a/src/Discord.Net.Core/Entities/Channels/BulkGuildChannelProperties.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Discord -{ - public class BulkGuildChannelProperties - { - /// - /// The id of the channel to apply this position to. - /// - public ulong Id { get; set; } - /// - /// The new zero-based position of this channel. - /// - public int Position { get; set; } - - public BulkGuildChannelProperties(ulong id, int position) - { - Id = id; - Position = position; - } - } -} diff --git a/src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs new file mode 100644 index 000000000..31f814334 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs @@ -0,0 +1,16 @@ +namespace Discord +{ + public class ReorderChannelProperties + { + /// The id of the channel to apply this position to. + public ulong Id { get; } + /// The new zero-based position of this channel. + public int Position { get; } + + public ReorderChannelProperties(ulong id, int position) + { + Id = id; + Position = position; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 2ce9b48d0..b3367fab5 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -56,9 +56,9 @@ namespace Discord /// Modifies this guild's embed. Task ModifyEmbedAsync(Action func, RequestOptions options = null); /// Bulk modifies the channels of this guild. - Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null); + Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null); /// Bulk modifies the roles of this guild. - Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null); + Task ReorderRolesAsync(IEnumerable args, RequestOptions options = null); /// Leaves this guild. If you are the owner, use Delete instead. Task LeaveAsync(RequestOptions options = null); diff --git a/src/Discord.Net.Core/Entities/Roles/BulkRoleProperties.cs b/src/Discord.Net.Core/Entities/Roles/BulkRoleProperties.cs deleted file mode 100644 index eacb6689d..000000000 --- a/src/Discord.Net.Core/Entities/Roles/BulkRoleProperties.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Discord -{ - public class BulkRoleProperties : RoleProperties - { - /// - /// The id of the role to be edited - /// - public ulong Id { get; } - - public BulkRoleProperties(ulong id) - { - Id = id; - } - } -} diff --git a/src/Discord.Net.Core/Entities/Roles/ReorderRoleProperties.cs b/src/Discord.Net.Core/Entities/Roles/ReorderRoleProperties.cs new file mode 100644 index 000000000..0c8afa24c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Roles/ReorderRoleProperties.cs @@ -0,0 +1,16 @@ +namespace Discord +{ + public class ReorderRoleProperties + { + /// The id of the role to be edited + public ulong Id { get; } + /// The new zero-based position of the role. + public int Position { get; } + + public ReorderRoleProperties(ulong id, int pos) + { + Id = id; + Position = pos; + } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs index 2bbb58ea6..f97fbda0b 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs @@ -7,9 +7,9 @@ namespace Discord.API.Rest internal class ModifyGuildChannelsParams { [JsonProperty("id")] - public ulong Id { get; set; } + public ulong Id { get; } [JsonProperty("position")] - public int Position { get; set; } + public int Position { get; } public ModifyGuildChannelsParams(ulong id, int position) { diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs index c3c20706b..287e1cafe 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs @@ -10,8 +10,6 @@ namespace Discord.API.Rest public Optional Name { get; set; } [JsonProperty("permissions")] public Optional Permissions { get; set; } - [JsonProperty("position")] - public Optional Position { get; set; } [JsonProperty("color")] public Optional Color { get; set; } [JsonProperty("hoist")] diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs index 38c3fb646..0e816a260 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs @@ -8,10 +8,13 @@ namespace Discord.API.Rest { [JsonProperty("id")] public ulong Id { get; } + [JsonProperty("position")] + public int Position { get; } - public ModifyGuildRolesParams(ulong id) + public ModifyGuildRolesParams(ulong id, int position) { Id = id; + Position = position; } } } diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 2e404003f..afa4af9e6 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -8,7 +8,6 @@ using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Collections.Immutable; using System.Diagnostics; using System.Globalization; using System.IO; @@ -1049,7 +1048,6 @@ namespace Discord.API Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Color, 0, nameof(args.Color)); Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); - Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); @@ -1061,17 +1059,8 @@ namespace Discord.API Preconditions.NotNull(args, nameof(args)); options = RequestOptions.CreateOrClone(options); - var roles = args.ToImmutableArray(); - switch (roles.Length) - { - case 0: - return ImmutableArray.Create(); - case 1: - return ImmutableArray.Create(await ModifyGuildRoleAsync(guildId, roles[0].Id, roles[0]).ConfigureAwait(false)); - default: - var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); - } + var ids = new BucketIds(guildId: guildId); + return await SendJsonAsync>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); } //Users diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 195ae27d0..98303cea6 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -75,23 +75,16 @@ namespace Discord.Rest return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client, - IEnumerable args, RequestOptions options) + public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client, + IEnumerable args, RequestOptions options) { var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position)); await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task> ModifyRolesAsync(IGuild guild, BaseDiscordClient client, - IEnumerable args, RequestOptions options) + public static async Task> ReorderRolesAsync(IGuild guild, BaseDiscordClient client, + IEnumerable args, RequestOptions options) { - var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id) - { - Color = x.Color.IsSpecified ? x.Color.Value.RawValue : Optional.Create(), - Hoist = x.Hoist, - Name = x.Name, - Permissions = x.Permissions.IsSpecified ? x.Permissions.Value.RawValue : Optional.Create(), - Position = x.Position - }); + var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id, x.Position)); return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client, diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 0622df6ce..e4e970487 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -114,14 +114,14 @@ namespace Discord.Rest var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } - public async Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null) + public async Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) { var arr = args.ToArray(); - await GuildHelper.ModifyChannelsAsync(this, Discord, arr, options); + await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options); } - public async Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null) + public async Task ReorderRolesAsync(IEnumerable args, RequestOptions options = null) { - var models = await GuildHelper.ModifyRolesAsync(this, Discord, args, options).ConfigureAwait(false); + var models = await GuildHelper.ReorderRolesAsync(this, Discord, args, options).ConfigureAwait(false); foreach (var model in models) { var role = GetRole(model.Id); diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index 0081351f0..d570f078b 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Model = Discord.API.Role; +using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; namespace Discord.Rest { @@ -23,10 +24,17 @@ namespace Discord.Rest Hoist = args.Hoist, Mentionable = args.Mentionable, Name = args.Name, - Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create(), - Position = args.Position + Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create() }; - return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false); + var model = await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false); + + if (args.Position.IsSpecified) + { + var bulkArgs = new[] { new BulkParams(role.Id, args.Position.Value) }; + await client.ApiClient.ModifyGuildRolesAsync(role.Guild.Id, bulkArgs, options).ConfigureAwait(false); + model.Position = args.Position.Value; + } + return model; } } } diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index be63f4da2..fb5d785c9 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -277,10 +277,10 @@ namespace Discord.WebSocket => GuildHelper.ModifyAsync(this, Discord, func, options); public Task ModifyEmbedAsync(Action func, RequestOptions options = null) => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); - public Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null) - => GuildHelper.ModifyChannelsAsync(this, Discord, args, options); - public Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null) - => GuildHelper.ModifyRolesAsync(this, Discord, args, options); + public Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) + => GuildHelper.ReorderChannelsAsync(this, Discord, args, options); + public Task ReorderRolesAsync(IEnumerable args, RequestOptions options = null) + => GuildHelper.ReorderRolesAsync(this, Discord, args, options); public Task LeaveAsync(RequestOptions options = null) => GuildHelper.LeaveAsync(this, Discord, options);