Browse Source

Introduce emoji role property into rolehelper (#360)

* Introduce emoji role property into rolehelper

* Add check for exclusive properties

* Oversight resolved

* Valid order for error responses

* Appending suggestions
pull/1966/head
Armano den Boef GitHub 3 years ago
parent
commit
d9aaf7aa49
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 6 deletions
  1. +17
    -2
      src/Discord.Net.Core/Entities/Roles/RoleProperties.cs
  2. +3
    -1
      src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs
  3. +20
    -3
      src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs

+ 17
- 2
src/Discord.Net.Core/Entities/Roles/RoleProperties.cs View File

@@ -1,3 +1,5 @@
using System;

namespace Discord
{
/// <summary>
@@ -50,11 +52,24 @@ namespace Discord
/// This value may not be set if the role is an @everyone role.
/// </remarks>
public Optional<bool> Hoist { get; set; }

/// <summary>
/// Gets or sets the icon of the role.
/// </summary>
public Optional<Image> Icon { get; set; }
/// <remarks>
/// This value cannot be set at the same time as Emoji, as they are both exclusive.
///
/// Setting an Icon will override a currently existing Emoji if present.
/// </remarks>
public Optional<Image?> Icon { get; set; }
/// <summary>
/// Gets or sets the unicode emoji of the role.
/// </summary>
/// <remarks>
/// This value cannot be set at the same time as Icon, as they are both exclusive.
///
/// Setting an Emoji will override a currently existing Icon if present.
/// </remarks>
public Optional<Emoji> Emoji { get; set; }
/// <summary>
/// Gets or sets whether or not this role can be mentioned.
/// </summary>


+ 3
- 1
src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs View File

@@ -14,7 +14,9 @@ namespace Discord.API.Rest
[JsonProperty("hoist")]
public Optional<bool> Hoist { get; set; }
[JsonProperty("icon")]
public Optional<Image> Icon { get; set; }
public Optional<Image?> Icon { get; set; }
[JsonProperty("unicode_emoji")]
public Optional<string> Emoji { get; set; }
[JsonProperty("mentionable")]
public Optional<bool> Mentionable { get; set; }
}


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

@@ -13,15 +13,20 @@ namespace Discord.Rest
{
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false);
}
public static async Task<Model> ModifyAsync(IRole role, BaseDiscordClient client,
public static async Task<Model> ModifyAsync(IRole role, BaseDiscordClient client,
Action<RoleProperties> func, RequestOptions options)
{
var args = new RoleProperties();
func(args);

if (args.Icon.IsSpecified)
if (args.Icon.IsSpecified || args.Emoji.IsSpecified)
{
role.Guild.Features.EnsureFeature(GuildFeature.RoleIcons);

if (args.Icon.IsSpecified && args.Emoji.IsSpecified)
{
throw new ArgumentException("Emoji and Icon properties cannot be present on a role at the same time.");
}
}

var apiArgs = new API.Rest.ModifyGuildRoleParams
@@ -31,8 +36,20 @@ namespace Discord.Rest
Mentionable = args.Mentionable,
Name = args.Name,
Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue.ToString() : Optional.Create<string>(),
Icon = args.Icon.IsSpecified ? args.Icon.Value.ToModel() : Optional<API.Image>.Unspecified
Icon = args.Icon.IsSpecified ? args.Icon.Value.Value.ToModel() : Optional<API.Image?>.Unspecified,
Emoji = args.Emoji.GetValueOrDefault()?.Name ?? Optional<string>.Unspecified
};

if (args.Icon.IsSpecified && role.Emoji != null)
{
apiArgs.Emoji = null;
}

if (args.Emoji.IsSpecified && !string.IsNullOrEmpty(role.Icon))
{
apiArgs.Icon = null;
}

var model = await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false);

if (args.Position.IsSpecified)


Loading…
Cancel
Save