Skip to content
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

Add new extension: DSharpPlus.Commands #1680

Merged
merged 110 commits into from
Jan 30, 2024
Merged

Conversation

OoLunar
Copy link
Member

@OoLunar OoLunar commented Nov 12, 2023

Summary

At the moment, both CommandsNext and SlashCommands are relatively unmaintained while containing a lot of... unoptimized code. Additionally, having these packages separate will force the consuming user to choose between text commands or interactions. This extension unifies all command frontends through command processors.

Requirements

Roadmap

Feature Currently Supported
Text Commands Yes
Slash Commands Yes
Command Aliases Text Commands
Generated Aliases No
Command Groups Yes
Custom Argument Type Converters Yes
Per Argument Type Converters Yes*
Built In Help Command No
Params (Auto Generated Arguments) Yes
XML Documentation No
Translation Classes Yes
Pre-Execution Checks Yes

Notes

Light testing has been done and core functionality is guaranteed, however more thorough testing is required.

@akiraveliara
Copy link
Member

as a first thing before i start reviewing: we should probably consider naming it something like Commands without suffix; and i believe the same pull request should also annotate UseCommandsNext and UseSlashCommands as obsolete, for removal sometime in the v5 cycle; either in 5.0 if it takes a while, or in a following minor release.

@OoLunar
Copy link
Member Author

OoLunar commented Nov 12, 2023

Because the rest of DSharpPlus is on .NET 7, I've chosen to keep CNext and Slashies not obsolete until .NET 8 releases

@akiraveliara
Copy link
Member

that'll be in a few days, and probably before merging this PR

@OoLunar
Copy link
Member Author

OoLunar commented Nov 12, 2023

Done

@OoLunar OoLunar changed the title Add new extension: CommandAll Add new extension: DSharpPlus.Commands Nov 12, 2023
@InFTord
Copy link
Member

InFTord commented Nov 13, 2023

Before any documentation work happens, i would suggest to archive old command articles, instead of removing them completely

Copy link
Member

@akiraveliara akiraveliara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overarching points:

  1. consider renaming DSharpPlus.Commands.Commands. since it mostly deals with construction of a command tree; DSharpPlus.Commands.Trees? Done - Lunar
  2. i really don't like multiple types in one file, it makes it harder to find these types later
  3. what exactly is the DX for configuring different processors? this seems a little doubtful given the implementation, but maybe you have a solution
  4. attributes should never contain logic, and much less throw exceptions. i believe @Instellate had a good design for checks in Introducing a new command framework #1553
  5. this looks like it is restricting text commands to the same or similar parameters as application commands, which i don't exactly like - application commands are relatively limited, ie in nesting depth and in not supporting overloads.

DSharpPlus.Commands/AbstractContext.cs Outdated Show resolved Hide resolved
DSharpPlus.Commands/AbstractContext.cs Outdated Show resolved Hide resolved
DSharpPlus.Commands/CommandExecutor.cs Outdated Show resolved Hide resolved
DSharpPlus.Commands/CommandExecutor.cs Outdated Show resolved Hide resolved
DSharpPlus.Commands/CommandExecutor.cs Outdated Show resolved Hide resolved
DSharpPlus.Commands/Processors/TextCommands/TextLogging.cs Outdated Show resolved Hide resolved
Directory.Packages.props Outdated Show resolved Hide resolved
DSharpPlus.Commands/Converters/ByteConverter.cs Outdated Show resolved Hide resolved
DSharpPlus.Commands/Converters/DateTimeConverter.cs Outdated Show resolved Hide resolved

public interface IArgumentConverter<TEventArgs, TOutput> : IArgumentConverter where TEventArgs : AsyncEventArgs
{
public Task<Optional<TOutput>> ConvertAsync(ConverterContext context, TEventArgs eventArgs);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience I use argument converters for some network related calls, such as to a db or external website. Shouldn't task be used when the CPU is idling?

@OoLunar
Copy link
Member Author

OoLunar commented Nov 14, 2023

what exactly is the DX for configuring different processors? this seems a little doubtful given the implementation, but maybe you have a solution

What do you mean by DX?

@akiraveliara
Copy link
Member

developer experience, as in, how tedious is it to configure a command processor

.github/workflows/build-commit.yml Outdated Show resolved Hide resolved
}
}

// If we didn't find the user in the guild, try to get the user from the API.
Copy link
Member

@Plerx2493 Plerx2493 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like making hidden calls in converters maybe we can introduce a option to configure if we should make calls here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can do that

{
add
{
if (this.UseDefaultCommandErrorHandler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should toggle this.UseDefaultCommandErrorHandler when we unregister it

this._commandErrored.Register(DefaultCommandErrorHandlerAsync);
}

// Attempt to get the user defined logging, otherwise setup a null logger since the D#+ Default Logger is internal.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should open internals when merging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should generally revamp that logger

DSharpPlus.Commands/ExtensionMethods.cs Show resolved Hide resolved
}

[SuppressMessage("Roslyn", "CA1859", Justification = "Incorrect warning in NET 8-rc2. TODO: Open an issue in dotnet/runtime.")]
private async Task<DiscordApplicationCommandOption> ToApplicationParameterAsync(Command command, CommandParameter parameter, int? i = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a bit more describtive parameter name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's... the parameter you're converting to an application parameter. How much more descriptive could it get?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was talking about the last parameter, its confusing when you read a long method and then theres a random i

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH. Yeah I can do that

@OoLunar OoLunar mentioned this pull request Nov 15, 2023
@OoLunar OoLunar marked this pull request as ready for review January 30, 2024 15:37
@OoLunar
Copy link
Member Author

OoLunar commented Jan 30, 2024

All changes and review comments will be moved into issues as we need to start receiving user feedback soon. Merging into nightlies.

@akiraveliara
Copy link
Member

i'll take a cursory look for intolerable flaws and then sign off on this

@akiraveliara
Copy link
Member

:shipit:

@akiraveliara akiraveliara self-requested a review January 30, 2024 15:44
Copy link
Member

@InFTord InFTord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will probably make a separate issue/pr about xmldocs, and gonna write some of those myself.
other than that, lgtm!

@OoLunar OoLunar merged commit 8f0f9a8 into DSharpPlus:master Jan 30, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants