@@ -569,16 +569,13 @@ namespace Discord | |||
/// <summary> | |||
/// Creates a new role with the provided name. | |||
/// </summary> | |||
/// <param name="name">The new name for the role.</param> | |||
/// <param name="permissions">The guild permission that the role should possess.</param> | |||
/// <param name="color">The color of the role.</param> | |||
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param> | |||
/// <param name="func">The delegate containing the properties to be applied to the role upon creation.</param> | |||
/// <param name="options">The options to be used when sending the request.</param> | |||
/// <returns> | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// role. | |||
/// </returns> | |||
Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null); | |||
Task<IRole> CreateRoleAsync(Action<RoleProperties> func, RequestOptions options = null); | |||
/// <summary> | |||
/// Adds a user to this guild. | |||
@@ -1,10 +1,10 @@ | |||
#pragma warning disable CS1591 | |||
#pragma warning disable CS1591 | |||
using Newtonsoft.Json; | |||
namespace Discord.API.Rest | |||
{ | |||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
internal class ModifyGuildRoleParams | |||
internal class GuildRoleParams | |||
{ | |||
[JsonProperty("name")] | |||
public Optional<string> Name { get; set; } |
@@ -4,7 +4,7 @@ using Newtonsoft.Json; | |||
namespace Discord.API.Rest | |||
{ | |||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
internal class ModifyGuildRolesParams : ModifyGuildRoleParams | |||
internal class ModifyGuildRolesParams : GuildRoleParams | |||
{ | |||
[JsonProperty("id")] | |||
public ulong Id { get; } | |||
@@ -1142,13 +1142,13 @@ namespace Discord.API | |||
var ids = new BucketIds(guildId: guildId); | |||
return await SendAsync<IReadOnlyCollection<Role>>("GET", () => $"guilds/{guildId}/roles", ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task<Role> CreateGuildRoleAsync(ulong guildId, RequestOptions options = null) | |||
public async Task<Role> CreateGuildRoleAsync(ulong guildId, GuildRoleParams args, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
options = RequestOptions.CreateOrClone(options); | |||
var ids = new BucketIds(guildId: guildId); | |||
return await SendAsync<Role>("POST", () => $"guilds/{guildId}/roles", ids, options: options).ConfigureAwait(false); | |||
return await SendJsonAsync<Role>("POST", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task DeleteGuildRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null) | |||
{ | |||
@@ -1159,7 +1159,7 @@ namespace Discord.API | |||
var ids = new BucketIds(guildId: guildId); | |||
await SendAsync("DELETE", () => $"guilds/{guildId}/roles/{roleId}", ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task<Role> ModifyGuildRoleAsync(ulong guildId, ulong roleId, Rest.ModifyGuildRoleParams args, RequestOptions options = null) | |||
public async Task<Role> ModifyGuildRoleAsync(ulong guildId, ulong roleId, Rest.GuildRoleParams args, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
Preconditions.NotEqual(roleId, 0, nameof(roleId)); | |||
@@ -250,22 +250,22 @@ namespace Discord.Rest | |||
//Roles | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client, | |||
string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) | |||
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client, Action<RoleProperties> func, RequestOptions options) | |||
{ | |||
if (name == null) throw new ArgumentNullException(paramName: nameof(name)); | |||
var args = new RoleProperties(); | |||
func(args); | |||
var apiArgs = new API.Rest.GuildRoleParams | |||
{ | |||
Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create<uint>(), | |||
Hoist = args.Hoist, | |||
Mentionable = args.Mentionable, | |||
Name = args.Name, | |||
Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create<ulong>() | |||
}; | |||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false); | |||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | |||
var role = RestRole.Create(client, guild, model); | |||
await role.ModifyAsync(x => | |||
{ | |||
x.Name = name; | |||
x.Permissions = (permissions ?? role.Permissions); | |||
x.Color = (color ?? Color.Default); | |||
x.Hoist = isHoisted; | |||
}, options).ConfigureAwait(false); | |||
return role; | |||
} | |||
@@ -525,19 +525,15 @@ namespace Discord.Rest | |||
/// <summary> | |||
/// Creates a new role with the provided name. | |||
/// </summary> | |||
/// <param name="name">The new name for the role.</param> | |||
/// <param name="permissions">The guild permission that the role should possess.</param> | |||
/// <param name="color">The color of the role.</param> | |||
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param> | |||
/// <param name="func">The delegate containing the properties to be applied to the role upon creation.</param> | |||
/// <param name="options">The options to be used when sending the request.</param> | |||
/// <returns> | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// role. | |||
/// </returns> | |||
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), | |||
bool isHoisted = false, RequestOptions options = null) | |||
public async Task<RestRole> CreateRoleAsync(Action<RoleProperties> func, RequestOptions options = null) | |||
{ | |||
var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options).ConfigureAwait(false); | |||
var role = await GuildHelper.CreateRoleAsync(this, Discord, func, options).ConfigureAwait(false); | |||
_roles = _roles.Add(role.Id, role); | |||
return role; | |||
} | |||
@@ -824,8 +820,8 @@ namespace Discord.Rest | |||
IRole IGuild.GetRole(ulong id) | |||
=> GetRole(id); | |||
/// <inheritdoc /> | |||
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) | |||
=> await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); | |||
async Task<IRole> IGuild.CreateRoleAsync(Action<RoleProperties> func, RequestOptions options) | |||
=> await CreateRoleAsync(func, options).ConfigureAwait(false); | |||
/// <inheritdoc /> | |||
async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options) | |||
@@ -18,7 +18,7 @@ namespace Discord.Rest | |||
{ | |||
var args = new RoleProperties(); | |||
func(args); | |||
var apiArgs = new API.Rest.ModifyGuildRoleParams | |||
var apiArgs = new API.Rest.GuildRoleParams | |||
{ | |||
Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create<uint>(), | |||
Hoist = args.Hoist, | |||
@@ -674,19 +674,15 @@ namespace Discord.WebSocket | |||
/// <summary> | |||
/// Creates a new role with the provided name. | |||
/// </summary> | |||
/// <param name="name">The new name for the role.</param> | |||
/// <param name="permissions">The guild permission that the role should possess.</param> | |||
/// <param name="color">The color of the role.</param> | |||
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param> | |||
/// <param name="func">The delegate containing the properties to be applied to the role upon creation.</param> | |||
/// <param name="options">The options to be used when sending the request.</param> | |||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
/// <returns> | |||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||
/// role. | |||
/// </returns> | |||
public Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), | |||
bool isHoisted = false, RequestOptions options = null) | |||
=> GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options); | |||
public Task<RestRole> CreateRoleAsync(Action<RoleProperties> func, RequestOptions options = null) | |||
=> GuildHelper.CreateRoleAsync(this, Discord, func, options); | |||
internal SocketRole AddRole(RoleModel model) | |||
{ | |||
var role = SocketRole.Create(this, Discord.State, model); | |||
@@ -1142,8 +1138,8 @@ namespace Discord.WebSocket | |||
IRole IGuild.GetRole(ulong id) | |||
=> GetRole(id); | |||
/// <inheritdoc /> | |||
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) | |||
=> await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); | |||
async Task<IRole> IGuild.CreateRoleAsync(Action<RoleProperties> func, RequestOptions options) | |||
=> await CreateRoleAsync(func, options).ConfigureAwait(false); | |||
/// <inheritdoc /> | |||
Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) | |||