Compare commits

...

35 Commits

Author SHA1 Message Date
3b507a5668 a lot of improvements 2024-09-14 21:06:06 +06:00
bb06ba1ca7 Add opportunity to use config in setup bot client 2024-09-14 20:17:38 +06:00
d772d275b3 start 9.3.0 2024-09-14 20:17:10 +06:00
e1e7c7a547 Merge pull request #103 from InsanusMokrassar/9.2.0
9.2.0
2024-09-06 00:11:20 +06:00
d8403dd3b7 update dependencies 2024-09-06 00:09:41 +06:00
17ac66f7fe start 9.2.0 2024-09-06 00:05:26 +06:00
b23c9b755a Merge pull request #102 from InsanusMokrassar/9.1.0
9.1.0
2024-08-15 21:32:02 +06:00
629ff7ee4e update dependencies 2024-08-15 21:30:04 +06:00
666ba9926e start 9.1.0 2024-08-15 21:29:17 +06:00
995bce3885 Merge pull request #101 from InsanusMokrassar/9.0.0
9.0.0
2024-08-12 16:35:14 +06:00
d597539b9e update dependencies 2024-08-12 16:24:34 +06:00
c80a7a1bda start 9.0.0 2024-08-12 16:22:42 +06:00
bd20c2d60f Merge pull request #100 from InsanusMokrassar/8.5.1
8.5.1
2024-07-24 16:10:12 +06:00
cfd42af6bc update dependencies 2024-07-24 16:08:27 +06:00
5c39fd2491 start 8.5.1 2024-07-24 16:06:56 +06:00
745b9cad72 Merge pull request #99 from InsanusMokrassar/8.5.0
8.5.0
2024-07-11 23:03:40 +06:00
f39947edd6 update dependencies 2024-07-11 23:01:37 +06:00
cacc1ef828 start 8.5.0 2024-07-11 23:00:11 +06:00
136d106b4c Merge pull request #98 from InsanusMokrassar/8.4.0
8.4.0
2024-06-27 23:20:42 +06:00
ddd3854d78 update dependencies 2024-06-27 22:31:45 +06:00
1c2bcb6907 start 8.4.0 2024-06-27 22:29:07 +06:00
8bd80c1c0c Merge pull request #97 from InsanusMokrassar/8.3.0
8.3.0
2024-04-23 18:50:57 +06:00
2234ffd55d update gradle wrapper 2024-04-23 18:44:51 +06:00
1a9d8b0d5e update dependencies 2024-04-23 18:44:26 +06:00
e00f40d06a start 8.3.0 2024-04-23 18:37:33 +06:00
9883d2b3b1 Merge pull request #96 from InsanusMokrassar/8.2.0
8.2.0
2024-02-18 21:34:04 +06:00
bdfd3b816c update dependencies 2024-02-18 21:31:45 +06:00
dd37ae0f2f start 8.2.0 2024-02-18 21:27:22 +06:00
8efe977e76 Merge pull request #95 from InsanusMokrassar/8.1.1
8.1.1
2024-02-10 23:45:26 +06:00
8290a68654 update dependencies 2024-02-10 23:44:52 +06:00
493a18a0f7 start 8.1.1 2024-02-10 23:41:36 +06:00
36608937af Merge pull request #94 from InsanusMokrassar/8.1.0
8.1.0
2024-01-14 18:42:36 +06:00
1b1b069d93 integrate startup launcher 2024-01-14 18:33:41 +06:00
37b5b8e867 start 8.1.0 2024-01-14 18:21:26 +06:00
468310c819 Merge pull request #93 from InsanusMokrassar/8.0.0
8.0.0
2024-01-12 20:28:24 +06:00
11 changed files with 185 additions and 49 deletions

View File

