mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-11-21 23:23:47 +00:00
start 1.1.2 + add opportunity to load object plugins
This commit is contained in:
parent
5ec1c8c55f
commit
e0a19bb5e5
@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## 1.1.2
|
||||
|
||||
* `Plugin`:
|
||||
* Now it is possible to use `object`s of plugins instead of classes
|
||||
|
||||
## 1.1.1
|
||||
|
||||
* `Versions`
|
||||
|
@ -18,7 +18,7 @@ import org.koin.dsl.module
|
||||
|
||||
@Serializable
|
||||
@SerialName("Hello")
|
||||
class HelloPlugin : Plugin {
|
||||
object HelloPlugin : Plugin {
|
||||
@Serializable
|
||||
data class HelloPluginConfig(
|
||||
val print: String
|
||||
|
@ -56,17 +56,17 @@ data class PlaguBot(
|
||||
}
|
||||
|
||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||
config.plugins.map {
|
||||
config.plugins.map { plugin ->
|
||||
launch {
|
||||
runCatchingSafely {
|
||||
logger.i("Start loading of $it")
|
||||
with(it) {
|
||||
logger.i("Start loading of $plugin")
|
||||
with(plugin) {
|
||||
setupBotPlugin(koin)
|
||||
}
|
||||
}.onFailure { e ->
|
||||
logger.w("Unable to load bot part of $it", e)
|
||||
logger.w("Unable to load bot part of $plugin", e)
|
||||
}.onSuccess {
|
||||
logger.i("Complete loading of $it")
|
||||
logger.i("Complete loading of $plugin")
|
||||
}
|
||||
}
|
||||
}.joinAll()
|
||||
|
@ -1,9 +1,11 @@
|
||||
package dev.inmo.plagubot.config
|
||||
|
||||
import dev.inmo.micro_utils.common.Warning
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Warning("This API is internal and can be changed without notifications of mentions of changes")
|
||||
@Serializable
|
||||
data class Config(
|
||||
val botToken: String,
|
||||
|
@ -5,4 +5,4 @@ kotlin.js.generate.externals=true
|
||||
kotlin.incremental=true
|
||||
|
||||
group=dev.inmo
|
||||
version=1.1.1
|
||||
version=1.1.2
|
||||
|
@ -13,7 +13,8 @@ class PluginSerializer : KSerializer<Plugin> {
|
||||
get() = String.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): Plugin {
|
||||
return Class.forName(decoder.decodeString()).getDeclaredConstructor().newInstance() as Plugin
|
||||
val kclass = Class.forName(decoder.decodeString()).kotlin
|
||||
return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as Plugin
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: Plugin) {
|
||||
|
Loading…
Reference in New Issue
Block a user