Skip to content

Commit

Permalink
Fix naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Mar 31, 2024
1 parent 802f2f7 commit c5f0992
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 70 deletions.
44 changes: 22 additions & 22 deletions Remora.Discord.Commands/Extensions/CommandTreeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public static class CommandTreeExtensions
* Various Discord-imposed limits.
*/

private const int MaxRootCommandsOrGroups = 100;
private const int MaxGroupCommands = 25;
private const int MaxChoiceValues = 25;
private const int MaxCommandParameters = 25;
private const int MaxCommandStringifiedLength = 4000;
private const int MaxCommandDescriptionLength = 100;
private const int MaxTreeDepth = 3; // Top level is a depth of 1
private const int _maxRootCommandsOrGroups = 100;
private const int _maxGroupCommands = 25;
private const int _maxChoiceValues = 25;
private const int _maxCommandParameters = 25;
private const int _maxCommandStringifiedLength = 4000;
private const int _maxCommandDescriptionLength = 100;
private const int _maxTreeDepth = 3; // Top level is a depth of 1

/// <summary>
/// Maps a set of Discord application commands to their respective command nodes.
Expand Down Expand Up @@ -188,12 +188,12 @@ public static IReadOnlyList<IBulkApplicationCommandData> CreateApplicationComman
throw new UnsupportedFeatureException("Overloads are not supported.", node);
}

if (GetCommandStringifiedLength(option) > MaxCommandStringifiedLength)
if (GetCommandStringifiedLength(option) > _maxCommandStringifiedLength)
{
throw new UnsupportedFeatureException
(
"One or more commands is too long (combined length of name, description, and value " +
$"properties), max {MaxCommandStringifiedLength}).",
$"properties), max {_maxCommandStringifiedLength}).",
node
);
}
Expand Down Expand Up @@ -223,11 +223,11 @@ public static IReadOnlyList<IBulkApplicationCommandData> CreateApplicationComman
}

// Perform validations
if (commands.Count > MaxRootCommandsOrGroups)
if (commands.Count > _maxRootCommandsOrGroups)
{
throw new UnsupportedFeatureException
(
$"Too many root-level commands or groups (max {MaxRootCommandsOrGroups}, found {commands.Count}).",
$"Too many root-level commands or groups (max {_maxRootCommandsOrGroups}, found {commands.Count}).",
tree.Root
);
}
Expand Down Expand Up @@ -372,11 +372,11 @@ private static IApplicationCommandOption? TranslateCommandNode
ILocalizationProvider localizationProvider
)
{
if (treeDepth > MaxTreeDepth)
if (treeDepth > _maxTreeDepth)
{
throw new UnsupportedFeatureException
(
$"A sub-command or group was nested too deeply (depth {treeDepth}, max {MaxTreeDepth}).",
$"A sub-command or group was nested too deeply (depth {treeDepth}, max {_maxTreeDepth}).",
node
);
}
Expand Down Expand Up @@ -468,11 +468,11 @@ ILocalizationProvider localizationProvider
return null;
}

if (subCommandCount > MaxGroupCommands)
if (subCommandCount > _maxGroupCommands)
{
throw new UnsupportedFeatureException
(
$"Too many commands under a group ({subCommandCount}, max {MaxGroupCommands}).",
$"Too many commands under a group ({subCommandCount}, max {_maxGroupCommands}).",
group
);
}
Expand Down Expand Up @@ -670,11 +670,11 @@ ILocalizationProvider localizationProvider
parameterOptions.Add(parameterOption);
}

