Fix exception thrown when given valid role

This commit is contained in:
Noi 2022-08-23 20:12:39 -07:00
parent 64bea79ef7
commit 785e69773e

View file

@ -15,8 +15,7 @@ public class EntityName {
/// Entity's unique ID value (snowflake). May be null if the value is not known. /// Entity's unique ID value (snowflake). May be null if the value is not known.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This value may be updated during runtime if the parent <see cref="EntityList"/> was instructed to /// This property may be updated during runtime if instructed to update the ID for persistence.
/// update the ID for persistence.
/// </remarks> /// </remarks>
public ulong? Id { public ulong? Id {
get => _id; get => _id;
@ -39,16 +38,12 @@ public class EntityName {
public EntityName(string input) { public EntityName(string input) {
if (string.IsNullOrWhiteSpace(input)) if (string.IsNullOrWhiteSpace(input))
throw new ArgumentNullException(nameof(input), "Specified name is blank."); throw new ArgumentNullException(nameof(input), "Specified name is blank.");
if (input.Length < 2) throw new ArgumentException("Input is not in a valid entity name format.");
// Check if type prefix was specified and extract it if (input[0] == '&') Type = EntityType.Role;
Type = default; else if (input[0] == '#') Type = EntityType.Channel;
if (input.Length >= 2) { else if (input[0] == '@') Type = EntityType.User;
if (input[0] == '&') Type = EntityType.Role; else throw new ArgumentException("Entity type unable to be inferred by given input.");
else if (input[0] == '#') Type = EntityType.Channel;
else if (input[0] == '@') Type = EntityType.User;
}
if (Type == default)
throw new ArgumentException("Entity type unable to be inferred by given input.");
input = input[1..]; // Remove prefix input = input[1..]; // Remove prefix
@ -116,6 +111,7 @@ public class EntityName {
} }
#region Helper methods #region Helper methods
// TODO convert all to extension methods
/// <summary> /// <summary>
/// Attempts to find the corresponding role within the given guild. /// Attempts to find the corresponding role within the given guild.
/// </summary> /// </summary>