Skip to content

Lightweight command manager for Kord (The Kotlin Discord API wrapper)

License

Notifications You must be signed in to change notification settings

Azuyamat/Kormmand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kormmand

A simple command, button, select menu and modal manager for Kord, a Kotlin Discord API wrapper.

This project is no longer being maintained. Short-lived, resting in peace, awaiting its sequel.

GitHub release (latest by date)

Planned features:

  • Slash command manager
  • Button manager
  • Select menu manager
  • Modal manager
  • Automatic help menu

Made with love by @azuyamat

Azuyamat logo

Table of Contents

Installation

Kormmand is available on Jitpack. Here is how to add it to your project.

Note: Replace Tag with the latest version of Kormmand.

Maven

Repository

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

Dependency

<dependency>
    <groupId>com.github.Azuyamat</groupId>
    <artifactId>Kormmand</artifactId>
    <version>Tag</version>
</dependency>
Gradle

Repository

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

Dependency

dependencies {
        implementation 'com.github.Azuyamat:Kormmand:Tag'
}
Kotlin Gradle

Repository

repositories {
    mavenCentral()
    maven("https://jitpack.io")
}

Dependency

dependencies {
    implementation("com.github.Azuyamat:Kormmand:Tag")
}

Usage

Commands

Command image

Creating a command

To create a command, start by initializing a class that extends the Command interface. Don't forget to include @CommandClass and @InteractionClass annotations. Otherwise, the command won't be registered.

@InteractionClass
@CommandClass
class HelpCommand : Command {
    override val name: String = "help"
    override val description: String = "Show the help menu."

    override suspend fun execute(event: GuildChatInputCommandInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "This is a test" }
    }
}

Registering commands

For commands to function, they must first be registered. To do this, you must create a CommandManager and register the commands via their package name.

Multiple command

Global commands

val commandManager = CommandManager(kord).apply {
    registerInteractions("commands")
}

Guild commands

Registering guild commands only requires that you add the guild id as a parameter.

val commandManager = CommandManager(kord).apply {
    registerInteractions("commands", "GUILDID")
}

Permission requirements

To add permission requirements to a command, you must add the permission property to the command.

@InteractionClass
@CommandClass
class HelpCommand : Command {
    override val name: String = "help"
    override val description: String = "Show the help menu."
    override val permission: Permission = Permission.Administrator

    override suspend fun execute(event: GuildChatInputCommandInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "You are an admin!" }
    }
}

Adding subcommands

To add subcommands to a command, you must add the builder property to the command.

@InteractionClass
@CommandClass
class HelpCommand : Command {
    override val name: String = "help"
    override val description: String = "Show the help menu."
    override val builder: GlobalChatInputCreateBuilder.() -> Unit = {
            subCommand("info", "Get info about a user."){
                user("user", "The user to get info about.")
            }
        }

    override suspend fun execute(event: GuildChatInputCommandInteractionCreateEvent) {
        val interaction = event.interaction
        val c = interaction.command
        val subCommandName = when (c) {
            is RootCommand -> null
            is GroupCommand -> c.name
            is SubCommand -> c.name
        }

        if (subCommandName == "info") {
            interaction.respondPublic {
                content = "This is a test" 
            }
        }
    }
}
Buttons

Button image

Creating a button

To create a button, start by initializing a class that extends the Button interface. Don't forget to add the @InteractionClass annotation. Otherwise, the button won't be registered.

@InteractionClass
class HelpButton : Button {
    override val id: String = "help"
    override val name: String = "help" // Not required for buttons
    override val description: String = "Show the help menu." // Not required for buttons

    override suspend fun execute(event: ButtonInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "This is a test" }
    }
}

Registering buttons

For a button to function, it must be registered by the bot at runtime. To do this, you must create a ButtonManager and register the button.

Multiple buttons
val buttonManager = ButtonManager(kord).apply {
    registerInteractions("buttons")
}
Guild-specific buttons

Don't know why you'd do this but you can register buttons that will only run in specific guilds

val buttonManager = ButtonManager(kord).apply {
    registerInteractions("buttons", "GUILDID")
}

Permission requirements

To add permission requirements to a button, you must add the permission property to the button.

@InteractionClass
class HelpButton : Button {
    override val name: String = "help" // Not required for buttons
    override val description: String = "Show the help menu." // Not required for buttons
    override val permission: Permission = Permission.Administrator

    override suspend fun execute(event: ButtonInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "You are an admin!" }
    }
}
Modals

Modal image

Creating a modal

To create a modal, start by initializing a class that extends the Modal interface. Don't forget to add the @InteractionClass annotation. Otherwise, the modal won't be registered.

@InteractionClass
class HelpModal : Modal {
    override val id: String = "modal"
    override val name: String = "modal" // Not required for modals
    override val description: String = "Show the help menu." // Not required for modals

    override suspend fun execute(event: ModalSubmitInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "This is a test" }
    }
}

Registering modals

For a modal to function, it must be registered by the bot at runtime. To do this, you must create a ModalManager and register the modal's package.

Multiple modals
val modalManager = ModalManager(kord).apply {
    registerInteractions("modals")
}
Guild-specific modals

Don't know why you'd do this but, you can register guild-specific modals

val modalManager = ModalManager(kord).apply {
    registerInteractions("modals", "GUILDID")
}

Permission requirements

To add permission requirements to a command, you must add the permission property to the modal.

@InteractionClass
class HelpModal : Modal {
    override val name: String = "help" // Not required for modals
    override val description: String = "Show the help menu." // Not required for modals
    override val permission: Permission = Permission.Administrator

    override suspend fun execute(event: ModalSubmitInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "You are an admin!" }
    }
}
Select Menus

Menu image

Creating a select menu

To create a select menu, start by initializing a class that extends the SelectMenu interface. Don't forget to add the @InteractionClass annotation. Otherwise, the select menu won't be registered.

@InteractionClass
class HelpMenu : SelectMenu {
    override val id: String = "jeff"
    override val name: String = "jeff" // Not required for select menus
    override val description: String = "Show the help menu." // Not required for select menus

    override suspend fun execute(event: SelectMenuInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "This is a test" }
    }
}

Registering a menu

For a select menu to function, it must be registered by the bot at runtime. To do this, you must create a SelectMenuManager and register the select menu's package.

Multiple select menus
val selectMenuManager = ModalManager(kord).apply {
    registerInteractions("selectMenus")
}
Guild-specific select menus

Once again, don't know why you'd do this but you can register guild-specific select menus

val selectMenuManager = ModalManager(kord).apply {
    registerInteractions("selectMenus", "GUILDID")
}

Permission requirements

To add permission requirements to a command, you must add the permission property to the select menu.

@InteractionClass
class HelpMenu : SelectMenu {
    override val name: String = "help" // Not required for select menu
    override val description: String = "Show the help menu." // Not required for select menu
    override val permission: Permission = Permission.Administrator

    override suspend fun execute(event: SelectMenuInteractionCreateEvent) {
        event.interaction.respondPublic {
            content = "You are an admin!" }
    }
}

Note: Buttons, modals and select menus use the first part of the interaction id. This means you can split your interaction id by // and use the first part as the id while having the rest as interaction parameters.

Example:

val task = interaction.modalId.split("//")[1]

Contributing

Contributions are welcome! If you have any issues or feature requests, please open an issue or a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Lightweight command manager for Kord (The Kotlin Discord API wrapper)

Topics

Resources

License

Stars

Watchers

Forks

Languages