Fix exception thrown when given valid role
This commit is contained in:
parent
64bea79ef7
commit
785e69773e
1 changed files with 7 additions and 11 deletions
|
@ -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
|
|
||||||
Type = default;
|
|
||||||
if (input.Length >= 2) {
|
|
||||||
if (input[0] == '&') Type = EntityType.Role;
|
if (input[0] == '&') Type = EntityType.Role;
|
||||||
else if (input[0] == '#') Type = EntityType.Channel;
|
else if (input[0] == '#') Type = EntityType.Channel;
|
||||||
else if (input[0] == '@') Type = EntityType.User;
|
else if (input[0] == '@') Type = EntityType.User;
|
||||||
}
|
else throw new ArgumentException("Entity type unable to be inferred by given input.");
|
||||||
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>
|
||||||
|
|
Loading…
Reference in a new issue