diff --git a/CHANGELOG.md b/CHANGELOG.md index f394ec363a..5ffc4c5e57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # TelegramBotAPI changelog +## 0.35.3 + +* `Common`: + * `Version`: + * `Klock`: `2.2.0` -> `2.3.1` + * `Ktor`: `1.6.1` -> `1.6.2` + * `MicroUtils`: `0.5.16` -> `0.5.18` +* `Core`: + * **`SimpleRequestCallFactory` and `MultipartRequestCallFactory` became a classes instead of objects to avoid + collisions in different bots** + * Support of strongly-typed ietf language codes has been added +* `API`: + * New extension `TelegramBot#downloadFile` for any `MediaContent` +* `Behaviour Builder`: + * New provider `defaultCoroutineScopeProvider` + * Now it is not necessary to provide `CoroutineScope` to `TelegramBot#buildBehaviour` + extension + * New `TelegramBot#buildBehaviour` extension with `FlowUpdatesFilter` and `CoroutineScope` with + default `CoroutineScope` + * New typealias `SimpleFilter` for unifying triggers filter signatures + * All waiters got real filters (`SimpleFilter`) and rename old filters as mappers + * New extensions for `Any`: `as`/`when`/`require` for `WithOptionalLanguageCode` and `WithLanguageCode` + ## 0.35.2 * `Common`: diff --git a/gradle.properties b/gradle.properties index 4db1b4bebc..feeee555b0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,15 +8,15 @@ kotlin.incremental.js=true kotlin_version=1.5.21 kotlin_coroutines_version=1.5.1 kotlin_serialisation_runtime_version=1.2.2 -klock_version=2.2.0 +klock_version=2.3.1 uuid_version=0.3.0 -ktor_version=1.6.1 +ktor_version=1.6.2 -micro_utils_version=0.5.16 +micro_utils_version=0.5.18 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.35.2 +library_version=0.35.3 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index 1948d03bc0..83582016f5 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -51,6 +51,7 @@ kotlin { api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version" api "dev.inmo:micro_utils.serialization.encapsulator:$micro_utils_version" api "dev.inmo:micro_utils.serialization.typed_serializer:$micro_utils_version" + api "dev.inmo:micro_utils.language_codes:$micro_utils_version" api "io.ktor:ktor-client-core:$ktor_version" } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt index 97225fce01..65a0f62e2f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt @@ -52,7 +52,7 @@ class KtorRequestsExecutor( ) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { private val callsFactories: List = callsFactories.run { if (!excludeDefaultFactories) { - this + listOf(SimpleRequestCallFactory, MultipartRequestCallFactory, DownloadFileRequestCallFactory) + this + listOf(SimpleRequestCallFactory(), MultipartRequestCallFactory(), DownloadFileRequestCallFactory) } else { this } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt index 87cae741b3..ca41189baf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.bot.Ktor.base +import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.utils.mapWithCommonValues @@ -9,7 +10,7 @@ import io.ktor.client.request.forms.formData import io.ktor.http.Headers import io.ktor.http.HttpHeaders -object MultipartRequestCallFactory : AbstractRequestCallFactory() { +class MultipartRequestCallFactory : AbstractRequestCallFactory() { override fun prepareCallBody( client: HttpClient, urlsKeeper: TelegramAPIUrlsKeeper, @@ -35,4 +36,7 @@ object MultipartRequestCallFactory : AbstractRequestCallFactory() { } ) } -} \ No newline at end of file + + @Deprecated("Use class MultipartRequestCallFactory() constructor call instead of just MultipartRequestCallFactory") + companion object : KtorCallFactory by MultipartRequestCallFactory() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/SimpleRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/SimpleRequestCallFactory.kt index 8dba9b73e5..6c83ac9eeb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/SimpleRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/SimpleRequestCallFactory.kt @@ -1,12 +1,13 @@ package dev.inmo.tgbotapi.bot.Ktor.base +import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.http.content.TextContent -object SimpleRequestCallFactory : AbstractRequestCallFactory() { +class SimpleRequestCallFactory : AbstractRequestCallFactory() { override fun prepareCallBody( client: HttpClient, urlsKeeper: TelegramAPIUrlsKeeper, @@ -19,4 +20,7 @@ object SimpleRequestCallFactory : AbstractRequestCallFactory() { ContentType.Application.Json ) } -} \ No newline at end of file + + @Deprecated("Use class SimpleRequestCallFactory() constructor call instead of just SimpleRequestCallFactory") + companion object : KtorCallFactory by SimpleRequestCallFactory() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt index bc6b7cac0b..d648ef9d71 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.requests.bot import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.types.commands.BotCommandScope -sealed interface MyCommandsRequest : SimpleRequest { +sealed interface MyCommandsRequest : SimpleRequest, WithOptionalLanguageCode { val scope: BotCommandScope - val languageCode: String? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt index 867b5fc978..2b8c494dff 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.requests.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer import dev.inmo.tgbotapi.types.commands.* import dev.inmo.tgbotapi.types.languageCodeField import dev.inmo.tgbotapi.types.scopeField @@ -12,11 +14,20 @@ data class DeleteMyCommands( @Serializable(BotCommandScopeSerializer::class) override val scope: BotCommandScope = BotCommandScopeDefault, @SerialName(languageCodeField) - override val languageCode: String? = null + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null ) : MyCommandsRequest { override fun method(): String = "deleteMyCommands" override val requestSerializer: SerializationStrategy = serializer() override val resultDeserializer: DeserializationStrategy = Boolean.serializer() + constructor( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? + ) : this( + scope, + languageCode ?.let(::IetfLanguageCode) + ) + companion object : MyCommandsRequest by DeleteMyCommands() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt index 31b8fe194a..511fc9e33f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.requests.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.commands.* import kotlinx.serialization.* @@ -13,7 +15,8 @@ data class GetMyCommands( @Serializable(BotCommandScopeSerializer::class) override val scope: BotCommandScope = BotCommandScopeDefault, @SerialName(languageCodeField) - override val languageCode: String? = null + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null ) : MyCommandsRequest> { override fun method(): String = "getMyCommands" override val resultDeserializer: DeserializationStrategy> @@ -21,5 +24,13 @@ data class GetMyCommands( override val requestSerializer: SerializationStrategy<*> get() = serializer() + constructor( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? + ) : this( + scope, + languageCode ?.let(::IetfLanguageCode) + ) + companion object : MyCommandsRequest> by GetMyCommands() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt index 4f926840e2..6df10c13b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.requests.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.commands.* import kotlinx.serialization.* @@ -13,7 +15,8 @@ class SetMyCommands( @Serializable(BotCommandScopeSerializer::class) override val scope: BotCommandScope = BotCommandScopeDefault, @SerialName(languageCodeField) - override val languageCode: String? = null + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null ) : MyCommandsRequest { override fun method(): String = "setMyCommands" override val resultDeserializer: DeserializationStrategy @@ -21,6 +24,16 @@ class SetMyCommands( override val requestSerializer: SerializationStrategy<*> get() = serializer() + constructor( + commands: List, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? + ) : this( + commands, + scope, + languageCode ?.let(::IetfLanguageCode) + ) + init { if (commands.size !in botCommandsLimit) { error("Bot commands list size able to be in range $botCommandsLimit, but incoming size is ${commands.size}") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt index e0a7bb9269..a72b698f6b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt @@ -5,12 +5,12 @@ import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* const val editMessageCaptionMethod = "editMessageCaption" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt index 161924ac62..315de59511 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt @@ -4,10 +4,10 @@ import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* fun EditInlineMessageCaption( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt index 17c1dc3cc1..53875a817a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt @@ -5,12 +5,12 @@ import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* const val editMessageTextMethod = "editMessageText" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt index 42226c395b..c0438f3a55 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt @@ -4,10 +4,10 @@ import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* fun EditInlineMessageText( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt index d327de74fa..1552a06819 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageReques import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* fun CopyMessage( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt index 31e2ab5d2d..0589229075 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt @@ -5,13 +5,13 @@ import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt index 729be79337..10ed428b25 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt @@ -6,13 +6,13 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.AnimationContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt index fe3481221d..f77ea46fb2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt @@ -7,13 +7,13 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.AudioContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt index 9d94c9cd58..1a6b729d9d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt @@ -6,13 +6,13 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.DocumentContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt index 2aa4bd292f..d132fbc460 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt @@ -6,13 +6,13 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.PhotoContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 13f1509876..067b8e29aa 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -6,13 +6,13 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.VideoContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt index ca9b4042cc..6412b39342 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt @@ -6,13 +6,13 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.VoiceContent +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index f11af12b50..b0e6391403 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -7,13 +7,13 @@ import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.PollContent import dev.inmo.tgbotapi.types.polls.* +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt index 2f2b594a7b..8f0f91fc58 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.CommonAbstracts.FromUser -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InlineMessageIdentifier +import dev.inmo.tgbotapi.types.InlineQueryIdentifier sealed interface ChosenInlineResult : FromUser { val resultId: InlineQueryIdentifier //chosen temporary, can be changed diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt index f63e10b046..2e6e95be52 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt index 30ad172859..f167a52275 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt @@ -6,10 +6,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt index fb640eac18..2316fbeb7f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt index 108efc3b2b..f5db3e5966 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt @@ -6,12 +6,12 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.files.abstracts.mimeTypeField import dev.inmo.tgbotapi.utils.MimeType +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt index 9b8da064fb..af41a9c0c6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt index 78a909ac5a..fe59a3b374 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt @@ -6,11 +6,11 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.utils.MimeType +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt index 7d399d2392..e37425cee8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt index 4966d82e24..c7d90cd9fb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt @@ -6,11 +6,11 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.utils.MimeType +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt index a0b4c36574..39a35fdb30 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt index 786a88bb55..10c3467c27 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt @@ -6,10 +6,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt index 3d9a9f2ff7..955eaa587e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt index ba211d7877..c9304ef296 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt @@ -6,12 +6,12 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.files.abstracts.mimeTypeField import dev.inmo.tgbotapi.utils.MimeType +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt index cf155b0e1a..41f3b6145a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt @@ -7,10 +7,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt index bf9bf21573..9b7e511f60 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt @@ -6,10 +6,10 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt index 7b61ea7ee0..fcb4a2b00f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt @@ -5,9 +5,9 @@ import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index 7af6629e9e..e038e9fef1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt @@ -6,9 +6,9 @@ import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt index 45a8e82c13..74ec4d15cf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt @@ -6,10 +6,10 @@ import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.AudioFile +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* internal const val audioInputMediaType = "audio" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index 6d9d23fbd0..7c503c4431 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -4,10 +4,10 @@ import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.DocumentFile +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* internal const val documentInputMediaType = "document" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt index 9e189b2283..1e74d24566 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt @@ -5,10 +5,10 @@ import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.PhotoSize +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* internal const val photoInputMediaType = "photo" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt index e7dac1004c..243f14131a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt @@ -5,9 +5,9 @@ import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.* internal const val videoInputMediaType = "video" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt index bcc2ea2875..1ee03ce417 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt @@ -1,5 +1,8 @@ package dev.inmo.tgbotapi.types +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer +import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat import dev.inmo.tgbotapi.types.chat.extended.ExtendedPrivateChatImpl import dev.inmo.tgbotapi.utils.* @@ -22,8 +25,17 @@ data class CommonUser( @SerialName(usernameField) override val username: Username? = null, @SerialName(languageCodeField) - val languageCode: String? = null -) : User() + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null +) : User(), WithOptionalLanguageCode { + constructor( + id: UserId, + firstName: String, + lastName: String = "", + username: Username? = null, + languageCode: String + ) : this(id, firstName, lastName, username, IetfLanguageCode(languageCode)) +} @PreviewFeature typealias ExtendedUser = ExtendedPrivateChatImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/abstracts/WithOptionalLanguageCode.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/abstracts/WithOptionalLanguageCode.kt new file mode 100644 index 0000000000..125cb17826 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/abstracts/WithOptionalLanguageCode.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.types.abstracts + +import dev.inmo.micro_utils.language_codes.IetfLanguageCode + +interface WithOptionalLanguageCode { + val ietfLanguageCode: IetfLanguageCode? + + val languageCode: String? + get() = ietfLanguageCode ?.code +} + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index ea4c261a33..275e00c00f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.types.MessageEntity.textsources.MultilevelTextSource -import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.link import dev.inmo.tgbotapi.utils.extensions.* diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/UserLocale.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/UserLocale.kt index 33e7b5920b..007efedfd0 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/UserLocale.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/UserLocale.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode import java.util.* -fun CommonUser.javaLocale(): Locale? = languageCode ?.let { - Locale.forLanguageTag(it) -} +fun IetfLanguageCode?.javaLocale() = this ?.code ?.let { Locale.forLanguageTag(it) } +fun WithOptionalLanguageCode?.javaLocale() = this ?.ietfLanguageCode ?.javaLocale() diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt index 5d6b5efee7..7f653730b6 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/DownloadFile.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.files.PathedFile import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent suspend fun TelegramBot.downloadFile( filePath: String @@ -30,3 +31,9 @@ suspend fun TelegramBot.downloadFile( ): ByteArray = downloadFile( getFileAdditionalInfo(file) ) + +suspend fun TelegramBot.downloadFile( + file: MediaContent +): ByteArray = downloadFile( + getFileAdditionalInfo(file.media) +) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt index 31abad88f5..3995e5384a 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.bot.DeleteMyCommands import dev.inmo.tgbotapi.types.commands.BotCommandScope @@ -7,5 +8,10 @@ import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.deleteMyCommands( scope: BotCommandScope = BotCommandScopeDefault, - languageCode: String? = null + languageCode: IetfLanguageCode? ) = execute(DeleteMyCommands(scope, languageCode)) + +suspend fun TelegramBot.deleteMyCommands( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = deleteMyCommands(scope, languageCode ?.let(::IetfLanguageCode)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt index 07a0c6a3ac..59fb66828d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.bot.GetMyCommands import dev.inmo.tgbotapi.types.commands.BotCommandScope @@ -7,5 +8,10 @@ import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.getMyCommands( scope: BotCommandScope = BotCommandScopeDefault, - languageCode: String? = null + languageCode: IetfLanguageCode? = null ) = execute(GetMyCommands(scope, languageCode)) + +suspend fun TelegramBot.getMyCommands( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = getMyCommands(scope, languageCode ?.let(::IetfLanguageCode)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt index d0d8b0a8cc..e7f5ef01bc 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.bot.SetMyCommands import dev.inmo.tgbotapi.types.BotCommand @@ -9,9 +10,21 @@ import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.setMyCommands( commands: List, scope: BotCommandScope = BotCommandScopeDefault, - languageCode: String? = null + languageCode: IetfLanguageCode? ) = execute(SetMyCommands(commands, scope, languageCode)) +suspend fun TelegramBot.setMyCommands( + vararg commands: BotCommand, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: IetfLanguageCode? +) = setMyCommands(commands.toList(), scope, languageCode) + +suspend fun TelegramBot.setMyCommands( + commands: List, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = setMyCommands(commands, scope, languageCode ?.let(::IetfLanguageCode)) + suspend fun TelegramBot.setMyCommands( vararg commands: BotCommand, scope: BotCommandScope = BotCommandScopeDefault, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt index e4473c5431..6ec5c5a862 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt @@ -10,6 +10,42 @@ import dev.inmo.tgbotapi.utils.PreviewFeature import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.plus +/** + * This function is used in [buildBehaviour] extensions to provide default [CoroutineScope] and allow to avoid all + * unnecessary parameters except of block + */ +expect var defaultCoroutineScopeProvider: () -> CoroutineScope + +/** + * Use this method in case you wish to make some additional actions with [flowUpdatesFilter]. + * + * **WARNING** This method WILL NOT launch any listening of updates. Use something like + * [startGettingOfUpdatesByLongPolling] or tools for work with webhooks + * + * @see [BehaviourContext] + * @see startGettingOfUpdatesByLongPolling + */ +@PreviewFeature +@Deprecated("Parameters has been reordered. Replace scope and flowUpdatesFilter for correct order") +suspend fun TelegramBot.buildBehaviour( + scope: CoroutineScope, + flowUpdatesFilter: FlowsUpdatesFilter, + defaultExceptionsHandler: ExceptionHandler? = null, + block: BehaviourContextReceiver +) { + BehaviourContext( + this, + scope.let { + if (defaultExceptionsHandler == null) { + it + } else { + it + ContextSafelyExceptionHandler(defaultExceptionsHandler) + } + }, + flowUpdatesFilter + ).block() +} + /** * Use this method in case you wish to make some additional actions with [flowUpdatesFilter]. * @@ -21,8 +57,8 @@ import kotlinx.coroutines.plus */ @PreviewFeature suspend fun TelegramBot.buildBehaviour( - scope: CoroutineScope, flowUpdatesFilter: FlowsUpdatesFilter, + scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) { @@ -49,7 +85,7 @@ suspend fun TelegramBot.buildBehaviour( */ @PreviewFeature suspend fun TelegramBot.buildBehaviour( - scope: CoroutineScope, + scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) = FlowsUpdatesFilter().let { diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt index c279181bb9..f02c6cd3bf 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.CallbackQuery.* @@ -14,13 +15,19 @@ private suspend fun BehaviourContext.waitCallbackQueries( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, mapper: suspend CallbackQuery.() -> O? ): List = expectFlow( initRequest, count, errorFactory ) { - it.asCallbackQueryUpdate() ?.data ?.mapper().let(::listOfNotNull) + val data = it.asCallbackQueryUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } }.toList().toList() @@ -28,17 +35,23 @@ private suspend inline fun BehaviourContext.waitCall count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: CallbackQueryMapper? = null + noinline filter: SimpleFilter? = null, + noinline mapper: CallbackQueryMapper? = null ) : List = waitCallbackQueries( count, initRequest, - errorFactory + errorFactory, + filter ?.let { + { + (it as? T) ?.let { filter(it) } == true + } + } ) { if (this is T) { - if (filter == null) { + if (mapper == null) { this } else { - filter(this) + mapper(this) } } else { null @@ -50,53 +63,62 @@ suspend fun BehaviourContext.waitDataCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitGameShortNameCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitInlineMessageIdCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitInlineMessageIdDataCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitInlineMessageIdGameShortNameCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitMessageCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitMessageDataCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitMessageGameShortNameCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitUnknownCallbackQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CallbackQueryMapper? = null -) = waitCallbacks(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: CallbackQueryMapper? = null +) = waitCallbacks(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt index 6157825208..801bdf0384 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate @@ -14,29 +15,37 @@ private suspend inline fun BehaviourContex count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline filter: SimpleFilter? = null, noinline mapper: ChatMemberUpdatedMapper ): List = expectFlow( initRequest, count, errorFactory ) { - (it as? T) ?.data.let(::listOfNotNull) + val casted = (it as? T) ?: return@expectFlow emptyList() + if (filter == null || filter(casted)) { + casted.data.mapper().let(::listOfNotNull) + } else { + emptyList() + } }.toList().toList() private suspend inline fun BehaviourContext.waitChatMemberUpdatedWithFilter( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: ChatMemberUpdatedMapper? = null + noinline filter: SimpleFilter? = null, + noinline mapper: ChatMemberUpdatedMapper? = null ) : List = waitChatMemberUpdated( count, initRequest, - errorFactory + errorFactory, + filter, ) { - if (filter == null) { + if (mapper == null) { this } else { - filter(this) + mapper(this) } } @@ -44,19 +53,22 @@ suspend fun BehaviourContext.waitChatMemberUpdated( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: ChatMemberUpdatedMapper? = null -) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: ChatMemberUpdatedMapper? = null +) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitCommonChatMemberUpdated( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: ChatMemberUpdatedMapper? = null -) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: ChatMemberUpdatedMapper? = null +) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitMyChatMemberUpdated( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: ChatMemberUpdatedMapper? = null -) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: ChatMemberUpdatedMapper? = null +) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index 67cbfec556..2e3063c057 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -4,13 +4,16 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter +import dev.inmo.tgbotapi.extensions.utils.withContent import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate import kotlinx.coroutines.flow.toList typealias CommonMessageToContentMapper = suspend CommonMessage.() -> T? @@ -20,18 +23,32 @@ private suspend fun BehaviourContext.waitCommonMessage( initRequest: Request<*>? = null, includeMediaGroups: Boolean = true, errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter>? = null, mapper: suspend CommonMessage.() -> O? ): List = expectFlow( initRequest, count, errorFactory ) { - if (includeMediaGroups) { - it.asSentMediaGroupUpdate() ?.data ?.mapNotNull { - (it as CommonMessage).mapper() - } ?.let { return@expectFlow it } + val messages = when (it) { + is SentMediaGroupUpdate -> { + if (includeMediaGroups) { + it.data.map { it as CommonMessage } + } else { + emptyList() + } + } + is BaseSentMessageUpdate -> listOf(it.data) + else -> return@expectFlow emptyList() + } + messages.mapNotNull { message -> + val asCommonMessage = message as CommonMessage + if (filter == null || filter(asCommonMessage)) { + asCommonMessage.mapper() + } else { + null + } } - it.asBaseSentMessageUpdate() ?.data ?.asCommonMessage() ?.mapper().let(::listOfNotNull) }.toList().toList() private suspend inline fun BehaviourContext.waitContent( @@ -39,20 +56,26 @@ private suspend inline fun BehaviourContext.waitCon initRequest: Request<*>? = null, includeMediaGroups: Boolean = true, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: CommonMessageToContentMapper? = null + noinline filter: SimpleFilter>? = null, + noinline mapper: CommonMessageToContentMapper? = null ) : List = waitCommonMessage( count, initRequest, includeMediaGroups, - errorFactory + errorFactory, + filter ?.let { + { + it.withContent() ?.let { filter(it) } == true + } + } ) { if (content is T) { @Suppress("UNCHECKED_CAST") val message = (this as CommonMessage) - if (filter == null) { + if (mapper == null) { message.content } else { - safelyWithoutExceptions { filter(message) } + safelyWithoutExceptions { mapper(message) } } } else { null @@ -64,140 +87,162 @@ suspend fun BehaviourContext.waitContentMessage( errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitContact( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitDice( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitGame( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitLocation( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitPoll( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitText( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVenue( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitAudioMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitDocumentMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitMedia( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = false, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitAnyMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVisualMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitAnimation( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitAudio( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = false, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitDocument( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = false, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitPhoto( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = false, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitSticker( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVideo( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = false, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVideoNote( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVoice( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) suspend fun BehaviourContext.waitInvoice( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 53fee66475..c0f7d534be 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.requests.abstracts.Request @@ -18,13 +19,19 @@ private suspend fun BehaviourContext.waitEventMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, + filter: SimpleFilter>? = null, mapper: suspend ChatEventMessage.() -> O? ): List = expectFlow( initRequest, count, errorFactory ) { - it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper().let(::listOfNotNull) + val data = it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } }.toList().toList() @@ -32,19 +39,25 @@ private suspend inline fun BehaviourContext.waitEvents( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: EventMessageToEventMapper? = null + noinline filter: SimpleFilter>? = null, + noinline mapper: EventMessageToEventMapper? = null ) : List = waitEventMessages( initRequest, errorFactory, - count + count, + filter ?.let { + { + (it.chatEvent as? T) ?.let { filter(it as ChatEventMessage) } == true + } + } ) { if (chatEvent is T) { @Suppress("UNCHECKED_CAST") val message = (this as ChatEventMessage) - if (filter == null) { + if (mapper == null) { message.chatEvent } else { - filter(message) + mapper(message) } } else { null @@ -55,124 +68,144 @@ suspend fun BehaviourContext.waitChannelEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitChatEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVoiceChatEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVoiceChatStartedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVoiceChatEndedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitVoiceChatParticipantsInvitedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitCommonEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitGroupEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitSupergroupEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitChannelChatCreatedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitDeleteChatPhotoEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitGroupChatCreatedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitLeftChatMemberEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitNewChatPhotoEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitNewChatMembersEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitNewChatTitleEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitPinnedMessageEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitProximityAlertTriggeredEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitSupergroupChatCreatedEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: EventMessageToEventMapper? = null -) = waitEvents(count, initRequest, errorFactory, filter) + filter: SimpleFilter>? = null, + mapper: EventMessageToEventMapper? = null +) = waitEvents(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt index 3c6ecf4a6f..1089c62113 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.InlineQueries.query.* @@ -12,13 +13,19 @@ private suspend fun BehaviourContext.waitInlineQueries( count: Int = 1, initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, + filter: SimpleFilter? = null, mapper: suspend InlineQuery.() -> O? ): List = expectFlow( initRequest, count, errorFactory ) { - it.asInlineQueryUpdate() ?.data ?.mapper().let(::listOfNotNull) + val data = it.asInlineQueryUpdate() ?.data + if (data != null && (filter == null || filter(data))) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } }.toList().toList() @@ -26,17 +33,23 @@ private suspend inline fun BehaviourContext.waitInline count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: InlineQueryMapper? = null + noinline filter: SimpleFilter? = null, + noinline mapper: InlineQueryMapper? = null ) : List = waitInlineQueries( count, initRequest, - errorFactory + errorFactory, + filter ?.let { + { + (it as? T) ?.let { casted -> filter(casted) } == true + } + } ) { if (this is T) { - if (filter == null) { + if (mapper == null) { this } else { - filter(this) + mapper(this) } } else { null @@ -47,18 +60,21 @@ suspend fun BehaviourContext.waitAnyInlineQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: InlineQueryMapper? = null -) = waitInlines(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: InlineQueryMapper? = null +) = waitInlines(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitBaseInlineQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: InlineQueryMapper? = null -) = waitInlines(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: InlineQueryMapper? = null +) = waitInlines(count, initRequest, errorFactory, filter, mapper) suspend fun BehaviourContext.waitLocationInlineQuery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: InlineQueryMapper? = null -) = waitInlines(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: InlineQueryMapper? = null +) = waitInlines(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt index c77cd0381b..22fa5b7313 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate import dev.inmo.tgbotapi.extensions.utils.asPassportMessage import dev.inmo.tgbotapi.requests.abstracts.Request @@ -17,30 +18,38 @@ suspend fun BehaviourContext.waitPassportMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, + filter: SimpleFilter? = null, mapper: suspend PassportMessage.() -> O? ): List = expectFlow( initRequest, count, errorFactory ) { - it.asMessageUpdate() ?.data ?.asPassportMessage() ?.mapper().let(::listOfNotNull) + val data = it.asMessageUpdate() ?.data ?.asPassportMessage() ?: return@expectFlow emptyList() + if (filter == null || filter(data)) { + data.mapper().let(::listOfNotNull) + } else { + emptyList() + } }.toList().toList() suspend inline fun BehaviourContext.waitPassportMessagesWith( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: PassportMessageMapper? = null + noinline filter: SimpleFilter? = null, + noinline mapper: PassportMessageMapper? = null ) : List = waitPassportMessages( initRequest, errorFactory, - count + count, + filter ) { if (passportData.data.any { it is T }) { - if (filter == null) { + if (mapper == null) { passportData } else { - filter(this) + mapper(this) } } else { null @@ -51,5 +60,6 @@ suspend fun BehaviourContext.waitAnyPassportMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: PassportMessageMapper? = null -) = waitPassportMessagesWith(count, initRequest, errorFactory, filter) + filter: SimpleFilter? = null, + mapper: PassportMessageMapper? = null +) = waitPassportMessagesWith(count, initRequest, errorFactory, filter, mapper) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index e6e4c3b565..51480d43d4 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate @@ -11,7 +12,7 @@ import dev.inmo.tgbotapi.types.CallbackQuery.* internal suspend inline fun BehaviourContext.onCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (T) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -41,56 +42,56 @@ internal suspend inline fun BehaviourContext.onCallb suspend fun BehaviourContext.onDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (DataCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (GameShortNameCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineMessageIdCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineMessageIdDataCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineMessageIdGameShortNameCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (MessageCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (MessageDataCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (MessageGameShortNameCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onUnknownCallbackQueryType( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (UnknownCallbackQueryType) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index eff524264b..6994853ec7 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatMemberUpdatedMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -13,7 +14,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -38,7 +39,7 @@ internal suspend inline fun BehaviourConte suspend fun BehaviourContext.onChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -50,7 +51,7 @@ suspend fun BehaviourContext.onChatMemberUpdated( suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -62,7 +63,7 @@ suspend fun BehaviourContext.onCommonChatMemberUpdated( suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index bbdd4d6b65..9c0d76855a 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.* @@ -17,7 +18,7 @@ import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.utils.PreviewFeature -typealias CommonMessageFilter = (suspend (CommonMessage) -> Boolean) +typealias CommonMessageFilter = SimpleFilter> @PreviewFeature internal suspend inline fun BehaviourContext.onContent( @@ -123,7 +124,7 @@ suspend fun BehaviourContext.onDocumentMediaGroupContent( suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, - additionalFilter: (suspend (CommonMessage>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 9e44c0d449..c72c39d18d 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -4,6 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate @@ -16,7 +17,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage internal suspend inline fun BehaviourContext.onEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { @@ -44,122 +45,122 @@ internal suspend inline fun BehaviourContext.onEvent( suspend fun BehaviourContext.onChannelEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatStartedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEndedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onCommonEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChannelChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDeleteChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLeftChatMember( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatMembers( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatTitle( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPinnedMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onProximityAlertTriggered( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 79db28675a..381bff6932 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserInlineQueryMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate @@ -11,7 +12,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.* internal suspend inline fun BehaviourContext.onInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (T) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -41,7 +42,7 @@ internal suspend inline fun BehaviourContext.onInlineQ suspend fun BehaviourContext.onAnyInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) @@ -49,7 +50,7 @@ suspend fun BehaviourContext.onAnyInlineQuery( suspend fun BehaviourContext.onBaseInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (BaseInlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) @@ -57,7 +58,7 @@ suspend fun BehaviourContext.onBaseInlineQuery( suspend fun BehaviourContext.onLocationInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (LocationInlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index dfc1e53bac..305baaddd8 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate @@ -19,7 +20,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (List>) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = flowsUpdatesFilter.expectFlow(bot) { update -> @@ -47,43 +48,43 @@ internal suspend inline fun BehaviourContext.bui suspend fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt index 30e35a4196..ed130e4f5d 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate @@ -13,7 +14,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportEle internal suspend inline fun BehaviourContext.onPassportMessageWith( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -40,7 +41,7 @@ internal suspend inline fun BehaviourCont suspend fun BehaviourContext.onPassportMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onPassportMessageWith( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt new file mode 100644 index 0000000000..b7b7ca17e1 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils + +typealias SimpleFilter = suspend (T) -> Boolean diff --git a/tgbotapi.extensions.behaviour_builder/src/jsMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt b/tgbotapi.extensions.behaviour_builder/src/jsMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt new file mode 100644 index 0000000000..93b2831568 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/jsMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers + +actual var defaultCoroutineScopeProvider = { + CoroutineScope(Dispatchers.Default) +} diff --git a/tgbotapi.extensions.behaviour_builder/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt b/tgbotapi.extensions.behaviour_builder/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt new file mode 100644 index 0000000000..3106aef3ca --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers + +actual var defaultCoroutineScopeProvider = { + CoroutineScope(Dispatchers.IO) +} diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index b8901c90e6..c0da943b17 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -23,6 +23,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.* import dev.inmo.tgbotapi.types.InlineQueries.query.* import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.types.actions.* import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.* @@ -3106,3 +3107,12 @@ inline fun Any.asFromUser(): FromUser? = this as? FromUser @PreviewFeature inline fun Any.requireFromUser(): FromUser = this as FromUser + +@PreviewFeature +inline fun Any.whenWithOptionalLanguageCode(block: (WithOptionalLanguageCode) -> T) = asWithOptionalLanguageCode() ?.let(block) + +@PreviewFeature +inline fun Any.asWithOptionalLanguageCode(): WithOptionalLanguageCode? = this as? WithOptionalLanguageCode + +@PreviewFeature +inline fun Any.requireWithOptionalLanguageCode(): WithOptionalLanguageCode = this as WithOptionalLanguageCode diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt index bff841b0ef..a1f341c16b 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.utils.extensions import dev.inmo.tgbotapi.extensions.utils.asFromUser -import dev.inmo.tgbotapi.extensions.utils.asFromUserMessage import dev.inmo.tgbotapi.extensions.utils.asUser import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat import dev.inmo.tgbotapi.types.User