-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commands Processor Cleanup #2075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
30cfcd8
to
7aeef2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At an absolute bare glance, there isn't much that looks off - I do have questions and concerns, but with the vague notion of "only large design issues" wishing to be addressed, I've commented on anything abhorrently problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some functional issues to fix
re: formatting, that isn't how contributing to a project works at all, and while your IDE breaking is somewhat of an argument i do have grievances with going out and making the formatting worse to then tell other people to go and fix that. i do not think that's okay.
re pooling multi-argument parameter arrays, i took a brief look at that and it's not really worth it, these arrays are relatively small - it could be worth it for arrays of very large flat types (like making an Int512 type in flat memory), but for reference-type and primitive arrays it's not usually worth it, particularly not for slash commands
DSharpPlus.Commands/ArgumentModifiers/MultiArgumentAttribute.cs
Outdated
Show resolved
Hide resolved
DSharpPlus.Commands/Processors/SlashCommands/EnumAutoCompleteProvider.cs
Outdated
Show resolved
Hide resolved
DSharpPlus.Commands/Processors/SlashCommands/Localization/LocalesHelper.cs
Outdated
Show resolved
Hide resolved
Checking to see if I can rebase the PR or not. Rerequesting in a moment.
ac48e92
to
fe3e25e
Compare
…actory`; Fixed runtime startup exceptions
…t static implementation on every command processor
- Finish moving `GetConverterFriendlyBaseType` - Prevent `AddConverter` from throwing when the same converter is attempting to be added again - Early return on `ParseParametersAsync` when no parameters need to be parsed - Move default value logic from `ParseParametersAsync` to `ParseParameterAsync` - `ParseParameterAsync` now provides the value that failed to parse when returning `ArgumentFailedConversionValue` - `ExecuteConverterAsync<T>` now handles multi-argument parameters
consider "variadic parameters" instead of "var-arg parameters" in docs - that's actually english :P |
docs/articles/commands/processors/slash_commands/translator_providers.md
Outdated
Show resolved
Hide resolved
docs/articles/commands/processors/text_commands/command_aliases.md
Outdated
Show resolved
Hide resolved
* Oops! I sneezed. * One of you hooligans needs to fix your IDE formatting. `dotnet format` * Fix context menu processors requiring exact types instead of ish types * ConfigureCommands event from #1680 * Documentation; Changed equality implementation on `ConverterDelegateFactory`; Fixed runtime startup exceptions * Move `GetConverterFriendlyBaseType` to `IArgumentConverter` to prevent static implementation on every command processor * Several bug fixes to argument parsing and conversion logic - Finish moving `GetConverterFriendlyBaseType` - Prevent `AddConverter` from throwing when the same converter is attempting to be added again - Early return on `ParseParametersAsync` when no parameters need to be parsed - Move default value logic from `ParseParametersAsync` to `ParseParameterAsync` - `ParseParameterAsync` now provides the value that failed to parse when returning `ArgumentFailedConversionValue` - `ExecuteConverterAsync<T>` now handles multi-argument parameters * Shadow `InteractionConverterContext.Argument` so `ConverterContext.Argument` can still be the raw value * Fix enum parsing for text commands, which now properly supports boxing (is it called boxing?) * There can only be one reply to a Discord message * Defer multi-argument parameter parsing to the base implementation * Theoretically add support for `TextMessageReplyAttribute` to most argument converters * Use `IArgumentConverter.GetConverterFriendlyBaseType` * Configure commands event args. This is non-negotiable. * Use `IArgumentConverter.GetConverterFriendlyBaseType]`; Defer multi-argument parameter parsing to the base implementation * `IArgumentConverter.GetConverterFriendlyBaseType`; Theoretically better support multi-argument parameters with slash registration * Update deps * Resolve 1 nullable warning * Fix logic within user command registration, no longer allowing it to be forever false * Remove old event registration logic * Expose `IServiceProvider` instead of pointlessly hiding it * Switch from `AsyncEventArgs` to `DiscordEventArgs` * Move converter result values to their own namespace instead of repeatedly redeclaring on generic types * Remove ConverterFriendlySearchFlags; Add new `EnumConverter<T>`; Use the generic version of EnumConverter for parameters. * Fix compiler errors * Fix params registering all parameters as required * Fix choice providers not registering; Correctly isolated slash command logic away from the command parameter builder; Add an autocomplete provider for enums with more than 25 fields * Remove object constructors and replace them with more type-specific constructors for compile-time safety. * Vast improvements to the autocomplete and choice providers API - `SlashAutoCompleteProviderAttribute.AutoCompleteAsync` and `SlashChoiceProviderAttribute.GrabChoicesAsync` will now truncate when more than 25 elements are provided. - When options are truncated, it will log which source gave too many options, which it previous didn't. - When the type cannot be created, it will log which type failed along with the exception. - Try to use the numeric values for enums when possible, serializing only to `string` when the base type is `ulong`. - Support double and float enums, because apparently that's a thing? - Change the method signatures to return an enumerable of the object directly instead of dictionaries - Remove `SnakeCasedNameAttribute` in it's entirety, replacing it with `IParameterNamingPolicy`. * Fix compiler error * Expose the conversion result to `ArgumentParseException`; Documentation on related members. * Missed a spot * Fields to properties * Correctly apply limit * Just git- I mean get * Line feeds? * `git diff --name-only --diff-filter=AM master | grep ".cs" | xargs -I{line} echo \'{line}\' | xargs dotnet csharpier` * Update deps * Add generic overloads * Format code in docs * Grammar; New empty `T : new()` generic restraint on `AddConverter<T>()` * Update autocomplete/choice provider documentation * Update the missing slash commands section * Rename `DSharpPlus.Commands.Processors.SlashCommands.ParameterNamingPolicies` to `DSharpPlus.Commands.Processors.SlashCommands.NamingPolicies` * New `Naming Policies` article * Document multi-argument parameters * Don't throw when enums fail to convert * Support all time units from nanosecond to years * Give converters their own section; Briefly go over built-in argument converters and their quirks * Add a guide for invoking argument converters manually * Enforce max argument count in MAPs * Undo formatting from `dotnet csharpier` The new formatting now follows two very simply rules: - If it does not go beyond the end of my 1080p screen with the file bar open, it stays inlined. - If Roslyn didn't yell at me about it. * Allow 3rd party command processors to implement their own generic enum converter * Begone MAPs, welcome in VAPs * Remove raw numbers :( * Footnote * Formatting * #1362 was never merged * Throw away the rest of the MAPs * docs * Interface checks * Variadic * Attempt to resolve #1950 * Rename `ParameterNamingPolicy` to `NamingPolicy`; Fix inverted if statement * Use `GetCultureInfo` * More docs * Localizing interactions * Double space * Fix final GitHub review
Summary
When writing up #2042, @quinchs had helpfully pointed out that the event args generic constraint is not required at all for invoking argument converters - instead the relevant data should be extracted to the most specific converter context type and passed to the
ConvertAsync
delegate through abstract classes - very similar to how we currently doCommandContext
s. This PR grew significantly larger than intended as it involved cleaning up the base command processor, extracting logic to other classes or merging duplicate code into virtual methods. Here's a generalized changelog of what's been done so far:DiscordInteractionData.Options
from anIEnumerable
to aIReadOnlyList
.DiscordEventArgs
generic constraint fromBaseCommandProcessor<TEventArgs, TConverter, TConverterContext, TCommandContext>
, completely removing the dependency on event arguments.BaseCommandProcessor.ConverterDelegateFactory.cs
.BaseCommandProcessor
now virtually handles argument parsing, default values,params
and other argument parsing related logic. Closes Issue with Slash Commands not Delimiting multiple entries in Discord #1954.InteractionNamingPolicy
for interaction command names and parameters. By default,SnakeCaseNamingPolicy
is used, howeverKebebCaseNamingPolicy
andLowerCaseNamingPolicy
are available. Additionally the user can implement their own naming policy if they desire. Closes InteractionLocalizerAttribute does not snake-case slash command names and args #1950. RemovesSnakeCasedNameAttribute
.MultiArgumentAttribute
. By default, theCommandParameterBuilder
will add theMultiArgumentAttribute
to the parameter when params is found.int.MaxValue
is used to differentiate between params and explicitly definedMAA
's. Attempts to correctly spread out interaction options when multiple multi-argument parameters are present, considering min/max values.TextMessageReplyAttribute
is now implicitly supported by most argument converters.params
.IArgumentConverter.GetConverterFriendlyBaseType
method, which is required for all argument conversion methods.ConfigureCommand
event, allowing for mass mutations on command builders and command parameters before they're verified and built. This is non-negotiable.InteractionConverterContext.Argument
soConverterContext.Argument
can still be the raw value.Notes
Tested. Only accepting feedback regarding grand design or possible functional bugs. Other feedback regarding docs, formatting or nits will be discarded - you have push access to this branch and I'd expect those final changes to be made before merging, not during active development.
Generated Changelog
This changelog does not account for renames and does include internal/private members.
New Types:
MultiArgumentAttribute
ArgumentFailedConversionResult
ArgumentNotParsedResult
ConfigureCommandsEventArgs
ConverterDelegateFactory
MessageCommandLogging
EnumAutoCompleteProvider
EnumOptionChoiceProvider
IInteractionNamingPolicy
KebabCaseNamingPolicy
LowercaseNamingPolicy
SnakeCaseNamingPolicy
UserCommandLogging
Removed Types:
SnakeCasedNameAttribute
ConverterSentinel
LazyConverter
EnumOptionProvider
Added Methods:
Removed Methods:
Added Properties:
Removed Properties:
Added Fields:
Removed Fields:
Added Events:
CommandsExtension.ConfiguringCommands