mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-12-22 22:17:12 +00:00
commit
8fe6fb4bf1
@ -8,8 +8,12 @@
|
||||
* `exposed`: `0.28.1` -> `0.29.1`
|
||||
* `tgbotapi`: `0.30.10` -> `0.32.5`
|
||||
* `microutils`: `0.4.11` -> `0.4.25`
|
||||
* `Bot`
|
||||
* New dependency `sdi`
|
||||
* Now it is possible to pass `Module` to configuration for providing a global plugins parameters like different
|
||||
common database or tools
|
||||
* `Plugin`
|
||||
* New method `BehaviourContext#invoke`
|
||||
* Two new methods `BehaviourContext#invoke`
|
||||
* Old method `invoke` has been deprecated
|
||||
|
||||
## 0.0.5
|
||||
|
@ -18,6 +18,7 @@ dependencies {
|
||||
api "org.jetbrains.exposed:exposed-jdbc:$kotlin_exposed_version"
|
||||
|
||||
api "dev.inmo:tgbotapi:$tgbotapi_version"
|
||||
api "dev.inmo:sdi:$sdi_version"
|
||||
api "dev.inmo:micro_utils.repos.exposed:$microutils_version"
|
||||
|
||||
api "com.github.matfax.klassindex:library:$klassindex_version"
|
||||
@ -34,6 +35,7 @@ application {
|
||||
kapt {
|
||||
arguments {
|
||||
arg("com.github.matfax.klassindex.IndexSubclasses", "dev.inmo.plagubot.Plugin")
|
||||
arg("com.github.matfax.klassindex.IndexAnnotated", "dev.inmo.sdi.SDIIncluded")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.plagubot
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||
import dev.inmo.plagubot.config.Config
|
||||
import dev.inmo.plagubot.config.*
|
||||
import dev.inmo.plagubot.config.configSerialFormat
|
||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||
@ -18,9 +18,11 @@ suspend inline fun initPlaguBot(
|
||||
) {
|
||||
val bot = telegramBot(config.botToken)
|
||||
|
||||
val paramsMap = config.params ?.toMap() ?: emptyMap()
|
||||
val database = config.params ?.database ?: config.database.database
|
||||
bot.buildBehaviour(scope) {
|
||||
val commands = config.plugins.flatMap {
|
||||
it.apply { invoke(config.database.database) }
|
||||
it.apply { invoke(database, paramsMap) }
|
||||
it.getCommands()
|
||||
}.let {
|
||||
val futureUnavailable = it.drop(botCommandsLimit.last)
|
||||
|
@ -2,6 +2,7 @@ package dev.inmo.plagubot.config
|
||||
|
||||
import com.github.matfax.klassindex.KlassIndex
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.sdi.Module
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.modules.*
|
||||
@ -37,6 +38,7 @@ internal val configSerialFormat: StringFormat
|
||||
@Serializable
|
||||
data class Config(
|
||||
val plugins: List<Plugin>,
|
||||
val database: DatabaseConfig,
|
||||
val botToken: String
|
||||
val database: DatabaseConfig = DatabaseConfig(),
|
||||
val botToken: String,
|
||||
val params: Module? = null
|
||||
)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.plagubot.config
|
||||
|
||||
import dev.inmo.sdi.SDIIncluded
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
@ -7,7 +8,12 @@ import org.jetbrains.exposed.sql.transactions.transactionManager
|
||||
import org.sqlite.JDBC
|
||||
import java.sql.Connection
|
||||
|
||||
const val defaultDatabaseParamsName = "defaultDatabase"
|
||||
inline val Map<String, Any>.database: Database?
|
||||
get() = (get(defaultDatabaseParamsName) as? DatabaseConfig) ?.database
|
||||
|
||||
@Serializable
|
||||
@SDIIncluded
|
||||
data class DatabaseConfig(
|
||||
val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared",
|
||||
val driver: String = JDBC::class.qualifiedName!!,
|
||||
|
@ -13,8 +13,8 @@ buildscript {
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
@ -8,9 +8,12 @@ kotlin_version=1.4.30
|
||||
kotlin_coroutines_version=1.4.2
|
||||
kotlin_serialisation_runtime_version=1.1.0-RC
|
||||
kotlin_exposed_version=0.29.1
|
||||
|
||||
sdi_version=0.4.0-rc2
|
||||
tgbotapi_version=0.32.5
|
||||
microutils_version=0.4.25
|
||||
klassindex_version=4.1.0-rc.1
|
||||
|
||||
sqlite_version=3.30.1
|
||||
|
||||
github_release_plugin_version=2.2.12
|
||||
|
@ -33,7 +33,13 @@ interface Plugin {
|
||||
*/
|
||||
suspend operator fun BehaviourContext.invoke(
|
||||
database: Database
|
||||
) {
|
||||
invoke(bot, database, flowsUpdatesFilter, scope)
|
||||
}
|
||||
) = invoke(bot, database, flowsUpdatesFilter, scope)
|
||||
|
||||
/**
|
||||
* This method (usually) will be invoked just one time in the whole application.
|
||||
*/
|
||||
suspend operator fun BehaviourContext.invoke(
|
||||
database: Database,
|
||||
params: Map<String, Any>
|
||||
) = invoke(database)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user