mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2025-12-05 22:06:02 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b507a5668 | |||
| bb06ba1ca7 | |||
| d772d275b3 | |||
| e1e7c7a547 | |||
| d8403dd3b7 | |||
| 17ac66f7fe | |||
| b23c9b755a | |||
| 629ff7ee4e | |||
| 666ba9926e | |||
| 995bce3885 | |||
| d597539b9e | |||
| c80a7a1bda | |||
| bd20c2d60f |
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,5 +1,37 @@
|
||||
# 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`:
|
||||
|
||||
@@ -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,14 +37,13 @@ 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.botPlugins.forEach {
|
||||
with(it) {
|
||||
@@ -60,7 +59,16 @@ data class PlaguBot(
|
||||
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) {
|
||||
@@ -117,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()
|
||||
@@ -134,6 +142,7 @@ data class PlaguBot(
|
||||
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 = {
|
||||
|
||||
@@ -14,7 +14,8 @@ data class Config(
|
||||
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>()
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ kotlin.js.generate.externals=true
|
||||
kotlin.incremental=true
|
||||
|
||||
group=dev.inmo
|
||||
version=8.5.1
|
||||
version=9.3.0
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
[versions]
|
||||
|
||||
kt = "1.9.23"
|
||||
kt-serialization = "1.6.3"
|
||||
kt = "2.0.20"
|
||||
kt-serialization = "1.7.2"
|
||||
kt-coroutines = "1.8.1"
|
||||
|
||||
microutils = "0.21.4"
|
||||
tgbotapi = "15.2.0"
|
||||
microutils = "0.22.2"
|
||||
tgbotapi = "18.1.0"
|
||||
|
||||
ksp = "1.9.23-1.0.20"
|
||||
ksp = "2.0.20-1.0.24"
|
||||
|
||||
jb-exposed = "0.50.1"
|
||||
jb-exposed = "0.54.0"
|
||||
jb-dokka = "1.9.20"
|
||||
|
||||
sqlite = "3.45.3.0"
|
||||
sqlite = "3.46.1.0"
|
||||
|
||||
gh-release = "2.5.2"
|
||||
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -10,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**
|
||||
@@ -20,8 +21,17 @@ import org.koin.core.module.Module
|
||||
*/
|
||||
@Serializable(PluginSerializer::class)
|
||||
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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user