diff --git a/CHANGELOG.md b/CHANGELOG.md index 15281370fb..b9f80096ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,75 @@ # 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`: + * 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 + +## 0.35.2 + +* `Common`: + * `Version`: + * `Kotlin`: `1.5.20` -> `1.5.21` + * `Coroutines`: `1.5.0` -> `1.5.1` + * `Serialization`: `1.2.1` -> `1.2.2` + * `Klock`: `2.1.2` -> `2.2.0` + * `Ktor`: `1.6.0` -> `1.6.1` + * `MicroUtils`: `0.5.15` -> `0.5.16` + +## 0.35.1 + +* `Common`: + * `Version`: + * `Kotlin`: `1.5.10` -> `1.5.20` + * `MicroUtils`: `0.5.6` -> `0.5.15` +* `Core`: + * New interface `MyCommandsRequest` (also see `Bot API 5.3` below) + * New extensions `TextSourcesList#make*String` for all parse modes + * All `MessageContent` subclasses now serializable + * `ChosenInlineResult` was replaced and modified to be sealed + * `ChosenInlineResult` now extends `FromUser` + * Added `Update#sourceUser` method + * More types assumed as sent by user types now implements `FromUser` interface + * Added `Any#whenFromUser`, `Any#asFromUser` and`Any#requireFromUser` extensions + * `MedaGroupUpdate` and its direct extenders `SentMediaGroupUpdate` and `EditMediaGroupUpdate` became + `sealed interface`s + * New built-in `RequestException` implementator `GetUpdatesConflict` has been added +* `Behaviour Builder`: + * ❗️ All triggers (`on*` extensions) have been modified to work in parallel by some marker by default (new parameter + `markerFactory`, in most cases will work async for different chats) + * New extensions `telegramBotWithBehaviour` + * All behaviour builder extensions got new parameter `defaultExceptionsHandler` + * Class `BehaviourContext` was rewritten as an interface with default realization `DefaultBehaviourContext` and + factory `BehaviourContext(TelegramBot, CoroutineScope, FlowsUpdatesFilter)` + * Extension `buildBehaviour` (and all related extensions/functions) for opportunity to pass + `defaultExceptionsHandler` + * Trigger `onContentMessage` and waiter `waitContentMessage` now may include media groups +* `API`: + * All `reply` and subsequent extensions have been replaced in send package +* `Utils`: + * With class casts like `as*` and `require*` now you may use `when*` with parameter callback + * Methods of `EntitiesBuilder` now will return builder itself, so you may create sequences like + `buildEntities { bold("Hello,") + italic(" world") }` directly in `buildEntities` body + * New extension `TelegramBot#longPollingFlow` has been added with returning value `Flow` with updates +* `Bot API 5.3`: + * Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children + * New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands` + * Renames according to `And more` of [June 25, 2021](https://core.telegram.org/bots/api-changelog#june-25-2021) update + ## 0.35.0 **ALL PREVIOUS DEPRECATIONS HAVE BEEN REMOVED** diff --git a/gradle.properties b/gradle.properties index 5fe3601c03..feeee555b0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,18 +5,18 @@ kotlin.js.generate.externals=true kotlin.incremental=true kotlin.incremental.js=true -kotlin_version=1.5.10 -kotlin_coroutines_version=1.5.0 -kotlin_serialisation_runtime_version=1.2.1 -klock_version=2.1.2 +kotlin_version=1.5.21 +kotlin_coroutines_version=1.5.1 +kotlin_serialisation_runtime_version=1.2.2 +klock_version=2.3.1 uuid_version=0.3.0 -ktor_version=1.6.0 +ktor_version=1.6.2 -micro_utils_version=0.5.6 +micro_utils_version=0.5.18 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.35.0 +library_version=0.35.3 github_release_plugin_version=2.2.12 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8bf36eef6a..5416585156 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip diff --git a/tgbotapi.core/README.md b/tgbotapi.core/README.md index edb5912051..f4eeda039d 100644 --- a/tgbotapi.core/README.md +++ b/tgbotapi.core/README.md @@ -9,7 +9,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility -This version compatible with [26th of April 2021 update of TelegramBotAPI (version 5.2)](https://core.telegram.org/bots/api-changelog#april-26-2021). +This version compatible with [25th of June 2021 update of TelegramBotAPI (version 5.3)](https://core.telegram.org/bots/api-changelog#june-25-2021). ## How to implement library? diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index e0db3fa289..6a8a112d06 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -53,6 +53,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" api "com.github.matfax.klassindex:library:4.+" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index d485657209..951cb4b17d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -4,12 +4,12 @@ import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.MultilevelTextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString import dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForCaption import dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForMessage import dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForText import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.textLength +import dev.inmo.tgbotapi.utils.extensions.makeString const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods" @@ -48,7 +48,7 @@ inline operator fun List.plus(text: String) = this + regular(text) ) typealias MultilevelTextSource = MultilevelTextSource -@Deprecated("Replaced", ReplaceWith("makeString()", "dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString")) +@Deprecated("Replaced", ReplaceWith("makeString()", "dev.inmo.tgbotapi.utils.extensions.makeString")) fun List.makeString() = makeString() @Deprecated( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/WithLanguageCode.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/WithLanguageCode.kt new file mode 100644 index 0000000000..d59d9c9cce --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/WithLanguageCode.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.micro_utils.language_codes.IetfLanguageCode + +interface WithOptionalLanguageCode { + val ietfLanguageCode: IetfLanguageCode? + + val languageCode: String? + get() = ietfLanguageCode ?.code +} + +interface WithLanguageCode : WithOptionalLanguageCode { + override val ietfLanguageCode: IetfLanguageCode + + override val languageCode: String + get() = ietfLanguageCode.code +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt index a9c6ec5f56..3ed3242660 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt @@ -25,6 +25,12 @@ fun newRequestException( message, cause ) + description.contains("Conflict: terminated by other getUpdates request") -> GetUpdatesConflict( + response, + plainAnswer, + message, + cause + ) else -> null } } ?: CommonRequestException(response, plainAnswer, message, cause) @@ -61,3 +67,6 @@ class WrongFileIdentifierException(response: Response, plainAnswer: String, mess class TooMuchRequestsException(val retryAfter: RetryAfterError, response: Response, plainAnswer: String, message: String?, cause: Throwable?) : RequestException(response, plainAnswer, message, cause) + +class GetUpdatesConflict(response: Response, plainAnswer: String, message: String?, cause: Throwable?) : + RequestException(response, plainAnswer, message, cause) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFile.kt index 1a02259ba6..d6111400e6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFile.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.requests.abstracts import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.StorageFile -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder 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 new file mode 100644 index 0000000000..e5fb89c6c3 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.requests.bot + +import dev.inmo.tgbotapi.CommonAbstracts.WithOptionalLanguageCode +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.commands.BotCommandScope + +sealed interface MyCommandsRequest : SimpleRequest, WithOptionalLanguageCode { + val scope: BotCommandScope +} 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 new file mode 100644 index 0000000000..61b01180cb --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt @@ -0,0 +1,32 @@ +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.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class DeleteMyCommands( + @SerialName(scopeField) + @Serializable(BotCommandScopeSerializer::class) + override val scope: BotCommandScope = BotCommandScopeDefault, + @SerialName(languageCodeField) + @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 ebb3ee54d2..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,17 +1,36 @@ package dev.inmo.tgbotapi.requests.bot -import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest -import dev.inmo.tgbotapi.types.BotCommand +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.* import kotlinx.serialization.builtins.ListSerializer private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer()) @Serializable -object GetMyCommands : SimpleRequest> { +data class GetMyCommands( + @SerialName(scopeField) + @Serializable(BotCommandScopeSerializer::class) + override val scope: BotCommandScope = BotCommandScopeDefault, + @SerialName(languageCodeField) + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null +) : MyCommandsRequest> { override fun method(): String = "getMyCommands" override val resultDeserializer: DeserializationStrategy> get() = getMyCommandsSerializer 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 1e8e068328..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,21 +1,39 @@ package dev.inmo.tgbotapi.requests.bot -import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +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.* import kotlinx.serialization.builtins.serializer @Serializable class SetMyCommands( @SerialName(botCommandsField) - val commands: List -) : SimpleRequest { + val commands: List, + @SerialName(scopeField) + @Serializable(BotCommandScopeSerializer::class) + override val scope: BotCommandScope = BotCommandScopeDefault, + @SerialName(languageCodeField) + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null +) : MyCommandsRequest { override fun method(): String = "setMyCommands" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() 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/chat/get/GetChatMembersCount.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetChatMemberCount.kt similarity index 71% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetChatMembersCount.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetChatMemberCount.kt index 9a7c11c0ff..c8c5a688b8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetChatMembersCount.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetChatMemberCount.kt @@ -8,13 +8,16 @@ import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @Serializable -data class GetChatMembersCount( +data class GetChatMemberCount( @SerialName(chatIdField) override val chatId: ChatIdentifier ): ChatRequest, SimpleRequest { - override fun method(): String = "getChatMembersCount" + override fun method(): String = "getChatMemberCount" override val resultDeserializer: DeserializationStrategy get() = Int.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +@Deprecated("Renamed", ReplaceWith("GetChatMemberCount", "dev.inmo.tgbotapi.requests.chat.get.GetChatMemberCount")) +typealias GetChatMembersCount = GetChatMemberCount diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/KickChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/BanChatMember.kt similarity index 78% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/KickChatMember.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/BanChatMember.kt index 58d62c3359..2dacaab43c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/KickChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/BanChatMember.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @Serializable -data class KickChatMember( +data class BanChatMember( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(userIdField) @@ -17,9 +17,12 @@ data class KickChatMember( @SerialName(revokeMessagesField) val revokeMessages: Boolean? = null ) : ChatMemberRequest, UntilDate { - override fun method(): String = "kickChatMember" + override fun method(): String = "banChatMember" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> get() = serializer() } + +@Deprecated("Renamed", ReplaceWith("BanChatMember", "dev.inmo.tgbotapi.requests.chat.members.BanChatMember")) +typealias KickChatMember = BanChatMember 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 189db1b32f..e0a7bb9269 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,7 +5,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 9b083f7a5c..161924ac62 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,7 +4,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 1fa5cd07bb..17c1dc3cc1 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,7 +5,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 15b3cbd32d..42226c395b 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,7 +4,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 56aa097cac..d327de74fa 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 c64ba21146..31e2ab5d2d 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,7 +5,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 ed1850ab78..729be79337 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 2de6a3229f..fe3481221d 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 06cc58a104..9d94c9cd58 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 87cc0e1c80..2aa4bd292f 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 7fc73a202e..13f1509876 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 98d8ec1075..ca9b4042cc 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 2a6a35efdc..f11af12b50 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt index c5b6685505..3ab043ed28 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.CallbackQuery +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.CallbackQueryIdentifier import dev.inmo.tgbotapi.types.User -sealed interface CallbackQuery { +sealed interface CallbackQuery : FromUser { val id: CallbackQueryIdentifier - val user: User val chatInstance: String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 4cbee6bedd..cf3f5c256b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types import dev.inmo.micro_utils.common.Warning import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt index 5751852819..3664311d96 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.ChatMember.abstracts import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt index d5c5acfde0..2551a7d017 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt @@ -5,7 +5,8 @@ import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.statusField import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 8c89fdf0d5..8a9ba6d089 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -82,6 +82,8 @@ val membersLimit = 1 .. 99999 val suggestedTipAmountsLimit = 1 .. 4 +val inputFieldPlaceholderLimit = 1 .. 64 + const val botActionActualityTime: Seconds = 5 // Made as lazy for correct work in K/JS @@ -234,6 +236,7 @@ const val hideUrlField = "hide_url" const val botCommandField = "command" const val botCommandsField = "commands" +const val scopeField = "scope" const val isMemberField = "is_member" const val canSendMessagesField = "can_send_messages" @@ -365,6 +368,8 @@ const val requireShippingAddressField = "need_shipping_address" const val shouldSendPhoneNumberToProviderField = "send_phone_number_to_provider" const val shouldSendEmailToProviderField = "send_email_to_provider" +const val inputFieldPlaceholderField = "input_field_placeholder" + const val priceDependOnShipAddressField = "is_flexible" const val documentField = "document" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult.kt index cee9a023b6..bf85756e09 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/BaseChosenInlineResult.kt @@ -1,10 +1,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class BaseChosenInlineResult( override val resultId: InlineQueryIdentifier, + @SerialName(fromField) override val user: User, override val inlineMessageId: InlineMessageIdentifier?, override val query: String 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 new file mode 100644 index 0000000000..2f2b594a7b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult + +import dev.inmo.tgbotapi.CommonAbstracts.FromUser +import dev.inmo.tgbotapi.types.* + +sealed interface ChosenInlineResult : FromUser { + val resultId: InlineQueryIdentifier //chosen temporary, can be changed + val inlineMessageId: InlineMessageIdentifier? + val query: String +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt index 16324e7e85..30388e7e6f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt @@ -1,11 +1,14 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult import dev.inmo.tgbotapi.types.location.StaticLocation +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class LocationChosenInlineResult( override val resultId: InlineQueryIdentifier, + @SerialName(fromField) override val user: User, val location: StaticLocation, override val inlineMessageId: InlineMessageIdentifier?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt index 4db078be40..c16c87b3df 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable 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 703d5ca43b..f63e10b046 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 c475060374..30ad172859 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 6d242e32f9..fb640eac18 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 @@ -6,7 +6,8 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +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 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 1541ae783b..108efc3b2b 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 c0af32ce1a..9b8da064fb 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 b78b03d017..78a909ac5a 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 c2a8154121..7d399d2392 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 9810cd6f27..4966d82e24 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 0a1aed3b2c..a0b4c36574 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 c835c7e469..786a88bb55 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 4d65516edc..3d9a9f2ff7 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,7 +7,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 fbf4a330b3..ba211d7877 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,7 +6,7 @@ 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.types.MessageEntity.textsources.makeString +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 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 55c91a8686..cf155b0e1a 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 @@ -6,7 +6,8 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +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 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 7bece71430..bf9bf21573 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 @@ -5,7 +5,8 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +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 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt index cc8d150dba..1cf5def126 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/serializers/InlineQueryResultSerializer.kt @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.serializers import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder 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 ef056d4857..7b61ea7ee0 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,7 +5,7 @@ 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.types.MessageEntity.textsources.makeString +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import kotlinx.serialization.SerialName diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt index 815272fb5a..364661cceb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContentSerializer.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types.InlineQueries import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.* import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt index 1d98928768..999d0deba6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt @@ -1,10 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.abstracts -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult -interface ChosenInlineResult { - val resultId: InlineQueryIdentifier //chosen temporary, can be changed - val user: User - val inlineMessageId: InlineMessageIdentifier? - val query: String -} \ No newline at end of file +@Deprecated("Replaced", ReplaceWith("ChosenInlineResult", "dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult")) +typealias ChosenInlineResult = ChosenInlineResult 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 aa9ec48be9..7af6629e9e 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 @@ -5,7 +5,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile 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.* +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 kotlinx.serialization.SerialName 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 c8a9a79b3d..45a8e82c13 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 @@ -1,12 +1,12 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.Performerable import dev.inmo.tgbotapi.requests.abstracts.InputFile 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.types.MessageEntity.textsources.makeString +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 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 06dc0d724d..6d9d23fbd0 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 @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +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 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 c243befc9b..9e189b2283 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 @@ -4,7 +4,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile 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.* +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 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt index a5358762e1..5eb959fbd4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder 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 cc8c545216..e7dac1004c 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 @@ -4,7 +4,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile 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.* +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 kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt index 2777e576f0..e5b632a974 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMediaSerializer.kt @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.types.typeField import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index 40c5a53b3b..b8fc500f45 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 9e07f371d9..a1311c6249 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index 0e99978665..6caf8ea9a9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index 2138cd9485..3bfc19a39c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 18c3125996..cab6dd1d6d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index 6c84646821..471c316a28 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index 67350033eb..67e3295968 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 7965ae799f..e7773ee7d1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index 7a9e6ad792..495b18c2c9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSource.kt index 3ac89386a4..340ccd1937 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSource.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.textLength +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.Serializable const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods" @@ -42,7 +43,8 @@ sealed interface MultilevelTextSource : TextSource { } } -fun List.makeString() = joinToString("") { it.source } +@Deprecated("Replaced", ReplaceWith("makeString()", "dev.inmo.tgbotapi.utils.extensions.makeString")) +fun TextSourcesList.makeString() = makeString(null) fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { if (isEmpty()) { return emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index 0a61ab2905..fd40c1a74c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TelegramDate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TelegramDate.kt index 8ac8a5c12e..80d9e0c443 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TelegramDate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TelegramDate.kt @@ -7,7 +7,6 @@ import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.JsonPrimitive @Serializable(TelegramDateSerializer::class) data class TelegramDate( 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 5c7fd10e41..b8774ea67c 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,9 +1,11 @@ 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.CommonAbstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat import dev.inmo.tgbotapi.types.chat.extended.ExtendedPrivateChatImpl import dev.inmo.tgbotapi.utils.* -import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.* import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder @@ -23,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/actions/BotAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt index a79b14781d..b258aeacf4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.actions -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonPollType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonPollType.kt index 681c44f03f..e049a332a5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonPollType.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonPollType.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types.buttons import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardMarkupSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardMarkupSerializer.kt index 328d9f61fa..e0562fbcfd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardMarkupSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardMarkupSerializer.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.buttons import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt index ad6c101b45..bfa3ad377e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt @@ -1,10 +1,14 @@ package dev.inmo.tgbotapi.types.buttons +import dev.inmo.tgbotapi.types.inputFieldPlaceholderField +import dev.inmo.tgbotapi.types.inputFieldPlaceholderLimit import kotlinx.serialization.* @Serializable data class ReplyForce( - val selective: Boolean? = null + val selective: Boolean? = null, + @SerialName(inputFieldPlaceholderField) + val inputFieldPlaceholder: String? = null ) : KeyboardMarkup { @SerialName("force_reply") @Required @@ -15,6 +19,12 @@ data class ReplyForce( val ReplyForceNonSelective = ReplyForce(false) val ReplyForceDefault = ReplyForce() } + + init { + if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) { + error("Field $inputFieldPlaceholderField length must be in $inputFieldPlaceholderLimit, but was ${inputFieldPlaceholder.length}") + } + } } @Deprecated("Renamed", ReplaceWith("ReplyForce", "dev.inmo.tgbotapi.types.buttons.ReplyForce")) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt index 70ff25aaf1..a88703b9ff 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.types.buttons +import dev.inmo.tgbotapi.types.inputFieldPlaceholderField +import dev.inmo.tgbotapi.types.inputFieldPlaceholderLimit import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,5 +12,13 @@ data class ReplyKeyboardMarkup( val resizeKeyboard: Boolean? = null, @SerialName("one_time_keyboard") val oneTimeKeyboard: Boolean? = null, + @SerialName(inputFieldPlaceholderField) + val inputFieldPlaceholder: String? = null, val selective: Boolean? = null -) : KeyboardMarkup +) : KeyboardMarkup { + init { + if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) { + error("Field $inputFieldPlaceholderField length must be in $inputFieldPlaceholderLimit, but was ${inputFieldPlaceholder.length}") + } + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt new file mode 100644 index 0000000000..9fa0b953d2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt @@ -0,0 +1,124 @@ +package dev.inmo.tgbotapi.types.commands + +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable +private class SurrogateBotCommandScope( + @SerialName(typeField) + @Required + val type: String, + @SerialName(chatIdField) + val chatId: ChatIdentifier? = null, + @SerialName(userIdField) + val userId: UserId? = null +) { + fun asBotCommandScope() = when (type) { + BotCommandScopeDefault.type -> BotCommandScopeDefault + BotCommandScopeAllPrivateChats.type -> BotCommandScopeAllPrivateChats + BotCommandScopeAllGroupChats.type -> BotCommandScopeAllGroupChats + BotCommandScopeAllChatAdministrators.type -> BotCommandScopeAllChatAdministrators + BotCommandScopeChatAdministrators.type -> BotCommandScopeChatAdministrators( + chatId ?: error("chat_administrators type must have $chatIdField field, but have no") + ) + BotCommandScopeChatMember.type -> BotCommandScopeChatMember( + chatId ?: error("chat_administrators type must have $chatIdField field, but have no"), + userId ?: error("chat_administrators type must have $userIdField field, but have no") + ) + else -> UnknownBotCommandScope(type) + } + + companion object { + fun from(scope: BotCommandScope) = when (scope) { + is UnknownBotCommandScope, + BotCommandScopeDefault, + BotCommandScopeAllPrivateChats, + BotCommandScopeAllGroupChats, + BotCommandScopeAllChatAdministrators -> SurrogateBotCommandScope(scope.type) + is BotCommandScopeChatAdministrators -> SurrogateBotCommandScope(scope.type, scope.chatId) + is BotCommandScopeChatMember -> SurrogateBotCommandScope(scope.type, scope.chatId, scope.userId) + } + } +} + +@Serializable(BotCommandScopeSerializer::class) +sealed interface BotCommandScope { + val type: String +} + +@Serializable +data class UnknownBotCommandScope internal constructor( + override val type: String +) : BotCommandScope + +@Serializable +object BotCommandScopeDefault : BotCommandScope { + @Required + override val type: String = "default" +} + +@Serializable +object BotCommandScopeAllPrivateChats : BotCommandScope { + @Required + override val type: String = "all_private_chats" +} + +@Serializable +object BotCommandScopeAllGroupChats : BotCommandScope { + @Required + override val type: String = "all_group_chats" +} + +@Serializable +object BotCommandScopeAllChatAdministrators : BotCommandScope { + @Required + override val type: String = "all_chat_administrators" +} + + +sealed interface ChatBotCommandScope : BotCommandScope { + val chatId: ChatIdentifier +} + +@Serializable +data class BotCommandScopeChatAdministrators( + override val chatId: ChatIdentifier +) : ChatBotCommandScope { + @Required + override val type: String = BotCommandScopeChatAdministrators.type + companion object { + const val type = "chat_administrators" + } +} + +@Serializable +data class BotCommandScopeChatMember( + override val chatId: ChatIdentifier, + val userId: UserId +) : ChatBotCommandScope { + @Required + override val type: String = BotCommandScopeChatMember.type + companion object { + const val type = "chat_member" + } +} + + +object BotCommandScopeSerializer : KSerializer { + + override val descriptor: SerialDescriptor = SurrogateBotCommandScope.serializer().descriptor + + override fun deserialize( + decoder: Decoder + ): BotCommandScope = SurrogateBotCommandScope.serializer().deserialize(decoder).asBotCommandScope() + + override fun serialize(encoder: Encoder, value: BotCommandScope) { + SurrogateBotCommandScope.serializer().serialize( + encoder, SurrogateBotCommandScope.from(value) + ) + } + +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt index 8feb10b0f0..7e34caf55f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types.dice import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.utils.RiskFeature -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt index 6cf7fc17b7..66100ae8ae 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt @@ -5,7 +5,9 @@ import dev.inmo.tgbotapi.CommonAbstracts.Titled import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.Photo +import kotlinx.serialization.Serializable +@Serializable data class Game( override val title: String, val description: String, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt index dfd71fe71a..22a9def5f3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt @@ -5,4 +5,4 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent data class LeftChatMember( val user: User -): CommonEvent +) : CommonEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt index 20d0c73370..b5909f032e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt @@ -6,7 +6,9 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import kotlinx.serialization.Serializable +@Serializable data class ContactContent( val contact: Contact ) : MessageContent { @@ -19,4 +21,4 @@ data class ContactContent( ): Request> = SendContact( chatId, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) -} \ No newline at end of file +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt index 891f848d56..f8e85ff6d3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt @@ -8,7 +8,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import kotlinx.serialization.Serializable +@Serializable data class DiceContent( val dice: Dice ) : MessageContent { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt index 5e7b21f9d9..85378995ad 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt @@ -8,7 +8,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.games.Game import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import kotlinx.serialization.Serializable +@Serializable data class GameContent( val game: Game ) : MessageContent { @@ -26,4 +28,4 @@ data class GameContent( allowSendingWithoutReply, replyMarkup ) -} \ No newline at end of file +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt index ddb139e0d6..a035a3e4f6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt @@ -8,7 +8,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.polls.Poll +import kotlinx.serialization.Serializable +@Serializable data class PollContent( val poll: Poll ) : MessageContent { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index ad5a3d089c..e2e83e0892 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -9,7 +9,9 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import kotlinx.serialization.Serializable +@Serializable data class TextContent( override val text: String, override val textSources: TextSourcesList = emptyList(), diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt index 60a355afe1..84e08f55fb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt @@ -8,7 +8,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.venue.Venue +import kotlinx.serialization.Serializable +@Serializable data class VenueContent( val venue: Venue ) : MessageContent { @@ -21,4 +23,4 @@ data class VenueContent( ): Request> = SendVenue( chatId, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) -} \ No newline at end of file +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index 96c11864e2..f38b11357c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -12,7 +12,9 @@ import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import kotlinx.serialization.Serializable +@Serializable data class AnimationContent( override val media: AnimationFile, val includedDocument: DocumentFile?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index c7d94ddce2..a8fc1083cc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -11,7 +11,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent +import kotlinx.serialization.Serializable +@Serializable data class AudioContent( override val media: AudioFile, override val text: String? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 140db64a47..0fca7ca43a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -14,7 +14,9 @@ import dev.inmo.tgbotapi.types.files.asDocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import kotlinx.serialization.Serializable +@Serializable data class DocumentContent( override val media: DocumentFile, override val text: String? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index 921282e298..6ecfa69d43 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -12,7 +12,9 @@ import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent +import kotlinx.serialization.Serializable +@Serializable data class PhotoContent( override val mediaCollection: Photo, override val text: String? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt index 7b0ab518e2..e456140a23 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt @@ -9,7 +9,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import kotlinx.serialization.Serializable +@Serializable data class StickerContent( override val media: Sticker ) : MediaContent { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 41e8e360c5..c168bdd128 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -11,7 +11,9 @@ import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.toInputMediaVideo import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent +import kotlinx.serialization.Serializable +@Serializable data class VideoContent( override val media: VideoFile, override val text: String? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt index 848e6bb1e9..4ca7bf80b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt @@ -9,7 +9,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoNoteFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import kotlinx.serialization.Serializable +@Serializable data class VideoNoteContent( override val media: VideoNoteFile ) : MediaContent { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 5cae1a9cb5..8dca1bb1a5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -11,7 +11,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import kotlinx.serialization.Serializable +@Serializable data class VoiceContent( override val media: VoiceFile, override val text: String? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt index b7dcca1c12..94dfa598c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt @@ -7,7 +7,9 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.payments.Invoice +import kotlinx.serialization.Serializable +@Serializable data class InvoiceContent( val invoice: Invoice ) : MessageContent { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt index b617d3c4c3..1332885dd8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.typeField import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt index 742e184d96..dfdfe4a1a7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.payments +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.payments.abstracts.* import kotlinx.serialization.SerialName @@ -11,7 +12,7 @@ data class PreCheckoutQuery( @SerialName(idField) val id: PreCheckoutQueryId, @SerialName(fromField) - val user: User, + override val user: User, @SerialName(currencyField) override val currency: Currency, @SerialName(totalAmountField) @@ -22,4 +23,4 @@ data class PreCheckoutQuery( val shippingOptionId: ShippingOptionIdentifier? = null, @SerialName(orderInfoField) val orderInfo: OrderInfo? = null -) : Currencied, Amounted +) : Currencied, Amounted, FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt index dfa1735728..7821211bf6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.payments +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -9,9 +10,9 @@ data class ShippingQuery( @SerialName(idField) val id: ShippingQueryIdentifier, @SerialName(fromField) - val user: User, + override val user: User, @SerialName(invoicePayloadField) val invoicePayload: InvoicePayload, @SerialName(shippingAddressField) val shippingAddress: ShippingAddress -) +) : FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt index d0e32260af..c4ea74bfa0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.polls +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -9,7 +10,7 @@ data class PollAnswer( @SerialName(pollIdField) val pollId: PollIdentifier, @SerialName(userField) - val user: User, + override val user: User, @SerialName(optionIdsField) val chosen: List -) +) : FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChosenInlineResultUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChosenInlineResultUpdate.kt index 8aa0d1e825..1f10df9add 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChosenInlineResultUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChosenInlineResultUpdate.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.update -import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.update.abstracts.Update data class ChosenInlineResultUpdate( override val updateId: UpdateIdentifier, override val data: ChosenInlineResult -) : Update \ No newline at end of file +) : Update diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt index b50e772ba7..740d7fab8e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt @@ -11,14 +11,14 @@ import dev.inmo.tgbotapi.types.update.abstracts.* * @see dev.inmo.tgbotapi.extensions.api.SetWebhookKt.includeWebhookInRoute * @see dev.inmo.tgbotapi.extensions.api.updates.UpdatesPollingKt.startGettingOfUpdates */ -interface MediaGroupUpdate : Update +sealed interface MediaGroupUpdate : Update -interface SentMediaGroupUpdate: MediaGroupUpdate { +sealed interface SentMediaGroupUpdate: MediaGroupUpdate { override val data: List> val origins: List } -interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate { +sealed interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate { override val data: MediaGroupMessage val origin: BaseMessageUpdate } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index 9b86454801..de735db1c4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update +import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.* interface FlowsUpdatesFilter : UpdatesFilter { @@ -41,11 +42,12 @@ fun FlowsUpdatesFilter( broadcastChannelsSize: Int = 100 ) = DefaultFlowsUpdatesFilter(broadcastChannelsSize) -@Suppress("EXPERIMENTAL_API_USAGE", "unused") +@Suppress("unused") class DefaultFlowsUpdatesFilter( - broadcastChannelsSize: Int = 100 + broadcastChannelsSize: Int = 100, + onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND ): FlowsUpdatesFilter { - private val updatesSharedFlow = MutableSharedFlow(extraBufferCapacity = broadcastChannelsSize) + private val updatesSharedFlow = MutableSharedFlow(extraBufferCapacity = broadcastChannelsSize, onBufferOverflow = onBufferOverflow) @Suppress("MemberVisibilityCanBePrivate") override val allUpdatesFlow: Flow = updatesSharedFlow.asSharedFlow() @Suppress("MemberVisibilityCanBePrivate") @@ -79,4 +81,4 @@ class DefaultFlowsUpdatesFilter( override val chatMemberUpdatedFlow: Flow = allUpdatesFlow.filterIsInstance() override val myChatMemberUpdatedFlow: Flow = allUpdatesFlow.filterIsInstance() override val unknownUpdateTypeFlow: Flow = allUpdatesFlow.filterIsInstance() -} \ No newline at end of file +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MimeType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MimeType.kt index 6864b0fa05..ee45272551 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MimeType.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MimeType.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.utils -import kotlinx.serialization.* +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/TextSourcesList.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/TextSourcesList.kt new file mode 100644 index 0000000000..d74f224c9a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/TextSourcesList.kt @@ -0,0 +1,30 @@ +package dev.inmo.tgbotapi.utils.extensions + +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.* + +inline fun TextSourcesList.makeString( + parseMode: ParseMode? = null +) = when (parseMode) { + MarkdownParseMode -> makeMarkdownString() + MarkdownV2ParseMode -> makeMarkdownV2String() + HTMLParseMode -> makeHtmlString() + null -> makeSourceString() +} + + +inline fun TextSourcesList.makeSourceString() = joinToString("") { + it.source +} + +inline fun TextSourcesList.makeHtmlString() = joinToString("") { + it.html +} + +inline fun TextSourcesList.makeMarkdownV2String() = joinToString("") { + it.markdownV2 +} + +inline fun TextSourcesList.makeMarkdownString() = joinToString("") { + it.markdown +} 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 6160f91965..ea4c261a33 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,35 +1,27 @@ package dev.inmo.tgbotapi.utils.internal -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +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.escapeMarkdownV2Link -import dev.inmo.tgbotapi.utils.extensions.toHtml - -private fun TextSourcesList.joinSubSourcesMarkdownV2() = joinToString("") { - it.markdownV2 -} - -private fun TextSourcesList.joinSubSourcesHtml() = joinToString("") { - it.html -} +import dev.inmo.tgbotapi.utils.extensions.* internal fun MultilevelTextSource.markdownV2Default( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "$openControlSymbol${subsources.joinSubSourcesMarkdownV2()}$closeControlSymbol" +) = "$openControlSymbol${subsources.makeMarkdownV2String()}$closeControlSymbol" internal fun MultilevelTextSource.htmlDefault( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "<$openControlSymbol>${subsources.joinSubSourcesHtml()}" +) = "<$openControlSymbol>${subsources.makeHtmlString()}" internal fun MultilevelTextSource.linkMarkdownV2( link: String -) = "[${subsources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" +) = "[${subsources.makeMarkdownV2String()}](${link.escapeMarkdownV2Link()})" internal fun MultilevelTextSource.linkHTML( link: String -) = "${subsources.joinSubSourcesHtml()}" +) = "${subsources.makeHtmlString()}" internal fun MultilevelTextSource.optionalPrefix( @@ -50,8 +42,8 @@ internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(m internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl) -internal fun MultilevelTextSource.cashTagMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.cashTagHTML(): String = subsources.joinSubSourcesHtml() +internal fun MultilevelTextSource.cashTagMarkdownV2(): String = subsources.makeMarkdownV2String() +internal fun MultilevelTextSource.cashTagHTML(): String = subsources.makeHtmlString() internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl) @@ -69,16 +61,16 @@ internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnde internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link) -internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.joinSubSourcesHtml() +internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.makeMarkdownV2String() +internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.makeHtmlString() internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when { source.startsWith("\\#") || source.startsWith("#") -> "" else -> "\\#" -} + subsources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + subsources.joinSubSourcesHtml() +} + subsources.makeMarkdownV2String() +internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + subsources.makeHtmlString() -internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml() +internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.makeMarkdownV2String() +internal fun MultilevelTextSource.phoneHTML(): String = subsources.makeHtmlString() diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt index 12596f0922..cf1f1d844e 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types import dev.inmo.tgbotapi.TestsJsonFormat import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer -import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString +import dev.inmo.tgbotapi.utils.extensions.makeString import kotlinx.serialization.builtins.ListSerializer import kotlin.test.Test import kotlin.test.assertEquals 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..d2e9da4d08 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.CommonAbstracts.WithLanguageCode import java.util.* -fun CommonUser.javaLocale(): Locale? = languageCode ?.let { - Locale.forLanguageTag(it) -} +fun IetfLanguageCode?.javaLocale() = this ?.code ?.let { Locale.forLanguageTag(it) } +fun WithLanguageCode?.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 new file mode 100644 index 0000000000..3995e5384a --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt @@ -0,0 +1,17 @@ +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 +import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault + +suspend fun TelegramBot.deleteMyCommands( + scope: BotCommandScope = BotCommandScopeDefault, + 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 22995619e7..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,6 +1,17 @@ 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 +import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault -suspend fun TelegramBot.getMyCommands() = execute(GetMyCommands) +suspend fun TelegramBot.getMyCommands( + scope: BotCommandScope = BotCommandScopeDefault, + 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 df5444d62c..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,13 +1,32 @@ 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 +import dev.inmo.tgbotapi.types.commands.BotCommandScope +import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.setMyCommands( - commands: List -) = execute(SetMyCommands(commands)) + commands: List, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: IetfLanguageCode? +) = execute(SetMyCommands(commands, scope, languageCode)) suspend fun TelegramBot.setMyCommands( - vararg commands: BotCommand -) = setMyCommands(commands.toList()) + 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, + languageCode: String? = null +) = setMyCommands(commands.toList(), scope, languageCode) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMemberCount.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMemberCount.kt new file mode 100644 index 0000000000..0f165b759a --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMemberCount.kt @@ -0,0 +1,24 @@ +package dev.inmo.tgbotapi.extensions.api.chat.get + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.get.GetChatMemberCount +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.getChatMemberCount( + chatId: ChatIdentifier +) = execute(GetChatMemberCount(chatId)) + +suspend fun TelegramBot.getChatMemberCount( + chat: PublicChat +) = getChatMemberCount(chat.id) + +@Deprecated("Renamed", ReplaceWith("getChatMemberCount", "dev.inmo.tgbotapi.extensions.api.chat.get.getChatMemberCount")) +suspend fun TelegramBot.getChatMembersCount( + chatId: ChatIdentifier +) = getChatMemberCount(chatId) + +@Deprecated("Renamed", ReplaceWith("getChatMemberCount", "dev.inmo.tgbotapi.extensions.api.chat.get.getChatMemberCount")) +suspend fun TelegramBot.getChatMembersCount( + chat: PublicChat +) = getChatMemberCount(chat) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMembersCount.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMembersCount.kt deleted file mode 100644 index 279d2dc3e9..0000000000 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMembersCount.kt +++ /dev/null @@ -1,14 +0,0 @@ -package dev.inmo.tgbotapi.extensions.api.chat.get - -import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.chat.get.GetChatMembersCount -import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat - -suspend fun TelegramBot.getChatMembersCount( - chatId: ChatIdentifier -) = execute(GetChatMembersCount(chatId)) - -suspend fun TelegramBot.getChatMembersCount( - chat: PublicChat -) = getChatMembersCount(chat.id) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/BanChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/BanChatMember.kt new file mode 100644 index 0000000000..6cf936caa6 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/BanChatMember.kt @@ -0,0 +1,66 @@ +package dev.inmo.tgbotapi.extensions.api.chat.members + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.members.BanChatMember +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.banChatMember( + chatId: ChatIdentifier, + userId: UserId, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = execute(BanChatMember(chatId, userId, untilDate, revokeMessages)) + +suspend fun TelegramBot.banChatMember( + chat: PublicChat, + userId: UserId, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chat.id, userId, untilDate, revokeMessages) + +suspend fun TelegramBot.banChatMember( + chatId: ChatId, + user: User, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chatId, user.id, untilDate, revokeMessages) + +suspend fun TelegramBot.banChatMember( + chat: PublicChat, + user: User, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chat.id, user.id, untilDate, revokeMessages) + +@Deprecated("Renamed", ReplaceWith("banChatMember", "dev.inmo.tgbotapi.extensions.api.chat.members.banChatMember")) +suspend fun TelegramBot.kickChatMember( + chatId: ChatIdentifier, + userId: UserId, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chatId, userId, untilDate, revokeMessages) + +@Deprecated("Renamed", ReplaceWith("banChatMember", "dev.inmo.tgbotapi.extensions.api.chat.members.banChatMember")) +suspend fun TelegramBot.kickChatMember( + chat: PublicChat, + userId: UserId, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chat, userId, untilDate, revokeMessages) + +@Deprecated("Renamed", ReplaceWith("banChatMember", "dev.inmo.tgbotapi.extensions.api.chat.members.banChatMember")) +suspend fun TelegramBot.kickChatMember( + chatId: ChatId, + user: User, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chatId, user, untilDate, revokeMessages) + +@Deprecated("Renamed", ReplaceWith("banChatMember", "dev.inmo.tgbotapi.extensions.api.chat.members.banChatMember")) +suspend fun TelegramBot.kickChatMember( + chat: PublicChat, + user: User, + untilDate: TelegramDate? = null, + revokeMessages: Boolean? = null +) = banChatMember(chat, user, untilDate, revokeMessages) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/KickChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/KickChatMember.kt deleted file mode 100644 index f924443d8b..0000000000 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/KickChatMember.kt +++ /dev/null @@ -1,34 +0,0 @@ -package dev.inmo.tgbotapi.extensions.api.chat.members - -import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.chat.members.KickChatMember -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat - -suspend fun TelegramBot.kickChatMember( - chatId: ChatIdentifier, - userId: UserId, - untilDate: TelegramDate? = null, - revokeMessages: Boolean? = null -) = execute(KickChatMember(chatId, userId, untilDate, revokeMessages)) - -suspend fun TelegramBot.kickChatMember( - chat: PublicChat, - userId: UserId, - untilDate: TelegramDate? = null, - revokeMessages: Boolean? = null -) = kickChatMember(chat.id, userId, untilDate, revokeMessages) - -suspend fun TelegramBot.kickChatMember( - chatId: ChatId, - user: User, - untilDate: TelegramDate? = null, - revokeMessages: Boolean? = null -) = kickChatMember(chatId, user.id, untilDate, revokeMessages) - -suspend fun TelegramBot.kickChatMember( - chat: PublicChat, - user: User, - untilDate: TelegramDate? = null, - revokeMessages: Boolean? = null -) = kickChatMember(chat.id, user.id, untilDate, revokeMessages) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt new file mode 100644 index 0000000000..fb0e8e0ad0 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -0,0 +1,761 @@ +package dev.inmo.tgbotapi.extensions.api.send + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.games.sendGame +import dev.inmo.tgbotapi.extensions.api.send.media.* +import dev.inmo.tgbotapi.extensions.api.send.payments.sendInvoice +import dev.inmo.tgbotapi.extensions.api.send.polls.sendQuizPoll +import dev.inmo.tgbotapi.extensions.api.send.polls.sendRegularPoll +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.send.media.rawSendingMediaGroupsWarning +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.dice.DiceAnimationType +import dev.inmo.tgbotapi.types.files.* +import dev.inmo.tgbotapi.types.games.Game +import dev.inmo.tgbotapi.types.location.StaticLocation +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.payments.LabeledPrice +import dev.inmo.tgbotapi.types.payments.abstracts.Currency +import dev.inmo.tgbotapi.types.polls.* +import dev.inmo.tgbotapi.types.venue.Venue +import dev.inmo.tgbotapi.utils.RiskFeature + + +// Contact + +suspend inline fun TelegramBot.reply( + to: Message, + phoneNumber: String, + firstName: String, + lastName: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendContact( + to.chat, + phoneNumber, + firstName, + lastName, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + contact: Contact, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendContact( + to.chat, + contact, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + + +// Dice + +suspend inline fun TelegramBot.replyWithDice( + to: Message, + animationType: DiceAnimationType? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendDice(to.chat, animationType, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + animationType: DiceAnimationType, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithDice(to, animationType, disableNotification, allowSendingWithoutReply, replyMarkup) + + +// Location + +suspend inline fun TelegramBot.reply( + to: Message, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyMarkup: KeyboardMarkup? = null +) = sendLocation( + to.chat, + latitude, + longitude, + disableNotification, + to.messageId, + replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + location: StaticLocation, + disableNotification: Boolean = false, + replyMarkup: KeyboardMarkup? = null +) = sendLocation( + to.chat, + location, + disableNotification, + to.messageId, + replyMarkup +) + + +// Text message + +suspend inline fun TelegramBot.reply( + to: Message, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage( + to.chat, + text, + parseMode, + disableWebPagePreview, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + entities: TextSourcesList, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage( + to.chat, + entities, + disableWebPagePreview, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + + +// Venue + +suspend inline fun TelegramBot.reply( + to: Message, + latitude: Double, + longitude: Double, + title: String, + address: String, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chat = to.chat, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + location: StaticLocation, + title: String, + address: String, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chat = to.chat, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + venue: Venue, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chat = to.chat, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup +) + + +// Game + +suspend inline fun TelegramBot.replyWithGame( + to: Message, + gameShortName: String, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + to.chat, gameShortName, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.replyWithGame( + to: Message, + game: Game, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + to.chat, game.title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + game: Game, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithGame(to, game, disableNotification, allowSendingWithoutReply, replyMarkup) + + +// Animation + +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + to.chat, + animation, + thumb, + text, + parseMode, + duration, + width, + height, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + animation: AnimationFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: InputFile, + entities: TextSourcesList, + thumb: InputFile? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + to.chat, + animation, + thumb, + entities, + duration, + width, + height, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + +suspend inline fun TelegramBot.reply( + to: Message, + animation: AnimationFile, + entities: TextSourcesList, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(to.chat, animation, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Audio + +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + audio: AudioFile, + text: String? = null, + parseMode: ParseMode? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, text, parseMode, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: InputFile, + thumb: InputFile? = null, + entities: TextSourcesList, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, thumb, entities, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + audio: AudioFile, + entities: TextSourcesList, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, entities, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Documents + +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, thumb, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.reply( + to: Message, + document: DocumentFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: InputFile, + thumb: InputFile? = null, + entities: TextSourcesList, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, thumb, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.reply( + to: Message, + document: DocumentFile, + entities: TextSourcesList, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + + +// Media Group + +@RiskFeature(rawSendingMediaGroupsWarning) +suspend inline fun TelegramBot.replyWithMediaGroup( + to: Message, + media: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) + +suspend inline fun TelegramBot.replyWithPlaylist( + to: Message, + media: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendPlaylist(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) + +suspend inline fun TelegramBot.replyWithDocuments( + to: Message, + media: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) + +suspend inline fun TelegramBot.replyWithGallery( + to: Message, + media: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) + + +// Photo + +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + fileId: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, fileId, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + photo: Photo, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + fileId: InputFile, + entities: TextSourcesList, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, fileId, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + photo: Photo, + entities: TextSourcesList, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, photo, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Sticker + +suspend inline fun TelegramBot.replyWithSticker( + to: Message, + sticker: InputFile, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + sticker: Sticker, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Videos + +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + video: VideoFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: InputFile, + thumb: InputFile? = null, + entities: TextSourcesList, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, thumb, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + video: VideoFile, + entities: TextSourcesList, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// VideoNotes + +suspend inline fun TelegramBot.replyWithVideoNote( + to: Message, + videoNote: InputFile, + thumb: InputFile? = null, + duration: Long? = null, + size: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideoNote(to.chat, videoNote, thumb, duration, size, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + videoNote: VideoNoteFile, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideoNote(to.chat, videoNote, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Voice + +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, text, parseMode, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + voice: VoiceFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: InputFile, + entities: TextSourcesList, + duration: Long? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, entities, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + voice: VoiceFile, + entities: TextSourcesList, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Invoice + +suspend inline fun TelegramBot.reply( + to: Message, + title: String, + description: String, + payload: String, + providerToken: String, + currency: Currency, + prices: List, + maxTipAmount: Int? = null, + suggestedTipAmounts: List? = null, + startParameter: StartParameter? = null, + providerData: String? = null, + requireName: Boolean = false, + requirePhoneNumber: Boolean = false, + requireEmail: Boolean = false, + requireShippingAddress: Boolean = false, + shouldSendPhoneNumberToProvider: Boolean = false, + shouldSendEmailToProvider: Boolean = false, + priceDependOnShipAddress: Boolean = false, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = sendInvoice(to.chat.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + + +// Polls + +suspend inline fun TelegramBot.reply( + to: Message, + question: String, + options: List, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + allowMultipleAnswers: Boolean = false, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + poll: RegularPoll, + isClosed: Boolean = false, + question: String = poll.question, + options: List = poll.options.map { it.text }, + isAnonymous: Boolean = poll.isAnonymous, + allowMultipleAnswers: Boolean = poll.allowMultipleAnswers, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + explanation: String? = null, + parseMode: ParseMode? = null, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + quizPoll: QuizPoll, + isClosed: Boolean = false, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + explanation: String? = null, + parseMode: ParseMode? = null, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + question: String, + options: List, + correctOptionId: Int, + entities: TextSourcesList, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + quizPoll: QuizPoll, + entities: TextSourcesList, + isClosed: Boolean = false, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt index 7edf1423e4..85fb7693db 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt @@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.requests.send.SendContact import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendContact( chatId: ChatIdentifier, @@ -58,37 +57,3 @@ suspend fun TelegramBot.sendContact( ) = sendContact( chat.id, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) - -suspend inline fun TelegramBot.reply( - to: Message, - phoneNumber: String, - firstName: String, - lastName: String? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendContact( - to.chat, - phoneNumber, - firstName, - lastName, - disableNotification, - to.messageId, - allowSendingWithoutReply, - replyMarkup -) - -suspend inline fun TelegramBot.reply( - to: Message, - contact: Contact, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendContact( - to.chat, - contact, - disableNotification, - to.messageId, - allowSendingWithoutReply, - replyMarkup -) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt index ff3ee673d4..9cac916e02 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt @@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.dice.DiceAnimationType -import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendDice( chatId: ChatIdentifier, @@ -28,19 +27,3 @@ suspend fun TelegramBot.sendDice( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.replyWithDice( - to: Message, - animationType: DiceAnimationType? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendDice(to.chat, animationType, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - animationType: DiceAnimationType? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = replyWithDice(to, animationType, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt index 7a98d1b72e..12990c8031 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt @@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.location.StaticLocation -import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendLocation( chatId: ChatIdentifier, @@ -106,31 +105,3 @@ suspend fun TelegramBot.sendStaticLocation( replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - latitude: Double, - longitude: Double, - disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = sendLocation( - to.chat, - latitude, - longitude, - disableNotification, - to.messageId, - replyMarkup -) - -suspend inline fun TelegramBot.reply( - to: Message, - location: StaticLocation, - disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = sendLocation( - to.chat, - location, - disableNotification, - to.messageId, - replyMarkup -) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt index 30447010b2..9b1bcf899d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt @@ -8,7 +8,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendMessage( chatId: ChatIdentifier, @@ -103,38 +102,3 @@ suspend fun TelegramBot.sendTextMessage( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendTextMessage(chat.id, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - text: String, - parseMode: ParseMode? = null, - disableWebPagePreview: Boolean? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendTextMessage( - to.chat, - text, - parseMode, - disableWebPagePreview, - disableNotification, - to.messageId, - allowSendingWithoutReply, - replyMarkup -) -suspend inline fun TelegramBot.reply( - to: Message, - entities: TextSourcesList, - disableWebPagePreview: Boolean? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendTextMessage( - to.chat, - entities, - disableWebPagePreview, - disableNotification, - to.messageId, - allowSendingWithoutReply, - replyMarkup -) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index 1f444aa8c0..6cfcbe6cf8 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.location.StaticLocation -import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.venue.Venue suspend fun TelegramBot.sendVenue( @@ -162,75 +161,3 @@ suspend fun TelegramBot.sendVenue( allowSendingWithoutReply = allowSendingWithoutReply, replyMarkup = replyMarkup ) - -suspend inline fun TelegramBot.reply( - to: Message, - latitude: Double, - longitude: Double, - title: String, - address: String, - foursquareId: FoursquareId? = null, - foursquareType: FoursquareType? = null, - googlePlaceId: GooglePlaceId? = null, - googlePlaceType: GooglePlaceType? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVenue( - chat = to.chat, - latitude = latitude, - longitude = longitude, - title = title, - address = address, - foursquareId = foursquareId, - foursquareType = foursquareType, - googlePlaceId = googlePlaceId, - googlePlaceType = googlePlaceType, - disableNotification = disableNotification, - replyToMessageId = to.messageId, - allowSendingWithoutReply = allowSendingWithoutReply, - replyMarkup = replyMarkup -) - -suspend inline fun TelegramBot.reply( - to: Message, - location: StaticLocation, - title: String, - address: String, - foursquareId: FoursquareId? = null, - foursquareType: FoursquareType? = null, - googlePlaceId: GooglePlaceId? = null, - googlePlaceType: GooglePlaceType? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVenue( - chat = to.chat, - latitude = location.latitude, - longitude = location.longitude, - title = title, - address = address, - foursquareId = foursquareId, - foursquareType = foursquareType, - googlePlaceId = googlePlaceId, - googlePlaceType = googlePlaceType, - disableNotification = disableNotification, - replyToMessageId = to.messageId, - allowSendingWithoutReply = allowSendingWithoutReply, - replyMarkup = replyMarkup -) - -suspend inline fun TelegramBot.reply( - to: Message, - venue: Venue, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVenue( - chat = to.chat, - venue = venue, - disableNotification = disableNotification, - replyToMessageId = to.messageId, - allowSendingWithoutReply = allowSendingWithoutReply, - replyMarkup = replyMarkup -) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt index bc95b64ca3..5dd0fa73d0 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.games import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithGame import dev.inmo.tgbotapi.requests.send.games.SendGame import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier @@ -55,30 +57,38 @@ suspend fun TelegramBot.sendGame( chat.id, game.title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) +@Deprecated( + "Replaced", + ReplaceWith("replyWithGame", "dev.inmo.tgbotapi.extensions.api.send.replyWithGame") +) suspend inline fun TelegramBot.replyWithGame( to: Message, gameShortName: String, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendGame( - to.chat, gameShortName, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup -) +) = replyWithGame(to, gameShortName, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("replyWithGame", "dev.inmo.tgbotapi.extensions.api.send.replyWithGame") +) suspend inline fun TelegramBot.replyWithGame( to: Message, game: Game, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendGame( - to.chat, game.title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup -) +) = replyWithGame(to, game, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, game: Game, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithGame(to, game, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, game, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt index df6646a8b0..67a3d7ba79 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendAnimation import dev.inmo.tgbotapi.types.ChatIdentifier @@ -87,59 +89,6 @@ suspend fun TelegramBot.sendAnimation( replyMarkup: KeyboardMarkup? = null ) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) -suspend inline fun TelegramBot.replyWithAnimation( - to: Message, - animation: InputFile, - thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, - duration: Long? = null, - width: Int? = null, - height: Int? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendAnimation( - to.chat, - animation, - thumb, - text, - parseMode, - duration, - width, - height, - disableNotification, - to.messageId, - allowSendingWithoutReply, - replyMarkup -) - -suspend inline fun TelegramBot.replyWithAnimation( - to: Message, - animation: AnimationFile, - text: String? = null, - parseMode: ParseMode? = null, - duration: Long? = null, - width: Int? = null, - height: Int? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - animation: AnimationFile, - text: String? = null, - parseMode: ParseMode? = null, - duration: Long? = null, - width: Int? = null, - height: Int? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = replyWithAnimation(to, animation, text, parseMode, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) - suspend fun TelegramBot.sendAnimation( chatId: ChatIdentifier, @@ -211,6 +160,10 @@ suspend fun TelegramBot.sendAnimation( replyMarkup: KeyboardMarkup? = null ) = sendAnimation(chat.id, animation, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("replyWithAnimation", "dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation") +) suspend inline fun TelegramBot.replyWithAnimation( to: Message, animation: InputFile, @@ -222,20 +175,23 @@ suspend inline fun TelegramBot.replyWithAnimation( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation( - to.chat, +) = replyWithAnimation( + to, animation, - thumb, entities, + thumb, duration, width, height, disableNotification, - to.messageId, allowSendingWithoutReply, replyMarkup ) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithAnimation( to: Message, animation: AnimationFile, @@ -246,8 +202,12 @@ suspend inline fun TelegramBot.replyWithAnimation( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(to.chat, animation, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, animation, entities, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, animation: AnimationFile, @@ -258,4 +218,69 @@ suspend inline fun TelegramBot.reply( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithAnimation(to, animation, entities, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, animation, entities, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) + + +@Deprecated( + "Replaced", + ReplaceWith("replyWithAnimation", "dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation") +) +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithAnimation( + to, + animation, + thumb, + text, + parseMode, + duration, + width, + height, + disableNotification, + allowSendingWithoutReply, + replyMarkup +) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithAnimation", "dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation") +) +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: AnimationFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, animation, text, parseMode, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.reply( + to: Message, + animation: AnimationFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, animation, text, parseMode, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt index f19f3ea605..e3846e02f4 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithAudio import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendAudio import dev.inmo.tgbotapi.types.ChatIdentifier @@ -81,42 +83,6 @@ suspend fun TelegramBot.sendAudio( replyMarkup: KeyboardMarkup? = null ) = sendAudio(chat.id, audio, text, parseMode, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) -suspend inline fun TelegramBot.replyWithAudio( - to: Message, - audio: InputFile, - thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, - duration: Long? = null, - performer: String? = null, - title: String? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.replyWithAudio( - to: Message, - audio: AudioFile, - text: String? = null, - parseMode: ParseMode? = null, - title: String? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, text, parseMode, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - audio: AudioFile, - text: String? = null, - parseMode: ParseMode? = null, - title: String? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = replyWithAudio(to, audio, text, parseMode, title, disableNotification, allowSendingWithoutReply, replyMarkup) - suspend inline fun TelegramBot.sendAudio( chatId: ChatIdentifier, @@ -182,6 +148,59 @@ suspend inline fun TelegramBot.sendAudio( replyMarkup: KeyboardMarkup? = null ) = sendAudio(chat.id, audio, entities, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithAudio", "dev.inmo.tgbotapi.extensions.api.send.replyWithAudio") +) +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithAudio(to, audio, thumb, text, parseMode, duration, performer, title, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: AudioFile, + text: String? = null, + parseMode: ParseMode? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, audio, text, parseMode, title, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.reply( + to: Message, + audio: AudioFile, + text: String? = null, + parseMode: ParseMode? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, audio, text, parseMode, title, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithAudio", "dev.inmo.tgbotapi.extensions.api.send.replyWithAudio") +) suspend inline fun TelegramBot.replyWithAudio( to: Message, audio: InputFile, @@ -193,8 +212,12 @@ suspend inline fun TelegramBot.replyWithAudio( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, thumb, entities, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = replyWithAudio(to, audio, thumb, entities, duration, performer, title, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithAudio( to: Message, audio: AudioFile, @@ -203,8 +226,12 @@ suspend inline fun TelegramBot.replyWithAudio( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, entities, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, audio, entities, title, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.repl") +) suspend inline fun TelegramBot.reply( to: Message, audio: AudioFile, @@ -213,4 +240,4 @@ suspend inline fun TelegramBot.reply( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithAudio(to, audio, entities, title, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, audio, entities, title, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt index a06dbc9ab9..bd3ce148e5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithDocument import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendDocument import dev.inmo.tgbotapi.types.ChatIdentifier @@ -77,41 +79,6 @@ suspend fun TelegramBot.sendDocument( disableContentTypeDetection: Boolean? = null ) = sendDocument(chat.id, document, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) -suspend inline fun TelegramBot.replyWithDocument( - to: Message, - document: InputFile, - thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null, - disableContentTypeDetection: Boolean? = null -) = sendDocument(to.chat, document, thumb, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) - -suspend inline fun TelegramBot.replyWithDocument( - to: Message, - document: DocumentFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null, - disableContentTypeDetection: Boolean? = null -) = sendDocument(to.chat, document, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) - -suspend inline fun TelegramBot.reply( - to: Message, - document: DocumentFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null, - disableContentTypeDetection: Boolean? = null -) = replyWithDocument(to, document, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) - - suspend inline fun TelegramBot.sendDocument( chatId: ChatIdentifier, document: InputFile, @@ -172,6 +139,57 @@ suspend inline fun TelegramBot.sendDocument( disableContentTypeDetection: Boolean? = null ) = sendDocument(chat.id, document, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithDocument", "dev.inmo.tgbotapi.extensions.api.send.replyWithDocument") +) +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = replyWithDocument(to, document, thumb, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: DocumentFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = reply(to, document, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.reply( + to: Message, + document: DocumentFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = reply(to, document, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithDocument", "dev.inmo.tgbotapi.extensions.api.send.replyWithDocument") +) suspend inline fun TelegramBot.replyWithDocument( to: Message, document: InputFile, @@ -181,8 +199,12 @@ suspend inline fun TelegramBot.replyWithDocument( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null, disableContentTypeDetection: Boolean? = null -) = sendDocument(to.chat, document, thumb, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) +) = replyWithDocument(to, document, thumb, entities, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithDocument( to: Message, document: DocumentFile, @@ -191,8 +213,12 @@ suspend inline fun TelegramBot.replyWithDocument( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null, disableContentTypeDetection: Boolean? = null -) = sendDocument(to.chat, document, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) +) = reply(to, document, entities, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, document: DocumentFile, @@ -201,4 +227,4 @@ suspend inline fun TelegramBot.reply( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null, disableContentTypeDetection: Boolean? = null -) = replyWithDocument(to, document, entities, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) +) = reply(to, document, entities, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index 01b8bb5077..7bc3706479 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -1,6 +1,10 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.replyWithDocuments +import dev.inmo.tgbotapi.extensions.api.send.replyWithGallery +import dev.inmo.tgbotapi.extensions.api.send.replyWithMediaGroup +import dev.inmo.tgbotapi.extensions.api.send.replyWithPlaylist import dev.inmo.tgbotapi.requests.send.media.* import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.* @@ -124,35 +128,56 @@ suspend fun TelegramBot.sendVisualMediaGroup( chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithMediaGroup", "dev.inmo.tgbotapi.extensions.api.send.replyWithMediaGroup") +) @RiskFeature(rawSendingMediaGroupsWarning) suspend inline fun TelegramBot.replyWithMediaGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = replyWithMediaGroup(to, media, disableNotification, allowSendingWithoutReply) +@Deprecated( + "Replaced", + ReplaceWith("replyWithPlaylist", "dev.inmo.tgbotapi.extensions.api.send.replyWithPlaylist") +) suspend inline fun TelegramBot.replyWithPlaylist( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendPlaylist(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = replyWithPlaylist(to, media, disableNotification, allowSendingWithoutReply) +@Deprecated( + "Replaced", + ReplaceWith("replyWithDocuments", "dev.inmo.tgbotapi.extensions.api.send.replyWithDocuments") +) suspend inline fun TelegramBot.replyWithDocumentsGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = replyWithDocuments(to, media, disableNotification, allowSendingWithoutReply) +@Deprecated( + "Replaced", + ReplaceWith("replyWithGallery", "dev.inmo.tgbotapi.extensions.api.send.replyWithGallery") +) suspend inline fun TelegramBot.replyWithVisualMediaGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = replyWithGallery(to, media, disableNotification, allowSendingWithoutReply) +@Deprecated( + "Replaced", + ReplaceWith("replyWithMediaGroup", "dev.inmo.tgbotapi.extensions.api.send.replyWithMediaGroup") +) suspend inline fun TelegramBot.reply( to: Message, media: List, diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt index 872ef23507..6b562f5c0e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithPhoto import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendPhoto import dev.inmo.tgbotapi.types.ChatIdentifier @@ -68,36 +70,6 @@ suspend fun TelegramBot.sendPhoto( replyMarkup: KeyboardMarkup? = null ) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) -suspend inline fun TelegramBot.replyWithPhoto( - to: Message, - fileId: InputFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.replyWithPhoto( - to: Message, - photo: Photo, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - photo: Photo, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = replyWithPhoto(to, photo, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) - suspend inline fun TelegramBot.sendPhoto( chatId: ChatIdentifier, @@ -149,6 +121,54 @@ suspend inline fun TelegramBot.sendPhoto( replyMarkup: KeyboardMarkup? = null ) = sendPhoto(chat.id, photo, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithPhoto", "dev.inmo.tgbotapi.extensions.api.send.replyWithPhoto") +) +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + fileId: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithPhoto(to, fileId, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + photo: Photo, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, photo, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.reply( + to: Message, + photo: Photo, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, photo, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +@Deprecated( + "Replaced", + ReplaceWith("replyWithPhoto", "dev.inmo.tgbotapi.extensions.api.send.replyWithPhoto") +) suspend inline fun TelegramBot.replyWithPhoto( to: Message, fileId: InputFile, @@ -156,8 +176,12 @@ suspend inline fun TelegramBot.replyWithPhoto( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = replyWithPhoto(to, fileId, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithPhoto( to: Message, photo: Photo, @@ -165,8 +189,12 @@ suspend inline fun TelegramBot.replyWithPhoto( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, photo, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, photo: Photo, @@ -174,4 +202,4 @@ suspend inline fun TelegramBot.reply( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithPhoto(to, photo, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, photo, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt index 9f7cac00f5..08b00f0704 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithSticker import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendSticker import dev.inmo.tgbotapi.types.ChatIdentifier @@ -48,26 +50,39 @@ suspend fun TelegramBot.sendSticker( replyMarkup: KeyboardMarkup? = null ) = sendSticker(chat, sticker.fileId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithSticker", "dev.inmo.tgbotapi.extensions.api.send.replyWithSticker") +) suspend inline fun TelegramBot.replyWithSticker( to: Message, sticker: InputFile, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = replyWithSticker(to, sticker, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithSticker( to: Message, sticker: Sticker, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, sticker, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, sticker: Sticker, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithSticker(to, sticker, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, sticker, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt index 5bcc1085c9..b4b29b3292 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithVideo import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVideo import dev.inmo.tgbotapi.types.ChatIdentifier @@ -81,41 +83,6 @@ suspend fun TelegramBot.sendVideo( replyMarkup: KeyboardMarkup? = null ) = sendVideo(chat.id, video, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) -suspend inline fun TelegramBot.replyWithVideo( - to: Message, - video: InputFile, - thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, - duration: Long? = null, - width: Int? = null, - height: Int? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.replyWithVideo( - to: Message, - video: VideoFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - video: VideoFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = replyWithVideo(to, video, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) - - suspend inline fun TelegramBot.sendVideo( chatId: ChatIdentifier, video: InputFile, @@ -180,6 +147,57 @@ suspend inline fun TelegramBot.sendVideo( replyMarkup: KeyboardMarkup? = null ) = sendVideo(chat.id, video, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithVideo", "dev.inmo.tgbotapi.extensions.api.send.replyWithVideo") +) +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: InputFile, + thumb: InputFile? = null, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithVideo(to, video, thumb, text, parseMode, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: VideoFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, video, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.reply( + to: Message, + video: VideoFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, video, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithVideo", "dev.inmo.tgbotapi.extensions.api.send.replyWithVideo") +) suspend inline fun TelegramBot.replyWithVideo( to: Message, video: InputFile, @@ -191,8 +209,12 @@ suspend inline fun TelegramBot.replyWithVideo( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, thumb, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = replyWithVideo(to, video, thumb, entities, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithVideo( to: Message, video: VideoFile, @@ -200,8 +222,12 @@ suspend inline fun TelegramBot.replyWithVideo( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, video, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, video: VideoFile, @@ -209,4 +235,4 @@ suspend inline fun TelegramBot.reply( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVideo(to, video, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, video, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt index 7bebc92be5..211d8b3427 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithVideoNote import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVideoNote import dev.inmo.tgbotapi.types.ChatIdentifier @@ -66,6 +68,11 @@ suspend fun TelegramBot.sendVideoNote( replyMarkup: KeyboardMarkup? = null ) = sendVideoNote(chat.id, videoNote, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithVideoNote", "dev.inmo.tgbotapi.extensions.api.send.replyWithVideoNote") +) suspend inline fun TelegramBot.replyWithVideoNote( to: Message, videoNote: InputFile, @@ -75,20 +82,28 @@ suspend inline fun TelegramBot.replyWithVideoNote( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(to.chat, videoNote, thumb, duration, size, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = replyWithVideoNote(to, videoNote, thumb, duration, size, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithVideoNote( to: Message, videoNote: VideoNoteFile, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(to.chat, videoNote, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, videoNote, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, videoNote: VideoNoteFile, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVideoNote(to, videoNote, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, videoNote, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt index 6024220d4b..697c2d181c 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt @@ -1,6 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.replyWithVoice import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVoice import dev.inmo.tgbotapi.types.ChatIdentifier @@ -72,37 +74,6 @@ suspend fun TelegramBot.sendVoice( replyMarkup: KeyboardMarkup? = null ) = sendVoice(chat.id, voice, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) -suspend inline fun TelegramBot.replyWithVoice( - to: Message, - voice: InputFile, - text: String? = null, - parseMode: ParseMode? = null, - duration: Long? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, text, parseMode, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.replyWithVoice( - to: Message, - voice: VoiceFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) - -suspend inline fun TelegramBot.reply( - to: Message, - voice: VoiceFile, - text: String? = null, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null -) = replyWithVoice(to, voice, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) - suspend inline fun TelegramBot.sendVoice( chatId: ChatIdentifier, @@ -159,6 +130,55 @@ suspend inline fun TelegramBot.sendVoice( replyMarkup: KeyboardMarkup? = null ) = sendVoice(chat.id, voice, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("replyWithVoice", "dev.inmo.tgbotapi.extensions.api.send.replyWithVoice") +) +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithVoice(to, voice, text, parseMode, duration, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: VoiceFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, voice, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) +suspend inline fun TelegramBot.reply( + to: Message, + voice: VoiceFile, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = reply(to, voice, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +@Deprecated( + "Replaced", + ReplaceWith("replyWithVoice", "dev.inmo.tgbotapi.extensions.api.send.replyWithVoice") +) suspend inline fun TelegramBot.replyWithVoice( to: Message, voice: InputFile, @@ -167,8 +187,12 @@ suspend inline fun TelegramBot.replyWithVoice( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, entities, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = replyWithVoice(to, voice, entities, duration, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithVoice( to: Message, voice: VoiceFile, @@ -176,8 +200,12 @@ suspend inline fun TelegramBot.replyWithVoice( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, voice, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.reply( to: Message, voice: VoiceFile, @@ -185,4 +213,4 @@ suspend inline fun TelegramBot.reply( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVoice(to, voice, entities, disableNotification, allowSendingWithoutReply, replyMarkup) +) = reply(to, voice, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt index 1fdce04371..9aaabef97d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.api.send.payments import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.requests.send.payments.SendInvoice import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -60,6 +61,11 @@ suspend fun TelegramBot.sendInvoice( replyMarkup: InlineKeyboardMarkup? = null ) = sendInvoice(user.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithInvoice( to: Message, title: String, @@ -82,4 +88,4 @@ suspend inline fun TelegramBot.replyWithInvoice( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = sendInvoice(to.chat.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt index 2662d17013..96db4a23d0 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.api.send.polls import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.requests.send.polls.SendQuizPoll import dev.inmo.tgbotapi.requests.send.polls.SendRegularPoll import dev.inmo.tgbotapi.types.ChatIdentifier @@ -227,6 +228,10 @@ suspend inline fun TelegramBot.sendQuizPoll( chat.id, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithRegularPoll( to: Message, question: String, @@ -238,8 +243,12 @@ suspend inline fun TelegramBot.replyWithRegularPoll( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithRegularPoll( to: Message, poll: RegularPoll, @@ -252,8 +261,12 @@ suspend inline fun TelegramBot.replyWithRegularPoll( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, question: String, @@ -267,8 +280,12 @@ suspend inline fun TelegramBot.replyWithQuizPoll( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, isClosed: Boolean = false, @@ -283,8 +300,12 @@ suspend inline fun TelegramBot.replyWithQuizPoll( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, quizPoll, isClosed, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, allowSendingWithoutReply, replyMarkup) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, question: String, @@ -297,8 +318,12 @@ suspend inline fun TelegramBot.replyWithQuizPoll( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, question, options, correctOptionId, isAnonymous, isClosed) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, isClosed: Boolean = false, @@ -312,4 +337,4 @@ suspend inline fun TelegramBot.replyWithQuizPoll( disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +) = reply(to, quizPoll, entities, isClosed, question, options, correctOptionId, isAnonymous, closeInfo, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.behaviour_builder/README.md b/tgbotapi.extensions.behaviour_builder/README.md index 70296ce190..c618a07ce8 100644 --- a/tgbotapi.extensions.behaviour_builder/README.md +++ b/tgbotapi.extensions.behaviour_builder/README.md @@ -15,7 +15,7 @@ bot.startGettingFlowsUpdatesByLongPolling { This library offer other way to do a lot of routine in more simple way: ```kotlin -telegramBot(token) { +telegramBotWithBehaviour(token) { onCommand("start".regex) { execute(SendTextMessage(it.chat.id, "This bot can ...")) // replaceable with reply(it, "This bot can ...") when you are using `tgbotapi.extensions.api` } @@ -28,7 +28,7 @@ In terminology of this project the `Triggers` are things which have no initial m messages and filter messages for context which will be used in subcontext. Full syntax with `onText` as an example: ```kotlin -telegramBot(TOKEN) { +telegramBotWithBehaviour(TOKEN) { onText( includeFilterByChatInBehaviourSubContext = true, // if false - last lambda will receive all messages instead of filtered by chat messages additionalFilter = { message: CommonMessage -> @@ -45,7 +45,7 @@ telegramBot(TOKEN) { Waiters targeted to get some content "here and now", they must be used inside some trigger main lambda: ```kotlin -telegramBot(TOKEN) { +telegramBotWithBehaviour(TOKEN) { onCommand("start") { message: CommonMessage -> val userPhotos = waitPhoto( SendTextMessage(it.chat.id, "Ok, send me some photo, please"), // init request, can be any `Request` object 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 cd14764a51..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 @@ -1,11 +1,50 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder +import dev.inmo.micro_utils.coroutines.ContextSafelyExceptionHandler +import dev.inmo.micro_utils.coroutines.ExceptionHandler import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter 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]. @@ -18,13 +57,20 @@ import kotlinx.coroutines.CoroutineScope */ @PreviewFeature suspend fun TelegramBot.buildBehaviour( - scope: CoroutineScope, flowUpdatesFilter: FlowsUpdatesFilter, + scope: CoroutineScope = defaultCoroutineScopeProvider(), + defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) { BehaviourContext( this, - scope, + scope.let { + if (defaultExceptionsHandler == null) { + it + } else { + it + ContextSafelyExceptionHandler(defaultExceptionsHandler) + } + }, flowUpdatesFilter ).block() } @@ -39,12 +85,14 @@ suspend fun TelegramBot.buildBehaviour( */ @PreviewFeature suspend fun TelegramBot.buildBehaviour( - scope: CoroutineScope, + scope: CoroutineScope = defaultCoroutineScopeProvider(), + defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) = FlowsUpdatesFilter().let { buildBehaviour( scope, it, + defaultExceptionsHandler, block ) longPolling( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index f4d91975fb..c92ff63c62 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.micro_utils.coroutines.weakLaunch +import dev.inmo.micro_utils.coroutines.* import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter @@ -15,15 +14,49 @@ typealias BehaviourContextAndTypeReceiver = suspend BehaviourContext.(I) - /** * This class contains all necessary tools for work with bots and especially for [buildBehaviour] * - * @param scope This param will be used for creating of some subscriptions inside of methods, updates listening and - * different other things in context of working with [CoroutineScope] and coroutines. - * @param flowsUpdatesFilter This parameter will be used to subscribe on different types of update + * @see DefaultBehaviourContext */ -data class BehaviourContext( - val bot: TelegramBot, - val scope: CoroutineScope, - val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() -) : FlowsUpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope +interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope { + val bot: TelegramBot + get() = this + + /** + * Will be used for creating of some subscriptions inside of methods, updates listening and different other things + * in context of working with [CoroutineScope] and coroutines. + */ + val scope: CoroutineScope + get() = this + + /** + * This parameter will be used to subscribe on different types of update + */ + val flowsUpdatesFilter: FlowsUpdatesFilter + get() = this + + fun copy( + bot: TelegramBot = this.bot, + scope: CoroutineScope = this.scope, + flowsUpdatesFilter: FlowsUpdatesFilter = this.flowsUpdatesFilter + ): BehaviourContext +} + +class DefaultBehaviourContext( + override val bot: TelegramBot, + override val scope: CoroutineScope, + override val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() +) : FlowsUpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope, BehaviourContext { + override fun copy( + bot: TelegramBot, + scope: CoroutineScope, + flowsUpdatesFilter: FlowsUpdatesFilter + ): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, flowsUpdatesFilter) +} + +fun BehaviourContext( + bot: TelegramBot, + scope: CoroutineScope, + flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() +) = DefaultBehaviourContext(bot, scope, flowsUpdatesFilter) /** * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and @@ -37,15 +70,18 @@ suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp: BehaviourContextAndTypeReceiver?, stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver -): T = supervisorScope { - val newContext = copy( +): T { + return copy( flowsUpdatesFilter = FlowsUpdatesFilter(), - scope = this - ) - newFlowsUpdatesFilterSetUp ?.let { - it.apply { invoke(newContext, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } + scope = LinkedSupervisorScope() + ).run { + newFlowsUpdatesFilterSetUp ?.let { + it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } + } + withContext(coroutineContext) { + behaviourContextReceiver().also { if (stopOnCompletion) stop() } + } } - newContext.behaviourContextReceiver().also { if (stopOnCompletion) stop() } } /** @@ -60,12 +96,12 @@ suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( newFlowsUpdatesFilterSetUp = updatesFilter ?.let { { oldOne -> weakLaunch { - oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) + oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(this, block = asUpdateReceiver) } } } ?: { oldOne -> weakLaunch { - oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) + oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(this, block = asUpdateReceiver) } }, stopOnCompletion, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/TelegramBot.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/TelegramBot.kt new file mode 100644 index 0000000000..eb62df598a --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/TelegramBot.kt @@ -0,0 +1,80 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutorBuilder +import dev.inmo.tgbotapi.bot.Ktor.telegramBot +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling +import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter +import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl +import kotlinx.coroutines.* +import kotlin.coroutines.coroutineContext + +/** + * Create bot using [telegramBot] and start listening for updates using [buildBehaviour]. + * Use this method in case you wish to make some additional actions with [flowsUpdatesFilter]. + * + * **WARNING** This method WILL NOT launch any listening of updates. Use something like + * [startGettingOfUpdatesByLongPolling] or tools for work with webhooks + * + * @return Created bot which has been used to create [BehaviourContext] via [buildBehaviour] + * + * @see [BehaviourContext] + * @see [buildBehaviour] + * @see startGettingOfUpdatesByLongPolling + */ +suspend fun telegramBotWithBehaviour( + token: String, + flowsUpdatesFilter: FlowsUpdatesFilter, + scope: CoroutineScope? = null, + apiUrl: String = telegramBotAPIDefaultUrl, + builder: KtorRequestsExecutorBuilder.() -> Unit = {}, + defaultExceptionsHandler: ExceptionHandler? = null, + block: BehaviourContextReceiver +): TelegramBot = telegramBot( + token, + apiUrl, + builder +).apply { + buildBehaviour( + scope ?: CoroutineScope(coroutineContext), + flowsUpdatesFilter, + defaultExceptionsHandler, + block + ) +} + +/** + * Create bot using [telegramBot] and start listening for updates using [buildBehaviour]. + * Use this method in case you wish to make some additional actions with [flowsUpdatesFilter]. + * + * **WARNING** This method WILL NOT launch any listening of updates. Use something like + * [startGettingOfUpdatesByLongPolling] or tools for work with webhooks + * + * @return Pair of [TelegramBot] and [Job]. This [Job] can be used to stop listening updates in your [block] you passed + * here + * + * @see [BehaviourContext] + * @see [buildBehaviour] + * @see startGettingOfUpdatesByLongPolling + */ +suspend fun telegramBotWithBehaviour( + token: String, + scope: CoroutineScope? = null, + apiUrl: String = telegramBotAPIDefaultUrl, + builder: KtorRequestsExecutorBuilder.() -> Unit = {}, + defaultExceptionsHandler: ExceptionHandler? = null, + block: BehaviourContextReceiver +): Pair { + return telegramBot( + token, + apiUrl, + builder + ).let { + it to it.buildBehaviour( + scope ?: CoroutineScope(coroutineContext), + defaultExceptionsHandler, + block + ) + } +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt index 2e95e776fb..822785234a 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/Base.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations +import dev.inmo.micro_utils.coroutines.safelyWithResult import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext @@ -38,11 +39,11 @@ suspend fun FlowsUpdatesFilter.expectFlow( filter: suspend (Update) -> List ): Flow { val flow = allUpdatesFlow.flatMapConcat { - val result = safelyWithoutExceptions { filter(it) } - (if (result == null || result.isEmpty()) { + val result = safelyWithResult { filter(it) } + (if (result.isFailure || result.getOrThrow().isEmpty()) { if (cancelTrigger(it)) { cancelRequestFactory(it) ?.also { - safelyWithoutExceptions { bot.execute(it) } + safelyWithResult { bot.execute(it) } throw cancelledByFilterException } } @@ -51,7 +52,7 @@ suspend fun FlowsUpdatesFilter.expectFlow( } emptyList() } else { - result + result.getOrThrow() }).asFlow() } val result = if (count == null) { 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 67b3746a09..67cbfec556 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 @@ -63,8 +63,9 @@ suspend fun BehaviourContext.waitContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, + includeMediaGroups: Boolean = true, filter: CommonMessageToContentMapper? = null -) = waitContent(count, initRequest, false, errorFactory, filter) +) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) suspend fun BehaviourContext.waitContact( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, 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 1c604ec76f..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 @@ -1,16 +1,19 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling - -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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 import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat 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) { it.asCallbackQueryUpdate() ?.data ?.let { query -> @@ -20,7 +23,10 @@ internal suspend inline fun BehaviourContext.onCallb null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerQuery -> +}.subscribeSafelyWithoutExceptionsAsync( + scope, + markerFactory::invoke +) { triggerQuery -> doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } @@ -36,47 +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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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 2150b7649b..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 @@ -1,8 +1,11 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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 import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate @@ -11,13 +14,17 @@ 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) { (it as? U) ?.data ?.let { chatMemberUpdated -> if (additionalFilter == null || additionalFilter(chatMemberUpdated)) chatMemberUpdated else null }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerChatMemberUpdated -> +}.subscribeSafelySkippingExceptionsAsync( + scope, + markerFactory::invoke +) { triggerChatMemberUpdated -> doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } @@ -32,30 +39,36 @@ 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( includeFilterByChatInBehaviourSubContext, additionalFilter, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, + markerFactory, scenarioReceiver ) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index 4ab3479166..9e90a3cd70 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -2,6 +2,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +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.asBotCommandTextSource import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.TextContent @@ -12,6 +14,7 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ): Job = onText( includeFilterByChatInBehaviourSubContext, @@ -27,6 +30,7 @@ suspend fun BehaviourContext.command( commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) } && (additionalFilter ?.invoke(message) != false) }, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.command( @@ -34,21 +38,24 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( command: String, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) 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 b649fe7f90..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 @@ -2,9 +2,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile @@ -15,36 +18,35 @@ 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( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { - if (includeMediaGroups) { - it.asSentMediaGroupUpdate() ?.data ?.mapNotNull { - if (it.content is T) { - val adaptedMessage = it as CommonMessage - if (additionalFilter == null || additionalFilter(adaptedMessage)) adaptedMessage else null - } else { - null - } - } ?.let { - return@expectFlow it - } + val messages = it.whenBaseSentMessageUpdate { + it.data.whenCommonMessage(::listOfNotNull) + } ?: if (includeMediaGroups) { + it.asSentMediaGroupUpdate() ?.data ?: emptyList() + } else { + emptyList() } - it.asBaseSentMessageUpdate() ?.data ?.asCommonMessage() ?.let { message -> + messages.mapNotNull { message -> if (message.content is T) { val adaptedMessage = message as CommonMessage if (additionalFilter == null || additionalFilter(adaptedMessage)) adaptedMessage else null } else { null } - }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> + } +}.subscribeSafelyWithoutExceptionsAsync( + scope, + markerFactory::invoke +) { triggerMessage -> doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } @@ -60,112 +62,134 @@ internal suspend inline fun BehaviourContext.onCont suspend fun BehaviourContext.onContentMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + includeMediaGroups: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGame( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLocation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPoll( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onText( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVenue( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAudioMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentMediaGroupContent( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) 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, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMedia( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAnimation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAudio( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocument( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSticker( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideo( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoNote( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInvoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, 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 62144e443c..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 @@ -1,9 +1,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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 import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -14,7 +17,8 @@ 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) { it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.let { message -> @@ -25,7 +29,10 @@ internal suspend inline fun BehaviourContext.onEvent( null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> +}.subscribeSafelyWithoutExceptionsAsync( + scope, + markerFactory::invoke +) { triggerMessage -> doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } @@ -38,102 +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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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 8ced3c83e4..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 @@ -1,15 +1,19 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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 import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat 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) { it.asInlineQueryUpdate() ?.data ?.let { query -> @@ -19,7 +23,10 @@ internal suspend inline fun BehaviourContext.onInlineQ null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerQuery -> +}.subscribeSafelyWithoutExceptionsAsync( + scope, + markerFactory::invoke +) { triggerQuery -> doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } @@ -35,20 +42,23 @@ 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, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onBaseInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (BaseInlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLocationInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (LocationInlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = 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 b49865f902..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 @@ -2,9 +2,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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 import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat @@ -17,7 +20,8 @@ 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 -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> @@ -27,7 +31,10 @@ internal suspend inline fun BehaviourContext.bui null } } ?: emptyList() -}.subscribeSafelyWithoutExceptions(scope) { mediaGroup -> +}.subscribeSafelyWithoutExceptionsAsync( + scope, + markerFactory::invoke +) { mediaGroup -> val mediaGroupChat = mediaGroup.chat!! doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { @@ -41,37 +48,44 @@ 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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, scenarioReceiver) +) = 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 92efd5f9cd..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 @@ -1,17 +1,21 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +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 import dev.inmo.tgbotapi.extensions.utils.asPassportMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement -suspend inline fun BehaviourContext.onPassportMessageWith( +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) { it.asMessageUpdate() ?.data ?.asPassportMessage() ?.let { message -> @@ -21,7 +25,10 @@ suspend inline fun BehaviourContext.onPas null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> +}.subscribeSafelyWithoutExceptionsAsync( + scope, + markerFactory::invoke +) { triggerMessage -> doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } @@ -34,11 +41,13 @@ suspend inline fun BehaviourContext.onPas suspend fun BehaviourContext.onPassportMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onPassportMessageWith( includeFilterByChatInBehaviourSubContext, additionalFilter, + markerFactory, scenarioReceiver ) 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/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt new file mode 100644 index 0000000000..64041bb198 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery + +object ByUserCallbackQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: CallbackQuery) = data.user +} + +object ByIdCallbackQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: CallbackQuery) = data.id +} + +object ByChatInstanceCallbackQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: CallbackQuery) = data.chatInstance +} + + diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt new file mode 100644 index 0000000000..c861c5cf17 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.ChatMemberUpdated + +object ByChatChatMemberUpdatedMarkerFactory : MarkerFactory { + override suspend fun invoke(data: ChatMemberUpdated) = data.chat +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt new file mode 100644 index 0000000000..6c99d26029 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery + +object ByUserInlineQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: InlineQuery) = data.from +} + +object ByIdInlineQueryMarkerFactory : MarkerFactory { + override suspend fun invoke(data: InlineQuery) = data.id +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt new file mode 100644 index 0000000000..2392d89d15 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +fun interface MarkerFactory { + suspend operator fun invoke(data: T): M +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt new file mode 100644 index 0000000000..233d3f3a3b --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat +import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage + +object ByChatMediaGroupMarkerFactory : MarkerFactory>, Any> { + override suspend fun invoke(data: List>) = data.chat ?: error("Data must not be empty") +} diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt new file mode 100644 index 0000000000..1beb82c59d --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt @@ -0,0 +1,15 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.message.abstracts.* + +object ByChatMessageMarkerFactory : MarkerFactory { + override suspend fun invoke(data: Message) = data.chat +} + +object ByUserMessageMarkerFactory : MarkerFactory { + override suspend fun invoke(data: Message) = when (data) { + is FromUserMessage -> data.user + is FromChannelGroupContentMessage<*> -> data.channel + else -> data.chat // including anonymous + } +} 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 92dc65b601..b8901c90e6 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 @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.requests.send.payments.SendInvoice import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.CallbackQuery.* @@ -19,7 +20,6 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.* import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.* -import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent import dev.inmo.tgbotapi.types.InlineQueries.query.* import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* @@ -52,126 +52,189 @@ import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.abstracts.* import dev.inmo.tgbotapi.utils.PreviewFeature +@PreviewFeature +inline fun Chat.whenBot(block: (Bot) -> T) = asBot() ?.let(block) + @PreviewFeature inline fun Chat.asBot(): Bot? = this as? Bot @PreviewFeature inline fun Chat.requireBot(): Bot = this as Bot +@PreviewFeature +inline fun Chat.whenCommonBot(block: (CommonBot) -> T) = asCommonBot() ?.let(block) + @PreviewFeature inline fun Chat.asCommonBot(): CommonBot? = this as? CommonBot @PreviewFeature inline fun Chat.requireCommonBot(): CommonBot = this as CommonBot +@PreviewFeature +inline fun Chat.whenCommonUser(block: (CommonUser) -> T) = asCommonUser() ?.let(block) + @PreviewFeature inline fun Chat.asCommonUser(): CommonUser? = this as? CommonUser @PreviewFeature inline fun Chat.requireCommonUser(): CommonUser = this as CommonUser +@PreviewFeature +inline fun Chat.whenExtendedBot(block: (ExtendedBot) -> T) = asExtendedBot() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedBot(): ExtendedBot? = this as? ExtendedBot @PreviewFeature inline fun Chat.requireExtendedBot(): ExtendedBot = this as ExtendedBot +@PreviewFeature +inline fun Chat.whenUser(block: (User) -> T) = asUser() ?.let(block) + @PreviewFeature inline fun Chat.asUser(): User? = this as? User @PreviewFeature inline fun Chat.requireUser(): User = this as User +@PreviewFeature +inline fun Chat.whenChannelChat(block: (ChannelChat) -> T) = asChannelChat() ?.let(block) + @PreviewFeature inline fun Chat.asChannelChat(): ChannelChat? = this as? ChannelChat @PreviewFeature inline fun Chat.requireChannelChat(): ChannelChat = this as ChannelChat +@PreviewFeature +inline fun Chat.whenGroupChat(block: (GroupChat) -> T) = asGroupChat() ?.let(block) + @PreviewFeature inline fun Chat.asGroupChat(): GroupChat? = this as? GroupChat @PreviewFeature inline fun Chat.requireGroupChat(): GroupChat = this as GroupChat +@PreviewFeature +inline fun Chat.whenPrivateChat(block: (PrivateChat) -> T) = asPrivateChat() ?.let(block) + @PreviewFeature inline fun Chat.asPrivateChat(): PrivateChat? = this as? PrivateChat @PreviewFeature inline fun Chat.requirePrivateChat(): PrivateChat = this as PrivateChat +@PreviewFeature +inline fun Chat.whenPublicChat(block: (PublicChat) -> T) = asPublicChat() ?.let(block) + @PreviewFeature inline fun Chat.asPublicChat(): PublicChat? = this as? PublicChat @PreviewFeature inline fun Chat.requirePublicChat(): PublicChat = this as PublicChat +@PreviewFeature +inline fun Chat.whenSuperPublicChat(block: (SuperPublicChat) -> T) = asSuperPublicChat() ?.let(block) + @PreviewFeature inline fun Chat.asSuperPublicChat(): SuperPublicChat? = this as? SuperPublicChat @PreviewFeature inline fun Chat.requireSuperPublicChat(): SuperPublicChat = this as SuperPublicChat +@PreviewFeature +inline fun Chat.whenSupergroupChat(block: (SupergroupChat) -> T) = asSupergroupChat() ?.let(block) + @PreviewFeature inline fun Chat.asSupergroupChat(): SupergroupChat? = this as? SupergroupChat @PreviewFeature inline fun Chat.requireSupergroupChat(): SupergroupChat = this as SupergroupChat +@PreviewFeature +inline fun Chat.whenUnknownChatType(block: (UnknownChatType) -> T) = asUnknownChatType() ?.let(block) + @PreviewFeature inline fun Chat.asUnknownChatType(): UnknownChatType? = this as? UnknownChatType @PreviewFeature inline fun Chat.requireUnknownChatType(): UnknownChatType = this as UnknownChatType +@PreviewFeature +inline fun Chat.whenUsernameChat(block: (UsernameChat) -> T) = asUsernameChat() ?.let(block) + @PreviewFeature inline fun Chat.asUsernameChat(): UsernameChat? = this as? UsernameChat @PreviewFeature inline fun Chat.requireUsernameChat(): UsernameChat = this as UsernameChat +@PreviewFeature +inline fun Chat.whenExtendedChannelChat(block: (ExtendedChannelChat) -> T) = asExtendedChannelChat() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedChannelChat(): ExtendedChannelChat? = this as? ExtendedChannelChat @PreviewFeature inline fun Chat.requireExtendedChannelChat(): ExtendedChannelChat = this as ExtendedChannelChat +@PreviewFeature +inline fun Chat.whenExtendedChat(block: (ExtendedChat) -> T) = asExtendedChat() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedChat(): ExtendedChat? = this as? ExtendedChat @PreviewFeature inline fun Chat.requireExtendedChat(): ExtendedChat = this as ExtendedChat +@PreviewFeature +inline fun Chat.whenExtendedGroupChat(block: (ExtendedGroupChat) -> T) = asExtendedGroupChat() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedGroupChat(): ExtendedGroupChat? = this as? ExtendedGroupChat @PreviewFeature inline fun Chat.requireExtendedGroupChat(): ExtendedGroupChat = this as ExtendedGroupChat +@PreviewFeature +inline fun Chat.whenExtendedPrivateChat(block: (ExtendedPrivateChat) -> T) = asExtendedPrivateChat() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedPrivateChat(): ExtendedPrivateChat? = this as? ExtendedPrivateChat @PreviewFeature inline fun Chat.requireExtendedPrivateChat(): ExtendedPrivateChat = this as ExtendedPrivateChat +@PreviewFeature +inline fun Chat.whenExtendedPublicChat(block: (ExtendedPublicChat) -> T) = asExtendedPublicChat() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedPublicChat(): ExtendedPublicChat? = this as? ExtendedPublicChat @PreviewFeature inline fun Chat.requireExtendedPublicChat(): ExtendedPublicChat = this as ExtendedPublicChat +@PreviewFeature +inline fun Chat.whenExtendedSupergroupChat(block: (ExtendedSupergroupChat) -> T) = asExtendedSupergroupChat() ?.let(block) + @PreviewFeature inline fun Chat.asExtendedSupergroupChat(): ExtendedSupergroupChat? = this as? ExtendedSupergroupChat @PreviewFeature inline fun Chat.requireExtendedSupergroupChat(): ExtendedSupergroupChat = this as ExtendedSupergroupChat +@PreviewFeature +inline fun CallbackQuery.whenDataCallbackQuery(block: (DataCallbackQuery) -> T) = asDataCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asDataCallbackQuery(): DataCallbackQuery? = this as? DataCallbackQuery @PreviewFeature inline fun CallbackQuery.requireDataCallbackQuery(): DataCallbackQuery = this as DataCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenGameShortNameCallbackQuery(block: (GameShortNameCallbackQuery) -> T) = asGameShortNameCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asGameShortNameCallbackQuery(): GameShortNameCallbackQuery? = this as? GameShortNameCallbackQuery @@ -180,6 +243,9 @@ inline fun CallbackQuery.asGameShortNameCallbackQuery(): GameShortNameCallbackQu inline fun CallbackQuery.requireGameShortNameCallbackQuery(): GameShortNameCallbackQuery = this as GameShortNameCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenInlineMessageIdCallbackQuery(block: (InlineMessageIdCallbackQuery) -> T) = asInlineMessageIdCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asInlineMessageIdCallbackQuery(): InlineMessageIdCallbackQuery? = this as? InlineMessageIdCallbackQuery @@ -188,6 +254,9 @@ inline fun CallbackQuery.asInlineMessageIdCallbackQuery(): InlineMessageIdCallba inline fun CallbackQuery.requireInlineMessageIdCallbackQuery(): InlineMessageIdCallbackQuery = this as InlineMessageIdCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenInlineMessageIdDataCallbackQuery(block: (InlineMessageIdDataCallbackQuery) -> T) = asInlineMessageIdDataCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asInlineMessageIdDataCallbackQuery(): InlineMessageIdDataCallbackQuery? = this as? InlineMessageIdDataCallbackQuery @@ -196,6 +265,9 @@ inline fun CallbackQuery.asInlineMessageIdDataCallbackQuery(): InlineMessageIdDa inline fun CallbackQuery.requireInlineMessageIdDataCallbackQuery(): InlineMessageIdDataCallbackQuery = this as InlineMessageIdDataCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenInlineMessageIdGameShortNameCallbackQuery(block: (InlineMessageIdGameShortNameCallbackQuery) -> T) = asInlineMessageIdGameShortNameCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asInlineMessageIdGameShortNameCallbackQuery(): InlineMessageIdGameShortNameCallbackQuery? = this as? InlineMessageIdGameShortNameCallbackQuery @@ -204,18 +276,27 @@ inline fun CallbackQuery.asInlineMessageIdGameShortNameCallbackQuery(): InlineMe inline fun CallbackQuery.requireInlineMessageIdGameShortNameCallbackQuery(): InlineMessageIdGameShortNameCallbackQuery = this as InlineMessageIdGameShortNameCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenMessageCallbackQuery(block: (MessageCallbackQuery) -> T) = asMessageCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asMessageCallbackQuery(): MessageCallbackQuery? = this as? MessageCallbackQuery @PreviewFeature inline fun CallbackQuery.requireMessageCallbackQuery(): MessageCallbackQuery = this as MessageCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenMessageDataCallbackQuery(block: (MessageDataCallbackQuery) -> T) = asMessageDataCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asMessageDataCallbackQuery(): MessageDataCallbackQuery? = this as? MessageDataCallbackQuery @PreviewFeature inline fun CallbackQuery.requireMessageDataCallbackQuery(): MessageDataCallbackQuery = this as MessageDataCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenMessageGameShortNameCallbackQuery(block: (MessageGameShortNameCallbackQuery) -> T) = asMessageGameShortNameCallbackQuery() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asMessageGameShortNameCallbackQuery(): MessageGameShortNameCallbackQuery? = this as? MessageGameShortNameCallbackQuery @@ -224,12 +305,18 @@ inline fun CallbackQuery.asMessageGameShortNameCallbackQuery(): MessageGameShort inline fun CallbackQuery.requireMessageGameShortNameCallbackQuery(): MessageGameShortNameCallbackQuery = this as MessageGameShortNameCallbackQuery +@PreviewFeature +inline fun CallbackQuery.whenUnknownCallbackQueryType(block: (UnknownCallbackQueryType) -> T) = asUnknownCallbackQueryType() ?.let(block) + @PreviewFeature inline fun CallbackQuery.asUnknownCallbackQueryType(): UnknownCallbackQueryType? = this as? UnknownCallbackQueryType @PreviewFeature inline fun CallbackQuery.requireUnknownCallbackQueryType(): UnknownCallbackQueryType = this as UnknownCallbackQueryType +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorDataField(block: (PassportElementErrorDataField) -> T) = asPassportElementErrorDataField() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorDataField(): PassportElementErrorDataField? = this as? PassportElementErrorDataField @@ -238,6 +325,9 @@ inline fun PassportElementError.asPassportElementErrorDataField(): PassportEleme inline fun PassportElementError.requirePassportElementErrorDataField(): PassportElementErrorDataField = this as PassportElementErrorDataField +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorFile(block: (PassportElementErrorFile) -> T) = asPassportElementErrorFile() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorFile(): PassportElementErrorFile? = this as? PassportElementErrorFile @@ -246,6 +336,9 @@ inline fun PassportElementError.asPassportElementErrorFile(): PassportElementErr inline fun PassportElementError.requirePassportElementErrorFile(): PassportElementErrorFile = this as PassportElementErrorFile +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorFiles(block: (PassportElementErrorFiles) -> T) = asPassportElementErrorFiles() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorFiles(): PassportElementErrorFiles? = this as? PassportElementErrorFiles @@ -254,6 +347,9 @@ inline fun PassportElementError.asPassportElementErrorFiles(): PassportElementEr inline fun PassportElementError.requirePassportElementErrorFiles(): PassportElementErrorFiles = this as PassportElementErrorFiles +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorFrontSide(block: (PassportElementErrorFrontSide) -> T) = asPassportElementErrorFrontSide() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorFrontSide(): PassportElementErrorFrontSide? = this as? PassportElementErrorFrontSide @@ -262,6 +358,9 @@ inline fun PassportElementError.asPassportElementErrorFrontSide(): PassportEleme inline fun PassportElementError.requirePassportElementErrorFrontSide(): PassportElementErrorFrontSide = this as PassportElementErrorFrontSide +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorReverseSide(block: (PassportElementErrorReverseSide) -> T) = asPassportElementErrorReverseSide() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorReverseSide(): PassportElementErrorReverseSide? = this as? PassportElementErrorReverseSide @@ -270,6 +369,9 @@ inline fun PassportElementError.asPassportElementErrorReverseSide(): PassportEle inline fun PassportElementError.requirePassportElementErrorReverseSide(): PassportElementErrorReverseSide = this as PassportElementErrorReverseSide +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorSelfie(block: (PassportElementErrorSelfie) -> T) = asPassportElementErrorSelfie() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorSelfie(): PassportElementErrorSelfie? = this as? PassportElementErrorSelfie @@ -278,6 +380,9 @@ inline fun PassportElementError.asPassportElementErrorSelfie(): PassportElementE inline fun PassportElementError.requirePassportElementErrorSelfie(): PassportElementErrorSelfie = this as PassportElementErrorSelfie +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorTranslationFile(block: (PassportElementErrorTranslationFile) -> T) = asPassportElementErrorTranslationFile() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorTranslationFile(): PassportElementErrorTranslationFile? = this as? PassportElementErrorTranslationFile @@ -286,6 +391,9 @@ inline fun PassportElementError.asPassportElementErrorTranslationFile(): Passpor inline fun PassportElementError.requirePassportElementErrorTranslationFile(): PassportElementErrorTranslationFile = this as PassportElementErrorTranslationFile +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorTranslationFiles(block: (PassportElementErrorTranslationFiles) -> T) = asPassportElementErrorTranslationFiles() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorTranslationFiles(): PassportElementErrorTranslationFiles? = this as? PassportElementErrorTranslationFiles @@ -294,6 +402,9 @@ inline fun PassportElementError.asPassportElementErrorTranslationFiles(): Passpo inline fun PassportElementError.requirePassportElementErrorTranslationFiles(): PassportElementErrorTranslationFiles = this as PassportElementErrorTranslationFiles +@PreviewFeature +inline fun PassportElementError.whenPassportElementErrorUnspecified(block: (PassportElementErrorUnspecified) -> T) = asPassportElementErrorUnspecified() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementErrorUnspecified(): PassportElementErrorUnspecified? = this as? PassportElementErrorUnspecified @@ -302,6 +413,9 @@ inline fun PassportElementError.asPassportElementErrorUnspecified(): PassportEle inline fun PassportElementError.requirePassportElementErrorUnspecified(): PassportElementErrorUnspecified = this as PassportElementErrorUnspecified +@PreviewFeature +inline fun PassportElementError.whenPassportElementFileError(block: (PassportElementFileError) -> T) = asPassportElementFileError() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementFileError(): PassportElementFileError? = this as? PassportElementFileError @@ -310,6 +424,9 @@ inline fun PassportElementError.asPassportElementFileError(): PassportElementFil inline fun PassportElementError.requirePassportElementFileError(): PassportElementFileError = this as PassportElementFileError +@PreviewFeature +inline fun PassportElementError.whenPassportElementFilesError(block: (PassportElementFilesError) -> T) = asPassportElementFilesError() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportElementFilesError(): PassportElementFilesError? = this as? PassportElementFilesError @@ -318,6 +435,9 @@ inline fun PassportElementError.asPassportElementFilesError(): PassportElementFi inline fun PassportElementError.requirePassportElementFilesError(): PassportElementFilesError = this as PassportElementFilesError +@PreviewFeature +inline fun PassportElementError.whenPassportMultipleElementsError(block: (PassportMultipleElementsError) -> T) = asPassportMultipleElementsError() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportMultipleElementsError(): PassportMultipleElementsError? = this as? PassportMultipleElementsError @@ -326,6 +446,9 @@ inline fun PassportElementError.asPassportMultipleElementsError(): PassportMulti inline fun PassportElementError.requirePassportMultipleElementsError(): PassportMultipleElementsError = this as PassportMultipleElementsError +@PreviewFeature +inline fun PassportElementError.whenPassportSingleElementError(block: (PassportSingleElementError) -> T) = asPassportSingleElementError() ?.let(block) + @PreviewFeature inline fun PassportElementError.asPassportSingleElementError(): PassportSingleElementError? = this as? PassportSingleElementError @@ -334,6 +457,9 @@ inline fun PassportElementError.asPassportSingleElementError(): PassportSingleEl inline fun PassportElementError.requirePassportSingleElementError(): PassportSingleElementError = this as PassportSingleElementError +@PreviewFeature +inline fun PassportElementError.whenUnknownPassportElementError(block: (UnknownPassportElementError) -> T) = asUnknownPassportElementError() ?.let(block) + @PreviewFeature inline fun PassportElementError.asUnknownPassportElementError(): UnknownPassportElementError? = this as? UnknownPassportElementError @@ -342,36 +468,54 @@ inline fun PassportElementError.asUnknownPassportElementError(): UnknownPassport inline fun PassportElementError.requireUnknownPassportElementError(): UnknownPassportElementError = this as UnknownPassportElementError +@PreviewFeature +inline fun EncryptedPassportElement.whenBankStatement(block: (BankStatement) -> T) = asBankStatement() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asBankStatement(): BankStatement? = this as? BankStatement @PreviewFeature inline fun EncryptedPassportElement.requireBankStatement(): BankStatement = this as BankStatement +@PreviewFeature +inline fun EncryptedPassportElement.whenCommonPassport(block: (CommonPassport) -> T) = asCommonPassport() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asCommonPassport(): CommonPassport? = this as? CommonPassport @PreviewFeature inline fun EncryptedPassportElement.requireCommonPassport(): CommonPassport = this as CommonPassport +@PreviewFeature +inline fun EncryptedPassportElement.whenDriverLicense(block: (DriverLicense) -> T) = asDriverLicense() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asDriverLicense(): DriverLicense? = this as? DriverLicense @PreviewFeature inline fun EncryptedPassportElement.requireDriverLicense(): DriverLicense = this as DriverLicense +@PreviewFeature +inline fun EncryptedPassportElement.whenEmail(block: (Email) -> T) = asEmail() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEmail(): Email? = this as? Email @PreviewFeature inline fun EncryptedPassportElement.requireEmail(): Email = this as Email +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedAddress(block: (EncryptedAddress) -> T) = asEncryptedAddress() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedAddress(): EncryptedAddress? = this as? EncryptedAddress @PreviewFeature inline fun EncryptedPassportElement.requireEncryptedAddress(): EncryptedAddress = this as EncryptedAddress +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPersonalDetails(block: (EncryptedPersonalDetails) -> T) = asEncryptedPersonalDetails() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPersonalDetails(): EncryptedPersonalDetails? = this as? EncryptedPersonalDetails @@ -380,42 +524,63 @@ inline fun EncryptedPassportElement.asEncryptedPersonalDetails(): EncryptedPerso inline fun EncryptedPassportElement.requireEncryptedPersonalDetails(): EncryptedPersonalDetails = this as EncryptedPersonalDetails +@PreviewFeature +inline fun EncryptedPassportElement.whenIdentityCard(block: (IdentityCard) -> T) = asIdentityCard() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asIdentityCard(): IdentityCard? = this as? IdentityCard @PreviewFeature inline fun EncryptedPassportElement.requireIdentityCard(): IdentityCard = this as IdentityCard +@PreviewFeature +inline fun EncryptedPassportElement.whenInternalPassport(block: (InternalPassport) -> T) = asInternalPassport() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asInternalPassport(): InternalPassport? = this as? InternalPassport @PreviewFeature inline fun EncryptedPassportElement.requireInternalPassport(): InternalPassport = this as InternalPassport +@PreviewFeature +inline fun EncryptedPassportElement.whenPassport(block: (Passport) -> T) = asPassport() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asPassport(): Passport? = this as? Passport @PreviewFeature inline fun EncryptedPassportElement.requirePassport(): Passport = this as Passport +@PreviewFeature +inline fun EncryptedPassportElement.whenPassportRegistration(block: (PassportRegistration) -> T) = asPassportRegistration() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asPassportRegistration(): PassportRegistration? = this as? PassportRegistration @PreviewFeature inline fun EncryptedPassportElement.requirePassportRegistration(): PassportRegistration = this as PassportRegistration +@PreviewFeature +inline fun EncryptedPassportElement.whenPhoneNumber(block: (PhoneNumber) -> T) = asPhoneNumber() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asPhoneNumber(): PhoneNumber? = this as? PhoneNumber @PreviewFeature inline fun EncryptedPassportElement.requirePhoneNumber(): PhoneNumber = this as PhoneNumber +@PreviewFeature +inline fun EncryptedPassportElement.whenRentalAgreement(block: (RentalAgreement) -> T) = asRentalAgreement() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asRentalAgreement(): RentalAgreement? = this as? RentalAgreement @PreviewFeature inline fun EncryptedPassportElement.requireRentalAgreement(): RentalAgreement = this as RentalAgreement +@PreviewFeature +inline fun EncryptedPassportElement.whenTemporaryRegistration(block: (TemporaryRegistration) -> T) = asTemporaryRegistration() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asTemporaryRegistration(): TemporaryRegistration? = this as? TemporaryRegistration @@ -423,6 +588,9 @@ inline fun EncryptedPassportElement.asTemporaryRegistration(): TemporaryRegistra inline fun EncryptedPassportElement.requireTemporaryRegistration(): TemporaryRegistration = this as TemporaryRegistration +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithTranslatableFilesCollection(block: (EncryptedPassportElementWithTranslatableFilesCollection) -> T) = asEncryptedPassportElementWithTranslatableFilesCollection() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithTranslatableFilesCollection(): EncryptedPassportElementWithTranslatableFilesCollection? = this as? EncryptedPassportElementWithTranslatableFilesCollection @@ -431,6 +599,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithTranslatableFi inline fun EncryptedPassportElement.requireEncryptedPassportElementWithTranslatableFilesCollection(): EncryptedPassportElementWithTranslatableFilesCollection = this as EncryptedPassportElementWithTranslatableFilesCollection +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithTranslatableIDDocument(block: (EncryptedPassportElementWithTranslatableIDDocument) -> T) = asEncryptedPassportElementWithTranslatableIDDocument() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithTranslatableIDDocument(): EncryptedPassportElementWithTranslatableIDDocument? = this as? EncryptedPassportElementWithTranslatableIDDocument @@ -439,12 +610,18 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithTranslatableID inline fun EncryptedPassportElement.requireEncryptedPassportElementWithTranslatableIDDocument(): EncryptedPassportElementWithTranslatableIDDocument = this as EncryptedPassportElementWithTranslatableIDDocument +@PreviewFeature +inline fun EncryptedPassportElement.whenUtilityBill(block: (UtilityBill) -> T) = asUtilityBill() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asUtilityBill(): UtilityBill? = this as? UtilityBill @PreviewFeature inline fun EncryptedPassportElement.requireUtilityBill(): UtilityBill = this as UtilityBill +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithFilesCollection(block: (EncryptedPassportElementWithFilesCollection) -> T) = asEncryptedPassportElementWithFilesCollection() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithFilesCollection(): EncryptedPassportElementWithFilesCollection? = this as? EncryptedPassportElementWithFilesCollection @@ -453,6 +630,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithFilesCollectio inline fun EncryptedPassportElement.requireEncryptedPassportElementWithFilesCollection(): EncryptedPassportElementWithFilesCollection = this as EncryptedPassportElementWithFilesCollection +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementTranslatable(block: (EncryptedPassportElementTranslatable) -> T) = asEncryptedPassportElementTranslatable() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementTranslatable(): EncryptedPassportElementTranslatable? = this as? EncryptedPassportElementTranslatable @@ -461,6 +641,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementTranslatable(): En inline fun EncryptedPassportElement.requireEncryptedPassportElementTranslatable(): EncryptedPassportElementTranslatable = this as EncryptedPassportElementTranslatable +@PreviewFeature +inline fun EncryptedPassportElement.whenUnknownEncryptedPassportElement(block: (UnknownEncryptedPassportElement) -> T) = asUnknownEncryptedPassportElement() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asUnknownEncryptedPassportElement(): UnknownEncryptedPassportElement? = this as? UnknownEncryptedPassportElement @@ -469,6 +652,9 @@ inline fun EncryptedPassportElement.asUnknownEncryptedPassportElement(): Unknown inline fun EncryptedPassportElement.requireUnknownEncryptedPassportElement(): UnknownEncryptedPassportElement = this as UnknownEncryptedPassportElement +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithData(block: (EncryptedPassportElementWithData) -> T) = asEncryptedPassportElementWithData() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithData(): EncryptedPassportElementWithData? = this as? EncryptedPassportElementWithData @@ -477,6 +663,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithData(): Encryp inline fun EncryptedPassportElement.requireEncryptedPassportElementWithData(): EncryptedPassportElementWithData = this as EncryptedPassportElementWithData +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithEmail(block: (EncryptedPassportElementWithEmail) -> T) = asEncryptedPassportElementWithEmail() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithEmail(): EncryptedPassportElementWithEmail? = this as? EncryptedPassportElementWithEmail @@ -485,6 +674,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithEmail(): Encry inline fun EncryptedPassportElement.requireEncryptedPassportElementWithEmail(): EncryptedPassportElementWithEmail = this as EncryptedPassportElementWithEmail +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithFrontSide(block: (EncryptedPassportElementWithFrontSide) -> T) = asEncryptedPassportElementWithFrontSide() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithFrontSide(): EncryptedPassportElementWithFrontSide? = this as? EncryptedPassportElementWithFrontSide @@ -493,6 +685,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithFrontSide(): E inline fun EncryptedPassportElement.requireEncryptedPassportElementWithFrontSide(): EncryptedPassportElementWithFrontSide = this as EncryptedPassportElementWithFrontSide +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithPhoneNumber(block: (EncryptedPassportElementWithPhoneNumber) -> T) = asEncryptedPassportElementWithPhoneNumber() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithPhoneNumber(): EncryptedPassportElementWithPhoneNumber? = this as? EncryptedPassportElementWithPhoneNumber @@ -501,6 +696,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithPhoneNumber(): inline fun EncryptedPassportElement.requireEncryptedPassportElementWithPhoneNumber(): EncryptedPassportElementWithPhoneNumber = this as EncryptedPassportElementWithPhoneNumber +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithReverseSide(block: (EncryptedPassportElementWithReverseSide) -> T) = asEncryptedPassportElementWithReverseSide() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithReverseSide(): EncryptedPassportElementWithReverseSide? = this as? EncryptedPassportElementWithReverseSide @@ -509,6 +707,9 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithReverseSide(): inline fun EncryptedPassportElement.requireEncryptedPassportElementWithReverseSide(): EncryptedPassportElementWithReverseSide = this as EncryptedPassportElementWithReverseSide +@PreviewFeature +inline fun EncryptedPassportElement.whenEncryptedPassportElementWithSelfie(block: (EncryptedPassportElementWithSelfie) -> T) = asEncryptedPassportElementWithSelfie() ?.let(block) + @PreviewFeature inline fun EncryptedPassportElement.asEncryptedPassportElementWithSelfie(): EncryptedPassportElementWithSelfie? = this as? EncryptedPassportElementWithSelfie @@ -517,36 +718,54 @@ inline fun EncryptedPassportElement.asEncryptedPassportElementWithSelfie(): Encr inline fun EncryptedPassportElement.requireEncryptedPassportElementWithSelfie(): EncryptedPassportElementWithSelfie = this as EncryptedPassportElementWithSelfie +@PreviewFeature +inline fun SecureValue.whenAddressSecureValue(block: (AddressSecureValue) -> T) = asAddressSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asAddressSecureValue(): AddressSecureValue? = this as? AddressSecureValue @PreviewFeature inline fun SecureValue.requireAddressSecureValue(): AddressSecureValue = this as AddressSecureValue +@PreviewFeature +inline fun SecureValue.whenBankStatementSecureValue(block: (BankStatementSecureValue) -> T) = asBankStatementSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asBankStatementSecureValue(): BankStatementSecureValue? = this as? BankStatementSecureValue @PreviewFeature inline fun SecureValue.requireBankStatementSecureValue(): BankStatementSecureValue = this as BankStatementSecureValue +@PreviewFeature +inline fun SecureValue.whenCommonPassportSecureValue(block: (CommonPassportSecureValue) -> T) = asCommonPassportSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asCommonPassportSecureValue(): CommonPassportSecureValue? = this as? CommonPassportSecureValue @PreviewFeature inline fun SecureValue.requireCommonPassportSecureValue(): CommonPassportSecureValue = this as CommonPassportSecureValue +@PreviewFeature +inline fun SecureValue.whenDriverLicenseSecureValue(block: (DriverLicenseSecureValue) -> T) = asDriverLicenseSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asDriverLicenseSecureValue(): DriverLicenseSecureValue? = this as? DriverLicenseSecureValue @PreviewFeature inline fun SecureValue.requireDriverLicenseSecureValue(): DriverLicenseSecureValue = this as DriverLicenseSecureValue +@PreviewFeature +inline fun SecureValue.whenIdentityCardSecureValue(block: (IdentityCardSecureValue) -> T) = asIdentityCardSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asIdentityCardSecureValue(): IdentityCardSecureValue? = this as? IdentityCardSecureValue @PreviewFeature inline fun SecureValue.requireIdentityCardSecureValue(): IdentityCardSecureValue = this as IdentityCardSecureValue +@PreviewFeature +inline fun SecureValue.whenIdentityWithReverseSideSecureValue(block: (IdentityWithReverseSideSecureValue) -> T) = asIdentityWithReverseSideSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asIdentityWithReverseSideSecureValue(): IdentityWithReverseSideSecureValue? = this as? IdentityWithReverseSideSecureValue @@ -555,6 +774,9 @@ inline fun SecureValue.asIdentityWithReverseSideSecureValue(): IdentityWithRever inline fun SecureValue.requireIdentityWithReverseSideSecureValue(): IdentityWithReverseSideSecureValue = this as IdentityWithReverseSideSecureValue +@PreviewFeature +inline fun SecureValue.whenInternalPassportSecureValue(block: (InternalPassportSecureValue) -> T) = asInternalPassportSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asInternalPassportSecureValue(): InternalPassportSecureValue? = this as? InternalPassportSecureValue @@ -563,12 +785,18 @@ inline fun SecureValue.asInternalPassportSecureValue(): InternalPassportSecureVa inline fun SecureValue.requireInternalPassportSecureValue(): InternalPassportSecureValue = this as InternalPassportSecureValue +@PreviewFeature +inline fun SecureValue.whenOtherDocumentsSecureValue(block: (OtherDocumentsSecureValue) -> T) = asOtherDocumentsSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asOtherDocumentsSecureValue(): OtherDocumentsSecureValue? = this as? OtherDocumentsSecureValue @PreviewFeature inline fun SecureValue.requireOtherDocumentsSecureValue(): OtherDocumentsSecureValue = this as OtherDocumentsSecureValue +@PreviewFeature +inline fun SecureValue.whenPassportRegistrationSecureValue(block: (PassportRegistrationSecureValue) -> T) = asPassportRegistrationSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asPassportRegistrationSecureValue(): PassportRegistrationSecureValue? = this as? PassportRegistrationSecureValue @@ -577,12 +805,18 @@ inline fun SecureValue.asPassportRegistrationSecureValue(): PassportRegistration inline fun SecureValue.requirePassportRegistrationSecureValue(): PassportRegistrationSecureValue = this as PassportRegistrationSecureValue +@PreviewFeature +inline fun SecureValue.whenPassportSecureValue(block: (PassportSecureValue) -> T) = asPassportSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asPassportSecureValue(): PassportSecureValue? = this as? PassportSecureValue @PreviewFeature inline fun SecureValue.requirePassportSecureValue(): PassportSecureValue = this as PassportSecureValue +@PreviewFeature +inline fun SecureValue.whenPersonalDetailsSecureValue(block: (PersonalDetailsSecureValue) -> T) = asPersonalDetailsSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asPersonalDetailsSecureValue(): PersonalDetailsSecureValue? = this as? PersonalDetailsSecureValue @@ -590,6 +824,9 @@ inline fun SecureValue.asPersonalDetailsSecureValue(): PersonalDetailsSecureValu inline fun SecureValue.requirePersonalDetailsSecureValue(): PersonalDetailsSecureValue = this as PersonalDetailsSecureValue +@PreviewFeature +inline fun SecureValue.whenRentalAgreementSecureValue(block: (RentalAgreementSecureValue) -> T) = asRentalAgreementSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asRentalAgreementSecureValue(): RentalAgreementSecureValue? = this as? RentalAgreementSecureValue @@ -597,6 +834,9 @@ inline fun SecureValue.asRentalAgreementSecureValue(): RentalAgreementSecureValu inline fun SecureValue.requireRentalAgreementSecureValue(): RentalAgreementSecureValue = this as RentalAgreementSecureValue +@PreviewFeature +inline fun SecureValue.whenTemporalRegistrationSecureValue(block: (TemporalRegistrationSecureValue) -> T) = asTemporalRegistrationSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asTemporalRegistrationSecureValue(): TemporalRegistrationSecureValue? = this as? TemporalRegistrationSecureValue @@ -605,30 +845,45 @@ inline fun SecureValue.asTemporalRegistrationSecureValue(): TemporalRegistration inline fun SecureValue.requireTemporalRegistrationSecureValue(): TemporalRegistrationSecureValue = this as TemporalRegistrationSecureValue +@PreviewFeature +inline fun SecureValue.whenUtilityBillSecureValue(block: (UtilityBillSecureValue) -> T) = asUtilityBillSecureValue() ?.let(block) + @PreviewFeature inline fun SecureValue.asUtilityBillSecureValue(): UtilityBillSecureValue? = this as? UtilityBillSecureValue @PreviewFeature inline fun SecureValue.requireUtilityBillSecureValue(): UtilityBillSecureValue = this as UtilityBillSecureValue +@PreviewFeature +inline fun SecureValue.whenSecureValueIdentity(block: (SecureValueIdentity) -> T) = asSecureValueIdentity() ?.let(block) + @PreviewFeature inline fun SecureValue.asSecureValueIdentity(): SecureValueIdentity? = this as? SecureValueIdentity @PreviewFeature inline fun SecureValue.requireSecureValueIdentity(): SecureValueIdentity = this as SecureValueIdentity +@PreviewFeature +inline fun SecureValue.whenSecureValueWithData(block: (SecureValueWithData) -> T) = asSecureValueWithData() ?.let(block) + @PreviewFeature inline fun SecureValue.asSecureValueWithData(): SecureValueWithData? = this as? SecureValueWithData @PreviewFeature inline fun SecureValue.requireSecureValueWithData(): SecureValueWithData = this as SecureValueWithData +@PreviewFeature +inline fun SecureValue.whenSecureValueWithFiles(block: (SecureValueWithFiles) -> T) = asSecureValueWithFiles() ?.let(block) + @PreviewFeature inline fun SecureValue.asSecureValueWithFiles(): SecureValueWithFiles? = this as? SecureValueWithFiles @PreviewFeature inline fun SecureValue.requireSecureValueWithFiles(): SecureValueWithFiles = this as SecureValueWithFiles +@PreviewFeature +inline fun SecureValue.whenSecureValueWithReverseSide(block: (SecureValueWithReverseSide) -> T) = asSecureValueWithReverseSide() ?.let(block) + @PreviewFeature inline fun SecureValue.asSecureValueWithReverseSide(): SecureValueWithReverseSide? = this as? SecureValueWithReverseSide @@ -636,6 +891,9 @@ inline fun SecureValue.asSecureValueWithReverseSide(): SecureValueWithReverseSid inline fun SecureValue.requireSecureValueWithReverseSide(): SecureValueWithReverseSide = this as SecureValueWithReverseSide +@PreviewFeature +inline fun SecureValue.whenSecureValueWithTranslations(block: (SecureValueWithTranslations) -> T) = asSecureValueWithTranslations() ?.let(block) + @PreviewFeature inline fun SecureValue.asSecureValueWithTranslations(): SecureValueWithTranslations? = this as? SecureValueWithTranslations @@ -644,6 +902,9 @@ inline fun SecureValue.asSecureValueWithTranslations(): SecureValueWithTranslati inline fun SecureValue.requireSecureValueWithTranslations(): SecureValueWithTranslations = this as SecureValueWithTranslations +@PreviewFeature +inline fun Message.whenAnonymousGroupContentMessageImpl(block: (AnonymousGroupContentMessageImpl) -> T) = asAnonymousGroupContentMessageImpl() ?.let(block) + @PreviewFeature inline fun Message.asAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl? = this as? AnonymousGroupContentMessageImpl @@ -652,6 +913,9 @@ inline fun Message.asAnonymousGroupContentMessageImpl(): AnonymousGroupContentMe inline fun Message.requireAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl = this as AnonymousGroupContentMessageImpl +@PreviewFeature +inline fun Message.whenChannelContentMessageImpl(block: (ChannelContentMessageImpl) -> T) = asChannelContentMessageImpl() ?.let(block) + @PreviewFeature inline fun Message.asChannelContentMessageImpl(): ChannelContentMessageImpl? = this as? ChannelContentMessageImpl @@ -660,6 +924,9 @@ inline fun Message.asChannelContentMessageImpl(): ChannelContentMessageImpl = this as ChannelContentMessageImpl +@PreviewFeature +inline fun Message.whenFromChannelGroupContentMessageImpl(block: (FromChannelGroupContentMessageImpl) -> T) = asFromChannelGroupContentMessageImpl() ?.let(block) + @PreviewFeature inline fun Message.asFromChannelGroupContentMessageImpl(): FromChannelGroupContentMessageImpl? = this as? FromChannelGroupContentMessageImpl @@ -668,12 +935,18 @@ inline fun Message.asFromChannelGroupContentMessageImpl(): FromChannelGroupConte inline fun Message.requireFromChannelGroupContentMessageImpl(): FromChannelGroupContentMessageImpl = this as FromChannelGroupContentMessageImpl +@PreviewFeature +inline fun Message.whenPassportMessage(block: (PassportMessage) -> T) = asPassportMessage() ?.let(block) + @PreviewFeature inline fun Message.asPassportMessage(): PassportMessage? = this as? PassportMessage @PreviewFeature inline fun Message.requirePassportMessage(): PassportMessage = this as PassportMessage +@PreviewFeature +inline fun Message.whenPrivateContentMessageImpl(block: (PrivateContentMessageImpl) -> T) = asPrivateContentMessageImpl() ?.let(block) + @PreviewFeature inline fun Message.asPrivateContentMessageImpl(): PrivateContentMessageImpl? = this as? PrivateContentMessageImpl @@ -682,6 +955,9 @@ inline fun Message.asPrivateContentMessageImpl(): PrivateContentMessageImpl = this as PrivateContentMessageImpl +@PreviewFeature +inline fun Message.whenChannelEventMessage(block: (ChannelEventMessage) -> T) = asChannelEventMessage() ?.let(block) + @PreviewFeature inline fun Message.asChannelEventMessage(): ChannelEventMessage? = this as? ChannelEventMessage @@ -690,6 +966,9 @@ inline fun Message.asChannelEventMessage(): ChannelEventMessage? = inline fun Message.requireChannelEventMessage(): ChannelEventMessage = this as ChannelEventMessage +@PreviewFeature +inline fun Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage) -> T) = asChannelMediaGroupMessage() ?.let(block) + @PreviewFeature inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage? = this as? ChannelMediaGroupMessage @@ -698,6 +977,9 @@ inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage = this as ChannelMediaGroupMessage +@PreviewFeature +inline fun Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage) -> T) = asCommonGroupEventMessage() ?.let(block) + @PreviewFeature inline fun Message.asCommonGroupEventMessage(): CommonGroupEventMessage? = this as? CommonGroupEventMessage @@ -706,6 +988,9 @@ inline fun Message.asCommonGroupEventMessage(): CommonGroupEventMessage = this as CommonGroupEventMessage +@PreviewFeature +inline fun Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T) = asCommonMediaGroupMessage() ?.let(block) + @PreviewFeature inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage? = this as? CommonMediaGroupMessage @@ -714,6 +999,9 @@ inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage = this as CommonMediaGroupMessage +@PreviewFeature +inline fun Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage) -> T) = asCommonSupergroupEventMessage() ?.let(block) + @PreviewFeature inline fun Message.asCommonSupergroupEventMessage(): CommonSupergroupEventMessage? = this as? CommonSupergroupEventMessage @@ -722,6 +1010,9 @@ inline fun Message.asCommonSupergroupEventMessage(): CommonSupergroupEventMessag inline fun Message.requireCommonSupergroupEventMessage(): CommonSupergroupEventMessage = this as CommonSupergroupEventMessage +@PreviewFeature +inline fun Message.whenAnonymousGroupContentMessage(block: (AnonymousGroupContentMessage) -> T) = asAnonymousGroupContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asAnonymousGroupContentMessage(): AnonymousGroupContentMessage? = this as? AnonymousGroupContentMessage @@ -731,19 +1022,28 @@ inline fun Message.requireAnonymousGroupContentMessage(): AnonymousGroupContentM this as AnonymousGroupContentMessage @PreviewFeature -inline fun Message.asChannelContentMessage(): ChannelContentMessageImpl? = +inline fun Message.whenChannelContentMessage(block: (ChannelContentMessage) -> T) = asChannelContentMessage() ?.let(block) + +@PreviewFeature +inline fun Message.asChannelContentMessage(): ChannelContentMessage? = this as? ChannelContentMessageImpl @PreviewFeature inline fun Message.requireChannelContentMessage(): ChannelContentMessageImpl = this as ChannelContentMessageImpl +@PreviewFeature +inline fun Message.whenChatEventMessage(block: (ChatEventMessage) -> T) = asChatEventMessage() ?.let(block) + @PreviewFeature inline fun Message.asChatEventMessage(): ChatEventMessage? = this as? ChatEventMessage @PreviewFeature inline fun Message.requireChatEventMessage(): ChatEventMessage = this as ChatEventMessage +@PreviewFeature +inline fun Message.whenCommonGroupContentMessage(block: (CommonGroupContentMessage) -> T) = asCommonGroupContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asCommonGroupContentMessage(): CommonGroupContentMessage? = this as? CommonGroupContentMessage @@ -752,18 +1052,27 @@ inline fun Message.asCommonGroupContentMessage(): CommonGroupContentMessage = this as CommonGroupContentMessage +@PreviewFeature +inline fun Message.whenCommonMessage(block: (CommonMessage) -> T) = asCommonMessage() ?.let(block) + @PreviewFeature inline fun Message.asCommonMessage(): CommonMessage? = this as? CommonMessage @PreviewFeature inline fun Message.requireCommonMessage(): CommonMessage = this as CommonMessage +@PreviewFeature +inline fun Message.whenContentMessage(block: (ContentMessage) -> T) = asContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asContentMessage(): ContentMessage? = this as? ContentMessage @PreviewFeature inline fun Message.requireContentMessage(): ContentMessage = this as ContentMessage +@PreviewFeature +inline fun Message.whenFromChannelGroupContentMessage(block: (FromChannelGroupContentMessage) -> T) = asFromChannelGroupContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asFromChannelGroupContentMessage(): FromChannelGroupContentMessage? = this as? FromChannelGroupContentMessage @@ -772,12 +1081,18 @@ inline fun Message.asFromChannelGroupContentMessage(): FromChannelGroupContentMe inline fun Message.requireFromChannelGroupContentMessage(): FromChannelGroupContentMessage = this as FromChannelGroupContentMessage +@PreviewFeature +inline fun Message.whenGroupEventMessage(block: (GroupEventMessage) -> T) = asGroupEventMessage() ?.let(block) + @PreviewFeature inline fun Message.asGroupEventMessage(): GroupEventMessage? = this as? GroupEventMessage @PreviewFeature inline fun Message.requireGroupEventMessage(): GroupEventMessage = this as GroupEventMessage +@PreviewFeature +inline fun Message.whenGroupContentMessage(block: (GroupContentMessage) -> T) = asGroupContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asGroupContentMessage(): GroupContentMessage? = this as? GroupContentMessage @@ -786,6 +1101,9 @@ inline fun Message.asGroupContentMessage(): GroupContentMessage? inline fun Message.requireGroupContentMessage(): GroupContentMessage = this as GroupContentMessage +@PreviewFeature +inline fun Message.whenMediaGroupMessage(block: (MediaGroupMessage) -> T) = asMediaGroupMessage() ?.let(block) + @PreviewFeature inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = this as? MediaGroupMessage @@ -794,24 +1112,36 @@ inline fun Message.asMediaGroupMessage(): MediaGroupMessage? inline fun Message.requireMediaGroupMessage(): MediaGroupMessage = this as MediaGroupMessage +@PreviewFeature +inline fun Message.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) = asPossiblyEditedMessage() ?.let(block) + @PreviewFeature inline fun Message.asPossiblyEditedMessage(): PossiblyEditedMessage? = this as? PossiblyEditedMessage @PreviewFeature inline fun Message.requirePossiblyEditedMessage(): PossiblyEditedMessage = this as PossiblyEditedMessage +@PreviewFeature +inline fun Message.whenPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T) = asPossiblyForwardedMessage() ?.let(block) + @PreviewFeature inline fun Message.asPossiblyForwardedMessage(): PossiblyForwardedMessage? = this as? PossiblyForwardedMessage @PreviewFeature inline fun Message.requirePossiblyForwardedMessage(): PossiblyForwardedMessage = this as PossiblyForwardedMessage +@PreviewFeature +inline fun Message.whenPossiblyPaymentMessage(block: (PossiblyPaymentMessage) -> T) = asPossiblyPaymentMessage() ?.let(block) + @PreviewFeature inline fun Message.asPossiblyPaymentMessage(): PossiblyPaymentMessage? = this as? PossiblyPaymentMessage @PreviewFeature inline fun Message.requirePossiblyPaymentMessage(): PossiblyPaymentMessage = this as PossiblyPaymentMessage +@PreviewFeature +inline fun Message.whenPrivateContentMessage(block: (PrivateContentMessage) -> T) = asPrivateContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asPrivateContentMessage(): PrivateContentMessage? = this as? PrivateContentMessage @@ -820,6 +1150,9 @@ inline fun Message.asPrivateContentMessage(): PrivateContentMessage = this as PrivateContentMessage +@PreviewFeature +inline fun Message.whenPublicContentMessage(block: (PublicContentMessage) -> T) = asPublicContentMessage() ?.let(block) + @PreviewFeature inline fun Message.asPublicContentMessage(): PublicContentMessage? = this as? PublicContentMessage @@ -828,12 +1161,18 @@ inline fun Message.asPublicContentMessage(): PublicContentMessage = this as PublicContentMessage +@PreviewFeature +inline fun Message.whenSignedMessage(block: (SignedMessage) -> T) = asSignedMessage() ?.let(block) + @PreviewFeature inline fun Message.asSignedMessage(): SignedMessage? = this as? SignedMessage @PreviewFeature inline fun Message.requireSignedMessage(): SignedMessage = this as SignedMessage +@PreviewFeature +inline fun Message.whenSupergroupEventMessage(block: (SupergroupEventMessage) -> T) = asSupergroupEventMessage() ?.let(block) + @PreviewFeature inline fun Message.asSupergroupEventMessage(): SupergroupEventMessage? = this as? SupergroupEventMessage @@ -842,12 +1181,18 @@ inline fun Message.asSupergroupEventMessage(): SupergroupEventMessage = this as SupergroupEventMessage +@PreviewFeature +inline fun Message.whenUnknownMessageType(block: (UnknownMessageType) -> T) = asUnknownMessageType() ?.let(block) + @PreviewFeature inline fun Message.asUnknownMessageType(): UnknownMessageType? = this as? UnknownMessageType @PreviewFeature inline fun Message.requireUnknownMessageType(): UnknownMessageType = this as UnknownMessageType +@PreviewFeature +inline fun Message.whenPossiblySentViaBotCommonMessage(block: (PossiblySentViaBotCommonMessage) -> T) = asPossiblySentViaBotCommonMessage() ?.let(block) + @PreviewFeature inline fun Message.asPossiblySentViaBotCommonMessage(): PossiblySentViaBotCommonMessage? = this as? PossiblySentViaBotCommonMessage @@ -856,72 +1201,108 @@ inline fun Message.asPossiblySentViaBotCommonMessage(): PossiblySentViaBotCommon inline fun Message.requirePossiblySentViaBotCommonMessage(): PossiblySentViaBotCommonMessage = this as PossiblySentViaBotCommonMessage +@PreviewFeature +inline fun Message.whenFromUserMessage(block: (FromUserMessage) -> T) = asFromUserMessage() ?.let(block) + @PreviewFeature inline fun Message.asFromUserMessage(): FromUserMessage? = this as? FromUserMessage @PreviewFeature inline fun Message.requireFromUserMessage(): FromUserMessage = this as FromUserMessage +@PreviewFeature +inline fun BotAction.whenFindLocationAction(block: (FindLocationAction) -> T) = asFindLocationAction() ?.let(block) + @PreviewFeature inline fun BotAction.asFindLocationAction(): FindLocationAction? = this as? FindLocationAction @PreviewFeature inline fun BotAction.requireFindLocationAction(): FindLocationAction = this as FindLocationAction +@PreviewFeature +inline fun BotAction.whenRecordVoiceAction(block: (RecordVoiceAction) -> T) = asRecordVoiceAction() ?.let(block) + @PreviewFeature inline fun BotAction.asRecordVoiceAction(): RecordVoiceAction? = this as? RecordVoiceAction @PreviewFeature inline fun BotAction.requireRecordVoiceAction(): RecordVoiceAction = this as RecordVoiceAction +@PreviewFeature +inline fun BotAction.whenRecordVideoAction(block: (RecordVideoAction) -> T) = asRecordVideoAction() ?.let(block) + @PreviewFeature inline fun BotAction.asRecordVideoAction(): RecordVideoAction? = this as? RecordVideoAction @PreviewFeature inline fun BotAction.requireRecordVideoAction(): RecordVideoAction = this as RecordVideoAction +@PreviewFeature +inline fun BotAction.whenRecordVideoNoteAction(block: (RecordVideoNoteAction) -> T) = asRecordVideoNoteAction() ?.let(block) + @PreviewFeature inline fun BotAction.asRecordVideoNoteAction(): RecordVideoNoteAction? = this as? RecordVideoNoteAction @PreviewFeature inline fun BotAction.requireRecordVideoNoteAction(): RecordVideoNoteAction = this as RecordVideoNoteAction +@PreviewFeature +inline fun BotAction.whenTypingAction(block: (TypingAction) -> T) = asTypingAction() ?.let(block) + @PreviewFeature inline fun BotAction.asTypingAction(): TypingAction? = this as? TypingAction @PreviewFeature inline fun BotAction.requireTypingAction(): TypingAction = this as TypingAction +@PreviewFeature +inline fun BotAction.whenUploadVoiceAction(block: (UploadVoiceAction) -> T) = asUploadVoiceAction() ?.let(block) + @PreviewFeature inline fun BotAction.asUploadVoiceAction(): UploadVoiceAction? = this as? UploadVoiceAction @PreviewFeature inline fun BotAction.requireUploadVoiceAction(): UploadVoiceAction = this as UploadVoiceAction +@PreviewFeature +inline fun BotAction.whenUploadDocumentAction(block: (UploadDocumentAction) -> T) = asUploadDocumentAction() ?.let(block) + @PreviewFeature inline fun BotAction.asUploadDocumentAction(): UploadDocumentAction? = this as? UploadDocumentAction @PreviewFeature inline fun BotAction.requireUploadDocumentAction(): UploadDocumentAction = this as UploadDocumentAction +@PreviewFeature +inline fun BotAction.whenUploadPhotoAction(block: (UploadPhotoAction) -> T) = asUploadPhotoAction() ?.let(block) + @PreviewFeature inline fun BotAction.asUploadPhotoAction(): UploadPhotoAction? = this as? UploadPhotoAction @PreviewFeature inline fun BotAction.requireUploadPhotoAction(): UploadPhotoAction = this as UploadPhotoAction +@PreviewFeature +inline fun BotAction.whenUploadVideoAction(block: (UploadVideoAction) -> T) = asUploadVideoAction() ?.let(block) + @PreviewFeature inline fun BotAction.asUploadVideoAction(): UploadVideoAction? = this as? UploadVideoAction @PreviewFeature inline fun BotAction.requireUploadVideoAction(): UploadVideoAction = this as UploadVideoAction +@PreviewFeature +inline fun BotAction.whenUploadVideoNoteAction(block: (UploadVideoNoteAction) -> T) = asUploadVideoNoteAction() ?.let(block) + @PreviewFeature inline fun BotAction.asUploadVideoNoteAction(): UploadVideoNoteAction? = this as? UploadVideoNoteAction @PreviewFeature inline fun BotAction.requireUploadVideoNoteAction(): UploadVideoNoteAction = this as UploadVideoNoteAction +@PreviewFeature +inline fun InlineQuery.whenBaseInlineQuery(block: (BaseInlineQuery) -> T) = asBaseInlineQuery() ?.let(block) + @PreviewFeature inline fun InlineQuery.asBaseInlineQuery(): BaseInlineQuery? = this as? BaseInlineQuery @@ -930,6 +1311,9 @@ inline fun InlineQuery.asBaseInlineQuery(): BaseInlineQuery? = inline fun InlineQuery.requireBaseInlineQuery(): BaseInlineQuery = this as BaseInlineQuery +@PreviewFeature +inline fun InlineQuery.whenLocationInlineQuery(block: (LocationInlineQuery) -> T) = asLocationInlineQuery() ?.let(block) + @PreviewFeature inline fun InlineQuery.asLocationInlineQuery(): LocationInlineQuery? = this as? LocationInlineQuery @@ -938,6 +1322,9 @@ inline fun InlineQuery.asLocationInlineQuery(): LocationInlineQuery? = inline fun InlineQuery.requireLocationInlineQuery(): LocationInlineQuery = this as LocationInlineQuery +@PreviewFeature +inline fun InputMessageContent.whenInputContactMessageContent(block: (InputContactMessageContent) -> T) = asInputContactMessageContent() ?.let(block) + @PreviewFeature inline fun InputMessageContent.asInputContactMessageContent(): InputContactMessageContent? = this as? InputContactMessageContent @@ -946,6 +1333,9 @@ inline fun InputMessageContent.asInputContactMessageContent(): InputContactMessa inline fun InputMessageContent.requireInputContactMessageContent(): InputContactMessageContent = this as InputContactMessageContent +@PreviewFeature +inline fun InputMessageContent.whenInputLocationMessageContent(block: (InputLocationMessageContent) -> T) = asInputLocationMessageContent() ?.let(block) + @PreviewFeature inline fun InputMessageContent.asInputLocationMessageContent(): InputLocationMessageContent? = this as? InputLocationMessageContent @@ -954,6 +1344,9 @@ inline fun InputMessageContent.asInputLocationMessageContent(): InputLocationMes inline fun InputMessageContent.requireInputLocationMessageContent(): InputLocationMessageContent = this as InputLocationMessageContent +@PreviewFeature +inline fun InputMessageContent.whenInputTextMessageContent(block: (InputTextMessageContent) -> T) = asInputTextMessageContent() ?.let(block) + @PreviewFeature inline fun InputMessageContent.asInputTextMessageContent(): InputTextMessageContent? = this as? InputTextMessageContent @@ -961,6 +1354,9 @@ inline fun InputMessageContent.asInputTextMessageContent(): InputTextMessageCont inline fun InputMessageContent.requireInputTextMessageContent(): InputTextMessageContent = this as InputTextMessageContent +@PreviewFeature +inline fun InputMessageContent.whenInputVenueMessageContent(block: (InputVenueMessageContent) -> T) = asInputVenueMessageContent() ?.let(block) + @PreviewFeature inline fun InputMessageContent.asInputVenueMessageContent(): InputVenueMessageContent? = this as? InputVenueMessageContent @@ -969,6 +1365,9 @@ inline fun InputMessageContent.asInputVenueMessageContent(): InputVenueMessageCo inline fun InputMessageContent.requireInputVenueMessageContent(): InputVenueMessageContent = this as InputVenueMessageContent +@PreviewFeature +inline fun InputMessageContent.whenInputInvoiceMessageContent(block: (InputInvoiceMessageContent) -> T) = asInputInvoiceMessageContent() ?.let(block) + @PreviewFeature inline fun InputMessageContent.asInputInvoiceMessageContent(): InputInvoiceMessageContent? = this as? InputInvoiceMessageContent @@ -977,6 +1376,9 @@ inline fun InputMessageContent.asInputInvoiceMessageContent(): InputInvoiceMessa inline fun InputMessageContent.requireInputInvoiceMessageContent(): InputInvoiceMessageContent = this as InputInvoiceMessageContent +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultArticle(block: (InlineQueryResultArticle) -> T) = asInlineQueryResultArticle() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultArticle(): InlineQueryResultArticle? = this as? InlineQueryResultArticle @@ -984,6 +1386,9 @@ inline fun InlineQueryResult.asInlineQueryResultArticle(): InlineQueryResultArti inline fun InlineQueryResult.requireInlineQueryResultArticle(): InlineQueryResultArticle = this as InlineQueryResultArticle +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultContact(block: (InlineQueryResultContact) -> T) = asInlineQueryResultContact() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultContact(): InlineQueryResultContact? = this as? InlineQueryResultContact @@ -991,12 +1396,18 @@ inline fun InlineQueryResult.asInlineQueryResultContact(): InlineQueryResultCont inline fun InlineQueryResult.requireInlineQueryResultContact(): InlineQueryResultContact = this as InlineQueryResultContact +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultGame(block: (InlineQueryResultGame) -> T) = asInlineQueryResultGame() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultGame(): InlineQueryResultGame? = this as? InlineQueryResultGame @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultGame(): InlineQueryResultGame = this as InlineQueryResultGame +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultLocation(block: (InlineQueryResultLocation) -> T) = asInlineQueryResultLocation() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultLocation(): InlineQueryResultLocation? = this as? InlineQueryResultLocation @@ -1005,6 +1416,9 @@ inline fun InlineQueryResult.asInlineQueryResultLocation(): InlineQueryResultLoc inline fun InlineQueryResult.requireInlineQueryResultLocation(): InlineQueryResultLocation = this as InlineQueryResultLocation +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultStickerCached(block: (InlineQueryResultStickerCached) -> T) = asInlineQueryResultStickerCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultStickerCached(): InlineQueryResultStickerCached? = this as? InlineQueryResultStickerCached @@ -1013,12 +1427,18 @@ inline fun InlineQueryResult.asInlineQueryResultStickerCached(): InlineQueryResu inline fun InlineQueryResult.requireInlineQueryResultStickerCached(): InlineQueryResultStickerCached = this as InlineQueryResultStickerCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVenue(block: (InlineQueryResultVenue) -> T) = asInlineQueryResultVenue() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVenue(): InlineQueryResultVenue? = this as? InlineQueryResultVenue @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultVenue(): InlineQueryResultVenue = this as InlineQueryResultVenue +@PreviewFeature +inline fun InlineQueryResult.whenDescribedInlineQueryResult(block: (DescribedInlineQueryResult) -> T) = asDescribedInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asDescribedInlineQueryResult(): DescribedInlineQueryResult? = this as? DescribedInlineQueryResult @@ -1027,12 +1447,18 @@ inline fun InlineQueryResult.asDescribedInlineQueryResult(): DescribedInlineQuer inline fun InlineQueryResult.requireDescribedInlineQueryResult(): DescribedInlineQueryResult = this as DescribedInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenFileInlineQueryResult(block: (FileInlineQueryResult) -> T) = asFileInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asFileInlineQueryResult(): FileInlineQueryResult? = this as? FileInlineQueryResult @PreviewFeature inline fun InlineQueryResult.requireFileInlineQueryResult(): FileInlineQueryResult = this as FileInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenOptionallyTitledInlineQueryResult(block: (OptionallyTitledInlineQueryResult) -> T) = asOptionallyTitledInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asOptionallyTitledInlineQueryResult(): OptionallyTitledInlineQueryResult? = this as? OptionallyTitledInlineQueryResult @@ -1041,12 +1467,18 @@ inline fun InlineQueryResult.asOptionallyTitledInlineQueryResult(): OptionallyTi inline fun InlineQueryResult.requireOptionallyTitledInlineQueryResult(): OptionallyTitledInlineQueryResult = this as OptionallyTitledInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenSizedInlineQueryResult(block: (SizedInlineQueryResult) -> T) = asSizedInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asSizedInlineQueryResult(): SizedInlineQueryResult? = this as? SizedInlineQueryResult @PreviewFeature inline fun InlineQueryResult.requireSizedInlineQueryResult(): SizedInlineQueryResult = this as SizedInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenThumbSizedInlineQueryResult(block: (ThumbSizedInlineQueryResult) -> T) = asThumbSizedInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asThumbSizedInlineQueryResult(): ThumbSizedInlineQueryResult? = this as? ThumbSizedInlineQueryResult @@ -1055,6 +1487,9 @@ inline fun InlineQueryResult.asThumbSizedInlineQueryResult(): ThumbSizedInlineQu inline fun InlineQueryResult.requireThumbSizedInlineQueryResult(): ThumbSizedInlineQueryResult = this as ThumbSizedInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenThumbedInlineQueryResult(block: (ThumbedInlineQueryResult) -> T) = asThumbedInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asThumbedInlineQueryResult(): ThumbedInlineQueryResult? = this as? ThumbedInlineQueryResult @@ -1062,6 +1497,9 @@ inline fun InlineQueryResult.asThumbedInlineQueryResult(): ThumbedInlineQueryRes inline fun InlineQueryResult.requireThumbedInlineQueryResult(): ThumbedInlineQueryResult = this as ThumbedInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenThumbedWithMimeTypeInlineQueryResult(block: (ThumbedWithMimeTypeInlineQueryResult) -> T) = asThumbedWithMimeTypeInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asThumbedWithMimeTypeInlineQueryResult(): ThumbedWithMimeTypeInlineQueryResult? = this as? ThumbedWithMimeTypeInlineQueryResult @@ -1070,18 +1508,27 @@ inline fun InlineQueryResult.asThumbedWithMimeTypeInlineQueryResult(): ThumbedWi inline fun InlineQueryResult.requireThumbedWithMimeTypeInlineQueryResult(): ThumbedWithMimeTypeInlineQueryResult = this as ThumbedWithMimeTypeInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenTitledInlineQueryResult(block: (TitledInlineQueryResult) -> T) = asTitledInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asTitledInlineQueryResult(): TitledInlineQueryResult? = this as? TitledInlineQueryResult @PreviewFeature inline fun InlineQueryResult.requireTitledInlineQueryResult(): TitledInlineQueryResult = this as TitledInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenUrlInlineQueryResult(block: (UrlInlineQueryResult) -> T) = asUrlInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asUrlInlineQueryResult(): UrlInlineQueryResult? = this as? UrlInlineQueryResult @PreviewFeature inline fun InlineQueryResult.requireUrlInlineQueryResult(): UrlInlineQueryResult = this as UrlInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenWithInputMessageContentInlineQueryResult(block: (WithInputMessageContentInlineQueryResult) -> T) = asWithInputMessageContentInlineQueryResult() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asWithInputMessageContentInlineQueryResult(): WithInputMessageContentInlineQueryResult? = this as? WithInputMessageContentInlineQueryResult @@ -1090,12 +1537,18 @@ inline fun InlineQueryResult.asWithInputMessageContentInlineQueryResult(): WithI inline fun InlineQueryResult.requireWithInputMessageContentInlineQueryResult(): WithInputMessageContentInlineQueryResult = this as WithInputMessageContentInlineQueryResult +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultAudio(block: (InlineQueryResultAudio) -> T) = asInlineQueryResultAudio() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultAudio(): InlineQueryResultAudio? = this as? InlineQueryResultAudio @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultAudio(): InlineQueryResultAudio = this as InlineQueryResultAudio +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultAudioCached(block: (InlineQueryResultAudioCached) -> T) = asInlineQueryResultAudioCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultAudioCached(): InlineQueryResultAudioCached? = this as? InlineQueryResultAudioCached @@ -1104,6 +1557,9 @@ inline fun InlineQueryResult.asInlineQueryResultAudioCached(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultAudioCached(): InlineQueryResultAudioCached = this as InlineQueryResultAudioCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultAudioCommon(block: (InlineQueryResultAudioCommon) -> T) = asInlineQueryResultAudioCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultAudioCommon(): InlineQueryResultAudioCommon? = this as? InlineQueryResultAudioCommon @@ -1112,6 +1568,9 @@ inline fun InlineQueryResult.asInlineQueryResultAudioCommon(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultAudioCommon(): InlineQueryResultAudioCommon = this as InlineQueryResultAudioCommon +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultDocument(block: (InlineQueryResultDocument) -> T) = asInlineQueryResultDocument() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultDocument(): InlineQueryResultDocument? = this as? InlineQueryResultDocument @@ -1120,6 +1579,9 @@ inline fun InlineQueryResult.asInlineQueryResultDocument(): InlineQueryResultDoc inline fun InlineQueryResult.requireInlineQueryResultDocument(): InlineQueryResultDocument = this as InlineQueryResultDocument +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultDocumentCached(block: (InlineQueryResultDocumentCached) -> T) = asInlineQueryResultDocumentCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultDocumentCached(): InlineQueryResultDocumentCached? = this as? InlineQueryResultDocumentCached @@ -1128,6 +1590,9 @@ inline fun InlineQueryResult.asInlineQueryResultDocumentCached(): InlineQueryRes inline fun InlineQueryResult.requireInlineQueryResultDocumentCached(): InlineQueryResultDocumentCached = this as InlineQueryResultDocumentCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultDocumentCommon(block: (InlineQueryResultDocumentCommon) -> T) = asInlineQueryResultDocumentCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultDocumentCommon(): InlineQueryResultDocumentCommon? = this as? InlineQueryResultDocumentCommon @@ -1136,12 +1601,18 @@ inline fun InlineQueryResult.asInlineQueryResultDocumentCommon(): InlineQueryRes inline fun InlineQueryResult.requireInlineQueryResultDocumentCommon(): InlineQueryResultDocumentCommon = this as InlineQueryResultDocumentCommon +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultGif(block: (InlineQueryResultGif) -> T) = asInlineQueryResultGif() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultGif(): InlineQueryResultGif? = this as? InlineQueryResultGif @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultGif(): InlineQueryResultGif = this as InlineQueryResultGif +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultGifCached(block: (InlineQueryResultGifCached) -> T) = asInlineQueryResultGifCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultGifCached(): InlineQueryResultGifCached? = this as? InlineQueryResultGifCached @@ -1150,6 +1621,9 @@ inline fun InlineQueryResult.asInlineQueryResultGifCached(): InlineQueryResultGi inline fun InlineQueryResult.requireInlineQueryResultGifCached(): InlineQueryResultGifCached = this as InlineQueryResultGifCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultGifCommon(block: (InlineQueryResultGifCommon) -> T) = asInlineQueryResultGifCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultGifCommon(): InlineQueryResultGifCommon? = this as? InlineQueryResultGifCommon @@ -1158,6 +1632,9 @@ inline fun InlineQueryResult.asInlineQueryResultGifCommon(): InlineQueryResultGi inline fun InlineQueryResult.requireInlineQueryResultGifCommon(): InlineQueryResultGifCommon = this as InlineQueryResultGifCommon +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultMpeg4Gif(block: (InlineQueryResultMpeg4Gif) -> T) = asInlineQueryResultMpeg4Gif() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultMpeg4Gif(): InlineQueryResultMpeg4Gif? = this as? InlineQueryResultMpeg4Gif @@ -1166,6 +1643,9 @@ inline fun InlineQueryResult.asInlineQueryResultMpeg4Gif(): InlineQueryResultMpe inline fun InlineQueryResult.requireInlineQueryResultMpeg4Gif(): InlineQueryResultMpeg4Gif = this as InlineQueryResultMpeg4Gif +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultMpeg4GifCached(block: (InlineQueryResultMpeg4GifCached) -> T) = asInlineQueryResultMpeg4GifCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultMpeg4GifCached(): InlineQueryResultMpeg4GifCached? = this as? InlineQueryResultMpeg4GifCached @@ -1174,6 +1654,9 @@ inline fun InlineQueryResult.asInlineQueryResultMpeg4GifCached(): InlineQueryRes inline fun InlineQueryResult.requireInlineQueryResultMpeg4GifCached(): InlineQueryResultMpeg4GifCached = this as InlineQueryResultMpeg4GifCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultMpeg4GifCommon(block: (InlineQueryResultMpeg4GifCommon) -> T) = asInlineQueryResultMpeg4GifCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultMpeg4GifCommon(): InlineQueryResultMpeg4GifCommon? = this as? InlineQueryResultMpeg4GifCommon @@ -1182,12 +1665,18 @@ inline fun InlineQueryResult.asInlineQueryResultMpeg4GifCommon(): InlineQueryRes inline fun InlineQueryResult.requireInlineQueryResultMpeg4GifCommon(): InlineQueryResultMpeg4GifCommon = this as InlineQueryResultMpeg4GifCommon +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultPhoto(block: (InlineQueryResultPhoto) -> T) = asInlineQueryResultPhoto() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultPhoto(): InlineQueryResultPhoto? = this as? InlineQueryResultPhoto @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultPhoto(): InlineQueryResultPhoto = this as InlineQueryResultPhoto +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultPhotoCached(block: (InlineQueryResultPhotoCached) -> T) = asInlineQueryResultPhotoCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultPhotoCached(): InlineQueryResultPhotoCached? = this as? InlineQueryResultPhotoCached @@ -1196,6 +1685,9 @@ inline fun InlineQueryResult.asInlineQueryResultPhotoCached(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultPhotoCached(): InlineQueryResultPhotoCached = this as InlineQueryResultPhotoCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultPhotoCommon(block: (InlineQueryResultPhotoCommon) -> T) = asInlineQueryResultPhotoCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultPhotoCommon(): InlineQueryResultPhotoCommon? = this as? InlineQueryResultPhotoCommon @@ -1204,12 +1696,18 @@ inline fun InlineQueryResult.asInlineQueryResultPhotoCommon(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultPhotoCommon(): InlineQueryResultPhotoCommon = this as InlineQueryResultPhotoCommon +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVideo(block: (InlineQueryResultVideo) -> T) = asInlineQueryResultVideo() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVideo(): InlineQueryResultVideo? = this as? InlineQueryResultVideo @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultVideo(): InlineQueryResultVideo = this as InlineQueryResultVideo +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVideoCached(block: (InlineQueryResultVideoCached) -> T) = asInlineQueryResultVideoCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVideoCached(): InlineQueryResultVideoCached? = this as? InlineQueryResultVideoCached @@ -1218,6 +1716,9 @@ inline fun InlineQueryResult.asInlineQueryResultVideoCached(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultVideoCached(): InlineQueryResultVideoCached = this as InlineQueryResultVideoCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVideoCommon(block: (InlineQueryResultVideoCommon) -> T) = asInlineQueryResultVideoCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVideoCommon(): InlineQueryResultVideoCommon? = this as? InlineQueryResultVideoCommon @@ -1226,12 +1727,18 @@ inline fun InlineQueryResult.asInlineQueryResultVideoCommon(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultVideoCommon(): InlineQueryResultVideoCommon = this as InlineQueryResultVideoCommon +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVoice(block: (InlineQueryResultVoice) -> T) = asInlineQueryResultVoice() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVoice(): InlineQueryResultVoice? = this as? InlineQueryResultVoice @PreviewFeature inline fun InlineQueryResult.requireInlineQueryResultVoice(): InlineQueryResultVoice = this as InlineQueryResultVoice +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVoiceCached(block: (InlineQueryResultVoiceCached) -> T) = asInlineQueryResultVoiceCached() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVoiceCached(): InlineQueryResultVoiceCached? = this as? InlineQueryResultVoiceCached @@ -1240,6 +1747,9 @@ inline fun InlineQueryResult.asInlineQueryResultVoiceCached(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultVoiceCached(): InlineQueryResultVoiceCached = this as InlineQueryResultVoiceCached +@PreviewFeature +inline fun InlineQueryResult.whenInlineQueryResultVoiceCommon(block: (InlineQueryResultVoiceCommon) -> T) = asInlineQueryResultVoiceCommon() ?.let(block) + @PreviewFeature inline fun InlineQueryResult.asInlineQueryResultVoiceCommon(): InlineQueryResultVoiceCommon? = this as? InlineQueryResultVoiceCommon @@ -1248,54 +1758,81 @@ inline fun InlineQueryResult.asInlineQueryResultVoiceCommon(): InlineQueryResult inline fun InlineQueryResult.requireInlineQueryResultVoiceCommon(): InlineQueryResultVoiceCommon = this as InlineQueryResultVoiceCommon +@PreviewFeature +inline fun ChatMember.whenCreatorChatMember(block: (CreatorChatMember) -> T) = asCreatorChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asCreatorChatMember(): CreatorChatMember? = this as? CreatorChatMember @PreviewFeature inline fun ChatMember.requireCreatorChatMember(): CreatorChatMember = this as CreatorChatMember +@PreviewFeature +inline fun ChatMember.whenKickedChatMember(block: (KickedChatMember) -> T) = asKickedChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asKickedChatMember(): KickedChatMember? = this as? KickedChatMember @PreviewFeature inline fun ChatMember.requireKickedChatMember(): KickedChatMember = this as KickedChatMember +@PreviewFeature +inline fun ChatMember.whenLeftChatMember(block: (LeftChatMember) -> T) = asLeftChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asLeftChatMember(): LeftChatMember? = this as? LeftChatMember @PreviewFeature inline fun ChatMember.requireLeftChatMember(): LeftChatMember = this as LeftChatMember +@PreviewFeature +inline fun ChatMember.whenMemberChatMember(block: (MemberChatMember) -> T) = asMemberChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asMemberChatMember(): MemberChatMember? = this as? MemberChatMember @PreviewFeature inline fun ChatMember.requireMemberChatMember(): MemberChatMember = this as MemberChatMember +@PreviewFeature +inline fun ChatMember.whenRestrictedChatMember(block: (RestrictedChatMember) -> T) = asRestrictedChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asRestrictedChatMember(): RestrictedChatMember? = this as? RestrictedChatMember @PreviewFeature inline fun ChatMember.requireRestrictedChatMember(): RestrictedChatMember = this as RestrictedChatMember +@PreviewFeature +inline fun ChatMember.whenAdministratorChatMember(block: (AdministratorChatMember) -> T) = asAdministratorChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asAdministratorChatMember(): AdministratorChatMember? = this as? AdministratorChatMember @PreviewFeature inline fun ChatMember.requireAdministratorChatMember(): AdministratorChatMember = this as AdministratorChatMember +@PreviewFeature +inline fun ChatMember.whenBannedChatMember(block: (BannedChatMember) -> T) = asBannedChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asBannedChatMember(): BannedChatMember? = this as? BannedChatMember @PreviewFeature inline fun ChatMember.requireBannedChatMember(): BannedChatMember = this as BannedChatMember +@PreviewFeature +inline fun ChatMember.whenSpecialRightsChatMember(block: (SpecialRightsChatMember) -> T) = asSpecialRightsChatMember() ?.let(block) + @PreviewFeature inline fun ChatMember.asSpecialRightsChatMember(): SpecialRightsChatMember? = this as? SpecialRightsChatMember @PreviewFeature inline fun ChatMember.requireSpecialRightsChatMember(): SpecialRightsChatMember = this as SpecialRightsChatMember +@PreviewFeature +inline fun InputMedia.whenAudioMediaGroupMemberInputMedia(block: (AudioMediaGroupMemberInputMedia) -> T) = asAudioMediaGroupMemberInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asAudioMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia? = this as? AudioMediaGroupMemberInputMedia @@ -1304,6 +1841,9 @@ inline fun InputMedia.asAudioMediaGroupMemberInputMedia(): AudioMediaGroupMember inline fun InputMedia.requireAudioMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia = this as AudioMediaGroupMemberInputMedia +@PreviewFeature +inline fun InputMedia.whenDocumentMediaGroupMemberInputMedia(block: (DocumentMediaGroupMemberInputMedia) -> T) = asDocumentMediaGroupMemberInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asDocumentMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia? = this as? DocumentMediaGroupMemberInputMedia @@ -1312,42 +1852,63 @@ inline fun InputMedia.asDocumentMediaGroupMemberInputMedia(): DocumentMediaGroup inline fun InputMedia.requireDocumentMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia = this as DocumentMediaGroupMemberInputMedia +@PreviewFeature +inline fun InputMedia.whenDuratedInputMedia(block: (DuratedInputMedia) -> T) = asDuratedInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asDuratedInputMedia(): DuratedInputMedia? = this as? DuratedInputMedia @PreviewFeature inline fun InputMedia.requireDuratedInputMedia(): DuratedInputMedia = this as DuratedInputMedia +@PreviewFeature +inline fun InputMedia.whenInputMediaAnimation(block: (InputMediaAnimation) -> T) = asInputMediaAnimation() ?.let(block) + @PreviewFeature inline fun InputMedia.asInputMediaAnimation(): InputMediaAnimation? = this as? InputMediaAnimation @PreviewFeature inline fun InputMedia.requireInputMediaAnimation(): InputMediaAnimation = this as InputMediaAnimation +@PreviewFeature +inline fun InputMedia.whenInputMediaAudio(block: (InputMediaAudio) -> T) = asInputMediaAudio() ?.let(block) + @PreviewFeature inline fun InputMedia.asInputMediaAudio(): InputMediaAudio? = this as? InputMediaAudio @PreviewFeature inline fun InputMedia.requireInputMediaAudio(): InputMediaAudio = this as InputMediaAudio +@PreviewFeature +inline fun InputMedia.whenInputMediaDocument(block: (InputMediaDocument) -> T) = asInputMediaDocument() ?.let(block) + @PreviewFeature inline fun InputMedia.asInputMediaDocument(): InputMediaDocument? = this as? InputMediaDocument @PreviewFeature inline fun InputMedia.requireInputMediaDocument(): InputMediaDocument = this as InputMediaDocument +@PreviewFeature +inline fun InputMedia.whenInputMediaPhoto(block: (InputMediaPhoto) -> T) = asInputMediaPhoto() ?.let(block) + @PreviewFeature inline fun InputMedia.asInputMediaPhoto(): InputMediaPhoto? = this as? InputMediaPhoto @PreviewFeature inline fun InputMedia.requireInputMediaPhoto(): InputMediaPhoto = this as InputMediaPhoto +@PreviewFeature +inline fun InputMedia.whenInputMediaVideo(block: (InputMediaVideo) -> T) = asInputMediaVideo() ?.let(block) + @PreviewFeature inline fun InputMedia.asInputMediaVideo(): InputMediaVideo? = this as? InputMediaVideo @PreviewFeature inline fun InputMedia.requireInputMediaVideo(): InputMediaVideo = this as InputMediaVideo +@PreviewFeature +inline fun InputMedia.whenMediaGroupMemberInputMedia(block: (MediaGroupMemberInputMedia) -> T) = asMediaGroupMemberInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia? = this as? MediaGroupMemberInputMedia @@ -1355,24 +1916,36 @@ inline fun InputMedia.asMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia inline fun InputMedia.requireMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = this as MediaGroupMemberInputMedia +@PreviewFeature +inline fun InputMedia.whenSizedInputMedia(block: (SizedInputMedia) -> T) = asSizedInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asSizedInputMedia(): SizedInputMedia? = this as? SizedInputMedia @PreviewFeature inline fun InputMedia.requireSizedInputMedia(): SizedInputMedia = this as SizedInputMedia +@PreviewFeature +inline fun InputMedia.whenThumbedInputMedia(block: (ThumbedInputMedia) -> T) = asThumbedInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asThumbedInputMedia(): ThumbedInputMedia? = this as? ThumbedInputMedia @PreviewFeature inline fun InputMedia.requireThumbedInputMedia(): ThumbedInputMedia = this as ThumbedInputMedia +@PreviewFeature +inline fun InputMedia.whenTitledInputMedia(block: (TitledInputMedia) -> T) = asTitledInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asTitledInputMedia(): TitledInputMedia? = this as? TitledInputMedia @PreviewFeature inline fun InputMedia.requireTitledInputMedia(): TitledInputMedia = this as TitledInputMedia +@PreviewFeature +inline fun InputMedia.whenVisualMediaGroupMemberInputMedia(block: (VisualMediaGroupMemberInputMedia) -> T) = asVisualMediaGroupMemberInputMedia() ?.let(block) + @PreviewFeature inline fun InputMedia.asVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia? = this as? VisualMediaGroupMemberInputMedia @@ -1381,42 +1954,63 @@ inline fun InputMedia.asVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemb inline fun InputMedia.requireVisualMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia = this as VisualMediaGroupMemberInputMedia +@PreviewFeature +inline fun Update.whenCallbackQueryUpdate(block: (CallbackQueryUpdate) -> T) = asCallbackQueryUpdate() ?.let(block) + @PreviewFeature inline fun Update.asCallbackQueryUpdate(): CallbackQueryUpdate? = this as? CallbackQueryUpdate @PreviewFeature inline fun Update.requireCallbackQueryUpdate(): CallbackQueryUpdate = this as CallbackQueryUpdate +@PreviewFeature +inline fun Update.whenChannelPostUpdate(block: (ChannelPostUpdate) -> T) = asChannelPostUpdate() ?.let(block) + @PreviewFeature inline fun Update.asChannelPostUpdate(): ChannelPostUpdate? = this as? ChannelPostUpdate @PreviewFeature inline fun Update.requireChannelPostUpdate(): ChannelPostUpdate = this as ChannelPostUpdate +@PreviewFeature +inline fun Update.whenChosenInlineResultUpdate(block: (ChosenInlineResultUpdate) -> T) = asChosenInlineResultUpdate() ?.let(block) + @PreviewFeature inline fun Update.asChosenInlineResultUpdate(): ChosenInlineResultUpdate? = this as? ChosenInlineResultUpdate @PreviewFeature inline fun Update.requireChosenInlineResultUpdate(): ChosenInlineResultUpdate = this as ChosenInlineResultUpdate +@PreviewFeature +inline fun Update.whenEditChannelPostUpdate(block: (EditChannelPostUpdate) -> T) = asEditChannelPostUpdate() ?.let(block) + @PreviewFeature inline fun Update.asEditChannelPostUpdate(): EditChannelPostUpdate? = this as? EditChannelPostUpdate @PreviewFeature inline fun Update.requireEditChannelPostUpdate(): EditChannelPostUpdate = this as EditChannelPostUpdate +@PreviewFeature +inline fun Update.whenEditMessageUpdate(block: (EditMessageUpdate) -> T) = asEditMessageUpdate() ?.let(block) + @PreviewFeature inline fun Update.asEditMessageUpdate(): EditMessageUpdate? = this as? EditMessageUpdate @PreviewFeature inline fun Update.requireEditMessageUpdate(): EditMessageUpdate = this as EditMessageUpdate +@PreviewFeature +inline fun Update.whenInlineQueryUpdate(block: (InlineQueryUpdate) -> T) = asInlineQueryUpdate() ?.let(block) + @PreviewFeature inline fun Update.asInlineQueryUpdate(): InlineQueryUpdate? = this as? InlineQueryUpdate @PreviewFeature inline fun Update.requireInlineQueryUpdate(): InlineQueryUpdate = this as InlineQueryUpdate +@PreviewFeature +inline fun Update.whenChannelPostMediaGroupUpdate(block: (ChannelPostMediaGroupUpdate) -> T) = asChannelPostMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asChannelPostMediaGroupUpdate(): ChannelPostMediaGroupUpdate? = this as? ChannelPostMediaGroupUpdate @@ -1424,6 +2018,9 @@ inline fun Update.asChannelPostMediaGroupUpdate(): ChannelPostMediaGroupUpdate? inline fun Update.requireChannelPostMediaGroupUpdate(): ChannelPostMediaGroupUpdate = this as ChannelPostMediaGroupUpdate +@PreviewFeature +inline fun Update.whenEditChannelPostMediaGroupUpdate(block: (EditChannelPostMediaGroupUpdate) -> T) = asEditChannelPostMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asEditChannelPostMediaGroupUpdate(): EditChannelPostMediaGroupUpdate? = this as? EditChannelPostMediaGroupUpdate @@ -1432,12 +2029,18 @@ inline fun Update.asEditChannelPostMediaGroupUpdate(): EditChannelPostMediaGroup inline fun Update.requireEditChannelPostMediaGroupUpdate(): EditChannelPostMediaGroupUpdate = this as EditChannelPostMediaGroupUpdate +@PreviewFeature +inline fun Update.whenEditMediaGroupUpdate(block: (EditMediaGroupUpdate) -> T) = asEditMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asEditMediaGroupUpdate(): EditMediaGroupUpdate? = this as? EditMediaGroupUpdate @PreviewFeature inline fun Update.requireEditMediaGroupUpdate(): EditMediaGroupUpdate = this as EditMediaGroupUpdate +@PreviewFeature +inline fun Update.whenEditMessageMediaGroupUpdate(block: (EditMessageMediaGroupUpdate) -> T) = asEditMessageMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asEditMessageMediaGroupUpdate(): EditMessageMediaGroupUpdate? = this as? EditMessageMediaGroupUpdate @@ -1445,78 +2048,117 @@ inline fun Update.asEditMessageMediaGroupUpdate(): EditMessageMediaGroupUpdate? inline fun Update.requireEditMessageMediaGroupUpdate(): EditMessageMediaGroupUpdate = this as EditMessageMediaGroupUpdate +@PreviewFeature +inline fun Update.whenMediaGroupUpdate(block: (MediaGroupUpdate) -> T) = asMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asMediaGroupUpdate(): MediaGroupUpdate? = this as? MediaGroupUpdate @PreviewFeature inline fun Update.requireMediaGroupUpdate(): MediaGroupUpdate = this as MediaGroupUpdate +@PreviewFeature +inline fun Update.whenMessageMediaGroupUpdate(block: (MessageMediaGroupUpdate) -> T) = asMessageMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asMessageMediaGroupUpdate(): MessageMediaGroupUpdate? = this as? MessageMediaGroupUpdate @PreviewFeature inline fun Update.requireMessageMediaGroupUpdate(): MessageMediaGroupUpdate = this as MessageMediaGroupUpdate +@PreviewFeature +inline fun Update.whenSentMediaGroupUpdate(block: (SentMediaGroupUpdate) -> T) = asSentMediaGroupUpdate() ?.let(block) + @PreviewFeature inline fun Update.asSentMediaGroupUpdate(): SentMediaGroupUpdate? = this as? SentMediaGroupUpdate @PreviewFeature inline fun Update.requireSentMediaGroupUpdate(): SentMediaGroupUpdate = this as SentMediaGroupUpdate +@PreviewFeature +inline fun Update.whenMessageUpdate(block: (MessageUpdate) -> T) = asMessageUpdate() ?.let(block) + @PreviewFeature inline fun Update.asMessageUpdate(): MessageUpdate? = this as? MessageUpdate @PreviewFeature inline fun Update.requireMessageUpdate(): MessageUpdate = this as MessageUpdate +@PreviewFeature +inline fun Update.whenPollAnswerUpdate(block: (PollAnswerUpdate) -> T) = asPollAnswerUpdate() ?.let(block) + @PreviewFeature inline fun Update.asPollAnswerUpdate(): PollAnswerUpdate? = this as? PollAnswerUpdate @PreviewFeature inline fun Update.requirePollAnswerUpdate(): PollAnswerUpdate = this as PollAnswerUpdate +@PreviewFeature +inline fun Update.whenPollUpdate(block: (PollUpdate) -> T) = asPollUpdate() ?.let(block) + @PreviewFeature inline fun Update.asPollUpdate(): PollUpdate? = this as? PollUpdate @PreviewFeature inline fun Update.requirePollUpdate(): PollUpdate = this as PollUpdate +@PreviewFeature +inline fun Update.whenPreCheckoutQueryUpdate(block: (PreCheckoutQueryUpdate) -> T) = asPreCheckoutQueryUpdate() ?.let(block) + @PreviewFeature inline fun Update.asPreCheckoutQueryUpdate(): PreCheckoutQueryUpdate? = this as? PreCheckoutQueryUpdate @PreviewFeature inline fun Update.requirePreCheckoutQueryUpdate(): PreCheckoutQueryUpdate = this as PreCheckoutQueryUpdate +@PreviewFeature +inline fun Update.whenShippingQueryUpdate(block: (ShippingQueryUpdate) -> T) = asShippingQueryUpdate() ?.let(block) + @PreviewFeature inline fun Update.asShippingQueryUpdate(): ShippingQueryUpdate? = this as? ShippingQueryUpdate @PreviewFeature inline fun Update.requireShippingQueryUpdate(): ShippingQueryUpdate = this as ShippingQueryUpdate +@PreviewFeature +inline fun Update.whenBaseEditMessageUpdate(block: (BaseEditMessageUpdate) -> T) = asBaseEditMessageUpdate() ?.let(block) + @PreviewFeature inline fun Update.asBaseEditMessageUpdate(): BaseEditMessageUpdate? = this as? BaseEditMessageUpdate @PreviewFeature inline fun Update.requireBaseEditMessageUpdate(): BaseEditMessageUpdate = this as BaseEditMessageUpdate +@PreviewFeature +inline fun Update.whenBaseMessageUpdate(block: (BaseMessageUpdate) -> T) = asBaseMessageUpdate() ?.let(block) + @PreviewFeature inline fun Update.asBaseMessageUpdate(): BaseMessageUpdate? = this as? BaseMessageUpdate @PreviewFeature inline fun Update.requireBaseMessageUpdate(): BaseMessageUpdate = this as BaseMessageUpdate +@PreviewFeature +inline fun Update.whenBaseSentMessageUpdate(block: (BaseSentMessageUpdate) -> T) = asBaseSentMessageUpdate() ?.let(block) + @PreviewFeature inline fun Update.asBaseSentMessageUpdate(): BaseSentMessageUpdate? = this as? BaseSentMessageUpdate @PreviewFeature inline fun Update.requireBaseSentMessageUpdate(): BaseSentMessageUpdate = this as BaseSentMessageUpdate +@PreviewFeature +inline fun Update.whenUnknownUpdate(block: (UnknownUpdate) -> T) = asUnknownUpdate() ?.let(block) + @PreviewFeature inline fun Update.asUnknownUpdate(): UnknownUpdate? = this as? UnknownUpdate @PreviewFeature inline fun Update.requireUnknownUpdate(): UnknownUpdate = this as UnknownUpdate +@PreviewFeature +inline fun Update.whenCommonChatMemberUpdatedUpdate(block: (CommonChatMemberUpdatedUpdate) -> T) = asCommonChatMemberUpdatedUpdate() ?.let(block) + @PreviewFeature inline fun Update.asCommonChatMemberUpdatedUpdate(): CommonChatMemberUpdatedUpdate? = this as? CommonChatMemberUpdatedUpdate @@ -1525,96 +2167,144 @@ inline fun Update.asCommonChatMemberUpdatedUpdate(): CommonChatMemberUpdatedUpda inline fun Update.requireCommonChatMemberUpdatedUpdate(): CommonChatMemberUpdatedUpdate = this as CommonChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.whenMyChatMemberUpdatedUpdate(block: (MyChatMemberUpdatedUpdate) -> T) = asMyChatMemberUpdatedUpdate() ?.let(block) + @PreviewFeature inline fun Update.asMyChatMemberUpdatedUpdate(): MyChatMemberUpdatedUpdate? = this as? MyChatMemberUpdatedUpdate @PreviewFeature inline fun Update.requireMyChatMemberUpdatedUpdate(): MyChatMemberUpdatedUpdate = this as MyChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.whenChatMemberUpdatedUpdate(block: (ChatMemberUpdatedUpdate) -> T) = asChatMemberUpdatedUpdate() ?.let(block) + @PreviewFeature inline fun Update.asChatMemberUpdatedUpdate(): ChatMemberUpdatedUpdate? = this as? ChatMemberUpdatedUpdate @PreviewFeature inline fun Update.requireChatMemberUpdatedUpdate(): ChatMemberUpdatedUpdate = this as ChatMemberUpdatedUpdate +@PreviewFeature +inline fun TelegramMediaFile.whenAnimationFile(block: (AnimationFile) -> T) = asAnimationFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asAnimationFile(): AnimationFile? = this as? AnimationFile @PreviewFeature inline fun TelegramMediaFile.requireAnimationFile(): AnimationFile = this as AnimationFile +@PreviewFeature +inline fun TelegramMediaFile.whenAudioFile(block: (AudioFile) -> T) = asAudioFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asAudioFile(): AudioFile? = this as? AudioFile @PreviewFeature inline fun TelegramMediaFile.requireAudioFile(): AudioFile = this as AudioFile +@PreviewFeature +inline fun TelegramMediaFile.whenDocumentFile(block: (DocumentFile) -> T) = asDocumentFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asDocumentFile(): DocumentFile? = this as? DocumentFile @PreviewFeature inline fun TelegramMediaFile.requireDocumentFile(): DocumentFile = this as DocumentFile +@PreviewFeature +inline fun TelegramMediaFile.whenFile(block: (File) -> T) = asFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asFile(): File? = this as? File @PreviewFeature inline fun TelegramMediaFile.requireFile(): File = this as File +@PreviewFeature +inline fun TelegramMediaFile.whenPathedFile(block: (PathedFile) -> T) = asPathedFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asPathedFile(): PathedFile? = this as? PathedFile @PreviewFeature inline fun TelegramMediaFile.requirePathedFile(): PathedFile = this as PathedFile +@PreviewFeature +inline fun TelegramMediaFile.whenPhotoSize(block: (PhotoSize) -> T) = asPhotoSize() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asPhotoSize(): PhotoSize? = this as? PhotoSize @PreviewFeature inline fun TelegramMediaFile.requirePhotoSize(): PhotoSize = this as PhotoSize +@PreviewFeature +inline fun TelegramMediaFile.whenSticker(block: (Sticker) -> T) = asSticker() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asSticker(): Sticker? = this as? Sticker @PreviewFeature inline fun TelegramMediaFile.requireSticker(): Sticker = this as Sticker +@PreviewFeature +inline fun TelegramMediaFile.whenVideoFile(block: (VideoFile) -> T) = asVideoFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asVideoFile(): VideoFile? = this as? VideoFile @PreviewFeature inline fun TelegramMediaFile.requireVideoFile(): VideoFile = this as VideoFile +@PreviewFeature +inline fun TelegramMediaFile.whenVideoNoteFile(block: (VideoNoteFile) -> T) = asVideoNoteFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asVideoNoteFile(): VideoNoteFile? = this as? VideoNoteFile @PreviewFeature inline fun TelegramMediaFile.requireVideoNoteFile(): VideoNoteFile = this as VideoNoteFile +@PreviewFeature +inline fun TelegramMediaFile.whenVoiceFile(block: (VoiceFile) -> T) = asVoiceFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asVoiceFile(): VoiceFile? = this as? VoiceFile @PreviewFeature inline fun TelegramMediaFile.requireVoiceFile(): VoiceFile = this as VoiceFile +@PreviewFeature +inline fun TelegramMediaFile.whenMimedMediaFile(block: (MimedMediaFile) -> T) = asMimedMediaFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asMimedMediaFile(): MimedMediaFile? = this as? MimedMediaFile @PreviewFeature inline fun TelegramMediaFile.requireMimedMediaFile(): MimedMediaFile = this as MimedMediaFile +@PreviewFeature +inline fun TelegramMediaFile.whenPlayableMediaFile(block: (PlayableMediaFile) -> T) = asPlayableMediaFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asPlayableMediaFile(): PlayableMediaFile? = this as? PlayableMediaFile @PreviewFeature inline fun TelegramMediaFile.requirePlayableMediaFile(): PlayableMediaFile = this as PlayableMediaFile +@PreviewFeature +inline fun TelegramMediaFile.whenSizedMediaFile(block: (SizedMediaFile) -> T) = asSizedMediaFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asSizedMediaFile(): SizedMediaFile? = this as? SizedMediaFile @PreviewFeature inline fun TelegramMediaFile.requireSizedMediaFile(): SizedMediaFile = this as SizedMediaFile +@PreviewFeature +inline fun TelegramMediaFile.whenThumbedMediaFile(block: (ThumbedMediaFile) -> T) = asThumbedMediaFile() ?.let(block) + @PreviewFeature inline fun TelegramMediaFile.asThumbedMediaFile(): ThumbedMediaFile? = this as? ThumbedMediaFile @@ -1622,29 +2312,44 @@ inline fun TelegramMediaFile.asThumbedMediaFile(): ThumbedMediaFile? = this as? inline fun TelegramMediaFile.requireThumbedMediaFile(): ThumbedMediaFile = this as ThumbedMediaFile @PreviewFeature -inline fun KeyboardMarkup.asForceReply(): ReplyForce? = this as? ReplyForce +inline fun KeyboardMarkup.whenForceReply(block: (ForceReply) -> T) = asForceReply() ?.let(block) + +@PreviewFeature +inline fun KeyboardMarkup.asForceReply(): ForceReply? = this as? ReplyForce @PreviewFeature inline fun KeyboardMarkup.requireForceReply(): ReplyForce = this as ReplyForce +@PreviewFeature +inline fun KeyboardMarkup.whenInlineKeyboardMarkup(block: (InlineKeyboardMarkup) -> T) = asInlineKeyboardMarkup() ?.let(block) + @PreviewFeature inline fun KeyboardMarkup.asInlineKeyboardMarkup(): InlineKeyboardMarkup? = this as? InlineKeyboardMarkup @PreviewFeature inline fun KeyboardMarkup.requireInlineKeyboardMarkup(): InlineKeyboardMarkup = this as InlineKeyboardMarkup +@PreviewFeature +inline fun KeyboardMarkup.whenReplyKeyboardMarkup(block: (ReplyKeyboardMarkup) -> T) = asReplyKeyboardMarkup() ?.let(block) + @PreviewFeature inline fun KeyboardMarkup.asReplyKeyboardMarkup(): ReplyKeyboardMarkup? = this as? ReplyKeyboardMarkup @PreviewFeature inline fun KeyboardMarkup.requireReplyKeyboardMarkup(): ReplyKeyboardMarkup = this as ReplyKeyboardMarkup +@PreviewFeature +inline fun KeyboardMarkup.whenReplyKeyboardRemove(block: (ReplyKeyboardRemove) -> T) = asReplyKeyboardRemove() ?.let(block) + @PreviewFeature inline fun KeyboardMarkup.asReplyKeyboardRemove(): ReplyKeyboardRemove? = this as? ReplyKeyboardRemove @PreviewFeature inline fun KeyboardMarkup.requireReplyKeyboardRemove(): ReplyKeyboardRemove = this as ReplyKeyboardRemove +@PreviewFeature +inline fun InlineKeyboardButton.whenCallbackDataInlineKeyboardButton(block: (CallbackDataInlineKeyboardButton) -> T) = asCallbackDataInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asCallbackDataInlineKeyboardButton(): CallbackDataInlineKeyboardButton? = this as? CallbackDataInlineKeyboardButton @@ -1653,6 +2358,9 @@ inline fun InlineKeyboardButton.asCallbackDataInlineKeyboardButton(): CallbackDa inline fun InlineKeyboardButton.requireCallbackDataInlineKeyboardButton(): CallbackDataInlineKeyboardButton = this as CallbackDataInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenCallbackGameInlineKeyboardButton(block: (CallbackGameInlineKeyboardButton) -> T) = asCallbackGameInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asCallbackGameInlineKeyboardButton(): CallbackGameInlineKeyboardButton? = this as? CallbackGameInlineKeyboardButton @@ -1661,6 +2369,9 @@ inline fun InlineKeyboardButton.asCallbackGameInlineKeyboardButton(): CallbackGa inline fun InlineKeyboardButton.requireCallbackGameInlineKeyboardButton(): CallbackGameInlineKeyboardButton = this as CallbackGameInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenLoginURLInlineKeyboardButton(block: (LoginURLInlineKeyboardButton) -> T) = asLoginURLInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asLoginURLInlineKeyboardButton(): LoginURLInlineKeyboardButton? = this as? LoginURLInlineKeyboardButton @@ -1669,6 +2380,9 @@ inline fun InlineKeyboardButton.asLoginURLInlineKeyboardButton(): LoginURLInline inline fun InlineKeyboardButton.requireLoginURLInlineKeyboardButton(): LoginURLInlineKeyboardButton = this as LoginURLInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenPayInlineKeyboardButton(block: (PayInlineKeyboardButton) -> T) = asPayInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asPayInlineKeyboardButton(): PayInlineKeyboardButton? = this as? PayInlineKeyboardButton @@ -1676,6 +2390,9 @@ inline fun InlineKeyboardButton.asPayInlineKeyboardButton(): PayInlineKeyboardBu inline fun InlineKeyboardButton.requirePayInlineKeyboardButton(): PayInlineKeyboardButton = this as PayInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenSwitchInlineQueryCurrentChatInlineKeyboardButton(block: (SwitchInlineQueryCurrentChatInlineKeyboardButton) -> T) = asSwitchInlineQueryCurrentChatInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asSwitchInlineQueryCurrentChatInlineKeyboardButton(): SwitchInlineQueryCurrentChatInlineKeyboardButton? = this as? SwitchInlineQueryCurrentChatInlineKeyboardButton @@ -1684,6 +2401,9 @@ inline fun InlineKeyboardButton.asSwitchInlineQueryCurrentChatInlineKeyboardButt inline fun InlineKeyboardButton.requireSwitchInlineQueryCurrentChatInlineKeyboardButton(): SwitchInlineQueryCurrentChatInlineKeyboardButton = this as SwitchInlineQueryCurrentChatInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenSwitchInlineQueryInlineKeyboardButton(block: (SwitchInlineQueryInlineKeyboardButton) -> T) = asSwitchInlineQueryInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asSwitchInlineQueryInlineKeyboardButton(): SwitchInlineQueryInlineKeyboardButton? = this as? SwitchInlineQueryInlineKeyboardButton @@ -1692,6 +2412,9 @@ inline fun InlineKeyboardButton.asSwitchInlineQueryInlineKeyboardButton(): Switc inline fun InlineKeyboardButton.requireSwitchInlineQueryInlineKeyboardButton(): SwitchInlineQueryInlineKeyboardButton = this as SwitchInlineQueryInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenURLInlineKeyboardButton(block: (URLInlineKeyboardButton) -> T) = asURLInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asURLInlineKeyboardButton(): URLInlineKeyboardButton? = this as? URLInlineKeyboardButton @@ -1699,6 +2422,9 @@ inline fun InlineKeyboardButton.asURLInlineKeyboardButton(): URLInlineKeyboardBu inline fun InlineKeyboardButton.requireURLInlineKeyboardButton(): URLInlineKeyboardButton = this as URLInlineKeyboardButton +@PreviewFeature +inline fun InlineKeyboardButton.whenUnknownInlineKeyboardButton(block: (UnknownInlineKeyboardButton) -> T) = asUnknownInlineKeyboardButton() ?.let(block) + @PreviewFeature inline fun InlineKeyboardButton.asUnknownInlineKeyboardButton(): UnknownInlineKeyboardButton? = this as? UnknownInlineKeyboardButton @@ -1707,78 +2433,117 @@ inline fun InlineKeyboardButton.asUnknownInlineKeyboardButton(): UnknownInlineKe inline fun InlineKeyboardButton.requireUnknownInlineKeyboardButton(): UnknownInlineKeyboardButton = this as UnknownInlineKeyboardButton +@PreviewFeature +inline fun Poll.whenMultipleAnswersPoll(block: (MultipleAnswersPoll) -> T) = asMultipleAnswersPoll() ?.let(block) + @PreviewFeature inline fun Poll.asMultipleAnswersPoll(): MultipleAnswersPoll? = this as? MultipleAnswersPoll @PreviewFeature inline fun Poll.requireMultipleAnswersPoll(): MultipleAnswersPoll = this as MultipleAnswersPoll +@PreviewFeature +inline fun Poll.whenQuizPoll(block: (QuizPoll) -> T) = asQuizPoll() ?.let(block) + @PreviewFeature inline fun Poll.asQuizPoll(): QuizPoll? = this as? QuizPoll @PreviewFeature inline fun Poll.requireQuizPoll(): QuizPoll = this as QuizPoll +@PreviewFeature +inline fun Poll.whenRegularPoll(block: (RegularPoll) -> T) = asRegularPoll() ?.let(block) + @PreviewFeature inline fun Poll.asRegularPoll(): RegularPoll? = this as? RegularPoll @PreviewFeature inline fun Poll.requireRegularPoll(): RegularPoll = this as RegularPoll +@PreviewFeature +inline fun Poll.whenUnknownPollType(block: (UnknownPollType) -> T) = asUnknownPollType() ?.let(block) + @PreviewFeature inline fun Poll.asUnknownPollType(): UnknownPollType? = this as? UnknownPollType @PreviewFeature inline fun Poll.requireUnknownPollType(): UnknownPollType = this as UnknownPollType +@PreviewFeature +inline fun ResendableContent.whenContactContent(block: (ContactContent) -> T) = asContactContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asContactContent(): ContactContent? = this as? ContactContent @PreviewFeature inline fun ResendableContent.requireContactContent(): ContactContent = this as ContactContent +@PreviewFeature +inline fun ResendableContent.whenDiceContent(block: (DiceContent) -> T) = asDiceContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asDiceContent(): DiceContent? = this as? DiceContent @PreviewFeature inline fun ResendableContent.requireDiceContent(): DiceContent = this as DiceContent +@PreviewFeature +inline fun ResendableContent.whenGameContent(block: (GameContent) -> T) = asGameContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asGameContent(): GameContent? = this as? GameContent @PreviewFeature inline fun ResendableContent.requireGameContent(): GameContent = this as GameContent +@PreviewFeature +inline fun ResendableContent.whenLocationContent(block: (LocationContent) -> T) = asLocationContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asLocationContent(): LocationContent? = this as? LocationContent @PreviewFeature inline fun ResendableContent.requireLocationContent(): LocationContent = this as LocationContent +@PreviewFeature +inline fun ResendableContent.whenPollContent(block: (PollContent) -> T) = asPollContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asPollContent(): PollContent? = this as? PollContent @PreviewFeature inline fun ResendableContent.requirePollContent(): PollContent = this as PollContent +@PreviewFeature +inline fun ResendableContent.whenTextContent(block: (TextContent) -> T) = asTextContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asTextContent(): TextContent? = this as? TextContent @PreviewFeature inline fun ResendableContent.requireTextContent(): TextContent = this as TextContent +@PreviewFeature +inline fun ResendableContent.whenVenueContent(block: (VenueContent) -> T) = asVenueContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asVenueContent(): VenueContent? = this as? VenueContent @PreviewFeature inline fun ResendableContent.requireVenueContent(): VenueContent = this as VenueContent +@PreviewFeature +inline fun ResendableContent.whenAudioMediaGroupContent(block: (AudioMediaGroupContent) -> T) = asAudioMediaGroupContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asAudioMediaGroupContent(): AudioMediaGroupContent? = this as? AudioMediaGroupContent @PreviewFeature inline fun ResendableContent.requireAudioMediaGroupContent(): AudioMediaGroupContent = this as AudioMediaGroupContent +@PreviewFeature +inline fun ResendableContent.whenDocumentMediaGroupContent(block: (DocumentMediaGroupContent) -> T) = asDocumentMediaGroupContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asDocumentMediaGroupContent(): DocumentMediaGroupContent? = this as? DocumentMediaGroupContent @@ -1787,6 +2552,9 @@ inline fun ResendableContent.asDocumentMediaGroupContent(): DocumentMediaGroupCo inline fun ResendableContent.requireDocumentMediaGroupContent(): DocumentMediaGroupContent = this as DocumentMediaGroupContent +@PreviewFeature +inline fun ResendableContent.whenMediaCollectionContent(block: (MediaCollectionContent) -> T) = asMediaCollectionContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asMediaCollectionContent(): MediaCollectionContent? = this as? MediaCollectionContent @@ -1795,186 +2563,279 @@ inline fun ResendableContent.asMediaCollectionContent(): MediaCollectionContent< inline fun ResendableContent.requireMediaCollectionContent(): MediaCollectionContent = this as MediaCollectionContent +@PreviewFeature +inline fun ResendableContent.whenMediaContent(block: (MediaContent) -> T) = asMediaContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asMediaContent(): MediaContent? = this as? MediaContent @PreviewFeature inline fun ResendableContent.requireMediaContent(): MediaContent = this as MediaContent +@PreviewFeature +inline fun ResendableContent.whenMediaGroupContent(block: (MediaGroupContent) -> T) = asMediaGroupContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asMediaGroupContent(): MediaGroupContent? = this as? MediaGroupContent @PreviewFeature inline fun ResendableContent.requireMediaGroupContent(): MediaGroupContent = this as MediaGroupContent +@PreviewFeature +inline fun ResendableContent.whenMessageContent(block: (MessageContent) -> T) = asMessageContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asMessageContent(): MessageContent? = this as? MessageContent @PreviewFeature inline fun ResendableContent.requireMessageContent(): MessageContent = this as MessageContent +@PreviewFeature +inline fun ResendableContent.whenVisualMediaGroupContent(block: (VisualMediaGroupContent) -> T) = asVisualMediaGroupContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asVisualMediaGroupContent(): VisualMediaGroupContent? = this as? VisualMediaGroupContent @PreviewFeature inline fun ResendableContent.requireVisualMediaGroupContent(): VisualMediaGroupContent = this as VisualMediaGroupContent +@PreviewFeature +inline fun ResendableContent.whenAnimationContent(block: (AnimationContent) -> T) = asAnimationContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asAnimationContent(): AnimationContent? = this as? AnimationContent @PreviewFeature inline fun ResendableContent.requireAnimationContent(): AnimationContent = this as AnimationContent +@PreviewFeature +inline fun ResendableContent.whenAudioContent(block: (AudioContent) -> T) = asAudioContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asAudioContent(): AudioContent? = this as? AudioContent @PreviewFeature inline fun ResendableContent.requireAudioContent(): AudioContent = this as AudioContent +@PreviewFeature +inline fun ResendableContent.whenDocumentContent(block: (DocumentContent) -> T) = asDocumentContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asDocumentContent(): DocumentContent? = this as? DocumentContent @PreviewFeature inline fun ResendableContent.requireDocumentContent(): DocumentContent = this as DocumentContent +@PreviewFeature +inline fun ResendableContent.whenPhotoContent(block: (PhotoContent) -> T) = asPhotoContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asPhotoContent(): PhotoContent? = this as? PhotoContent @PreviewFeature inline fun ResendableContent.requirePhotoContent(): PhotoContent = this as PhotoContent +@PreviewFeature +inline fun ResendableContent.whenStickerContent(block: (StickerContent) -> T) = asStickerContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asStickerContent(): StickerContent? = this as? StickerContent @PreviewFeature inline fun ResendableContent.requireStickerContent(): StickerContent = this as StickerContent +@PreviewFeature +inline fun ResendableContent.whenVideoContent(block: (VideoContent) -> T) = asVideoContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asVideoContent(): VideoContent? = this as? VideoContent @PreviewFeature inline fun ResendableContent.requireVideoContent(): VideoContent = this as VideoContent +@PreviewFeature +inline fun ResendableContent.whenVideoNoteContent(block: (VideoNoteContent) -> T) = asVideoNoteContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asVideoNoteContent(): VideoNoteContent? = this as? VideoNoteContent @PreviewFeature inline fun ResendableContent.requireVideoNoteContent(): VideoNoteContent = this as VideoNoteContent +@PreviewFeature +inline fun ResendableContent.whenVoiceContent(block: (VoiceContent) -> T) = asVoiceContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asVoiceContent(): VoiceContent? = this as? VoiceContent @PreviewFeature inline fun ResendableContent.requireVoiceContent(): VoiceContent = this as VoiceContent +@PreviewFeature +inline fun ResendableContent.whenInvoiceContent(block: (InvoiceContent) -> T) = asInvoiceContent() ?.let(block) + @PreviewFeature inline fun ResendableContent.asInvoiceContent(): InvoiceContent? = this as? InvoiceContent @PreviewFeature inline fun ResendableContent.requireInvoiceContent(): InvoiceContent = this as InvoiceContent +@PreviewFeature +inline fun TextSource.whenMultilevelTextSource(block: (MultilevelTextSource) -> T) = asMultilevelTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asMultilevelTextSource(): MultilevelTextSource? = this as? MultilevelTextSource @PreviewFeature inline fun TextSource.requireMultilevelTextSource(): MultilevelTextSource = this as MultilevelTextSource +@PreviewFeature +inline fun TextSource.whenBoldTextSource(block: (BoldTextSource) -> T) = asBoldTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asBoldTextSource(): BoldTextSource? = this as? BoldTextSource @PreviewFeature inline fun TextSource.requireBoldTextSource(): BoldTextSource = this as BoldTextSource +@PreviewFeature +inline fun TextSource.whenBotCommandTextSource(block: (BotCommandTextSource) -> T) = asBotCommandTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asBotCommandTextSource(): BotCommandTextSource? = this as? BotCommandTextSource @PreviewFeature inline fun TextSource.requireBotCommandTextSource(): BotCommandTextSource = this as BotCommandTextSource +@PreviewFeature +inline fun TextSource.whenCashTagTextSource(block: (CashTagTextSource) -> T) = asCashTagTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asCashTagTextSource(): CashTagTextSource? = this as? CashTagTextSource @PreviewFeature inline fun TextSource.requireCashTagTextSource(): CashTagTextSource = this as CashTagTextSource +@PreviewFeature +inline fun TextSource.whenCodeTextSource(block: (CodeTextSource) -> T) = asCodeTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asCodeTextSource(): CodeTextSource? = this as? CodeTextSource @PreviewFeature inline fun TextSource.requireCodeTextSource(): CodeTextSource = this as CodeTextSource +@PreviewFeature +inline fun TextSource.whenEMailTextSource(block: (EMailTextSource) -> T) = asEMailTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asEMailTextSource(): EMailTextSource? = this as? EMailTextSource @PreviewFeature inline fun TextSource.requireEMailTextSource(): EMailTextSource = this as EMailTextSource +@PreviewFeature +inline fun TextSource.whenHashTagTextSource(block: (HashTagTextSource) -> T) = asHashTagTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asHashTagTextSource(): HashTagTextSource? = this as? HashTagTextSource @PreviewFeature inline fun TextSource.requireHashTagTextSource(): HashTagTextSource = this as HashTagTextSource +@PreviewFeature +inline fun TextSource.whenItalicTextSource(block: (ItalicTextSource) -> T) = asItalicTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asItalicTextSource(): ItalicTextSource? = this as? ItalicTextSource @PreviewFeature inline fun TextSource.requireItalicTextSource(): ItalicTextSource = this as ItalicTextSource +@PreviewFeature +inline fun TextSource.whenMentionTextSource(block: (MentionTextSource) -> T) = asMentionTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asMentionTextSource(): MentionTextSource? = this as? MentionTextSource @PreviewFeature inline fun TextSource.requireMentionTextSource(): MentionTextSource = this as MentionTextSource +@PreviewFeature +inline fun TextSource.whenPhoneNumberTextSource(block: (PhoneNumberTextSource) -> T) = asPhoneNumberTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asPhoneNumberTextSource(): PhoneNumberTextSource? = this as? PhoneNumberTextSource @PreviewFeature inline fun TextSource.requirePhoneNumberTextSource(): PhoneNumberTextSource = this as PhoneNumberTextSource +@PreviewFeature +inline fun TextSource.whenPreTextSource(block: (PreTextSource) -> T) = asPreTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asPreTextSource(): PreTextSource? = this as? PreTextSource @PreviewFeature inline fun TextSource.requirePreTextSource(): PreTextSource = this as PreTextSource +@PreviewFeature +inline fun TextSource.whenRegularTextSource(block: (RegularTextSource) -> T) = asRegularTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asRegularTextSource(): RegularTextSource? = this as? RegularTextSource @PreviewFeature inline fun TextSource.requireRegularTextSource(): RegularTextSource = this as RegularTextSource +@PreviewFeature +inline fun TextSource.whenStrikethroughTextSource(block: (StrikethroughTextSource) -> T) = asStrikethroughTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asStrikethroughTextSource(): StrikethroughTextSource? = this as? StrikethroughTextSource @PreviewFeature inline fun TextSource.requireStrikethroughTextSource(): StrikethroughTextSource = this as StrikethroughTextSource +@PreviewFeature +inline fun TextSource.whenTextLinkTextSource(block: (TextLinkTextSource) -> T) = asTextLinkTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asTextLinkTextSource(): TextLinkTextSource? = this as? TextLinkTextSource @PreviewFeature inline fun TextSource.requireTextLinkTextSource(): TextLinkTextSource = this as TextLinkTextSource +@PreviewFeature +inline fun TextSource.whenTextMentionTextSource(block: (TextMentionTextSource) -> T) = asTextMentionTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asTextMentionTextSource(): TextMentionTextSource? = this as? TextMentionTextSource @PreviewFeature inline fun TextSource.requireTextMentionTextSource(): TextMentionTextSource = this as TextMentionTextSource +@PreviewFeature +inline fun TextSource.whenURLTextSource(block: (URLTextSource) -> T) = asURLTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asURLTextSource(): URLTextSource? = this as? URLTextSource @PreviewFeature inline fun TextSource.requireURLTextSource(): URLTextSource = this as URLTextSource +@PreviewFeature +inline fun TextSource.whenUnderlineTextSource(block: (UnderlineTextSource) -> T) = asUnderlineTextSource() ?.let(block) + @PreviewFeature inline fun TextSource.asUnderlineTextSource(): UnderlineTextSource? = this as? UnderlineTextSource @PreviewFeature inline fun TextSource.requireUnderlineTextSource(): UnderlineTextSource = this as UnderlineTextSource +@PreviewFeature +inline fun DiceAnimationType.whenBasketballDiceAnimationType(block: (BasketballDiceAnimationType) -> T) = asBasketballDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asBasketballDiceAnimationType(): BasketballDiceAnimationType? = this as? BasketballDiceAnimationType @@ -1983,6 +2844,9 @@ inline fun DiceAnimationType.asBasketballDiceAnimationType(): BasketballDiceAnim inline fun DiceAnimationType.requireBasketballDiceAnimationType(): BasketballDiceAnimationType = this as BasketballDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.whenBowlingDiceAnimationType(block: (BowlingDiceAnimationType) -> T) = asBowlingDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asBowlingDiceAnimationType(): BowlingDiceAnimationType? = this as? BowlingDiceAnimationType @@ -1990,24 +2854,36 @@ inline fun DiceAnimationType.asBowlingDiceAnimationType(): BowlingDiceAnimationT inline fun DiceAnimationType.requireBowlingDiceAnimationType(): BowlingDiceAnimationType = this as BowlingDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.whenCubeDiceAnimationType(block: (CubeDiceAnimationType) -> T) = asCubeDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asCubeDiceAnimationType(): CubeDiceAnimationType? = this as? CubeDiceAnimationType @PreviewFeature inline fun DiceAnimationType.requireCubeDiceAnimationType(): CubeDiceAnimationType = this as CubeDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.whenCustomDiceAnimationType(block: (CustomDiceAnimationType) -> T) = asCustomDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asCustomDiceAnimationType(): CustomDiceAnimationType? = this as? CustomDiceAnimationType @PreviewFeature inline fun DiceAnimationType.requireCustomDiceAnimationType(): CustomDiceAnimationType = this as CustomDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.whenDartsDiceAnimationType(block: (DartsDiceAnimationType) -> T) = asDartsDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asDartsDiceAnimationType(): DartsDiceAnimationType? = this as? DartsDiceAnimationType @PreviewFeature inline fun DiceAnimationType.requireDartsDiceAnimationType(): DartsDiceAnimationType = this as DartsDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.whenFootballDiceAnimationType(block: (FootballDiceAnimationType) -> T) = asFootballDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asFootballDiceAnimationType(): FootballDiceAnimationType? = this as? FootballDiceAnimationType @@ -2016,6 +2892,9 @@ inline fun DiceAnimationType.asFootballDiceAnimationType(): FootballDiceAnimatio inline fun DiceAnimationType.requireFootballDiceAnimationType(): FootballDiceAnimationType = this as FootballDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.whenSlotMachineDiceAnimationType(block: (SlotMachineDiceAnimationType) -> T) = asSlotMachineDiceAnimationType() ?.let(block) + @PreviewFeature inline fun DiceAnimationType.asSlotMachineDiceAnimationType(): SlotMachineDiceAnimationType? = this as? SlotMachineDiceAnimationType @@ -2024,30 +2903,45 @@ inline fun DiceAnimationType.asSlotMachineDiceAnimationType(): SlotMachineDiceAn inline fun DiceAnimationType.requireSlotMachineDiceAnimationType(): SlotMachineDiceAnimationType = this as SlotMachineDiceAnimationType +@PreviewFeature +inline fun ChatEvent.whenChannelChatCreated(block: (ChannelChatCreated) -> T) = asChannelChatCreated() ?.let(block) + @PreviewFeature inline fun ChatEvent.asChannelChatCreated(): ChannelChatCreated? = this as? ChannelChatCreated @PreviewFeature inline fun ChatEvent.requireChannelChatCreated(): ChannelChatCreated = this as ChannelChatCreated +@PreviewFeature +inline fun ChatEvent.whenDeleteChatPhoto(block: (DeleteChatPhoto) -> T) = asDeleteChatPhoto() ?.let(block) + @PreviewFeature inline fun ChatEvent.asDeleteChatPhoto(): DeleteChatPhoto? = this as? DeleteChatPhoto @PreviewFeature inline fun ChatEvent.requireDeleteChatPhoto(): DeleteChatPhoto = this as DeleteChatPhoto +@PreviewFeature +inline fun ChatEvent.whenGroupChatCreated(block: (GroupChatCreated) -> T) = asGroupChatCreated() ?.let(block) + @PreviewFeature inline fun ChatEvent.asGroupChatCreated(): GroupChatCreated? = this as? GroupChatCreated @PreviewFeature inline fun ChatEvent.requireGroupChatCreated(): GroupChatCreated = this as GroupChatCreated +@PreviewFeature +inline fun ChatEvent.whenLeftChatMember(block: (LeftChatMember) -> T) = asLeftChatMember() ?.let(block) + @PreviewFeature inline fun ChatEvent.asLeftChatMember(): LeftChatMember? = this as? LeftChatMember @PreviewFeature inline fun ChatEvent.requireLeftChatMember(): LeftChatMember = this as LeftChatMember +@PreviewFeature +inline fun ChatEvent.whenMessageAutoDeleteTimerChanged(block: (MessageAutoDeleteTimerChanged) -> T) = asMessageAutoDeleteTimerChanged() ?.let(block) + @PreviewFeature inline fun ChatEvent.asMessageAutoDeleteTimerChanged(): MessageAutoDeleteTimerChanged? = this as? MessageAutoDeleteTimerChanged @@ -2056,78 +2950,117 @@ inline fun ChatEvent.asMessageAutoDeleteTimerChanged(): MessageAutoDeleteTimerCh inline fun ChatEvent.requireMessageAutoDeleteTimerChanged(): MessageAutoDeleteTimerChanged = this as MessageAutoDeleteTimerChanged +@PreviewFeature +inline fun ChatEvent.whenNewChatMembers(block: (NewChatMembers) -> T) = asNewChatMembers() ?.let(block) + @PreviewFeature inline fun ChatEvent.asNewChatMembers(): NewChatMembers? = this as? NewChatMembers @PreviewFeature inline fun ChatEvent.requireNewChatMembers(): NewChatMembers = this as NewChatMembers +@PreviewFeature +inline fun ChatEvent.whenNewChatPhoto(block: (NewChatPhoto) -> T) = asNewChatPhoto() ?.let(block) + @PreviewFeature inline fun ChatEvent.asNewChatPhoto(): NewChatPhoto? = this as? NewChatPhoto @PreviewFeature inline fun ChatEvent.requireNewChatPhoto(): NewChatPhoto = this as NewChatPhoto +@PreviewFeature +inline fun ChatEvent.whenNewChatTitle(block: (NewChatTitle) -> T) = asNewChatTitle() ?.let(block) + @PreviewFeature inline fun ChatEvent.asNewChatTitle(): NewChatTitle? = this as? NewChatTitle @PreviewFeature inline fun ChatEvent.requireNewChatTitle(): NewChatTitle = this as NewChatTitle +@PreviewFeature +inline fun ChatEvent.whenPinnedMessage(block: (PinnedMessage) -> T) = asPinnedMessage() ?.let(block) + @PreviewFeature inline fun ChatEvent.asPinnedMessage(): PinnedMessage? = this as? PinnedMessage @PreviewFeature inline fun ChatEvent.requirePinnedMessage(): PinnedMessage = this as PinnedMessage +@PreviewFeature +inline fun ChatEvent.whenProximityAlertTriggered(block: (ProximityAlertTriggered) -> T) = asProximityAlertTriggered() ?.let(block) + @PreviewFeature inline fun ChatEvent.asProximityAlertTriggered(): ProximityAlertTriggered? = this as? ProximityAlertTriggered @PreviewFeature inline fun ChatEvent.requireProximityAlertTriggered(): ProximityAlertTriggered = this as ProximityAlertTriggered +@PreviewFeature +inline fun ChatEvent.whenSupergroupChatCreated(block: (SupergroupChatCreated) -> T) = asSupergroupChatCreated() ?.let(block) + @PreviewFeature inline fun ChatEvent.asSupergroupChatCreated(): SupergroupChatCreated? = this as? SupergroupChatCreated @PreviewFeature inline fun ChatEvent.requireSupergroupChatCreated(): SupergroupChatCreated = this as SupergroupChatCreated +@PreviewFeature +inline fun ChatEvent.whenChannelEvent(block: (ChannelEvent) -> T) = asChannelEvent() ?.let(block) + @PreviewFeature inline fun ChatEvent.asChannelEvent(): ChannelEvent? = this as? ChannelEvent @PreviewFeature inline fun ChatEvent.requireChannelEvent(): ChannelEvent = this as ChannelEvent +@PreviewFeature +inline fun ChatEvent.whenCommonEvent(block: (CommonEvent) -> T) = asCommonEvent() ?.let(block) + @PreviewFeature inline fun ChatEvent.asCommonEvent(): CommonEvent? = this as? CommonEvent @PreviewFeature inline fun ChatEvent.requireCommonEvent(): CommonEvent = this as CommonEvent +@PreviewFeature +inline fun ChatEvent.whenGroupEvent(block: (GroupEvent) -> T) = asGroupEvent() ?.let(block) + @PreviewFeature inline fun ChatEvent.asGroupEvent(): GroupEvent? = this as? GroupEvent @PreviewFeature inline fun ChatEvent.requireGroupEvent(): GroupEvent = this as GroupEvent +@PreviewFeature +inline fun ChatEvent.whenSupergroupEvent(block: (SupergroupEvent) -> T) = asSupergroupEvent() ?.let(block) + @PreviewFeature inline fun ChatEvent.asSupergroupEvent(): SupergroupEvent? = this as? SupergroupEvent @PreviewFeature inline fun ChatEvent.requireSupergroupEvent(): SupergroupEvent = this as SupergroupEvent +@PreviewFeature +inline fun ChatEvent.whenVoiceChatEvent(block: (VoiceChatEvent) -> T) = asVoiceChatEvent() ?.let(block) + @PreviewFeature inline fun ChatEvent.asVoiceChatEvent(): VoiceChatEvent? = this as? VoiceChatEvent @PreviewFeature inline fun ChatEvent.requireVoiceChatEvent(): VoiceChatEvent = this as VoiceChatEvent +@PreviewFeature +inline fun ChatEvent.whenVoiceChatEnded(block: (VoiceChatEnded) -> T) = asVoiceChatEnded() ?.let(block) + @PreviewFeature inline fun ChatEvent.asVoiceChatEnded(): VoiceChatEnded? = this as? VoiceChatEnded @PreviewFeature inline fun ChatEvent.requireVoiceChatEnded(): VoiceChatEnded = this as VoiceChatEnded +@PreviewFeature +inline fun ChatEvent.whenVoiceChatParticipantsInvited(block: (VoiceChatParticipantsInvited) -> T) = asVoiceChatParticipantsInvited() ?.let(block) + @PreviewFeature inline fun ChatEvent.asVoiceChatParticipantsInvited(): VoiceChatParticipantsInvited? = this as? VoiceChatParticipantsInvited @@ -2136,18 +3069,27 @@ inline fun ChatEvent.asVoiceChatParticipantsInvited(): VoiceChatParticipantsInvi inline fun ChatEvent.requireVoiceChatParticipantsInvited(): VoiceChatParticipantsInvited = this as VoiceChatParticipantsInvited +@PreviewFeature +inline fun ChatEvent.whenVoiceChatStarted(block: (VoiceChatStarted) -> T) = asVoiceChatStarted() ?.let(block) + @PreviewFeature inline fun ChatEvent.asVoiceChatStarted(): VoiceChatStarted? = this as? VoiceChatStarted @PreviewFeature inline fun ChatEvent.requireVoiceChatStarted(): VoiceChatStarted = this as VoiceChatStarted +@PreviewFeature +inline fun CommonSendInvoiceData.whenSendInvoice(block: (SendInvoice) -> T) = asSendInvoice() ?.let(block) + @PreviewFeature inline fun CommonSendInvoiceData.asSendInvoice(): SendInvoice? = this as? SendInvoice @PreviewFeature inline fun CommonSendInvoiceData.requireVoiceChatParticipantsInvited(): SendInvoice = this as SendInvoice +@PreviewFeature +inline fun CommonSendInvoiceData.whenInputInvoiceMessageContent(block: (InputInvoiceMessageContent) -> T) = asInputInvoiceMessageContent() ?.let(block) + @PreviewFeature inline fun CommonSendInvoiceData.asInputInvoiceMessageContent(): InputInvoiceMessageContent? = this as? InputInvoiceMessageContent @@ -2155,3 +3097,12 @@ inline fun CommonSendInvoiceData.asInputInvoiceMessageContent(): InputInvoiceMes @PreviewFeature inline fun CommonSendInvoiceData.requireInputInvoiceMessageContent(): InputInvoiceMessageContent = this as InputInvoiceMessageContent + +@PreviewFeature +inline fun Any.whenFromUser(block: (FromUser) -> T) = asFromUser() ?.let(block) + +@PreviewFeature +inline fun Any.asFromUser(): FromUser? = this as? FromUser + +@PreviewFeature +inline fun Any.requireFromUser(): FromUser = this as FromUser 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 153cbe2600..bff841b0ef 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,6 +1,10 @@ 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 import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* @@ -13,7 +17,6 @@ fun Update.sourceChat(): Chat? = when (this) { is MediaGroupUpdate -> when (this) { is SentMediaGroupUpdate -> data.chat is EditMediaGroupUpdate -> data.chat - else -> null } is BaseMessageUpdate -> data.chat is InlineQueryUpdate -> data.from @@ -24,3 +27,6 @@ fun Update.sourceChat(): Chat? = when (this) { is ShippingQueryUpdate -> data.user else -> null } + +@PreviewFeature +fun Update.sourceUser(): User? = data.asFromUser()?.user ?: sourceChat()?.asUser() diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/EntitiesBuilder.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/EntitiesBuilder.kt index c0f09e5d9a..24f7fd1ca7 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/EntitiesBuilder.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/EntitiesBuilder.kt @@ -28,16 +28,34 @@ class EntitiesBuilder internal constructor( */ fun build(): TextSourcesList = entities.toList() - fun add(source: TextSource) { + fun add(source: TextSource): EntitiesBuilder { entitiesList.add(source) + return this + } + + fun addAll(sources: Iterable): EntitiesBuilder { + entitiesList.addAll(sources) + return this } operator fun TextSource.unaryPlus() = add(this) - operator fun TextSourcesList.unaryPlus() = entitiesList.addAll(this) - operator fun invoke(vararg source: TextSource) = entitiesList.addAll(source) + operator fun TextSourcesList.unaryPlus() = addAll(this) + operator fun invoke(vararg source: TextSource) = addAll(source.toList()) - operator fun String.unaryPlus() { + operator fun String.unaryPlus(): EntitiesBuilder { add(dev.inmo.tgbotapi.types.MessageEntity.textsources.regular(this)) + return this@EntitiesBuilder + } + + operator fun plus(text: String) = text.unaryPlus() + operator fun plus(source: TextSource) = add(source) + operator fun plus(sources: Iterable) = addAll(sources) + + operator fun plus(other: EntitiesBuilder) = if (other == this) { + // do nothing; assume user is using something like regular("Hello, ") + bold("world") in buildEntities + this + } else { + addAll(other.entitiesList) } } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt index 8029ee9a8d..2b8bc76fc6 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt @@ -8,10 +8,12 @@ fun ReplyKeyboardMarkup( vararg buttons: KeyboardButton, resizeKeyboard: Boolean? = null, oneTimeKeyboard: Boolean? = null, + inputFieldPlaceholder: String? = null, selective: Boolean? = null ): ReplyKeyboardMarkup = ReplyKeyboardMarkup( flatMatrix { buttons.forEach { +it } }, resizeKeyboard, oneTimeKeyboard, + inputFieldPlaceholder, selective ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index 6cb849335e..e972a61121 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving import dev.inmo.micro_utils.coroutines.* import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.bot.exceptions.GetUpdatesConflict import dev.inmo.tgbotapi.bot.exceptions.RequestException import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier @@ -17,13 +18,11 @@ import io.ktor.client.features.HttpRequestTimeoutException import kotlinx.coroutines.* import kotlinx.coroutines.flow.* -fun TelegramBot.startGettingOfUpdatesByLongPolling( +fun TelegramBot.longPollingFlow( timeoutSeconds: Seconds = 30, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: (ExceptionHandler)? = null, allowedUpdates: List? = null, - updatesReceiver: UpdateReceiver -): Job = scope.launch { +): Flow = channelFlow { var lastUpdateIdentifier: UpdateIdentifier? = null while (isActive) { @@ -33,6 +32,9 @@ fun TelegramBot.startGettingOfUpdatesByLongPolling( if (e is RequestException) { delay(1000L) } + if (e is GetUpdatesConflict && (exceptionsHandler == null || exceptionsHandler == defaultSafelyExceptionHandler)) { + println("Warning!!! Other bot with the same bot token requests updates with getUpdate in parallel") + } } ) { val updates = execute( @@ -43,6 +45,12 @@ fun TelegramBot.startGettingOfUpdatesByLongPolling( ) ).let { originalUpdates -> val converted = originalUpdates.convertWithMediaGroupUpdates() + /** + * Dirty hack for cases when the media group was retrieved not fully: + * + * We are throw out the last media group and will reretrieve it again in the next get updates + * and it will guarantee that it is full + */ /** * Dirty hack for cases when the media group was retrieved not fully: * @@ -56,17 +64,31 @@ fun TelegramBot.startGettingOfUpdatesByLongPolling( } } - safely { + safelyWithResult { for (update in updates) { - updatesReceiver(update) + send(update) lastUpdateIdentifier = update.lastUpdateIdentifier() } + }.onFailure { + cancel(it as? CancellationException ?: return@onFailure) } } } } +fun TelegramBot.startGettingOfUpdatesByLongPolling( + timeoutSeconds: Seconds = 30, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + exceptionsHandler: (ExceptionHandler)? = null, + allowedUpdates: List? = null, + updatesReceiver: UpdateReceiver +): Job = longPollingFlow(timeoutSeconds, exceptionsHandler, allowedUpdates).subscribeSafely( + scope, + exceptionsHandler ?: defaultSafelyExceptionHandler, + updatesReceiver +) + fun TelegramBot.retrieveAccumulatedUpdates( avoidInlineQueries: Boolean = false, avoidCallbackQueries: Boolean = false,