Plug and PlugSockets - kordlib/kordx.commands GitHub Wiki
Plugs
are a way to autowire classes that don't directly fit the existing structures. If you need to autowire something that's not part of the CommandProcessor
but related to it, you use a Plug
and PlugSocket
.
An example implementation is the EventListener
Simply provide an implementation of the Plug
:
class PrintingPlug : Plug {
fun print(message: String) {
println(message)
}
}
PlugSockets
are classes that will directly interact with Plugs
.
class PrintingPlugSocket : PlugSocket {
override suspend fun handle(container: plugContainer) {
container.getPlugs<PrintingPlug>().forEach { it.print("hello world") }
plugs.foreEach { it.print("hello world!") }
}
}
you can manually add plugs and sockets to your ProcessorBuilder
:
fun ProcessorBuilder.addDepedencies(plugs: List<PrintingPlug>, socket: PrintingPlugSocket) {
plugs.forEach { +it }
+socket
}
Alternatively you can use Autowiring to do it automatically.