Compare commits

..

No commits in common. "b99bb9ee642cf19aa075dcfbd73b7f765aa8f5c3" and "5ec1c8c55faa26b01d06e852e84c61edec05085f" have entirely different histories.

8 changed files with 22 additions and 38 deletions

View File

@ -1,14 +1,5 @@
# Changelog # Changelog
## 1.1.2
* `Versions`
* `tgbotapi`: `2.0.3`
* `microutils`: `0.11.3`
* `kslog`: `0.3.1`
* `Plugin`:
* Now it is possible to use `object`s of plugins instead of classes
## 1.1.1 ## 1.1.1
* `Versions` * `Versions`

View File

@ -1,9 +1,7 @@
package dev.inmo.plagubot package dev.inmo.plagubot
import dev.inmo.kslog.common.KSLog import dev.inmo.kslog.common.*
import dev.inmo.kslog.common.i import dev.inmo.plagubot.config.*
import dev.inmo.plagubot.config.Config
import dev.inmo.plagubot.config.defaultJsonFormat
import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonObject
import java.io.File import java.io.File

View File

@ -5,17 +5,20 @@ import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
import kotlinx.serialization.SerialName import kotlinx.serialization.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Database
import org.koin.core.Koin import org.koin.core.Koin
import org.koin.core.KoinApplication
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.module.Module import org.koin.core.module.Module
import org.koin.dsl.module
@Serializable @Serializable
@SerialName("Hello") @SerialName("Hello")
object HelloPlugin : Plugin { class HelloPlugin : Plugin {
@Serializable @Serializable
data class HelloPluginConfig( data class HelloPluginConfig(
val print: String val print: String

View File

@ -1,14 +1,11 @@
package dev.inmo.plagubot package dev.inmo.plagubot
import dev.inmo.kslog.common.* import dev.inmo.kslog.common.*
import dev.inmo.micro_utils.common.Warning
import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.plagubot.config.Config import dev.inmo.plagubot.config.*
import dev.inmo.plagubot.config.defaultJsonFormat
import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.webhook.deleteWebhook import dev.inmo.tgbotapi.extensions.api.webhook.deleteWebhook
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -21,14 +18,12 @@ import org.koin.core.context.GlobalContext
import org.koin.core.module.Module import org.koin.core.module.Module
import org.koin.core.scope.Scope import org.koin.core.scope.Scope
import org.koin.dsl.module import org.koin.dsl.module
import java.util.logging.Level
import java.util.logging.Logger
val Scope.plagubot: PlaguBot val Scope.plagubot: PlaguBot
get() = get() get() = get()
val Koin.plagubot: PlaguBot
get() = get()
@OptIn(Warning::class)
@Serializable @Serializable
data class PlaguBot( data class PlaguBot(
private val json: JsonObject, private val json: JsonObject,
@ -61,17 +56,17 @@ data class PlaguBot(
} }
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
config.plugins.map { plugin -> config.plugins.map {
launch { launch {
runCatchingSafely { runCatchingSafely {
logger.i("Start loading of $plugin") logger.i("Start loading of $it")
with(plugin) { with(it) {
setupBotPlugin(koin) setupBotPlugin(koin)
} }
}.onFailure { e -> }.onFailure { e ->
logger.w("Unable to load bot part of $plugin", e) logger.w("Unable to load bot part of $it", e)
}.onSuccess { }.onSuccess {
logger.i("Complete loading of $plugin") logger.i("Complete loading of $it")
} }
} }
}.joinAll() }.joinAll()

View File

@ -1,11 +1,9 @@
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,

View File

@ -5,4 +5,4 @@ kotlin.js.generate.externals=true
kotlin.incremental=true kotlin.incremental=true
group=dev.inmo group=dev.inmo
version=1.1.2 version=1.1.1

View File

@ -4,9 +4,9 @@ kt = "1.6.21"
kt-serialization = "1.3.3" kt-serialization = "1.3.3"
kt-coroutines = "1.6.2" kt-coroutines = "1.6.2"
microutils = "0.11.3" microutils = "0.11.0"
tgbotapi = "2.0.3" tgbotapi = "2.0.2"
kslog = "0.3.1" kslog = "0.3.0"
jb-exposed = "0.38.2" jb-exposed = "0.38.2"
jb-dokka = "1.6.21" jb-dokka = "1.6.21"

View File

@ -13,8 +13,7 @@ class PluginSerializer : KSerializer<Plugin> {
get() = String.serializer().descriptor get() = String.serializer().descriptor
override fun deserialize(decoder: Decoder): Plugin { override fun deserialize(decoder: Decoder): Plugin {
val kclass = Class.forName(decoder.decodeString()).kotlin return Class.forName(decoder.decodeString()).getDeclaredConstructor().newInstance() as Plugin
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) {