Matt-MX/KtPaperGui

Option & Flag arguments

Matt-MX opened this issue · 1 comments

Declarative commands should have a flag/option argument type introduced.

Example implementation

val player by username()
val after by optionArgument<Date>()
val order by optionArgument<OrderByEnum>()
val boolean_option by flag()

("history" / player) {
    + after // Register the after argument
    + order // Alternatively call .withKeyValue(order) for java

    runs<CommandSender> {
        val records = Database.queryHistory(player)
            .recordsAfterDate(after())
            .orderBy(order())
            .get()
            
        if (records.isEmpty)
            return@runs reply(!"&cThat user has no records.")
            
        for (record in records) {
            reply(!record)
        }
    }
} register this

This example command would be invoked like this:

/history MattMX --after 13/06/2024 --order date_asc --boolean-option

The argument type's format should be relatively customizable.

/history MattMX -after:13/06/2024 -order:date_asc -boolean-option

These arguments should have permissions requirements for whomever executes them.

val max_results by optionArgument<Int>()

// `value` is the supplied value as an Int at invocation.
max_results requires { sender.getHighestPermissionLevel("history.max_results") >= value }
max_results permission { sender.reply(!"&cYou can't query that many max results!") }
max_resutls default 10

// ...