This document neither explains Kotlin, Kord, nor Kord-Extensions, if you don't know these things stop reading now before complaining about these things not getting explained
- What is a plugin
- How to make a plugin
- How to assemble a plugin
- How to run the bot
- How to dockerize the bot
- What are Extension Points
- The mikbot-api
- Featured plugins
To Mikbot a plugin is essentially a single file changing KordEx configurations, everything else is KordEx and therefor not explained here.
Kord-Extensions already provides "plugins", but KordEx calls them Extensions, a Mikbot plugin is simply one or more KordEx extensions + optional additional KordEx configuration housed in a zip file, therefor the plugin interface also has only 2 main functions
ExtensibleBotBuilder.ExtensionsBuilder.addExtensions()
which is to add ExtensionsExtensibleBotBuilder.apply()
which is to change the KordEx/ExtensibleBot configuration
And since you probably ignored the big warning at the top, you can read more about those here
If you want to make a plugin you should really use Gradle, using Maven, or no build tool at all is possible, but all official tooling is only provided for Gradle.
Example build.gradle.kts
This is the most basic configuration, for more options read the Gradle plugin documentation
plugins {
id("com.google.devtools.ksp") version "1.6.21-1.0.5" // used for plugin-processor
kotlin("jvm") version "1.6.21"
id("dev.schlaubi.mikbot.gradle-plugin") version "2.2.0"
}
repositories {
mavenCentral()
}
mikbotPlugin {
description.set("This is a cool plugin!")
provider.set("Schlaubi")
license.set("MIT")
}
Example Plugin main class
import com.kotlindiscord.kord.extensions.builders.ExtensibleBotBuilder
import dev.schlaubi.mikbot.plugin.api.Plugin
import dev.schlaubi.mikbot.plugin.api.PluginMain
import dev.schlaubi.mikbot.plugin.api.PluginWrapper
@PluginMain
class MyCoolPlugin(wrapper: PluginWrapper) : Plugin(wrapper) {
override suspend fun ExtensibleBotBuilder.ExtensionsBuilder.addExtensions() {
add(::MyExtension123)
}
}
You have 3 ways of building/distributing your plugin
-
The
assemblePlugin
task: Can be used to generate a single plugin.zip file (Found inbuild/plugin
) -
The
bot
distribution: Can be used to generate your own distribution of the bot bundling the plugin (Read more here) -
Plugin publishing: You can read more about that here
In case of File not found exception
Set ksp("dev.schlaubi", "plugin-processor", "2.2.0")
to implementation("dev.schlaubi", "plugin-processor", "2.2.0")
and reload your dependencies. Then change it back again. (Workaround)
Alternatively to generating a zip file, you can also use shadowJar, but make sure to add the manifest is added. For more information about Packaging read the packaging documentation and the plugins documentation
There are two ways to run the bot
- Running it from a distribution
- Running through Gradle
- You can read more about that here
If you want to dockerize a bot with bundled plugins, you can use this Dockerfile
FROM gradle:jdk22 as builder
WORKDIR /usr/app
COPY . .
RUN gradle --no-daemon installBotDist
FROM ibm-semeru-runtimes:open-22-jre-focal
WORKDIR /usr/app
COPY --from=builder /usr/app/install/bot-pluginName .
ENTRYPOINT ["/usr/app/bin/mikmusic"]
Extension points are interfaces plugins can provide for other plugins to implement. A good example is the gdpr plugin, which provides an interface for other plugins to add GDPR data points
The GDPR plugin has an extension point like this.
/**
* Extension point for GDPR functionalities.
*/
interface GDPRExtensionPoint : ExtensionPoint {
/**
* Provides the [DataPoints][DataPoint] of this module.
*/
fun provideDataPoints(): List<DataPoint>
}
Then another plugin can implement this data point like this
Implementations of ExtensionPoints are called Extensions, but have nothing to do with KordExteensions Extensions, which are the extensions added in the plugin main
@Extension
class Connect4GDPRExtensionPoint : GDPRExtensionPoint {
override fun provideDataPoints(): List<DataPoint> = listOf(Connect4StatsDataPoint, Connect4ProcessDataPoint)
}
The GDPR plugin can then access the data points like this
pluginSystem.getExtensions<GDPRExtensionPoint>().flatMap { it.provideDataPoints() }
The mikbot api itself provides some utilities itself in extension to kordex
The bot has a Connection to MongoDB using KMongo if database credentials are present, you can use these like this
object PluginDatabase : KordExKoinComponent {
val stats = database.getCollection<PluginStats>("plugin_stats")
}
The bot bundles stdx-envconf for configuration, you can find the bots own configuration file here
The bot has an AllShardsReadyEvent which is fired once all shards fired a ReadyEvent
The bot also has a Settings and Owner module, so you can group all related commands into a single KordExtensions Extension.
You can add commands to these extensions like this
@Extension
class YourPluginSettingsExtension : SettingsExtensionPoint {
override suspend fun SettingsModule.apply() {
disableBansCommand()
}
}
For the OwnerModule use the OwnerExtensionPoint
For the SettingsModule use the SettingsExtensionPoint
Both modules also have permission helpers
SlashCommand<*, *>.ownerOnly()
- registers the command onOWNER_GUILD
and requires the PermissionADMINISTRATOR
SlashCommand<*, *>.guildAdminOnly()
- disables the command in dms and requiresMANAGE_SERVER
There is currently no hosted documentation for all the utility classes, but they all have doc comments, you can read here
Plugin adding functionality to comply with the GDPR
Dependency: plugin("dev.schlaubi", "mikbot-gdpr", "<version>")
Docs: README.md
An API to have a webserver in multiple plugins on the same port powered by Ktor
Dependency: plugin("dev.schlaubi", "mikbot-ktor", "<version>")
Docs: README.md
- Read the Setup Guide to learn how to operate the bot runtime
- Read the Game API guide to learn how to make a game