Skip to content

Flight 2.0.0a

Pre-release
Pre-release
Compare
Choose a tag to compare
@devoxin devoxin released this 21 Apr 22:36
· 58 commits to master since this release

This update introduces subcommands. While I don't feel like the implementation is a clean one, subcommands do appear to work as per my testing.

The help command has not been updated to support subcommands yet.
Executing a command without specifying a subcommand will invoke the top-level command. To make the top-level command send a list of available subcommands, you can do something like;

@Command
fun mycommand(ctx: Context, subcommand: String?) {
    val cmd = ctx.invokedCommand as CommandFunction

    val sc = buildString {
        for (c in cmd.subcommands.values.toSet()) {
            appendln("${c.name}: ${c.properties.description}")
        }
    }

    if (subcommand != null) {
        ctx.send("`${subcommand}` isn't a valid subcommand. Try one of these:\n$sc")
    } else {
        ctx.send("Available Subcommands:\n$sc")
    }
}

Added

  • Context.invokedCommand.
    • This is an executable, but if the invoked command is a subcommand, this can be cast to SubCommandFunction.
    • The same applies if the invoked command is a top-level command; it can be cast to CommandFunction.

Removed

  • Removed CommandRegistry.registerCommands shortcuts from CommandClient.

Changed

  • Renamed CommandRegistry.registerCommands to CommandRegistry.register.
  • Moved execution stuff to Executable class. This makes it a little more streamlined to execute commands.
  • Command categories are now detected by package name. This behavior can be changed by overriding Cog.name() to return a non-null string.