@@ -1,9 +1,89 @@
# Changelog
## 9.3.0
* `Bot`:
* Now bot is not built-in into `PlaguBot` and setted up as all other `Koin` dependencies
* Now it is possible to use `testServer` parameter for bots out of the box
* `Plugin`:
* New method `setupBotClient` with arguments to let plugin setup bot more freely
## 9.2.0
* `Versions`:
* `kotlin`: `2.0.20`
* `serialization`: `1.7.2`
* `microutils`: `0.22.2`
* `tgbotapi`: `18.1.0`
* `exposed`: `0.54.0`
* `sqlite`: `3.46.1.0`
## 9.1.0
* `Versions`:
* `tgbotapi`: `17.0.0`
## 9.0.0
* `Versions`:
* `Kotlin`: `2.0.10`
* `Serialization`: `1.7.1`
* `MicroUtils`: `0.22.0`
* `tgbotapi`: `16.0.0`
* `Exposed`: `0.53.0`
## 8.5.1
* `Versions`:
* `MicroUtils`: `0.21.4`
* `tgbotapi`: `15.2.0`
## 8.5.0
* `Versions`:
* `MicroUtils`: `0.21.2`
* `tgbotapi`: `15.1.0`
## 8.4.0
* `Versions`:
* `Coroutines`: `1.8.1`
* `MicroUtils`: `0.21.1`
* `tgbotapi`: `15.0.0`
* `Exposed`: `0.51.1`
## 8.3.0
* `Versions`:
* `Serialization`: `1.6.3`
* `MicroUtils`: `0.20.45`
* `tgbotapi`: `12.0.1`
* `Exposed`: `0.49.0`
* `SQLite`: `3.45.3.0`
* `Koin`: `3.5.6`
## 8.2.0
* `Versions`:
* `Coroutines`: `1.8.0`
* `tgbotapi`: `10.1.0`
* `MicroUtils`: `0.20.35`
## 8.1.1
* `Versions`:
* `tgbotapi`: `10.0.1`
* `MicroUtils`: `0.20.32`
* `Exposed`: `0.47.0`
## 8.1.0
* Integrate `dev.inmo:micro_utils.startup` into project
## 8.0.0
* `Versions`:
* `tgbotapi`: `1.0.0`
* `tgbotapi`: `10.0.0`
* `MicroUtils`: `0.20.26`
* `Exposed`: `0.46.0`

View File

