Giter Site home page Giter Site logo

jdak's Introduction

JDAK - JDA Command Framework in Kotlin

A Light-Weight, Fast, Flexible, Functional Programming Command framework for JDA written in Kotlin

  • High performance
  • Support all Application Commands
  • Auto complete, Middlewares and more!
  • Functional Programming style

Installation

Maven

<dependency>
    <groupId>io.github.sonmoosans</groupId>
    <artifactId>jdak</artifactId>
    <version>1.2.0</version>
</dependency>

Gradle

implementation 'io.github.sonmoosans:jdak:1.2.0'

Getting Started

val jda = JDABuilder.createDefault(System.getenv("TOKEN"))
    .build()
    .awaitReady()

JDAK.global(jda) {
    //put your global commands here
}

JDAK.guilds(jda, guilds) { 
    //put your guild-only commands here
}

Creating a Slash command

slashcommand("hello", "Say hello") {
    //options
    val text = string("text", "text to send")
    val size = int("size", "Size of text").optional()
    
    //handle interaction events
    onEvent {
        event.reply("${text.value} in size of ${size.value}").queue()
    }
}

Creating a Context command

usercommand("Test") {
    it.reply("Hello World").queue()
}

messagecommand("Test") {
    it.reply("Hello World").queue()
}

Nested Slash commands

For more information, read Discord's documentation

//root command
slashcommand("test", "debug commands") {
    //subcommand group
    group("beta", "Beta features") {
        //subcommand
        subcommand("kill", "Kill someone") {
            val user = user("user", "The selected user")
            
            onEvent {
                event.reply("Killed ${user.value.asMention}").queue()
            }
        }
    }
}

Auto Complete

We have built-in support for auto-complete which allows you to setup auto-complete in few lines of code

slashcommand("hello", "Say hello") {
    val text = string("text", "text to send")
        .autoComplete {
            mapOf(
                "Hello" to "World",
                "Money" to "Shark"
            )
        }

    onEvent {
        event.reply(text.value).queue()
    }
}

Localizations

We support localizations for all Application commands

messagecommand("Test", mapOf(DiscordLocale.CHINESE_TAIWAN to "測試")) {
    it.reply("Hello World").queue()
}

slashcommand("test", "debug commands") {
    nameLocale = mapOf(
        DiscordLocale.CHINESE_TAIWAN to "測試"
    )

    onEvent {
        event.reply("Killed ${target.value.asMention}").queue()
    }
}

Middleware

Middleware can be used to check for permissions when the user uses specified commands
It allows you to control the event handler for each command

//Check if the bot has admin permissions
middleware({ event, next ->
    val member = event.member

    if (member == null) {
        println("Outside of guild")
    } else if (member.permissions.contains(Permission.ADMINISTRATOR)) {
        println("Are you admin!")
    } else {
        println("Ignore event: Missing permissions")

        return@middleware
    }

    next() //call the next handler
}) {
    protectedCommands()
}

Permissions

JDAK also supports to set guildOnly and permissions options

messagecommand("Test",
    guildOnly = true,
    permissions = DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR)
) {
    it.reply("Hello World").queue()
}

slashcommand("test", "debug commands") {
    guildOnly = true
    permissions = DefaultMemberPermissions.enabledFor(Permission.ADMINISTRATOR)
    
    val target = user("target", "The target to kill")
    
    onEvent {
        event.reply("Killed ${target.value.asMention}")
            .queue()
    }
}

Limit

We only support Application commands, text commands are not supported

jdak's People

Contributors

fuma-nama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.