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

Enable dynamic command names #2

Open
Nikey646 opened this issue Nov 6, 2020 · 4 comments
Open

Enable dynamic command names #2

Nikey646 opened this issue Nov 6, 2020 · 4 comments

Comments

@Nikey646
Copy link

Nikey646 commented Nov 6, 2020

Being capable of defining the group or command name at runtime would be nice.

This would allow applications to use an external source (EG: a configuration file) to define the structure of commands.

@Nihlus
Copy link
Member

Nihlus commented Nov 6, 2020

It'd be an interesting thing to have - I am, however, not too sure how I'd make an API like that look. Do you have any examples of how you'd like to use it, or how you'd hook into the various parameters of the defined commands?

Spitballing, I think my first go at it would start by abstracting out information about the structure of a command into a separate container, and having that container be mutable at group registration time (probably via some fluent API, allowing runtime modification/overriding of fallback attributes).

Maybe something like this?

serviceCollection.AddCommandGroup<MyGroup>
(
    g => g
        .WithCommand(MyGroup.MyCommand)
        .WithNamedParameter
        ( 
            // unsure of how to access parameters here - by name, index, or either/both? //
            longName: "my-parameter",
            shortName: 'p'
        )
)

I know Discord.NET has something like this, but I'm not familiar with that portion of their API.

@Nikey646
Copy link
Author

Nikey646 commented Nov 7, 2020

The start of the Discord.Net implementation is CommandService.CreateModuleAsync

The usage for the metadata that Remora.Commands has similar to

// ModuleBuilder is the type
commandService.CreateModuleAsync(group, (ModuleBuilder b) => b.AddCommand(command, ExecuteCommandFunc, CreateCommandFunc);

void CreateCommandFunc(CommandBuilder builder)
{
    builder.AddAliases("b", "c")
                .AddParameter(name, type, CreateParameterFunc);
}

void CreateParameterFunc(ParameterBuilder builder) 
{
    builder.TypeReader = myTypeReader;
}

A similar pattern could be used if you wanted to do something similar to Discord.Net.

@Nihlus
Copy link
Member

Nihlus commented Nov 8, 2020

Right, I see, so it creates groups without involving declaring a class at all. That's interesting - it's a lot more involved than I first considered.

@Nikey646
Copy link
Author

Nikey646 commented Nov 9, 2020

Correct, it basically allows the user to construct the equivalent of the CommandNode / GroupNode via an API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants