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