update dependencies && add opportunity to use several targetChatIds instead of one

This commit is contained in:
2023-08-12 23:49:25 +06:00
parent 6eb43055a7
commit 29e5a04135
6 changed files with 51 additions and 34 deletions

View File

@@ -1,6 +1,5 @@
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
@@ -10,14 +9,26 @@ import kotlinx.serialization.Serializable
data class ChatConfig(
@SerialName("targetChat")
@Serializable(FullChatIdentifierSerializer::class)
val targetChatId: IdChatIdentifier,
val targetChatId: IdChatIdentifier? = null,
@SerialName("sourceChat")
@Serializable(FullChatIdentifierSerializer::class)
val sourceChatId: IdChatIdentifier,
@SerialName("cacheChat")
@Serializable(FullChatIdentifierSerializer::class)
val cacheChatId: IdChatIdentifier
val cacheChatId: IdChatIdentifier,
@SerialName("targetChats")
val targetChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(),
) {
val allTargetChatIds by lazy {
listOfNotNull(targetChatId) + targetChatIds
}
init {
require(targetChatId != null || targetChatIds.isNotEmpty()) {
"One of fields, 'targetChat' or 'targetChats' should be presented"
}
}
fun check(chatId: IdChatIdentifier) = when (chatId) {
targetChatId,
sourceChatId,

View File

@@ -1,6 +1,5 @@
package dev.inmo.plaguposter.common
import dev.inmo.kslog.common.i
import dev.inmo.kslog.common.iS
import dev.inmo.kslog.common.logger
import dev.inmo.plagubot.Plugin
@@ -27,7 +26,7 @@ object CommonPlugin : Plugin {
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
val config = koin.get<ChatConfig>()
Log.iS { "Target chat info: ${getChat(config.targetChatId)}" }
Log.iS { "Target chats info: ${config.allTargetChatIds.map { getChat(it) }.joinToString()}" }
Log.iS { "Source chat info: ${getChat(config.sourceChatId)}" }
Log.iS { "Cache chat info: ${getChat(config.cacheChatId)}" }
}