if (parameterOptions.Count > MaxCommandParameters)
if (parameterOptions.Count > _maxCommandParameters)
{
throw new UnsupportedFeatureException
(
$"Too many parameters in a command (had {parameterOptions.Count}, max {MaxCommandParameters}).",
$"Too many parameters in a command (had {parameterOptions.Count}, max {_maxCommandParameters}).",
command
);
}
Expand All @@ -696,7 +696,7 @@ ILocalizationProvider localizationProvider
if (actualParameterType.IsEnum)
{
// Add the choices directly
if (Enum.GetValues(actualParameterType).Length <= MaxChoiceValues)
if (Enum.GetValues(actualParameterType).Length <= _maxChoiceValues)
{
choices = new(EnumExtensions.GetEnumChoices(actualParameterType, localizationProvider));
}
Expand Down Expand Up @@ -810,15 +810,15 @@ private static void ValidateNodeDescription(string description, IChildNode node)
var type = command.GetCommandType();
if (type is ApplicationCommandType.ChatInput)
{
if (description.Length <= MaxCommandDescriptionLength)
if (description.Length <= _maxCommandDescriptionLength)
{
return;
}

throw new UnsupportedFeatureException
(
$"A command description was too long (length {description.Length}, "
+ $"max {MaxCommandDescriptionLength}).",
+ $"max {_maxCommandDescriptionLength}).",
node
);
}
Expand All @@ -837,15 +837,15 @@ private static void ValidateNodeDescription(string description, IChildNode node)
default:
{
// Assume it uses the default limits
if (description.Length <= MaxCommandDescriptionLength)
if (description.Length <= _maxCommandDescriptionLength)
{
return;
}

throw new UnsupportedFeatureException
(
$"A group or parameter description was too long (length {description.Length}, "
+ $"max {MaxCommandDescriptionLength}).",
+ $"max {_maxCommandDescriptionLength}).",
node
);
}
Expand Down
16 changes: 8 additions & 8 deletions Remora.Discord.Commands/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace Remora.Discord.Commands.Extensions;
/// </summary>
internal static class EnumExtensions
{
private const int MaxChoiceNameLength = 100;
private const int MaxChoiceValueLength = 100;
private const int _maxChoiceNameLength = 100;
private const int _maxChoiceValueLength = 100;

private static readonly ConcurrentDictionary<Type, IReadOnlyList<IApplicationCommandOptionChoice>> _choiceCache
= new();
Expand Down Expand Up @@ -75,7 +75,7 @@ ILocalizationProvider localizationProvider
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the enum has more than 25 members, or if any of its members translated names or values exceeds one of
/// <see cref="MaxChoiceNameLength"/> or <see cref="MaxChoiceValueLength"/>.
/// <see cref="_maxChoiceNameLength"/> or <see cref="_maxChoiceValueLength"/>.
/// </exception>
/// <param name="enumType">The enumeration type.</param>
/// <param name="localizationProvider">The localization provider.</param>
Expand Down Expand Up @@ -108,19 +108,19 @@ ILocalizationProvider localizationProvider
var localizedDisplayNames = provider.GetStrings(displayString);
foreach (var (locale, localizedDisplayName) in localizedDisplayNames)
{
if (localizedDisplayName.Length > MaxChoiceNameLength)
if (localizedDisplayName.Length > _maxChoiceNameLength)
{
throw new ArgumentOutOfRangeException
(
nameof(enumType),
$"The localized display name for the locale {locale} of the enumeration member "
+ $"{type.Name}::{enumName} is too long (max {MaxChoiceNameLength})."
+ $"{type.Name}::{enumName} is too long (max {_maxChoiceNameLength})."
);
}
}
var valueString = enumName;
if (valueString.Length <= MaxChoiceValueLength)
if (valueString.Length <= _maxChoiceValueLength)
{
choices.Add
(
Expand All @@ -137,13 +137,13 @@ ILocalizationProvider localizationProvider
// Try converting the enum's value representation
valueString = value.ToString() ?? throw new InvalidOperationException();
if (valueString.Length > MaxChoiceValueLength)
if (valueString.Length > _maxChoiceValueLength)
{
throw new ArgumentOutOfRangeException
(
nameof(enumType),
$"The length of the enumeration member {type.Name}::{enumName} value is too long " +
$"(max {MaxChoiceValueLength})."
$"(max {_maxChoiceValueLength})."
);
}
Expand Down
4 changes: 2 additions & 2 deletions Remora.Discord.Extensions/Formatting/AnsiStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public string Build()
/// </summary>
private sealed class StyleState
{
private const char EscapeChar = '\u001b';
private const char _escapeChar = '\u001b';

private bool _hasChanged;
private bool _isBold;
Expand Down Expand Up @@ -246,7 +246,7 @@ public void AppendToStringBuilder(StringBuilder stringBuilder)

_hasChanged = false;

stringBuilder.Append($"{EscapeChar}[{AnsiStyle.Reset}");
stringBuilder.Append($"{_escapeChar}[{AnsiStyle.Reset}");

if (this.IsBold)
{
Expand Down
10 changes: 5 additions & 5 deletions Remora.Discord.Interactivity/CustomIDHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class CustomIDHelpers
/// Gets the name used to build IDs for select menu components.
/// This may include text, role, channel etc. select menus.
/// </summary>
private const string SelectComponentName = "select-menu";
private const string _selectComponentName = "select-menu";

/// <summary>
/// Creates an ID string that can be used with button components.
Expand Down Expand Up @@ -98,7 +98,7 @@ public static string CreateButtonIDWithState(string name, string state, params s
/// </param>
/// <returns>The custom ID.</returns>
public static string CreateSelectMenuID(string name)
=> FormatID(SelectComponentName, name, null, Array.Empty<string>());
=> FormatID(_selectComponentName, name, null, Array.Empty<string>());

/// <summary>
/// Creates an ID string with state information that can be used with select menu components.
Expand All @@ -109,7 +109,7 @@ public static string CreateSelectMenuID(string name)
/// <param name="state">The state value passed with the custom ID.</param>
/// <returns>The custom ID.</returns>
public static string CreateSelectMenuIDWithState(string name, string state)
=> FormatID(SelectComponentName, name, state, Array.Empty<string>());
=> FormatID(_selectComponentName, name, state, Array.Empty<string>());

/// <summary>
/// Creates an ID string that can be used with select menu components.
Expand All @@ -123,7 +123,7 @@ public static string CreateSelectMenuIDWithState(string name, string state)
/// </param>
/// <returns>The custom ID.</returns>
public static string CreateSelectMenuID(string name, params string[] path)
=> FormatID(SelectComponentName, name, null, path);
=> FormatID(_selectComponentName, name, null, path);

/// <summary>
/// Creates an ID string with state information that can be used with select menu components.
Expand All @@ -138,7 +138,7 @@ public static string CreateSelectMenuID(string name, params string[] path)
/// </param>
/// <returns>The custom ID.</returns>
public static string CreateSelectMenuIDWithState(string name, string state, params string[] path)
=> FormatID(SelectComponentName, name, state, path);
=> FormatID(_selectComponentName, name, state, path);

/// <summary>
/// Creates an ID string that can be used with modals.
Expand Down
Loading

0 comments on commit c5f0992

Please sign in to comment.