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
git clone --recurse-submodules https://github.com/l1ving/bot-kt.git
- In Intellij IDEA select
File -> New -> Project from existing sources
- Import the
build.gradle
file - Wait for the Gradle import to finish
git clone https://github.com/l1ving/bot-kt.git
cd bot-kt
./completeBuild.sh
Note: completeBuild.sh
has the optional -s
(silent) and --no-lint
(don't require ktlint) options, in that order.
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"
}
Hit the Run
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.
java -jar bot-kt-v1.9.3.jar
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.
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.
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'