@@ -569,13 +569,17 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Creates a new role with the provided name. | /// Creates a new role with the provided name. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="func">The delegate containing the properties to be applied to the role upon creation.</param> | |||||
/// <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="isMentionable">Whether the role is mentionable or not.</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// role. | /// role. | ||||
/// </returns> | /// </returns> | ||||
Task<IRole> CreateRoleAsync(Action<RoleProperties> func, RequestOptions options = null); | |||||
Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, bool isMentionable = false, RequestOptions options = null); | |||||
/// <summary> | /// <summary> | ||||
/// Adds a user to this guild. | /// Adds a user to this guild. | ||||
@@ -1,3 +1,6 @@ | |||||
using System; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -20,5 +23,33 @@ namespace Discord | |||||
/// <returns> A <c>bool</c> indicating if the guild boost messages are enabled in the system channel. </returns> | /// <returns> A <c>bool</c> indicating if the guild boost messages are enabled in the system channel. </returns> | ||||
public static bool GetGuildBoostMessagesEnabled(this IGuild guild) | public static bool GetGuildBoostMessagesEnabled(this IGuild guild) | ||||
=> !guild.SystemChannelFlags.HasFlag(SystemChannelMessageDeny.GuildBoost); | => !guild.SystemChannelFlags.HasFlag(SystemChannelMessageDeny.GuildBoost); | ||||
/// <summary> | |||||
/// Creates a new role with the provided name. | |||||
/// </summary> | |||||
/// <param name="guild">The guild you want to create the role for.</param> | |||||
/// <param name="func">The delegate to modify the properties of the role with.</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | |||||
/// role. | |||||
/// </returns> | |||||
public static async Task<IRole> CreateRoleAsync(this IGuild guild, Action<RoleProperties> func, RequestOptions options = null) | |||||
{ | |||||
if (func is null) | |||||
throw new ArgumentNullException(nameof(func)); | |||||
var args = new RoleProperties(); | |||||
func(args); | |||||
return await guild.CreateRoleAsync( | |||||
args.Name.GetValueOrDefault(), | |||||
args.Permissions.GetValueOrDefault(), | |||||
args.Color.GetValueOrDefault(), | |||||
args.Hoist.GetValueOrDefault(), | |||||
args.Mentionable.GetValueOrDefault(), | |||||
options); | |||||
} | |||||
} | } | ||||
} | } |
@@ -250,17 +250,16 @@ namespace Discord.Rest | |||||
//Roles | //Roles | ||||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | ||||
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client, Action<RoleProperties> func, RequestOptions options) | |||||
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client, | |||||
string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) | |||||
{ | { | ||||
var args = new RoleProperties(); | |||||
func(args); | |||||
var apiArgs = new API.Rest.GuildRoleParams | 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>() | |||||
Color = color?.RawValue ?? Optional.Create<uint>(), | |||||
Hoist = isHoisted, | |||||
Mentionable = isMentionable, | |||||
Name = name, | |||||
Permissions = permissions?.RawValue ?? Optional.Create<ulong>() | |||||
}; | }; | ||||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | ||||
@@ -431,7 +430,7 @@ namespace Discord.Rest | |||||
var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false); | var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false); | ||||
return emote.ToEntity(); | return emote.ToEntity(); | ||||
} | } | ||||
public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles, | |||||
public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles, | |||||
RequestOptions options) | RequestOptions options) | ||||
{ | { | ||||
var apiargs = new CreateGuildEmoteParams | var apiargs = new CreateGuildEmoteParams | ||||
@@ -446,7 +445,7 @@ namespace Discord.Rest | |||||
return emote.ToEntity(); | return emote.ToEntity(); | ||||
} | } | ||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | ||||
public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func, | |||||
public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func, | |||||
RequestOptions options) | RequestOptions options) | ||||
{ | { | ||||
if (func == null) throw new ArgumentNullException(paramName: nameof(func)); | if (func == null) throw new ArgumentNullException(paramName: nameof(func)); | ||||
@@ -464,7 +463,7 @@ namespace Discord.Rest | |||||
var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false); | var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false); | ||||
return emote.ToEntity(); | return emote.ToEntity(); | ||||
} | } | ||||
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) | |||||
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) | |||||
=> client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options); | => client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options); | ||||
} | } | ||||
} | } |
@@ -197,7 +197,7 @@ namespace Discord.Rest | |||||
role?.Update(model); | role?.Update(model); | ||||
} | } | ||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public Task LeaveAsync(RequestOptions options = null) | public Task LeaveAsync(RequestOptions options = null) | ||||
=> GuildHelper.LeaveAsync(this, Discord, options); | => GuildHelper.LeaveAsync(this, Discord, options); | ||||
@@ -525,15 +525,20 @@ namespace Discord.Rest | |||||
/// <summary> | /// <summary> | ||||
/// Creates a new role with the provided name. | /// Creates a new role with the provided name. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="func">The delegate containing the properties to be applied to the role upon creation.</param> | |||||
/// <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="isMentionable">Whether the role is mentionable or not.</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// role. | /// role. | ||||
/// </returns> | /// </returns> | ||||
public async Task<RestRole> CreateRoleAsync(Action<RoleProperties> func, RequestOptions options = null) | |||||
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), | |||||
bool isHoisted = false, bool isMentionable = false, RequestOptions options = null) | |||||
{ | { | ||||
var role = await GuildHelper.CreateRoleAsync(this, Discord, func, options).ConfigureAwait(false); | |||||
var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); | |||||
_roles = _roles.Add(role.Id, role); | _roles = _roles.Add(role.Id, role); | ||||
return role; | return role; | ||||
} | } | ||||
@@ -820,8 +825,8 @@ namespace Discord.Rest | |||||
IRole IGuild.GetRole(ulong id) | IRole IGuild.GetRole(ulong id) | ||||
=> GetRole(id); | => GetRole(id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IRole> IGuild.CreateRoleAsync(Action<RoleProperties> func, RequestOptions options) | |||||
=> await CreateRoleAsync(func, options).ConfigureAwait(false); | |||||
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) | |||||
=> await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options) | async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options) | ||||
@@ -674,15 +674,22 @@ namespace Discord.WebSocket | |||||
/// <summary> | /// <summary> | ||||
/// Creates a new role with the provided name. | /// Creates a new role with the provided name. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="func">The delegate containing the properties to be applied to the role upon creation.</param> | |||||
/// <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="isMentionable">Whether the role is mentionable or not.</param> | |||||
/// <param name="options">The options to be used when sending the request.</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> | /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous creation operation. The task result contains the newly created | /// A task that represents the asynchronous creation operation. The task result contains the newly created | ||||
/// role. | /// role. | ||||
/// </returns> | /// </returns> | ||||
public Task<RestRole> CreateRoleAsync(Action<RoleProperties> func, RequestOptions options = null) | |||||
=> GuildHelper.CreateRoleAsync(this, Discord, func, options); | |||||
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), | |||||
bool isHoisted = false, bool isMentionable = false, RequestOptions options = null) | |||||
{ | |||||
return await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); | |||||
} | |||||
internal SocketRole AddRole(RoleModel model) | internal SocketRole AddRole(RoleModel model) | ||||
{ | { | ||||
var role = SocketRole.Create(this, Discord.State, model); | var role = SocketRole.Create(this, Discord.State, model); | ||||
@@ -1138,8 +1145,8 @@ namespace Discord.WebSocket | |||||
IRole IGuild.GetRole(ulong id) | IRole IGuild.GetRole(ulong id) | ||||
=> GetRole(id); | => GetRole(id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IRole> IGuild.CreateRoleAsync(Action<RoleProperties> func, RequestOptions options) | |||||
=> await CreateRoleAsync(func, options).ConfigureAwait(false); | |||||
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) | |||||
=> await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) | Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||