Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.
/ bot-kt Public archive

Easy to use Kotlin Discord bot framework

License

Notifications You must be signed in to change notification settings

5HT2/bot-kt

Repository files navigation

bot-kt

CodeFactor Docker Action Gradle Action

Why should you use this over other Kotlin bots:

  • Plugin support in the form of Kotlin
  • Extremely easy to add your own commands
  • Really easy to configure
  • Entirely modular, including config types and commands
  • Config types support providing a URL instead of a file name, allowing you to load configurations remotely
  • Command registration is automatic, just create an object which extends BotCommand(name = "Example", description = "Example Command")
  • Has a DSL for our own Brigadier-like command system, making creating a command as easy as just writing a few lambdas
  • Has (optional) automatic updating

Contributing

  1. git clone --recurse-submodules https://github.com/l1ving/bot-kt.git
  2. In Intellij IDEA select File -> New -> Project from existing sources
  3. Import the build.gradle file
  4. Wait for the Gradle import to finish

Or without an IDE

  1. git clone https://github.com/l1ving/bot-kt.git
  2. cd bot-kt
  3. ./completeBuild.sh

Note: completeBuild.sh has the optional -s (silent) and --no-lint (don't require ktlint) options, in that order.

Usage

Create your config/auth.json like below. Generate githubToken with repo:status and public_repo access checked here and you can get your bot token here.

The githubToken is only required if you want to use any of the Github commands, such as ;issue

{
    "botToken": "token",
    "githubToken": "token"
}
`user.json` example

All elements are optional. statusMessageType defaults to "Playing".

{
    "autoUpdate": "true",
    "primaryServerId": "573954110454366214",
    "startUpChannel": "dev-bot",
    "statusMessage": "out for raids",
    "statusMessageType": "3"
}

Running

Running in Intellij

Hit the Run ▶️ button in the top right of your IDE, to the right of MainKt.

If the MainKt run configuration isn't imported automatically in Intellij, try File -> Close Project and then reopen the project.

If that still does not help, Hit Add Configuration in the upper right of your IDE, select the MainKt configuration on the left and hit Ok.

Running prebuilt binaries

java -jar bot-kt-v1.9.3.jar

Disabling update checking

If you're working on your own fork or just don't care for updates for some reason, you can create a file named noUpdateCheck in the same directory where you run the bot from.

If you're on Windows, please make sure you don't have .txt at the end, as Windows hides file extensions by default.

Creating a new command

Create an object in the commands package that extends BotCommand(name = "Example", description = "Example Command).

Look at ExampleCommand for example usage of our Command DSL.

Creating a new config type

Simply create a new dataclass inside FileManager, and register it inside ConfigType.

Here's an example:

object FileManager {
    var exampleConfigData: ExampleConfig? = null
}
/**
 * [someValue] is a value from inside your example.json
 */
data class ExampleConfig(val someValue: String)
/**
 * Note that [configPath] can also be an https URL, but you will not be able to write the config if it's a remote URL. This is fine for remotely configuring a setting.
 */
enum class ConfigType(val configPath: String, var data: Any?, val clazz: Class<*>) {
    EXAMPLE("example.json", exampleConfigData, ExampleConfig::class.java);
}

Storing the value: (can be a remote file online or just a local file)

{
    "someValue": "This is a String value for my ExampleConfig"
}

Reading the value:

val config = FileManager.readConfigSafe<ExampleConfig>(ConfigType.EXAMPLE, false) // setting reload to true instead of false will forcefully load it from the URL / memory instead of returning the cached version

config?.someValue?.let {
    println("Value is '$it'")
}

// > Value is 'This is a String value for my ExampleConfig'