| @@ -1,20 +0,0 @@ | |||||
| namespace Discord | |||||
| { | |||||
| public class BulkGuildChannelProperties | |||||
| { | |||||
| /// <summary> | |||||
| /// The id of the channel to apply this position to. | |||||
| /// </summary> | |||||
| public ulong Id { get; set; } | |||||
| /// <summary> | |||||
| /// The new zero-based position of this channel. | |||||
| /// </summary> | |||||
| public int Position { get; set; } | |||||
| public BulkGuildChannelProperties(ulong id, int position) | |||||
| { | |||||
| Id = id; | |||||
| Position = position; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,16 @@ | |||||
| namespace Discord | |||||
| { | |||||
| public class ReorderChannelProperties | |||||
| { | |||||
| /// <summary>The id of the channel to apply this position to.</summary> | |||||
| public ulong Id { get; } | |||||
| /// <summary>The new zero-based position of this channel. </summary> | |||||
| public int Position { get; } | |||||
| public ReorderChannelProperties(ulong id, int position) | |||||
| { | |||||
| Id = id; | |||||
| Position = position; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -56,9 +56,9 @@ namespace Discord | |||||
| /// <summary> Modifies this guild's embed. </summary> | /// <summary> Modifies this guild's embed. </summary> | ||||
| Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null); | Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null); | ||||
| /// <summary> Bulk modifies the channels of this guild. </summary> | /// <summary> Bulk modifies the channels of this guild. </summary> | ||||
| Task ModifyChannelsAsync(IEnumerable<BulkGuildChannelProperties> args, RequestOptions options = null); | |||||
| Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null); | |||||
| /// <summary> Bulk modifies the roles of this guild. </summary> | /// <summary> Bulk modifies the roles of this guild. </summary> | ||||
| Task ModifyRolesAsync(IEnumerable<BulkRoleProperties> args, RequestOptions options = null); | |||||
| Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null); | |||||
| /// <summary> Leaves this guild. If you are the owner, use Delete instead. </summary> | /// <summary> Leaves this guild. If you are the owner, use Delete instead. </summary> | ||||
| Task LeaveAsync(RequestOptions options = null); | Task LeaveAsync(RequestOptions options = null); | ||||
| @@ -1,15 +0,0 @@ | |||||
| namespace Discord | |||||
| { | |||||
| public class BulkRoleProperties : RoleProperties | |||||
| { | |||||
| /// <summary> | |||||
| /// The id of the role to be edited | |||||
| /// </summary> | |||||
| public ulong Id { get; } | |||||
| public BulkRoleProperties(ulong id) | |||||
| { | |||||
| Id = id; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,16 @@ | |||||
| namespace Discord | |||||
| { | |||||
| public class ReorderRoleProperties | |||||
| { | |||||
| /// <summary>The id of the role to be edited</summary> | |||||
| public ulong Id { get; } | |||||
| /// <summary>The new zero-based position of the role.</summary> | |||||
| public int Position { get; } | |||||
| public ReorderRoleProperties(ulong id, int pos) | |||||
| { | |||||
| Id = id; | |||||
| Position = pos; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -7,9 +7,9 @@ namespace Discord.API.Rest | |||||
| internal class ModifyGuildChannelsParams | internal class ModifyGuildChannelsParams | ||||
| { | { | ||||
| [JsonProperty("id")] | [JsonProperty("id")] | ||||
| public ulong Id { get; set; } | |||||
| public ulong Id { get; } | |||||
| [JsonProperty("position")] | [JsonProperty("position")] | ||||
| public int Position { get; set; } | |||||
| public int Position { get; } | |||||
| public ModifyGuildChannelsParams(ulong id, int position) | public ModifyGuildChannelsParams(ulong id, int position) | ||||
| { | { | ||||
| @@ -10,8 +10,6 @@ namespace Discord.API.Rest | |||||
| public Optional<string> Name { get; set; } | public Optional<string> Name { get; set; } | ||||
| [JsonProperty("permissions")] | [JsonProperty("permissions")] | ||||
| public Optional<ulong> Permissions { get; set; } | public Optional<ulong> Permissions { get; set; } | ||||
| [JsonProperty("position")] | |||||
| public Optional<int> Position { get; set; } | |||||
| [JsonProperty("color")] | [JsonProperty("color")] | ||||
| public Optional<uint> Color { get; set; } | public Optional<uint> Color { get; set; } | ||||
| [JsonProperty("hoist")] | [JsonProperty("hoist")] | ||||
| @@ -8,10 +8,13 @@ namespace Discord.API.Rest | |||||
| { | { | ||||
| [JsonProperty("id")] | [JsonProperty("id")] | ||||
| public ulong Id { get; } | public ulong Id { get; } | ||||
| [JsonProperty("position")] | |||||
| public int Position { get; } | |||||
| public ModifyGuildRolesParams(ulong id) | |||||
| public ModifyGuildRolesParams(ulong id, int position) | |||||
| { | { | ||||
| Id = id; | Id = id; | ||||
| Position = position; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -8,7 +8,6 @@ using Newtonsoft.Json; | |||||
| using System; | using System; | ||||
| using System.Collections.Concurrent; | using System.Collections.Concurrent; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | |||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Globalization; | using System.Globalization; | ||||
| using System.IO; | using System.IO; | ||||
| @@ -1049,7 +1048,6 @@ namespace Discord.API | |||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| Preconditions.AtLeast(args.Color, 0, nameof(args.Color)); | Preconditions.AtLeast(args.Color, 0, nameof(args.Color)); | ||||
| Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | ||||
| Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); | |||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| var ids = new BucketIds(guildId: guildId); | var ids = new BucketIds(guildId: guildId); | ||||
| @@ -1061,17 +1059,8 @@ namespace Discord.API | |||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| var roles = args.ToImmutableArray(); | |||||
| switch (roles.Length) | |||||
| { | |||||
| case 0: | |||||
| return ImmutableArray.Create<Role>(); | |||||
| 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<IReadOnlyCollection<Role>>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); | |||||
| } | |||||
| var ids = new BucketIds(guildId: guildId); | |||||
| return await SendJsonAsync<IReadOnlyCollection<Role>>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); | |||||
| } | } | ||||
| //Users | //Users | ||||
| @@ -75,23 +75,16 @@ namespace Discord.Rest | |||||
| return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client, | |||||
| IEnumerable<BulkGuildChannelProperties> args, RequestOptions options) | |||||
| public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client, | |||||
| IEnumerable<ReorderChannelProperties> args, RequestOptions options) | |||||
| { | { | ||||
| var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position)); | var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position)); | ||||
| await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task<IReadOnlyCollection<RoleModel>> ModifyRolesAsync(IGuild guild, BaseDiscordClient client, | |||||
| IEnumerable<BulkRoleProperties> args, RequestOptions options) | |||||
| public static async Task<IReadOnlyCollection<RoleModel>> ReorderRolesAsync(IGuild guild, BaseDiscordClient client, | |||||
| IEnumerable<ReorderRoleProperties> args, RequestOptions options) | |||||
| { | { | ||||
| var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id) | |||||
| { | |||||
| Color = x.Color.IsSpecified ? x.Color.Value.RawValue : Optional.Create<uint>(), | |||||
| Hoist = x.Hoist, | |||||
| Name = x.Name, | |||||
| Permissions = x.Permissions.IsSpecified ? x.Permissions.Value.RawValue : Optional.Create<ulong>(), | |||||
| 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); | return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client, | public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client, | ||||
| @@ -114,14 +114,14 @@ namespace Discord.Rest | |||||
| var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); | var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); | ||||
| Update(model); | Update(model); | ||||
| } | } | ||||
| public async Task ModifyChannelsAsync(IEnumerable<BulkGuildChannelProperties> args, RequestOptions options = null) | |||||
| public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null) | |||||
| { | { | ||||
| var arr = args.ToArray(); | var arr = args.ToArray(); | ||||
| await GuildHelper.ModifyChannelsAsync(this, Discord, arr, options); | |||||
| await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options); | |||||
| } | } | ||||
| public async Task ModifyRolesAsync(IEnumerable<BulkRoleProperties> args, RequestOptions options = null) | |||||
| public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> 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) | foreach (var model in models) | ||||
| { | { | ||||
| var role = GetRole(model.Id); | var role = GetRole(model.Id); | ||||
| @@ -1,6 +1,7 @@ | |||||
| using System; | using System; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Model = Discord.API.Role; | using Model = Discord.API.Role; | ||||
| using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; | |||||
| namespace Discord.Rest | namespace Discord.Rest | ||||
| { | { | ||||
| @@ -23,10 +24,17 @@ namespace Discord.Rest | |||||
| Hoist = args.Hoist, | Hoist = args.Hoist, | ||||
| Mentionable = args.Mentionable, | Mentionable = args.Mentionable, | ||||
| Name = args.Name, | Name = args.Name, | ||||
| Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create<ulong>(), | |||||
| Position = args.Position | |||||
| Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create<ulong>() | |||||
| }; | }; | ||||
| 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; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -277,10 +277,10 @@ namespace Discord.WebSocket | |||||
| => GuildHelper.ModifyAsync(this, Discord, func, options); | => GuildHelper.ModifyAsync(this, Discord, func, options); | ||||
| public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null) | public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null) | ||||
| => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); | => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); | ||||
| public Task ModifyChannelsAsync(IEnumerable<BulkGuildChannelProperties> args, RequestOptions options = null) | |||||
| => GuildHelper.ModifyChannelsAsync(this, Discord, args, options); | |||||
| public Task ModifyRolesAsync(IEnumerable<BulkRoleProperties> args, RequestOptions options = null) | |||||
| => GuildHelper.ModifyRolesAsync(this, Discord, args, options); | |||||
| public Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null) | |||||
| => GuildHelper.ReorderChannelsAsync(this, Discord, args, options); | |||||
| public Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null) | |||||
| => GuildHelper.ReorderRolesAsync(this, Discord, args, options); | |||||
| public Task LeaveAsync(RequestOptions options = null) | public Task LeaveAsync(RequestOptions options = null) | ||||
| => GuildHelper.LeaveAsync(this, Discord, options); | => GuildHelper.LeaveAsync(this, Discord, options); | ||||