Browse Source

Cleaned up and fixed several reorder issues.

tags/1.0-rc
RogueException 8 years ago
parent
commit
20f7ba431f
13 changed files with 66 additions and 78 deletions
  1. +0
    -20
      src/Discord.Net.Core/Entities/Channels/BulkGuildChannelProperties.cs
  2. +16
    -0
      src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs
  3. +2
    -2
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  4. +0
    -15
      src/Discord.Net.Core/Entities/Roles/BulkRoleProperties.cs
  5. +16
    -0
      src/Discord.Net.Core/Entities/Roles/ReorderRoleProperties.cs
  6. +2
    -2
      src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs
  7. +0
    -2
      src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs
  8. +4
    -1
      src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs
  9. +2
    -13
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  10. +5
    -12
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  11. +4
    -4
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  12. +11
    -3
      src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs
  13. +4
    -4
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 0
- 20
src/Discord.Net.Core/Entities/Channels/BulkGuildChannelProperties.cs View File

@@ -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;
}
}
}

+ 16
- 0
src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs View File

@@ -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;
}
}
}

+ 2
- 2
src/Discord.Net.Core/Entities/Guilds/IGuild.cs View File

@@ -56,9 +56,9 @@ namespace Discord
/// <summary> Modifies this guild's embed. </summary>
Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null);
/// <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>
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>
Task LeaveAsync(RequestOptions options = null);



+ 0
- 15
src/Discord.Net.Core/Entities/Roles/BulkRoleProperties.cs View File

@@ -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;
}
}
}

+ 16
- 0
src/Discord.Net.Core/Entities/Roles/ReorderRoleProperties.cs View File

@@ -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;
}
}
}

+ 2
- 2
src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs View File

@@ -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)
{


+ 0
- 2
src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs View File

@@ -10,8 +10,6 @@ namespace Discord.API.Rest
public Optional<string> Name { get; set; }
[JsonProperty("permissions")]
public Optional<ulong> Permissions { get; set; }
[JsonProperty("position")]
public Optional<int> Position { get; set; }
[JsonProperty("color")]
public Optional<uint> Color { get; set; }
[JsonProperty("hoist")]


+ 4
- 1
src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs View File

@@ -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;
}
}
}

+ 2
- 13
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -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<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


+ 5
- 12
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -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<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));
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);
}
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,


+ 4
- 4
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -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<BulkGuildChannelProperties> args, RequestOptions options = null)
public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> 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<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)
{
var role = GetRole(model.Id);


+ 11
- 3
src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs View File

@@ -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<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;
}
}
}

+ 4
- 4
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -277,10 +277,10 @@ namespace Discord.WebSocket
=> GuildHelper.ModifyAsync(this, Discord, func, options);
public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
=> 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)
=> GuildHelper.LeaveAsync(this, Discord, options);


Loading…
Cancel
Save