@@ -20,6 +20,7 @@ dependencies {
api libs.tgbotapi.behaviourBuilder.fsm
api libs.microutils.repos.exposed
api libs.microutils.koin
api libs.microutils.startup.launcher
api libs.sqlite

View File

@@ -32,8 +32,6 @@ object HelloPlugin : Plugin {
override fun Module.setupDI(database: Database, params: JsonObject) {
single {
get<Json>().decodeFromJsonElement(HelloPluginConfig.serializer(), params["helloPlugin"] ?: return@single null)
}
}
@@ -43,6 +41,11 @@ object HelloPlugin : Plugin {
data class SaidHelloOnce(override val context: IdChatIdentifier) : InternalFSMState
}
override suspend fun startPlugin(koin: Koin) {
super.startPlugin(koin)
logger.i { "This logic called BEFORE the bot will be started and setup" }
}
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
val toPrint = koin.getOrNull<HelloPluginConfig>() ?.print ?: "Hello :)"
logger.d { toPrint }

View File

@@ -8,6 +8,7 @@ import dev.inmo.micro_utils.fsm.common.StatesManager
import dev.inmo.micro_utils.fsm.common.managers.*
import dev.inmo.micro_utils.koin.getAllDistinct
import dev.inmo.plagubot.config.*
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.webhook.deleteWebhook
@@ -15,7 +16,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import kotlinx.coroutines.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.json.JsonObject
import org.jetbrains.exposed.sql.Database
import org.koin.core.Koin
@@ -37,33 +37,45 @@ data class PlaguBot(
private val json: JsonObject,
private val config: Config
) : Plugin {
@Transient
private val bot = telegramBot(
token = config.botToken,
apiUrl = config.botApiServer
) {
setupBotClient()
override fun KtorRequestsExecutorBuilder.setupBotClient(scope: Scope, params: JsonObject) {
config.botPlugins.forEach {
with(it) {
setupBotClient(scope, params)
}
}
}
override fun KtorRequestsExecutorBuilder.setupBotClient() {
config.plugins.forEach {
config.botPlugins.forEach {
with(it) {
setupBotClient()
}
}
}
override fun Module.setupDI(database: Database, params: JsonObject) {
single { config }
single { config.plugins }
single { config.databaseConfig }
single { config.databaseConfig.database }
override fun Module.setupDI(config: JsonObject) {
single { this@PlaguBot.config }
single { this@PlaguBot.config.plugins }
single { this@PlaguBot.config.databaseConfig }
single { this@PlaguBot.config.databaseConfig.database }
single { defaultJsonFormat }
single { this@PlaguBot }
single { bot }
single {
val config = get<Config>()
telegramBot(
token = config.botToken,
testServer = config.testServer,
apiUrl = config.botApiServer
) {
setupBotClient(this@single, json)
}
}
}
override fun Module.setupDI(database: Database, params: JsonObject) {
setupDI(params)
includes(
config.plugins.mapNotNull {
config.botPlugins.mapNotNull {
runCatching {
module {
with(it) {
@@ -71,14 +83,31 @@ data class PlaguBot(
}
}
}.onFailure { e ->
logger.w("Unable to load DI part of $it", e)
logger.w(e) { "Unable to load DI part of $it" }
}.getOrNull()
}
)
}
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
override suspend fun startPlugin(koin: Koin) {
super.startPlugin(koin)
config.plugins.forEach { plugin ->
runCatchingSafely {
logger.i { "Starting of $plugin common logic" }
with(plugin) {
startPlugin(koin)
}
}.onFailure { e ->
logger.w(e) { "Unable to load common logic of $plugin" }
}.onSuccess {
logger.i { "Complete loading of $plugin common logic" }
}
}
}
override suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
config.botPlugins.forEach { plugin ->
runCatchingSafely {
logger.i("Start loading of $plugin")
with(plugin) {
@@ -96,7 +125,7 @@ data class PlaguBot(
* This method will create an [Job] which will be the main [Job] of ran instance
*/
suspend fun start(
scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
): Job {
logger.i("Start initialization")
val koinApp = KoinApplication.init()
@@ -105,12 +134,15 @@ data class PlaguBot(
setupDI(config.databaseConfig.database, json)
}
)
logger.i("Modules loaded")
logger.i("Modules loaded. Starting koin")
GlobalContext.startKoin(koinApp)
logger.i("Koin started")
logger.i("Koin started. Starting plugins common logic")
startPlugin(koinApp.koin)
logger.i("Plugins common logic started. Starting setup of bot logic part")
lateinit var behaviourContext: BehaviourContext
val onStartContextsConflictResolver by lazy { koinApp.koin.getAllDistinct<OnStartContextsConflictResolver>() }
val onUpdateContextsConflictResolver by lazy { koinApp.koin.getAllDistinct<OnUpdateContextsConflictResolver>() }
val bot = koinApp.koin.get<TelegramBot>()
bot.buildBehaviourWithFSM(
scope = scope,
defaultExceptionsHandler = {

View File

@@ -1,17 +1,21 @@
package dev.inmo.plagubot.config
import dev.inmo.micro_utils.common.Warning
import dev.inmo.micro_utils.startup.plugin.StartPlugin
import dev.inmo.plagubot.Plugin
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Warning("This API is internal and can be changed without notifications of mentions of changes")
@Warning("This API is internal and can be changed without notifications or mentions of changes")
@Serializable
data class Config(
val botToken: String,
val plugins: List<Plugin>,
val plugins: List<StartPlugin>,
@SerialName("database")
val databaseConfig: DatabaseConfig = DatabaseConfig(),
val botApiServer: String = telegramBotAPIDefaultUrl
)
val botApiServer: String = telegramBotAPIDefaultUrl,
val testServer: Boolean = false
) {
val botPlugins = plugins.filterIsInstance<Plugin>()
}

View File

@@ -20,13 +20,13 @@ if (new File(projectDir, "secret.gradle").exists()) {
releaseAssets.from('bot/build/distributions')
owner "InsanusMokrassar"
repo "PlaguBot"
owner = "InsanusMokrassar"
repo = "PlaguBot"
tagName "v${project.version}"
releaseName "${project.version}"
targetCommitish "${project.version}"
tagName = "v${project.version}"
releaseName = "${project.version}"
targetCommitish = "${project.version}"
body getCurrentVersionChangelog()
body = getCurrentVersionChangelog()
}
}

View File

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

View File

@@ -1,22 +1,22 @@
[versions]
kt = "1.9.22"
kt-serialization = "1.6.2"
kt-coroutines = "1.7.3"
kt = "2.0.20"
kt-serialization = "1.7.2"
kt-coroutines = "1.8.1"
microutils = "0.20.26"
tgbotapi = "10.0.0"
microutils = "0.22.2"
tgbotapi = "18.1.0"
ksp = "1.9.22-1.0.16"
ksp = "2.0.20-1.0.24"
jb-exposed = "0.46.0"
jb-dokka = "1.9.10"
jb-exposed = "0.54.0"
jb-dokka = "1.9.20"
sqlite = "3.44.1.0"
sqlite = "3.46.1.0"
gh-release = "2.4.1"
gh-release = "2.5.2"
koin = "3.5.3"
koin = "3.5.6"
[libraries]
@@ -30,6 +30,8 @@ tgbotapi-behaviourBuilder-fsm = { module = "dev.inmo:tgbotapi.behaviour_builder.
microutils-repos-exposed = { module = "dev.inmo:micro_utils.repos.exposed", version.ref = "microutils" }
microutils-koin = { module = "dev.inmo:micro_utils.koin", version.ref = "microutils" }
microutils-koin-generator = { module = "dev.inmo:micro_utils.koin.generator", version.ref = "microutils" }
microutils-startup-launcher = { module = "dev.inmo:micro_utils.startup.launcher", version.ref = "microutils" }
microutils-startup-plugin = { module = "dev.inmo:micro_utils.startup.plugin", version.ref = "microutils" }
koin = { module = "io.insert-koin:koin-core", version.ref = "koin" }

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -14,6 +14,7 @@ dependencies {
api libs.tgbotapi
api libs.microutils.repos.exposed
api libs.microutils.startup.plugin
api libs.koin
}

View File

@@ -1,6 +1,7 @@
package dev.inmo.plagubot
import dev.inmo.micro_utils.fsm.common.State
import dev.inmo.micro_utils.startup.plugin.StartPlugin
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM
@@ -9,6 +10,7 @@ import kotlinx.serialization.json.JsonObject
import org.jetbrains.exposed.sql.Database
import org.koin.core.Koin
import org.koin.core.module.Module
import org.koin.core.scope.Scope
/**
* **ANY REALIZATION OF [Plugin] MUST HAVE CONSTRUCTOR WITH ABSENCE OF INCOMING PARAMETERS**
@@ -18,16 +20,27 @@ import org.koin.core.module.Module
* too.
*/
@Serializable(PluginSerializer::class)
interface Plugin {
interface Plugin : StartPlugin {
@Deprecated("Deprecated in favor to setupBotClient with arguments")
fun KtorRequestsExecutorBuilder.setupBotClient() {}
/**
* Will be called on stage of bot setup
*
* @param scope The scope of [org.koin.core.module.Module.single] of bot definition
* @param params Params (in fact, the whole bot config)
*/
fun KtorRequestsExecutorBuilder.setupBotClient(scope: Scope, params: JsonObject) = setupBotClient()
/**
* This method will be called when this plugin should configure di module based on the incoming params
*/
fun Module.setupDI(
database: Database,
params: JsonObject
) {}
) {
setupDI(params)
}
/**
* Override this method in cases when you want to declare common bot behaviour. In case you wish to use FSM, you