Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>pull/2459/head
@@ -145,10 +145,10 @@ namespace Discord | |||
if (name.Length > 32) | |||
throw new ArgumentOutOfRangeException(nameof(name), "Name length must be less than or equal to 32."); | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new FormatException($"{nameof(name)} must match the regex ^[\\w-]{{1,32}}$"); | |||
if (!Regex.IsMatch(name, @"^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$")) | |||
throw new ArgumentException(@"Name must match the regex ^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$", nameof(name)); | |||
if (name.Any(x => char.IsUpper(x))) | |||
if (name.Any(char.IsUpper)) | |||
throw new FormatException("Name cannot contain any uppercase characters."); | |||
} | |||
@@ -42,8 +42,9 @@ namespace Discord | |||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | |||
Preconditions.AtMost(name.Length, SlashCommandBuilder.MaxNameLength, nameof(name)); | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Option name cannot contain any special characters or whitespaces!", nameof(name)); | |||
if (Type == ApplicationCommandType.Slash && !Regex.IsMatch(name, @"^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$")) | |||
throw new ArgumentException(@"Name must match the regex ^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$", nameof(name)); | |||
} | |||
_nameLocalizations = value; | |||
} | |||
@@ -67,7 +67,8 @@ namespace Discord | |||
Name = Name, | |||
IsDefaultPermission = IsDefaultPermission, | |||
IsDMEnabled = IsDMEnabled, | |||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified | |||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified, | |||
NameLocalizations = NameLocalizations | |||
}; | |||
return props; | |||
@@ -157,14 +158,6 @@ namespace Discord | |||
Preconditions.NotNullOrEmpty(name, nameof(name)); | |||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | |||
Preconditions.AtMost(name.Length, MaxNameLength, nameof(name)); | |||
// Discord updated the docs, this regex prevents special characters like @!$%(... etc, | |||
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); | |||
if (name.Any(x => char.IsUpper(x))) | |||
throw new FormatException("Name cannot contain any uppercase characters."); | |||
} | |||
/// <summary> | |||
@@ -65,7 +65,8 @@ namespace Discord | |||
Name = Name, | |||
IsDefaultPermission = IsDefaultPermission, | |||
IsDMEnabled = IsDMEnabled, | |||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified | |||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified, | |||
NameLocalizations = NameLocalizations | |||
}; | |||
return props; | |||
@@ -155,14 +156,6 @@ namespace Discord | |||
Preconditions.NotNullOrEmpty(name, nameof(name)); | |||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | |||
Preconditions.AtMost(name.Length, MaxNameLength, nameof(name)); | |||
// Discord updated the docs, this regex prevents special characters like @!$%(... etc, | |||
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); | |||
if (name.Any(x => char.IsUpper(x))) | |||
throw new FormatException("Name cannot contain any uppercase characters."); | |||
} | |||
/// <summary> | |||
@@ -207,10 +207,9 @@ namespace Discord | |||
{ | |||
Preconditions.Options(name, description); | |||
// Discord updated the docs, this regex prevents special characters like @!$%( and s p a c e s.. etc, | |||
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); | |||
// https://discord.com/developers/docs/interactions/application-commands | |||
if (!Regex.IsMatch(name, @"^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$")) | |||
throw new ArgumentException(@"Name must match the regex ^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$", nameof(name)); | |||
// make sure theres only one option with default set to true | |||
if (isDefault == true && Options?.Any(x => x.IsDefault == true) == true) | |||
@@ -376,12 +375,11 @@ namespace Discord | |||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | |||
Preconditions.AtMost(name.Length, MaxNameLength, nameof(name)); | |||
// Discord updated the docs, this regex prevents special characters like @!$%(... etc, | |||
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); | |||
// https://discord.com/developers/docs/interactions/application-commands | |||
if (!Regex.IsMatch(name, @"^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$")) | |||
throw new ArgumentException(@"Name must match the regex ^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$", nameof(name)); | |||
if (name.Any(x => char.IsUpper(x))) | |||
if (name.Any(char.IsUpper)) | |||
throw new FormatException("Name cannot contain any uppercase characters."); | |||
} | |||
@@ -587,10 +585,9 @@ namespace Discord | |||
{ | |||
Preconditions.Options(name, description); | |||
// Discord updated the docs, this regex prevents special characters like @!$%( and s p a c e s.. etc, | |||
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); | |||
// https://discord.com/developers/docs/interactions/application-commands | |||
if (!Regex.IsMatch(name, @"^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$")) | |||
throw new ArgumentException(@"Name must match the regex ^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$", nameof(name)); | |||
// make sure theres only one option with default set to true | |||
if (isDefault && Options?.Any(x => x.IsDefault == true) == true) | |||
@@ -966,8 +963,10 @@ namespace Discord | |||
{ | |||
Preconditions.AtLeast(name.Length, 1, nameof(name)); | |||
Preconditions.AtMost(name.Length, SlashCommandBuilder.MaxNameLength, nameof(name)); | |||
if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) | |||
throw new ArgumentException("Option name cannot contain any special characters or whitespaces!", nameof(name)); | |||
// https://discord.com/developers/docs/interactions/application-commands | |||
if (!Regex.IsMatch(name, @"^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$")) | |||
throw new ArgumentException(@"Name must match the regex ^[-_\p{L}\p{N}\p{IsDevanagari}\p{IsThai}]{1,32}$", nameof(name)); | |||
} | |||
private static void EnsureValidCommandOptionDescription(string description) | |||