complete timer plugin

This commit is contained in:
2022-12-14 11:50:02 +06:00
parent c632a2ba14
commit b9c78982b5
22 changed files with 304 additions and 52 deletions

View File

@@ -1,15 +1,27 @@
package dev.inmo.plaguposter.common
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer
import dev.inmo.tgbotapi.types.IdChatIdentifier
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatConfig(
@SerialName("targetChat")
val targetChatId: ChatId,
@Serializable(FullChatIdentifierSerializer::class)
val targetChatId: IdChatIdentifier,
@SerialName("sourceChat")
val sourceChatId: ChatId,
@Serializable(FullChatIdentifierSerializer::class)
val sourceChatId: IdChatIdentifier,
@SerialName("cacheChat")
val cacheChatId: ChatId
)
@Serializable(FullChatIdentifierSerializer::class)
val cacheChatId: IdChatIdentifier
) {
fun check(chatId: IdChatIdentifier) = when (chatId) {
targetChatId,
sourceChatId,
cacheChatId -> true
else -> false
}
}

View File

@@ -6,10 +6,20 @@ import dev.inmo.kslog.common.logger
import dev.inmo.plagubot.Plugin
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.serialization.json.JsonObject
import org.jetbrains.exposed.sql.Database
import org.koin.core.Koin
import org.koin.core.module.Module
object CommonPlugin : Plugin {
private val Log = logger
override fun Module.setupDI(database: Database, params: JsonObject) {
single { CoroutineScope(Dispatchers.Default + SupervisorJob()) }
}
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
val config = koin.get<ChatConfig>()