mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2025-09-14 20:49:36 +00:00
update dependencies && add opportunity to use several targetChatIds instead of one
This commit is contained in:
@@ -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,
|
||||
|
@@ -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)}" }
|
||||
}
|
||||
|
Reference in New Issue
Block a user