Giter Site home page Giter Site logo

kordx.commands's People

Contributors

bartarys avatar drschlaubi avatar hopebaron avatar lukellmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kordx.commands's Issues

Bintray is deprecated

This extension is hosted on Bintray according to README.md, though it is impossible to fetch because JFrog deprecated Bintray. Is it possible to upload this extension to the Maven Central Repository?

RoleArgument not working

The regex of RoleArgument ('^<#&\d+>$') has an '#' instead of an '@', as roles look like this: <@&767105440315998218>

Breaks on latest Kord snapshots

Trying to use the bot function breaks with latest kord version

Exception in thread "main" java.lang.NoSuchMethodError: 'int dev.kord.core.ClientResources.getShardCount()'
    at today.howoldisjava8.discord_bot.LauncherKt.main(Launcher.kt:91)

The problem is this line

Since the called functions is inline when compiling kxc it inlined this code

https://github.com/kordlib/kord/blob/aa46ddf6aa7257d710dc535b4f4c26c95a38763a/core/src/main/kotlin/Kord.kt#L114-L128

but the implementation has been updated to

https://github.com/kordlib/kord/blob/62ab68e41ef24e55d73802efa4f0ba7158c15ddd/core/src/main/kotlin/Kord.kt#L115-L129

this causes problems as ClientResources.shardCount no longer exists

Don't create multiple instances of Commands and respective CommandData for each alias name.

Instead of creating multiple instances of the Command and CommandData in CommandBuilder.build, we can create single Command and store the aliases as List<String> and in BuildEnvironment.addCommand we can point primary name and each aliases to same instance of the Command.

Benefits:

  • Lookup time won't be affected. As we will still search the commands by LinkedHashMap#get, so the lookup time will still be O(1).
  • Startup of the application will get reduced, due to less work to do (not creating multiple soft copies of same command).
  • Heap size will be smaller.
  • Better to generalize the commands i.e. when creating a "help" command or something like that, we want to put aliases of commands together, and in current architecture we have to iterate through all the Command instances which are both alias and parent to respond with a message which will be expensive.
  • Will be easier to lookup for the other aliases, in current architecture if we want to find all the aliases for a command by one of its alias, we have to go through find Command instance representing alias then find parent command name from the aliasInfo and then re query the commands to find the parent Command instance cast its aliasInfo to AliasInfo.Parent then get list of all aliases.

The bot function should not login itself to the gateway.

Description of problem

If the bot function logs itself in, the user won't be able to use any functionality from the CommandsProcessor.
As such we can't get the list of commands, and the structure of the bot becomes inside-out (restricted to event handling).

One of the use-case of this (not automatically logging in) could be listen for MessageCreateEvent/MessageUpdateEvent and filter out the messages which does not contains the command in it. To filter this, one need reference to CommandsProcessor.commands and CommandsProcessor.prefix but it is impossible to do so with the bot function.
(creating bot with BotBuilder manually instead of bot() function is an option, but it will create noise in the code).

Suggested Solution

  • Change the bot function signature (not backward compatible):

    /**
     * Creates a bot with the given [kord] instance, applying [configure] to the bot's configuration.
     */
    suspend inline fun bot(kord: Kord, configure: KordProcessorBuilder.() -> Unit): CommandProcessor =
            BotBuilder(kord).apply { processorBuilder.configure() }.build()

    Doing this we can't assure the backward compatibility with the older function, but as this library wasn't stable and used much as of now we shall change the method signature.

  • Deprecate the current function and define new which can optionally login:

    @Deprecated(
        message = "Use bot(kord, login, configure) instead.",
        replaceWith = ReplaceWith("bot(kord, login = true, configure)"),
        level = DeprecationLevel.WARNING
    )
    suspend inline fun bot(kord: Kord, configure: KordProcessorBuilder.() -> Unit) {
        bot(kord, true, configure)
    }
    
    suspend inline fun bot(
            kord: Kord,
            login: Boolean,
            configure: KordProcessorBuilder.() -> Unit
    ): CommandProcessor =
            BotBuilder(kord)
                    .apply { processorBuilder.configure() }
                    .build()
                    .also { if (login) kord.login() }

Allow command aliases to supplied at command creation.

Currently aliases are supplied when configuring commands:

command(name) {
    alias(aliasOne, aliasTwo, aliasThree)
    
    invoke {
        //....
    }
}

It would be rather simple and more concise to also allow these to be supplied after the name:

command(name, aliasOne, aliasTwo, aliasThree) {
    
    invoke {
        //....
    }
}

I don't think we'll ever use the arguments after a command's name for anything else, so there's not much risk capitalising the space like this.

Add support for sub commands

You should be able to add sub commands to a command like this

command("main") {
   command("sub") {
     command("subsub") {
     }
   }
}

Feature Improvements

Suggestions

  • Command error handling for those thrown in execution
  • Support for message edits when processing commands
  • Possible DSL for error handlers
  • DSL for building markdown in descriptions + optional escaping

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.