From 45b32fd6f7f65770d67445657bd70a5e518ea345 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Jun 2021 21:20:28 +0600 Subject: [PATCH 01/57] start 0.35.1 --- CHANGELOG.md | 2 + gradle.properties | 2 +- tgbotapi.extensions.fsm/build.gradle | 64 +++++++++++++++++++ .../mpp_publish_template.kpsb | 1 + 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tgbotapi.extensions.fsm/build.gradle create mode 100644 tgbotapi.extensions.fsm/mpp_publish_template.kpsb diff --git a/CHANGELOG.md b/CHANGELOG.md index 15281370fb..2d0739c5cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.35.1 + ## 0.35.0 **ALL PREVIOUS DEPRECATIONS HAVE BEEN REMOVED** diff --git a/gradle.properties b/gradle.properties index 5fe3601c03..95df6f6f73 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.5.6 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.35.0 +library_version=0.35.1 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.extensions.fsm/build.gradle b/tgbotapi.extensions.fsm/build.gradle new file mode 100644 index 0000000000..810af2519b --- /dev/null +++ b/tgbotapi.extensions.fsm/build.gradle @@ -0,0 +1,64 @@ +buildscript { + repositories { + mavenLocal() + jcenter() + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" + } +} + +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" +} + +project.version = "$library_version" +project.group = "$library_group" + +apply from: "publish.gradle" + +repositories { + mavenLocal() + jcenter() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + api project(":tgbotapi.core") + } + } + + commonTest { + dependencies { + implementation kotlin('test-common') + implementation kotlin('test-annotations-common') + } + } + jvmTest { + dependencies { + implementation kotlin('test-junit') + } + } + jsTest { + dependencies { + implementation kotlin('test-junit') + implementation kotlin('test-js') + } + } + } +} diff --git a/tgbotapi.extensions.fsm/mpp_publish_template.kpsb b/tgbotapi.extensions.fsm/mpp_publish_template.kpsb new file mode 100644 index 0000000000..c44ebca2dc --- /dev/null +++ b/tgbotapi.extensions.fsm/mpp_publish_template.kpsb @@ -0,0 +1 @@ +{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Finite State Machine","description":"Library for TelegramBotAPI for working with states and managing it","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}]}} From 55b1d3734d0bd5de1fe9fcf1b7e57ca70cc5741f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Jun 2021 21:51:30 +0600 Subject: [PATCH 02/57] telegramBotWithBehaviour --- CHANGELOG.md | 3 + gradle.properties | 2 +- .../README.md | 6 +- .../behaviour_builder/TelegramBot.kt | 75 +++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/TelegramBot.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d0739c5cb..d5f815e739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.35.1 +* `Behaviour Builder`: + * New extensions `telegramBotWithBehaviour` + ## 0.35.0 **ALL PREVIOUS DEPRECATIONS HAVE BEEN REMOVED** diff --git a/gradle.properties b/gradle.properties index 95df6f6f73..9f1b558a6a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.1.2 uuid_version=0.3.0 ktor_version=1.6.0 -micro_utils_version=0.5.6 +micro_utils_version=0.5.12 javax_activation_version=1.1.1 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/TelegramBot.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/TelegramBot.kt new file mode 100644 index 0000000000..aec72211c6 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/TelegramBot.kt @@ -0,0 +1,75 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +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 = {}, + block: BehaviourContextReceiver +): TelegramBot = telegramBot( + token, + apiUrl, + builder +).apply { + buildBehaviour( + scope ?: CoroutineScope(coroutineContext), + flowsUpdatesFilter, + 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 = {}, + block: BehaviourContextReceiver +): Pair { + return telegramBot( + token, + apiUrl, + builder + ).let { + it to it.buildBehaviour( + scope ?: CoroutineScope(coroutineContext), + block + ) + } +} From 66d37b72eb46265c51ccafd59bfff542a6da29c1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Jun 2021 22:14:45 +0600 Subject: [PATCH 03/57] add when* syntax --- .../tgbotapi/extensions/utils/ClassCasts.kt | 946 +++++++++++++++++- 1 file changed, 944 insertions(+), 2 deletions(-) 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..2054dd2da1 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 @@ -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 From 65fd3ced3653d9282630b59785280f7baf298217 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jun 2021 11:21:02 +0600 Subject: [PATCH 04/57] start replacement of reply methods --- .../tgbotapi/extensions/api/send/Replies.kt | 381 ++++++++++++++++++ .../extensions/api/send/SendContact.kt | 34 -- .../tgbotapi/extensions/api/send/SendDice.kt | 16 - .../extensions/api/send/SendLocation.kt | 28 -- .../extensions/api/send/SendMessage.kt | 35 -- .../tgbotapi/extensions/api/send/SendVenue.kt | 72 ---- .../extensions/api/send/games/SendGame.kt | 24 +- .../api/send/media/SendAnimation.kt | 143 ++++--- .../extensions/api/send/media/SendAudio.kt | 105 +++-- 9 files changed, 548 insertions(+), 290 deletions(-) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt 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..51a5519478 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -0,0 +1,381 @@ +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.sendAnimation +import dev.inmo.tgbotapi.extensions.api.send.media.sendAudio +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.dice.DiceAnimationType +import dev.inmo.tgbotapi.types.files.AnimationFile +import dev.inmo.tgbotapi.types.files.AudioFile +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.venue.Venue + + +// 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) 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..aeaf39f7c9 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 @@ -58,37 +58,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..99f1349625 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 @@ -28,19 +28,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..d54cef6d01 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 @@ -106,31 +106,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..6b0ac23d4b 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 @@ -103,38 +103,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..73674855fb 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 @@ -162,75 +162,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..3b6ba4fa26 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.replyWithGame +import dev.inmo.tgbotapi.extensions.api.send.reply 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..4690da33a3 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.replyWithAnimation +import dev.inmo.tgbotapi.extensions.api.send.reply 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) From 61cf9936fb844cdb7ff42652a479740e7d1e76b6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jun 2021 12:49:47 +0600 Subject: [PATCH 05/57] complete migration of replies --- .../tgbotapi/extensions/api/send/Replies.kt | 388 +++++++++++++++++- .../extensions/api/send/media/SendDocument.kt | 102 +++-- .../api/send/media/SendMediaGroup.kt | 31 +- .../extensions/api/send/media/SendPhoto.kt | 94 +++-- .../extensions/api/send/media/SendSticker.kt | 21 +- .../extensions/api/send/media/SendVideo.kt | 102 +++-- .../api/send/media/SendVideoNote.kt | 21 +- .../extensions/api/send/media/SendVoice.kt | 96 +++-- .../api/send/payments/SendInvoice.kt | 8 +- .../extensions/api/send/polls/SendPoll.kt | 37 +- 10 files changed, 736 insertions(+), 164 deletions(-) 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 index 51a5519478..b4fbfee26d 100644 --- 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 @@ -2,20 +2,28 @@ 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.sendAnimation -import dev.inmo.tgbotapi.extensions.api.send.media.sendAudio +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.AnimationFile -import dev.inmo.tgbotapi.types.files.AudioFile +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 @@ -379,3 +387,375 @@ suspend inline fun TelegramBot.reply( 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.reply( + to: Message, + media: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendPlaylist(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) + +suspend inline fun TelegramBot.reply( + to: Message, + media: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) + +suspend inline fun TelegramBot.reply( + 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/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..55c6d54a25 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,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.replyWithMediaGroup import dev.inmo.tgbotapi.requests.send.media.* import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.* @@ -124,35 +126,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("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithPlaylist( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendPlaylist(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = reply(to, media, disableNotification, allowSendingWithoutReply) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithDocumentsGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = reply(to, media, disableNotification, allowSendingWithoutReply) +@Deprecated( + "Replaced", + ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") +) suspend inline fun TelegramBot.replyWithVisualMediaGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) +) = reply(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) From 1e181bc04233c6a76a0c7315e2b828b2731f61c4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jun 2021 12:54:50 +0600 Subject: [PATCH 06/57] fixes --- .../inmo/tgbotapi/extensions/api/send/Replies.kt | 6 +++--- .../extensions/api/send/media/SendMediaGroup.kt | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) 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 index b4fbfee26d..fb0e8e0ad0 100644 --- 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 @@ -446,21 +446,21 @@ suspend inline fun TelegramBot.replyWithMediaGroup( allowSendingWithoutReply: Boolean? = null ) = sendMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) -suspend inline fun TelegramBot.reply( +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.reply( +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.reply( +suspend inline fun TelegramBot.replyWithGallery( to: Message, media: List, disableNotification: Boolean = false, 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 55c6d54a25..970f647a67 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,7 +1,9 @@ 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.replyWithPlaylist +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.requests.send.media.* import dev.inmo.tgbotapi.types.ChatIdentifier @@ -141,36 +143,36 @@ suspend inline fun TelegramBot.replyWithMediaGroup( @Deprecated( "Replaced", - ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") + ReplaceWith("replyWithPlaylist", "dev.inmo.tgbotapi.extensions.api.send.replyWithPlaylist") ) suspend inline fun TelegramBot.replyWithPlaylist( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = reply(to, media, disableNotification, allowSendingWithoutReply) +) = replyWithPlaylist(to, media, disableNotification, allowSendingWithoutReply) @Deprecated( "Replaced", - ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") + ReplaceWith("replyWithDocuments", "dev.inmo.tgbotapi.extensions.api.send.replyWithDocuments") ) suspend inline fun TelegramBot.replyWithDocumentsGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = reply(to, media, disableNotification, allowSendingWithoutReply) +) = replyWithDocuments(to, media, disableNotification, allowSendingWithoutReply) @Deprecated( "Replaced", - ReplaceWith("reply", "dev.inmo.tgbotapi.extensions.api.send.reply") + ReplaceWith("replyWithGallery", "dev.inmo.tgbotapi.extensions.api.send.replyWithGallery") ) suspend inline fun TelegramBot.replyWithVisualMediaGroup( to: Message, media: List, disableNotification: Boolean = false, allowSendingWithoutReply: Boolean? = null -) = reply(to, media, disableNotification, allowSendingWithoutReply) +) = replyWithGallery(to, media, disableNotification, allowSendingWithoutReply) @Deprecated( "Replaced", From e10d47b7e4d2ea53907c066c45f1bb7f420ee12b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jun 2021 12:56:15 +0600 Subject: [PATCH 07/57] fill changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f815e739..21ad11bf93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * `Behaviour Builder`: * New extensions `telegramBotWithBehaviour` +* `API`: + * All `reply` and subsequent extension have been replaced in send package ## 0.35.0 From e39dd2d086ed3d244277e090b606c1bcef7b3cf7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jun 2021 12:56:40 +0600 Subject: [PATCH 08/57] remove redundant fsm module --- tgbotapi.extensions.fsm/build.gradle | 64 ------------------- .../mpp_publish_template.kpsb | 1 - 2 files changed, 65 deletions(-) delete mode 100644 tgbotapi.extensions.fsm/build.gradle delete mode 100644 tgbotapi.extensions.fsm/mpp_publish_template.kpsb diff --git a/tgbotapi.extensions.fsm/build.gradle b/tgbotapi.extensions.fsm/build.gradle deleted file mode 100644 index 810af2519b..0000000000 --- a/tgbotapi.extensions.fsm/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -buildscript { - repositories { - mavenLocal() - jcenter() - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - } -} - -plugins { - id "org.jetbrains.kotlin.multiplatform" - id "org.jetbrains.kotlin.plugin.serialization" -} - -project.version = "$library_version" -project.group = "$library_group" - -apply from: "publish.gradle" - -repositories { - mavenLocal() - jcenter() - mavenCentral() - maven { url "https://kotlin.bintray.com/kotlinx" } -} - -kotlin { - jvm() - js(IR) { - browser() - nodejs() - } - - sourceSets { - commonMain { - dependencies { - implementation kotlin('stdlib') - api project(":tgbotapi.core") - } - } - - commonTest { - dependencies { - implementation kotlin('test-common') - implementation kotlin('test-annotations-common') - } - } - jvmTest { - dependencies { - implementation kotlin('test-junit') - } - } - jsTest { - dependencies { - implementation kotlin('test-junit') - implementation kotlin('test-js') - } - } - } -} diff --git a/tgbotapi.extensions.fsm/mpp_publish_template.kpsb b/tgbotapi.extensions.fsm/mpp_publish_template.kpsb deleted file mode 100644 index c44ebca2dc..0000000000 --- a/tgbotapi.extensions.fsm/mpp_publish_template.kpsb +++ /dev/null @@ -1 +0,0 @@ -{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Finite State Machine","description":"Library for TelegramBotAPI for working with states and managing it","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}]}} From 85270dd12dacf5c5eed433c92fd519ec2dfb59d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jun 2021 14:34:58 +0600 Subject: [PATCH 09/57] update micro_utils --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21ad11bf93..3d56ffbc2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.35.1 +* `Common`: + * `Version`: + * `MicroUtils`: `0.5.6` -> `0.5.13` * `Behaviour Builder`: * New extensions `telegramBotWithBehaviour` * `API`: diff --git a/gradle.properties b/gradle.properties index 9f1b558a6a..1bb0509fe7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.1.2 uuid_version=0.3.0 ktor_version=1.6.0 -micro_utils_version=0.5.12 +micro_utils_version=0.5.13 javax_activation_version=1.1.1 From bf28a8b0a65522929c9dd2fda06711bc84ed5582 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 25 Jun 2021 12:45:20 +0600 Subject: [PATCH 10/57] add performInParallel for behaviour builder --- CHANGELOG.md | 2 + .../CallbackQueryTriggers.kt | 56 +++++++----- .../ChatMemberUpdatedTriggers.kt | 35 +++++--- .../triggers_handling/CommandHandling.kt | 11 ++- .../triggers_handling/ContentTriggers.kt | 90 ++++++++++++------- .../triggers_handling/EventTriggers.kt | 83 +++++++++++------ .../triggers_handling/InlineQueryTriggers.kt | 36 +++++--- .../triggers_handling/MediaGroupTriggers.kt | 46 ++++++---- .../triggers_handling/PassportTriggers.kt | 27 +++--- .../behaviour_builder/utils/WrapWithLaunch.kt | 21 +++++ 10 files changed, 271 insertions(+), 136 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d56ffbc2d..37789223d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `MicroUtils`: `0.5.6` -> `0.5.13` * `Behaviour Builder`: * New extensions `telegramBotWithBehaviour` + * All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter + `performInParallel`, by default `true`) * `API`: * All `reply` and subsequent extension have been replaced in send package 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..5da55b1abb 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 @@ -4,13 +4,17 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.CallbackQuery.* +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch internal suspend inline fun BehaviourContext.onCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (T) -> Boolean)? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asCallbackQueryUpdate() ?.data ?.let { query -> @@ -20,63 +24,75 @@ internal suspend inline fun BehaviourContext.onCallb null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerQuery -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerQuery) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { triggerQuery -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerQuery) + } } -} +) suspend fun BehaviourContext.onDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (DataCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (GameShortNameCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdDataCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdGameShortNameCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onMessageCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onMessageDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageDataCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageGameShortNameCallbackQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onUnknownCallbackQueryType( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (UnknownCallbackQueryType) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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..bb9d7bb9e1 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -3,59 +3,72 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.ChatMemberUpdated import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + performInParallel: Boolean = true, 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 -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerChatMemberUpdated) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { triggerChatMemberUpdated -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerChatMemberUpdated) + } } -} +) suspend fun BehaviourContext.onChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, + performInParallel, scenarioReceiver ) suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, + performInParallel, scenarioReceiver ) suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, + performInParallel, 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..14fa5ac397 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 @@ -12,6 +12,7 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> ): Job = onText( includeFilterByChatInBehaviourSubContext, @@ -27,6 +28,7 @@ suspend fun BehaviourContext.command( commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) } && (additionalFilter ?.invoke(message) != false) }, + performInParallel, scenarioReceiver ) suspend fun BehaviourContext.command( @@ -34,21 +36,24 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( command: String, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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..5f078c986e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile @@ -22,6 +23,7 @@ internal suspend inline fun BehaviourContext.onCont includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { if (includeMediaGroups) { @@ -44,128 +46,152 @@ internal suspend inline fun BehaviourContext.onCont null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) + } } -} +) suspend fun BehaviourContext.onContentMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onDice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onGame( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onLocation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onPoll( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onText( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVenue( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onAudioMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onDocumentMediaGroupContent( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: (suspend (CommonMessage>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onMedia( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onAnimation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onAudio( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onDocument( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onSticker( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVideo( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVideoNote( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onInvoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, 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..8d2317218c 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -4,6 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -15,6 +16,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage internal suspend inline fun BehaviourContext.onEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.let { message -> @@ -25,115 +27,138 @@ internal suspend inline fun BehaviourContext.onEvent( null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) + } } -} +) suspend fun BehaviourContext.onChannelEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatStartedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEndedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onCommonEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onGroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onSupergroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onChannelChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onDeleteChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onGroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onLeftChatMember( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onNewChatMembers( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onNewChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onNewChatTitle( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onPinnedMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onProximityAlertTriggered( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onSupergroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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..2cb5ec3ca9 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.InlineQueries.query.* @@ -10,6 +11,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.* internal suspend inline fun BehaviourContext.onInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (T) -> Boolean)? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asInlineQueryUpdate() ?.data ?.let { query -> @@ -19,36 +21,42 @@ internal suspend inline fun BehaviourContext.onInlineQ null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerQuery -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerQuery) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { triggerQuery -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerQuery) + } } -} +) suspend fun BehaviourContext.onAnyInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onBaseInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (BaseInlineQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onLocationInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (LocationInlineQuery) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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..b52da85431 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat @@ -18,6 +19,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = flowsUpdatesFilter.expectFlow(bot) { update -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> @@ -27,51 +29,61 @@ internal suspend inline fun BehaviourContext.bui null } } ?: emptyList() -}.subscribeSafelyWithoutExceptions(scope) { mediaGroup -> - val mediaGroupChat = mediaGroup.chat!! - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(mediaGroup) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { mediaGroup -> + val mediaGroupChat = mediaGroup.chat!! + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(mediaGroup) + } } -} +) suspend fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVisualMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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..3aaf4f7f0a 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -3,15 +3,17 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.optionallyWrapWithLaunch 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, + performInParallel: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asMessageUpdate() ?.data ?.asPassportMessage() ?.let { message -> @@ -21,24 +23,29 @@ suspend inline fun BehaviourContext.onPas null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) +}.subscribeSafelyWithoutExceptions( + scope, + optionallyWrapWithLaunch(performInParallel) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) + } } -} +) suspend fun BehaviourContext.onPassportMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + performInParallel: Boolean = true, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onPassportMessageWith( includeFilterByChatInBehaviourSubContext, additionalFilter, + performInParallel, scenarioReceiver ) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt new file mode 100644 index 0000000000..3a2f27ba20 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils + +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions +import kotlinx.coroutines.CoroutineScope + +internal fun CoroutineScope.wrapWithLaunch( + block: suspend (T) -> Unit +): suspend (T) -> Unit = { + launchSafelyWithoutExceptions { + block(it) + } +} + +internal fun CoroutineScope.optionallyWrapWithLaunch( + wrap: Boolean, + block: suspend (T) -> Unit +): suspend (T) -> Unit = if (wrap) { + wrapWithLaunch(block) +} else { + block +} From b60fab48716add1d0dab50152de54070d5852e97 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 01:27:28 +0600 Subject: [PATCH 11/57] BotCommandScope --- CHANGELOG.md | 3 + .../types/commands/BotCommandScope.kt | 120 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 37789223d9..67f14cd528 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ `performInParallel`, by default `true`) * `API`: * All `reply` and subsequent extension have been replaced in send package + +* `Bot API 5.3`: + * Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children ## 0.35.0 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..dcb606e335 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt @@ -0,0 +1,120 @@ +package dev.inmo.tgbotapi.types.commands + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RiskFeature +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) { + "default" -> BotCommandScopeDefault + "all_private_chats" -> BotCommandScopeAllPrivateChats + "all_group_chats" -> BotCommandScopeAllGroupChats + "all_chat_administrators" -> BotCommandScopeAllChatAdministrators + "chat_administrators" -> BotCommandScopeChatAdministrators( + chatId ?: error("chat_administrators type must have $chatIdField field, but have no") + ) + "chat_member" -> 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 = "chat_administrators" +} + +@Serializable +data class BotCommandScopeChatMember( + override val chatId: ChatIdentifier, + val userId: UserId +) : ChatBotCommandScope { + @Required + override val type: String = "chat_member" +} + + +object BotCommandScopeSerializer : KSerializer { + + @RiskFeature + 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) + ) + } + +} From 7f69052deab47c6d0617918496ac435c82be107a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 01:42:35 +0600 Subject: [PATCH 12/57] *MyCommands actualization --- CHANGELOG.md | 1 + .../inmo/tgbotapi/requests/bot/BotCommand.kt | 9 ++++++++ .../tgbotapi/requests/bot/DeleteMyCommands.kt | 22 +++++++++++++++++++ .../tgbotapi/requests/bot/GetMyCommands.kt | 13 +++++++++-- .../tgbotapi/requests/bot/SetMyCommands.kt | 10 +++++++-- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../extensions/api/bot/DeleteMyCommands.kt | 11 ++++++++++ .../extensions/api/bot/GetMyCommands.kt | 7 +++++- .../extensions/api/bot/SetMyCommands.kt | 14 ++++++++---- 9 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 67f14cd528..0ae7235f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * `Bot API 5.3`: * Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children + * New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands` ## 0.35.0 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..bc6b7cac0b --- /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.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.commands.BotCommandScope + +sealed interface MyCommandsRequest : SimpleRequest { + val scope: BotCommandScope + val languageCode: String? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt new file mode 100644 index 0000000000..867b5fc978 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt @@ -0,0 +1,22 @@ +package dev.inmo.tgbotapi.requests.bot + +import dev.inmo.tgbotapi.types.commands.* +import dev.inmo.tgbotapi.types.languageCodeField +import dev.inmo.tgbotapi.types.scopeField +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class DeleteMyCommands( + @SerialName(scopeField) + @Serializable(BotCommandScopeSerializer::class) + override val scope: BotCommandScope = BotCommandScopeDefault, + @SerialName(languageCodeField) + override val languageCode: String? = null +) : MyCommandsRequest { + override fun method(): String = "deleteMyCommands" + override val requestSerializer: SerializationStrategy = serializer() + override val resultDeserializer: DeserializationStrategy = Boolean.serializer() + + 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..10ade23af5 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,26 @@ package dev.inmo.tgbotapi.requests.bot import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest -import dev.inmo.tgbotapi.types.BotCommand +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) + override val languageCode: String? = null +) : MyCommandsRequest> { override fun method(): String = "getMyCommands" override val resultDeserializer: DeserializationStrategy> get() = getMyCommandsSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() + + 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..efb4d62657 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 @@ -2,14 +2,20 @@ package dev.inmo.tgbotapi.requests.bot import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest 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) + override val languageCode: String? = null +) : MyCommandsRequest { override fun method(): String = "setMyCommands" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() 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..8d9f796715 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 @@ -234,6 +234,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" 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..31abad88f5 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.extensions.api.bot + +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: String? = null +) = execute(DeleteMyCommands(scope, languageCode)) 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..07a0c6a3ac 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 @@ -2,5 +2,10 @@ package dev.inmo.tgbotapi.extensions.api.bot 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: String? = null +) = execute(GetMyCommands(scope, languageCode)) 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..d0d8b0a8cc 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 @@ -3,11 +3,17 @@ package dev.inmo.tgbotapi.extensions.api.bot 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: String? = null +) = execute(SetMyCommands(commands, scope, languageCode)) suspend fun TelegramBot.setMyCommands( - vararg commands: BotCommand -) = setMyCommands(commands.toList()) + vararg commands: BotCommand, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = setMyCommands(commands.toList(), scope, languageCode) From 656bb687392596f950d5e3a823bb40d4dc601f99 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 01:48:41 +0600 Subject: [PATCH 13/57] add support of input_field_placeholder --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 4 ++++ .../dev/inmo/tgbotapi/types/buttons/ReplyForce.kt | 12 +++++++++++- .../tgbotapi/types/buttons/ReplyKeyboardMarkup.kt | 12 +++++++++++- .../utils/types/buttons/ReplyKeyboardMarkup.kt | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) 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 8d9f796715..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 @@ -366,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/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.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 ) From 69b64e9908917cfc7f8d1764264853c4bcb32d87 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 01:58:20 +0600 Subject: [PATCH 14/57] and more... :) --- CHANGELOG.md | 1 + ...tMembersCount.kt => GetChatMemberCount.kt} | 7 +- .../{KickChatMember.kt => BanChatMember.kt} | 7 +- .../api/chat/get/GetChatMemberCount.kt | 24 +++++++ .../api/chat/get/GetChatMembersCount.kt | 14 ---- .../api/chat/members/BanChatMember.kt | 66 +++++++++++++++++++ .../api/chat/members/KickChatMember.kt | 34 ---------- 7 files changed, 101 insertions(+), 52 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/{GetChatMembersCount.kt => GetChatMemberCount.kt} (71%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/{KickChatMember.kt => BanChatMember.kt} (78%) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMemberCount.kt delete mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/get/GetChatMembersCount.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/BanChatMember.kt delete mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/KickChatMember.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ae7235f5f..dbc3f3c982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * `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 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.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) From 871291412690ce36f3d1fc15385be9de7c951c62 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 01:59:25 +0600 Subject: [PATCH 15/57] update actuality of core --- CHANGELOG.md | 1 - tgbotapi.core/README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbc3f3c982..a8df89c884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ `performInParallel`, by default `true`) * `API`: * All `reply` and subsequent extension have been replaced in send package - * `Bot API 5.3`: * Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children * New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands` 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? From 449f2727c47873da960540415ae9e284d499ff01 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 02:04:08 +0600 Subject: [PATCH 16/57] update dependencies --- CHANGELOG.md | 3 ++- gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8df89c884..74a667ead1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ * `Common`: * `Version`: - * `MicroUtils`: `0.5.6` -> `0.5.13` + * `Kotlin`: `1.5.10` -> `1.5.20` + * `MicroUtils`: `0.5.6` -> `0.5.14` * `Behaviour Builder`: * New extensions `telegramBotWithBehaviour` * All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter diff --git a/gradle.properties b/gradle.properties index 1bb0509fe7..3e0f971c34 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,14 +5,14 @@ kotlin.js.generate.externals=true kotlin.incremental=true kotlin.incremental.js=true -kotlin_version=1.5.10 +kotlin_version=1.5.20 kotlin_coroutines_version=1.5.0 kotlin_serialisation_runtime_version=1.2.1 klock_version=2.1.2 uuid_version=0.3.0 ktor_version=1.6.0 -micro_utils_version=0.5.13 +micro_utils_version=0.5.14 javax_activation_version=1.1.1 From b9de0025171533a8ff649765b2dcbaca4d88c59a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 12:15:52 +0600 Subject: [PATCH 17/57] rewrite to use subscribeSafelyWithoutExceptionsAsync in triggers of behaviour builder --- .../CallbackQueryTriggers.kt | 72 ++++++----- .../ChatMemberUpdatedTriggers.kt | 47 ++++--- .../triggers_handling/CommandHandling.kt | 18 +-- .../triggers_handling/ContentTriggers.kt | 117 +++++++++--------- .../triggers_handling/EventTriggers.kt | 109 ++++++++-------- .../triggers_handling/InlineQueryTriggers.kt | 45 +++---- .../triggers_handling/MediaGroupTriggers.kt | 59 ++++----- .../triggers_handling/PassportTriggers.kt | 33 ++--- .../CallbackQueryMarkerFactories.kt | 17 +++ .../ChatMemberUpdatedMarkerFactories.kt | 7 ++ .../InlineQueryMarkerFactories.kt | 11 ++ .../utils/marker_factories/MarkerFactory.kt | 5 + .../MediaGroupMarkerFactories.kt | 8 ++ .../MessageMarkerFactories.kt | 7 ++ 14 files changed, 307 insertions(+), 248 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/CallbackQueryMarkerFactories.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/ChatMemberUpdatedMarkerFactories.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/InlineQueryMarkerFactories.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt 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 5da55b1abb..e6e4c3b565 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,20 +1,18 @@ 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.optionallyWrapWithLaunch +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.* -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch internal suspend inline fun BehaviourContext.onCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (T) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asCallbackQueryUpdate() ?.data ?.let { query -> @@ -24,75 +22,75 @@ internal suspend inline fun BehaviourContext.onCallb null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerQuery -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerQuery) - } + markerFactory::invoke +) { triggerQuery -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerQuery) } -) +} suspend fun BehaviourContext.onDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (DataCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (GameShortNameCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdDataCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineMessageIdGameShortNameCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageDataCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (MessageGameShortNameCallbackQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onUnknownCallbackQueryType( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (UnknownCallbackQueryType) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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 bb9d7bb9e1..eff524264b 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,74 +1,73 @@ 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.optionallyWrapWithLaunch +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 import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + 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( +}.subscribeSafelySkippingExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerChatMemberUpdated -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerChatMemberUpdated) - } + markerFactory::invoke +) { triggerChatMemberUpdated -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerChatMemberUpdated) } -) +} suspend fun BehaviourContext.onChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + 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 14fa5ac397..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,7 +14,7 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ): Job = onText( includeFilterByChatInBehaviourSubContext, @@ -28,7 +30,7 @@ suspend fun BehaviourContext.command( commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) } && (additionalFilter ?.invoke(message) != false) }, - performInParallel, + markerFactory, scenarioReceiver ) suspend fun BehaviourContext.command( @@ -36,24 +38,24 @@ suspend fun BehaviourContext.command( requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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 5f078c986e..6dcab2502f 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,10 +2,11 @@ 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.optionallyWrapWithLaunch +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 @@ -23,7 +24,7 @@ internal suspend inline fun BehaviourContext.onCont includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, noinline additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { if (includeMediaGroups) { @@ -46,152 +47,152 @@ internal suspend inline fun BehaviourContext.onCont null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) - } + markerFactory::invoke +) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) } -) +} suspend fun BehaviourContext.onContentMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGame( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLocation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPoll( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onText( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVenue( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAudioMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentMediaGroupContent( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: (suspend (CommonMessage>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMedia( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAnimation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onAudio( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocument( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSticker( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideo( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoNote( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInvoice( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, performInParallel, 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 8d2317218c..9e44c0d449 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,10 +1,11 @@ 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.optionallyWrapWithLaunch +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 @@ -16,7 +17,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage internal suspend inline fun BehaviourContext.onEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.let { message -> @@ -27,138 +28,138 @@ internal suspend inline fun BehaviourContext.onEvent( null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) - } + markerFactory::invoke +) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) } -) +} suspend fun BehaviourContext.onChannelEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatStartedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEndedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onCommonEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChannelChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDeleteChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLeftChatMember( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatMembers( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatTitle( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPinnedMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onProximityAlertTriggered( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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 2cb5ec3ca9..79db28675a 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,9 +1,10 @@ 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.optionallyWrapWithLaunch +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.* @@ -11,7 +12,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.* internal suspend inline fun BehaviourContext.onInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (T) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asInlineQueryUpdate() ?.data ?.let { query -> @@ -21,42 +22,42 @@ internal suspend inline fun BehaviourContext.onInlineQ null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerQuery -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } - } else { - null - }, - stopOnCompletion = false - ) { - scenarioReceiver(triggerQuery) - } + markerFactory::invoke +) { triggerQuery -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } + } else { + null + }, + stopOnCompletion = false + ) { + scenarioReceiver(triggerQuery) } -) +} suspend fun BehaviourContext.onAnyInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (InlineQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onBaseInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (BaseInlineQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLocationInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (LocationInlineQuery) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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 b52da85431..dfc1e53bac 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,10 +2,11 @@ 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.optionallyWrapWithLaunch +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 @@ -19,7 +20,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = flowsUpdatesFilter.expectFlow(bot) { update -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> @@ -29,61 +30,61 @@ internal suspend inline fun BehaviourContext.bui null } } ?: emptyList() -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { mediaGroup -> - val mediaGroupChat = mediaGroup.chat!! - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(mediaGroup) - } + markerFactory::invoke +) { mediaGroup -> + val mediaGroupChat = mediaGroup.chat!! + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(mediaGroup) } -) +} suspend fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, performInParallel, 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 3aaf4f7f0a..30e35a4196 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,9 +1,10 @@ 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.optionallyWrapWithLaunch +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 @@ -13,7 +14,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportEle internal suspend inline fun BehaviourContext.onPassportMessageWith( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { it.asMessageUpdate() ?.data ?.asPassportMessage() ?.let { message -> @@ -23,29 +24,29 @@ internal suspend inline fun BehaviourCont null } }.let(::listOfNotNull) -}.subscribeSafelyWithoutExceptions( +}.subscribeSafelyWithoutExceptionsAsync( scope, - optionallyWrapWithLaunch(performInParallel) { triggerMessage -> - doInSubContextWithUpdatesFilter( - updatesFilter = if (includeFilterByChatInBehaviourSubContext) { - { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null, - stopOnCompletion = false - ) { - scenarioReceiver(triggerMessage) - } + markerFactory::invoke +) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null, + stopOnCompletion = false + ) { + scenarioReceiver(triggerMessage) } -) +} suspend fun BehaviourContext.onPassportMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, - performInParallel: Boolean = true, + markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onPassportMessageWith( includeFilterByChatInBehaviourSubContext, additionalFilter, - performInParallel, + markerFactory, scenarioReceiver ) 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..1b98924dc9 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MessageMarkerFactories.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories + +import dev.inmo.tgbotapi.types.message.abstracts.Message + +object ByChatMessageMarkerFactory : MarkerFactory { + override suspend fun invoke(data: Message) = data.chat +} From ee8cc2aa46a776cf83be440ed9db5e340aededf5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 17:05:34 +0600 Subject: [PATCH 18/57] defaultExceptionsHandler in behaviour builder --- CHANGELOG.md | 1 + .../behaviour_builder/BehaviourBuilders.kt | 14 +++++++++++++- .../behaviour_builder/BehaviourContext.kt | 4 ++-- .../extensions/behaviour_builder/TelegramBot.kt | 5 +++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a667ead1..a5313b3487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * New extensions `telegramBotWithBehaviour` * All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter `performInParallel`, by default `true`) + * All behaviour builder extensions got new parameter `defaultExceptionsHandler` * `API`: * All `reply` and subsequent extension have been replaced in send package * `Bot API 5.3`: 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..e4473c5431 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,14 @@ 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 /** * Use this method in case you wish to make some additional actions with [flowUpdatesFilter]. @@ -20,11 +23,18 @@ import kotlinx.coroutines.CoroutineScope suspend fun TelegramBot.buildBehaviour( scope: CoroutineScope, flowUpdatesFilter: FlowsUpdatesFilter, + defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) { BehaviourContext( this, - scope, + scope.let { + if (defaultExceptionsHandler == null) { + it + } else { + it + ContextSafelyExceptionHandler(defaultExceptionsHandler) + } + }, flowUpdatesFilter ).block() } @@ -40,11 +50,13 @@ suspend fun TelegramBot.buildBehaviour( @PreviewFeature suspend fun TelegramBot.buildBehaviour( scope: CoroutineScope, + 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..6ee5b6821e 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 @@ -60,12 +60,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 index aec72211c6..eb62df598a 100644 --- 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 @@ -1,5 +1,6 @@ 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 @@ -28,6 +29,7 @@ suspend fun telegramBotWithBehaviour( scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, + defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ): TelegramBot = telegramBot( token, @@ -37,6 +39,7 @@ suspend fun telegramBotWithBehaviour( buildBehaviour( scope ?: CoroutineScope(coroutineContext), flowsUpdatesFilter, + defaultExceptionsHandler, block ) } @@ -60,6 +63,7 @@ suspend fun telegramBotWithBehaviour( scope: CoroutineScope? = null, apiUrl: String = telegramBotAPIDefaultUrl, builder: KtorRequestsExecutorBuilder.() -> Unit = {}, + defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ): Pair { return telegramBot( @@ -69,6 +73,7 @@ suspend fun telegramBotWithBehaviour( ).let { it to it.buildBehaviour( scope ?: CoroutineScope(coroutineContext), + defaultExceptionsHandler, block ) } From 47fe048b10b987e1081b781b74414bcaf8c48ecf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 27 Jun 2021 19:28:21 +0600 Subject: [PATCH 19/57] refactor and fixes in ContentTriggers --- .../triggers_handling/ContentTriggers.kt | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) 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 6dcab2502f..81dfbbb894 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 @@ -15,6 +15,7 @@ import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate import dev.inmo.tgbotapi.utils.PreviewFeature typealias CommonMessageFilter = (suspend (CommonMessage) -> Boolean) @@ -27,26 +28,21 @@ internal suspend inline fun BehaviourContext.onCont 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) + } }.subscribeSafelyWithoutExceptionsAsync( scope, markerFactory::invoke @@ -66,9 +62,10 @@ 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, markerFactory, scenarioReceiver) +) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, From 77dff639f03d1348072b48eb5921d45417b8c5d8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Jun 2021 01:00:20 +0600 Subject: [PATCH 20/57] updates --- CHANGELOG.md | 2 +- gradle.properties | 2 +- .../updateshandlers/FlowsUpdatesFilter.kt | 8 +++-- .../behaviour_builder/BehaviourContext.kt | 20 +++++++------ .../behaviour_builder/expectations/Base.kt | 9 +++--- .../utils/formatting/EntitiesBuilder.kt | 26 +++++++++++++--- .../utils/updates/retrieving/LongPolling.kt | 30 +++++++++++++++---- 7 files changed, 69 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5313b3487..542d7294ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * `Common`: * `Version`: * `Kotlin`: `1.5.10` -> `1.5.20` - * `MicroUtils`: `0.5.6` -> `0.5.14` + * `MicroUtils`: `0.5.6` -> `0.5.15` * `Behaviour Builder`: * New extensions `telegramBotWithBehaviour` * All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter diff --git a/gradle.properties b/gradle.properties index 3e0f971c34..ce77349519 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.1.2 uuid_version=0.3.0 ktor_version=1.6.0 -micro_utils_version=0.5.14 +micro_utils_version=0.5.15 javax_activation_version=1.1.1 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..35e565c1d1 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 { @@ -43,9 +44,10 @@ fun FlowsUpdatesFilter( @Suppress("EXPERIMENTAL_API_USAGE", "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.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 6ee5b6821e..5180e25055 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 @@ -37,15 +36,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() } } /** 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.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..1898f62f3f 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 + this + } else { + addAll(other.entitiesList) } } 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..1584f94c9d 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 @@ -17,13 +17,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) { @@ -43,6 +41,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 +60,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, From 21c5d42dc2e668587a23d01a79ba17b0857d82d1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Jun 2021 10:29:45 +0600 Subject: [PATCH 21/57] BehaviourContext now is interface --- CHANGELOG.md | 2 + .../behaviour_builder/BehaviourContext.kt | 50 ++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 542d7294ba..35d813280c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ * All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter `performInParallel`, by default `true`) * 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)` * `API`: * All `reply` and subsequent extension have been replaced in send package * `Bot API 5.3`: 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 5180e25055..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 @@ -14,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 From fd6e4b05226956caea05a20e164d21e47e066c48 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Jun 2021 11:10:09 +0600 Subject: [PATCH 22/57] final refactor, fixes and upfilling of changelog --- CHANGELOG.md | 18 +++++++++++---- .../types/commands/BotCommandScope.kt | 23 +++++++++++-------- .../updateshandlers/FlowsUpdatesFilter.kt | 2 +- .../behaviour_builder/utils/WrapWithLaunch.kt | 21 ----------------- .../MessageMarkerFactories.kt | 10 +++++++- .../utils/formatting/EntitiesBuilder.kt | 2 +- 6 files changed, 39 insertions(+), 37 deletions(-) delete mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 35d813280c..2042b9ccb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,15 +6,25 @@ * `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) * `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 triggers (`on*` extensions) have been modified to work in parallel by default (new parameter - `performInParallel`, by default `true`) * 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)` + factory `BehaviourContext(TelegramBot, CoroutineScope, FlowsUpdatesFilter)` + * Extension `buildBehaviour` (and all related extensions/functions) for opportunity to pass + `defaultExceptionsHandler` + * Trigger `onContentMessage` now may include media groups * `API`: - * All `reply` and subsequent extension have been replaced in send package + * 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` 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 index dcb606e335..fe2f02f8e1 100644 --- 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 @@ -18,14 +18,14 @@ private class SurrogateBotCommandScope( val userId: UserId? = null ) { fun asBotCommandScope() = when (type) { - "default" -> BotCommandScopeDefault - "all_private_chats" -> BotCommandScopeAllPrivateChats - "all_group_chats" -> BotCommandScopeAllGroupChats - "all_chat_administrators" -> BotCommandScopeAllChatAdministrators - "chat_administrators" -> BotCommandScopeChatAdministrators( + 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") ) - "chat_member" -> BotCommandScopeChatMember( + 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") ) @@ -89,7 +89,10 @@ data class BotCommandScopeChatAdministrators( override val chatId: ChatIdentifier ) : ChatBotCommandScope { @Required - override val type: String = "chat_administrators" + override val type: String = BotCommandScopeChatAdministrators.type + companion object { + const val type = "chat_administrators" + } } @Serializable @@ -98,13 +101,15 @@ data class BotCommandScopeChatMember( val userId: UserId ) : ChatBotCommandScope { @Required - override val type: String = "chat_member" + override val type: String = BotCommandScopeChatMember.type + companion object { + const val type = "chat_member" + } } object BotCommandScopeSerializer : KSerializer { - @RiskFeature override val descriptor: SerialDescriptor = SurrogateBotCommandScope.serializer().descriptor override fun deserialize( 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 35e565c1d1..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 @@ -42,7 +42,7 @@ fun FlowsUpdatesFilter( broadcastChannelsSize: Int = 100 ) = DefaultFlowsUpdatesFilter(broadcastChannelsSize) -@Suppress("EXPERIMENTAL_API_USAGE", "unused") +@Suppress("unused") class DefaultFlowsUpdatesFilter( broadcastChannelsSize: Int = 100, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt deleted file mode 100644 index 3a2f27ba20..0000000000 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/WrapWithLaunch.kt +++ /dev/null @@ -1,21 +0,0 @@ -package dev.inmo.tgbotapi.extensions.behaviour_builder.utils - -import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions -import kotlinx.coroutines.CoroutineScope - -internal fun CoroutineScope.wrapWithLaunch( - block: suspend (T) -> Unit -): suspend (T) -> Unit = { - launchSafelyWithoutExceptions { - block(it) - } -} - -internal fun CoroutineScope.optionallyWrapWithLaunch( - wrap: Boolean, - block: suspend (T) -> Unit -): suspend (T) -> Unit = if (wrap) { - wrapWithLaunch(block) -} else { - block -} 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 index 1b98924dc9..1beb82c59d 100644 --- 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 @@ -1,7 +1,15 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories -import dev.inmo.tgbotapi.types.message.abstracts.Message +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.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 1898f62f3f..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 @@ -52,7 +52,7 @@ class EntitiesBuilder internal constructor( operator fun plus(sources: Iterable) = addAll(sources) operator fun plus(other: EntitiesBuilder) = if (other == this) { - // do nothing; assume user + // do nothing; assume user is using something like regular("Hello, ") + bold("world") in buildEntities this } else { addAll(other.entitiesList) From 0c1017901fef155e9cbebe868210ae999f395ce4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 28 Jun 2021 11:12:51 +0600 Subject: [PATCH 23/57] optimize imports --- .../kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFile.kt | 3 ++- .../kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt | 1 - .../kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt | 1 - .../kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt | 3 ++- .../types/ChatMember/abstracts/AdministratorChatMember.kt | 3 ++- .../dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt | 3 ++- .../InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt | 3 ++- .../InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt | 3 ++- .../InlineQueryResult/InlineQueryResultVoiceImpl.kt | 3 ++- .../serializers/InlineQueryResultSerializer.kt | 3 ++- .../types/InlineQueries/InputMessageContentSerializer.kt | 3 ++- .../dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt | 3 ++- .../dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt | 2 +- .../dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt | 3 ++- .../dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt | 3 ++- .../dev/inmo/tgbotapi/types/InputMedia/InputMediaSerializer.kt | 3 ++- .../dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt | 3 ++- .../types/InputMedia/MediaGroupMemberInputMediaSerializer.kt | 3 ++- .../commonMain/kotlin/dev/inmo/tgbotapi/types/TelegramDate.kt | 1 - .../src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt | 1 - .../kotlin/dev/inmo/tgbotapi/types/actions/BotAction.kt | 3 ++- .../dev/inmo/tgbotapi/types/buttons/KeyboardButtonPollType.kt | 3 ++- .../inmo/tgbotapi/types/buttons/KeyboardMarkupSerializer.kt | 3 ++- .../kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt | 1 - .../kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt | 3 ++- .../types/passport/encrypted/EncryptedElementSerializer.kt | 1 - .../src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MimeType.kt | 3 ++- .../tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt | 3 ++- .../dev/inmo/tgbotapi/extensions/api/send/SendContact.kt | 1 - .../kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt | 1 - .../dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt | 1 - .../dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt | 1 - .../kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt | 1 - .../dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt | 2 +- .../inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt | 2 +- .../inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt | 2 +- .../behaviour_builder/triggers_handling/ContentTriggers.kt | 1 - .../kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt | 1 - 38 files changed, 46 insertions(+), 38 deletions(-) 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/GetMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt index 10ade23af5..31b8fe194a 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,6 +1,5 @@ package dev.inmo.tgbotapi.requests.bot -import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.commands.* import kotlinx.serialization.* 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 efb4d62657..4f926840e2 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,6 +1,5 @@ package dev.inmo.tgbotapi.requests.bot -import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.commands.* import kotlinx.serialization.* 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/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt index 6d242e32f9..7d30eb4cab 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.types.MessageEntity.textsources.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..1449e23d16 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.types.MessageEntity.textsources.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..0030d3b9ff 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.types.MessageEntity.textsources.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/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/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index aa9ec48be9..1460caa5de 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.types.MessageEntity.textsources.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..d5f639dc02 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,6 +1,6 @@ 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.* 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..ed8ac8b06a 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.types.MessageEntity.textsources.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..4930a2df7d 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.types.MessageEntity.textsources.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..505f848d59 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.types.MessageEntity.textsources.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/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..bcc2ea2875 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 @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.types 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 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/commands/BotCommandScope.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt index fe2f02f8e1..9fa0b953d2 100644 --- 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 @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.commands import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.utils.RiskFeature import kotlinx.serialization.* import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder 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/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/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/internal/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index 6160f91965..7b167bb6f3 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,6 +1,7 @@ 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 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 aeaf39f7c9..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, 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 99f1349625..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, 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 d54cef6d01..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, 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 6b0ac23d4b..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, 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 73674855fb..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( 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 3b6ba4fa26..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,8 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.games import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.extensions.api.send.replyWithGame 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 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 4690da33a3..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,8 +1,8 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation 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 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 970f647a67..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,10 +1,10 @@ package dev.inmo.tgbotapi.extensions.api.send.media import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.extensions.api.send.replyWithPlaylist 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.* 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 81dfbbb894..bbdd4d6b65 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 @@ -15,7 +15,6 @@ import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate import dev.inmo.tgbotapi.utils.PreviewFeature typealias CommonMessageFilter = (suspend (CommonMessage) -> Boolean) 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 2054dd2da1..a425707050 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 @@ -19,7 +19,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.* From 919b1590e39d52189be8a76bb10f88e57340a853 Mon Sep 17 00:00:00 2001 From: vasya Date: Mon, 28 Jun 2021 20:30:12 +0300 Subject: [PATCH 24/57] add Update#sourceUser method --- .../utils/extensions/UpdateChatRetriever.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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..8d2a4d5f17 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,8 @@ package dev.inmo.tgbotapi.extensions.utils.extensions +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.* @@ -24,3 +26,20 @@ fun Update.sourceChat(): Chat? = when (this) { is ShippingQueryUpdate -> data.user else -> null } + +@PreviewFeature +fun Update.sourceUser(): User? = when (this) { + is MediaGroupUpdate -> when (this) { + is SentMediaGroupUpdate -> data.chat?.asUser() + is EditMediaGroupUpdate -> data.chat.asUser() + else -> null + } + is BaseMessageUpdate -> data.chat.asUser() + is InlineQueryUpdate -> data.from + is ChosenInlineResultUpdate -> data.user + is CallbackQueryUpdate -> data.user + is PreCheckoutQueryUpdate -> data.user + is PollAnswerUpdate -> data.user + is ShippingQueryUpdate -> data.user + else -> null +} From c5e089a45db6b6b6c1dcf1ecafcb04c40111c20e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 29 Jun 2021 00:01:40 +0600 Subject: [PATCH 25/57] make*String extensions --- CHANGELOG.md | 1 + .../tgbotapi/CommonAbstracts/TextSource.kt | 4 +-- .../edit/caption/EditChatMessageCaption.kt | 2 +- .../edit/caption/EditInlineMessageCaption.kt | 2 +- .../requests/edit/text/EditChatMessageText.kt | 2 +- .../edit/text/EditInlineMessageText.kt | 2 +- .../tgbotapi/requests/send/CopyMessage.kt | 2 +- .../tgbotapi/requests/send/SendMessage.kt | 2 +- .../requests/send/media/SendAnimation.kt | 2 +- .../tgbotapi/requests/send/media/SendAudio.kt | 2 +- .../requests/send/media/SendDocument.kt | 2 +- .../tgbotapi/requests/send/media/SendPhoto.kt | 2 +- .../tgbotapi/requests/send/media/SendVideo.kt | 2 +- .../tgbotapi/requests/send/media/SendVoice.kt | 2 +- .../tgbotapi/requests/send/polls/SendPoll.kt | 2 +- .../InlineQueryResultAudioCachedImpl.kt | 2 +- .../InlineQueryResultAudioImpl.kt | 2 +- .../InlineQueryResultDocumentCachedImpl.kt | 2 +- .../InlineQueryResultDocumentImpl.kt | 2 +- .../InlineQueryResultGifCachedImpl.kt | 2 +- .../InlineQueryResultGifImpl.kt | 2 +- .../InlineQueryResultMpeg4GifCachedImpl.kt | 2 +- .../InlineQueryResultMpeg4GifImpl.kt | 2 +- .../InlineQueryResultPhotoCachedImpl.kt | 2 +- .../InlineQueryResultPhotoImpl.kt | 2 +- .../InlineQueryResultVideoCachedImpl.kt | 2 +- .../InlineQueryResultVideoImpl.kt | 2 +- .../InlineQueryResultVoiceCachedImpl.kt | 2 +- .../InlineQueryResultVoiceImpl.kt | 2 +- .../InputTextMessageContent.kt | 2 +- .../types/InputMedia/InputMediaAnimation.kt | 2 +- .../types/InputMedia/InputMediaAudio.kt | 2 +- .../types/InputMedia/InputMediaDocument.kt | 2 +- .../types/InputMedia/InputMediaPhoto.kt | 2 +- .../types/InputMedia/InputMediaVideo.kt | 2 +- .../textsources/BoldTextSource.kt | 1 + .../textsources/CashTagTextSource.kt | 1 + .../textsources/EMailTextSource.kt | 1 + .../textsources/HashTagTextSource.kt | 1 + .../textsources/ItalicTextSource.kt | 1 + .../textsources/MentionTextSource.kt | 1 + .../textsources/PhoneNumberTextSource.kt | 1 + .../textsources/StrikethroughTextSource.kt | 1 + .../textsources/TextMentionTextSource.kt | 1 + .../MessageEntity/textsources/TextSource.kt | 4 ++- .../textsources/UnderlineTextSource.kt | 1 + .../utils/extensions/TextSourcesList.kt | 30 ++++++++++++++++ .../MultilevelTextSourceFormatting.kt | 35 +++++++------------ .../inmo/tgbotapi/types/TextSourcesTests.kt | 2 +- 49 files changed, 93 insertions(+), 59 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/TextSourcesList.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2042b9ccb8..c753c1c4e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * `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 * `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) 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/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/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 7d30eb4cab..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 @@ -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/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 1449e23d16..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 @@ -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/InlineQueryResultVoiceImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt index 0030d3b9ff..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 @@ -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/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/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index 1460caa5de..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 @@ -6,7 +6,7 @@ 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 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 d5f639dc02..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 @@ -6,7 +6,7 @@ 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 ed8ac8b06a..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 @@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList -import dev.inmo.tgbotapi.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.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 4930a2df7d..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 @@ -5,7 +5,7 @@ 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.PhotoSize 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 505f848d59..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 @@ -5,7 +5,7 @@ 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 kotlinx.serialization.* 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/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 7b167bb6f3..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 @@ -4,33 +4,24 @@ 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( @@ -51,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) @@ -70,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 From 732e2a3906572ae383f32c089d65019160962bbe Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 29 Jun 2021 00:06:07 +0600 Subject: [PATCH 26/57] serializable subclasses of MessageContent --- CHANGELOG.md | 1 + .../commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt | 2 ++ .../dev/inmo/tgbotapi/types/message/content/ContactContent.kt | 4 +++- .../dev/inmo/tgbotapi/types/message/content/DiceContent.kt | 2 ++ .../dev/inmo/tgbotapi/types/message/content/GameContent.kt | 4 +++- .../dev/inmo/tgbotapi/types/message/content/PollContent.kt | 2 ++ .../dev/inmo/tgbotapi/types/message/content/TextContent.kt | 2 ++ .../dev/inmo/tgbotapi/types/message/content/VenueContent.kt | 4 +++- .../tgbotapi/types/message/content/media/AnimationContent.kt | 2 ++ .../inmo/tgbotapi/types/message/content/media/AudioContent.kt | 2 ++ .../tgbotapi/types/message/content/media/DocumentContent.kt | 2 ++ .../inmo/tgbotapi/types/message/content/media/PhotoContent.kt | 2 ++ .../tgbotapi/types/message/content/media/StickerContent.kt | 2 ++ .../inmo/tgbotapi/types/message/content/media/VideoContent.kt | 2 ++ .../tgbotapi/types/message/content/media/VideoNoteContent.kt | 2 ++ .../inmo/tgbotapi/types/message/content/media/VoiceContent.kt | 2 ++ .../inmo/tgbotapi/types/message/payments/InvoiceContent.kt | 2 ++ 17 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c753c1c4e2..56e18fb320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * `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 * `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) 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/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 { From 30c138029e14207d38e06446ea51ae28845877de Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 00:37:53 +0300 Subject: [PATCH 27/57] add asFromUserMessage calls to Update#sourceUser --- .../extensions/utils/extensions/UpdateChatRetriever.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 8d2a4d5f17..aaffa37c64 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,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.utils.extensions +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 @@ -30,11 +31,11 @@ fun Update.sourceChat(): Chat? = when (this) { @PreviewFeature fun Update.sourceUser(): User? = when (this) { is MediaGroupUpdate -> when (this) { - is SentMediaGroupUpdate -> data.chat?.asUser() - is EditMediaGroupUpdate -> data.chat.asUser() + is SentMediaGroupUpdate -> data.chat?.asUser() ?: data.first().asFromUserMessage()?.user + is EditMediaGroupUpdate -> data.chat.asUser() ?: data.asFromUserMessage()?.user else -> null } - is BaseMessageUpdate -> data.chat.asUser() + is BaseMessageUpdate -> data.chat.asUser() ?: data.asFromUserMessage()?.user is InlineQueryUpdate -> data.from is ChosenInlineResultUpdate -> data.user is CallbackQueryUpdate -> data.user From 022e6f623ab88853949f1b48bc81bd2f70232eaf Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 00:57:32 +0300 Subject: [PATCH 28/57] add FromUser interface to objects where field `user` is present --- .../dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt | 5 +++-- .../ChosenInlineResult/RawChosenInlineResult.kt | 5 +++-- .../types/InlineQueries/abstracts/ChosenInlineResult.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt | 5 +++-- .../inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt | 5 +++-- .../dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt | 5 +++-- .../kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt | 5 +++-- .../kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt | 5 +++-- 9 files changed, 25 insertions(+), 18 deletions(-) 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/ChatMemberUpdated.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt index 856e113ac0..e4ce566f49 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember import dev.inmo.tgbotapi.types.chat.abstracts.Chat import kotlinx.serialization.SerialName @@ -10,7 +11,7 @@ data class ChatMemberUpdated( @SerialName(chatField) val chat: Chat, @SerialName(fromField) - val user: User, + override val user: User, @SerialName(dateField) val date: TelegramDate, @SerialName(oldChatMemberField) @@ -19,4 +20,4 @@ data class ChatMemberUpdated( val newChatMemberState: ChatMember, @SerialName(inviteLinkField) val inviteLink: ChatInviteLink? = null -) +) : FromUser 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..3eb1c7c78e 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,5 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult import dev.inmo.tgbotapi.types.location.StaticLocation @@ -11,14 +12,14 @@ internal data class RawChosenInlineResult( @SerialName(resultIdField) val resultId: InlineQueryIdentifier, //chosen temporary, can be changed @SerialName(fromField) - val user: User, + override val user: User, @SerialName(queryField) val query: String, @SerialName(locationField) val location: StaticLocation? = null, @SerialName(inlineMessageIdField) val inlineMessageId: InlineMessageIdentifier? = null -) { +) : FromUser { val asChosenInlineResult: ChosenInlineResult by lazy { location ?.let { LocationChosenInlineResult(resultId, user, location, inlineMessageId, query) 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..51a55025a9 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,10 @@ package dev.inmo.tgbotapi.types.InlineQueries.abstracts +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* -interface ChosenInlineResult { +interface ChosenInlineResult : FromUser { val resultId: InlineQueryIdentifier //chosen temporary, can be changed - val user: User val inlineMessageId: InlineMessageIdentifier? val query: String } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt index 0d05b81f0e..c02ad3b67e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.games +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 GameHighScore ( @SerialName(positionField) val position: Long, @SerialName(userField) - val user: User, + override val user: User, @SerialName(scoreField) val score: Long -) \ No newline at end of file +) : FromUser \ No newline at end of file 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..859a87cdd1 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 @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.message.ChatEvents +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent data class LeftChatMember( - val user: User -): CommonEvent + override val user: User +): CommonEvent, FromUser 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 From 12a35da4b67c5962ea8ad67ba24a23cbf5836bb6 Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 03:34:27 +0300 Subject: [PATCH 29/57] remove unnecessary FromUser usages --- .../kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt | 5 ++--- .../kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt | 7 +++---- .../tgbotapi/types/message/ChatEvents/LeftChatMember.kt | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt index e4ce566f49..856e113ac0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types -import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember import dev.inmo.tgbotapi.types.chat.abstracts.Chat import kotlinx.serialization.SerialName @@ -11,7 +10,7 @@ data class ChatMemberUpdated( @SerialName(chatField) val chat: Chat, @SerialName(fromField) - override val user: User, + val user: User, @SerialName(dateField) val date: TelegramDate, @SerialName(oldChatMemberField) @@ -20,4 +19,4 @@ data class ChatMemberUpdated( val newChatMemberState: ChatMember, @SerialName(inviteLinkField) val inviteLink: ChatInviteLink? = null -) : FromUser +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt index c02ad3b67e..f4a71608d0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt @@ -1,16 +1,15 @@ package dev.inmo.tgbotapi.types.games -import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class GameHighScore ( +data class GameHighScore( @SerialName(positionField) val position: Long, @SerialName(userField) - override val user: User, + val user: User, @SerialName(scoreField) val score: Long -) : FromUser \ No newline at end of file +) \ No newline at end of file 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 859a87cdd1..e9ba9470ae 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,5 +5,5 @@ import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent data class LeftChatMember( - override val user: User -): CommonEvent, FromUser + val user: User +) : CommonEvent From 067e36adc6470b8ac9dcb39d4bfe23790e390ea4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 29 Jun 2021 11:53:36 +0600 Subject: [PATCH 30/57] ChosenInlineResult now is sealed --- CHANGELOG.md | 1 + .../ChosenInlineResult/BaseChosenInlineResult.kt | 1 - .../ChosenInlineResult/ChosenInlineResult.kt | 10 ++++++++++ .../ChosenInlineResult/LocationChosenInlineResult.kt | 1 - .../InlineQueries/abstracts/ChosenInlineResult.kt | 10 +++------- 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 56e18fb320..02b37a8993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * 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 * `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) 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..2594985fb1 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,7 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult data class BaseChosenInlineResult( override val resultId: InlineQueryIdentifier, 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..fee3f1df51 --- /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.types.* + +sealed interface ChosenInlineResult { + val resultId: InlineQueryIdentifier //chosen temporary, can be changed + val user: User + 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..3d1e201983 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,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 data class LocationChosenInlineResult( 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 From b2915857d7454510c34be9b72b7dd496d992731c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 29 Jun 2021 11:55:46 +0600 Subject: [PATCH 31/57] remove usages of deprecated ChosenInlineResult --- .../InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt | 3 +-- .../inmo/tgbotapi/types/update/ChosenInlineResultUpdate.kt | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) 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..0bdfedfe6c 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 @@ -20,7 +19,7 @@ internal data class RawChosenInlineResult( val inlineMessageId: InlineMessageIdentifier? = null ) { val asChosenInlineResult: ChosenInlineResult by lazy { - location ?.let { + location?.let { LocationChosenInlineResult(resultId, user, location, inlineMessageId, query) } ?: BaseChosenInlineResult(resultId, user, inlineMessageId, query) } 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 From 38826a5e7ef2a5d8e3ca1177d653b69373264ca6 Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 21:06:46 +0300 Subject: [PATCH 32/57] remove FromUser interface from RawChosenInlineResult --- .../ChosenInlineResult/RawChosenInlineResult.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 3eb1c7c78e..4db078be40 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,6 +1,5 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult -import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult import dev.inmo.tgbotapi.types.location.StaticLocation @@ -12,14 +11,14 @@ internal data class RawChosenInlineResult( @SerialName(resultIdField) val resultId: InlineQueryIdentifier, //chosen temporary, can be changed @SerialName(fromField) - override val user: User, + val user: User, @SerialName(queryField) val query: String, @SerialName(locationField) val location: StaticLocation? = null, @SerialName(inlineMessageIdField) val inlineMessageId: InlineMessageIdentifier? = null -) : FromUser { +) { val asChosenInlineResult: ChosenInlineResult by lazy { location ?.let { LocationChosenInlineResult(resultId, user, location, inlineMessageId, query) From c00adb0784184bd022f625248d4c078e09754f43 Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 21:07:18 +0300 Subject: [PATCH 33/57] remove redundant import in LeftChatMember.kt --- .../dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt | 1 - 1 file changed, 1 deletion(-) 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 e9ba9470ae..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 @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent From 45ea103c9ad10800ea1570f3e9c7a12a2fc9d892 Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 21:08:41 +0300 Subject: [PATCH 34/57] bring back strange InsanusMokrassar's space :) --- .../kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt index f4a71608d0..0d05b81f0e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt @@ -5,7 +5,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class GameHighScore( +data class GameHighScore ( @SerialName(positionField) val position: Long, @SerialName(userField) From cffcf2277e63e5041b70bc87120798b1eeeefd4b Mon Sep 17 00:00:00 2001 From: Vasya Date: Tue, 29 Jun 2021 21:35:46 +0300 Subject: [PATCH 35/57] add asFromUser, whenFromUser, requireFromUser to ClassCasts.kt --- .../dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 a425707050..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.* @@ -3096,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 From 560179a5742b01bca8d3475068226769e92c39e0 Mon Sep 17 00:00:00 2001 From: Vasya Date: Tue, 29 Jun 2021 21:47:08 +0300 Subject: [PATCH 36/57] simplify Update#sourceUser --- .../utils/extensions/UpdateChatRetriever.kt | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) 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 aaffa37c64..49493e952f 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,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.utils.extensions +import dev.inmo.tgbotapi.extensions.utils.asFromUser import dev.inmo.tgbotapi.extensions.utils.asFromUserMessage import dev.inmo.tgbotapi.extensions.utils.asUser import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat @@ -29,18 +30,4 @@ fun Update.sourceChat(): Chat? = when (this) { } @PreviewFeature -fun Update.sourceUser(): User? = when (this) { - is MediaGroupUpdate -> when (this) { - is SentMediaGroupUpdate -> data.chat?.asUser() ?: data.first().asFromUserMessage()?.user - is EditMediaGroupUpdate -> data.chat.asUser() ?: data.asFromUserMessage()?.user - else -> null - } - is BaseMessageUpdate -> data.chat.asUser() ?: data.asFromUserMessage()?.user - is InlineQueryUpdate -> data.from - is ChosenInlineResultUpdate -> data.user - is CallbackQueryUpdate -> data.user - is PreCheckoutQueryUpdate -> data.user - is PollAnswerUpdate -> data.user - is ShippingQueryUpdate -> data.user - else -> null -} +fun Update.sourceUser(): User? = data.asFromUser()?.user ?: sourceChat()?.asUser() From 65801f510486e185c9ee4755b0d5d9a96119a993 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Jun 2021 10:40:23 +0600 Subject: [PATCH 37/57] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b37a8993..c5d6b4862a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ * New extensions `TextSourcesList#make*String` for all parse modes * All `MessageContent` subclasses now serializable * `ChosenInlineResult` was replaced and modified to be sealed + * 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 * `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) From 6ba9a31fb98d5b1f6923ee5f4f5fe46da63eb610 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Jun 2021 11:12:09 +0600 Subject: [PATCH 38/57] seal of MediaGroupUpdates --- CHANGELOG.md | 2 ++ .../types/update/MediaGroupUpdates/MediaGroupUpdate.kt | 6 +++--- .../extensions/utils/extensions/UpdateChatRetriever.kt | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d6b4862a..1555b1efa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ * 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 * `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) 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.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 49493e952f..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 @@ -17,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 From 4f920abb61ea89e7ba3cd52abb174033785fe9cd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Jun 2021 11:26:31 +0600 Subject: [PATCH 39/57] upfixes --- CHANGELOG.md | 1 + .../ChosenInlineResult/BaseChosenInlineResult.kt | 4 ++++ .../InlineQueries/ChosenInlineResult/ChosenInlineResult.kt | 4 ++-- .../ChosenInlineResult/LocationChosenInlineResult.kt | 4 ++++ .../InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1555b1efa0..db9552b996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * 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 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 2594985fb1..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,9 +1,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* +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 index fee3f1df51..2f2b594a7b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/ChosenInlineResult.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* -sealed interface ChosenInlineResult { +sealed interface ChosenInlineResult : FromUser { val resultId: InlineQueryIdentifier //chosen temporary, can be changed - val user: User 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 3d1e201983..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 @@ -2,9 +2,13 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* 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 0bdfedfe6c..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 @@ -19,7 +19,7 @@ internal data class RawChosenInlineResult( val inlineMessageId: InlineMessageIdentifier? = null ) { val asChosenInlineResult: ChosenInlineResult by lazy { - location?.let { + location ?.let { LocationChosenInlineResult(resultId, user, location, inlineMessageId, query) } ?: BaseChosenInlineResult(resultId, user, inlineMessageId, query) } From a241c91adff7c863838970d1e9ae58748539462a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Jun 2021 11:45:56 +0600 Subject: [PATCH 40/57] waitContentMessage with includeMediaGroups --- CHANGELOG.md | 2 +- .../extensions/behaviour_builder/expectations/WaitContent.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db9552b996..9015597905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ factory `BehaviourContext(TelegramBot, CoroutineScope, FlowsUpdatesFilter)` * Extension `buildBehaviour` (and all related extensions/functions) for opportunity to pass `defaultExceptionsHandler` - * Trigger `onContentMessage` now may include media groups + * Trigger `onContentMessage` and waiter `waitContentMessage` now may include media groups * `API`: * All `reply` and subsequent extensions have been replaced in send package * `Utils`: 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 }, From 75cebf5aa3325ab2acaa57059e5c00c02018ebb4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Jun 2021 13:57:20 +0600 Subject: [PATCH 41/57] add GetUpdatesConflict --- CHANGELOG.md | 1 + .../dev/inmo/tgbotapi/bot/exceptions/RequestException.kt | 9 +++++++++ .../extensions/utils/updates/retrieving/LongPolling.kt | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9015597905..27dd9d8a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * 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) 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..038411dc74 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 @@ -24,6 +24,12 @@ fun newRequestException( plainAnswer, message, cause + ), + description.contains("Conflict: terminated by other getUpdates request") -> GetUpdatesConflict( + response, + plainAnswer, + message, + cause ) else -> null } @@ -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.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 1584f94c9d..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 @@ -31,6 +32,9 @@ fun TelegramBot.longPollingFlow( 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( From 7ec4fc460a66217444e01f0ff4336eb263a1f55d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Jun 2021 14:01:59 +0600 Subject: [PATCH 42/57] fix build --- .../kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 038411dc74..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 @@ -24,7 +24,7 @@ fun newRequestException( plainAnswer, message, cause - ), + ) description.contains("Conflict: terminated by other getUpdates request") -> GetUpdatesConflict( response, plainAnswer, From 0b92edc05ead7b7a5a151f5c71e212d3edbeecbd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Jul 2021 23:41:48 +0600 Subject: [PATCH 43/57] Update gradle-wrapper.properties --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From f89380393910c5a9670f74227e83f00dfdd367b8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Jul 2021 11:18:54 +0600 Subject: [PATCH 44/57] start 0.35.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ce77349519..2a2be81e18 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.5.15 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.35.1 +library_version=0.35.2 github_release_plugin_version=2.2.12 From 93eebe37ce384a27107fff27b3d82b20142123e1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Jul 2021 11:20:33 +0600 Subject: [PATCH 45/57] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27dd9d8a82..60f307165f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.35.2 + ## 0.35.1 * `Common`: From 3c75d6a2c72d0d013b4064517e78c9790c001cd4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Jul 2021 11:23:33 +0600 Subject: [PATCH 46/57] Update dependencies --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2a2be81e18..f531036ea8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,10 +7,10 @@ kotlin.incremental.js=true kotlin_version=1.5.20 kotlin_coroutines_version=1.5.0 -kotlin_serialisation_runtime_version=1.2.1 -klock_version=2.1.2 +kotlin_serialisation_runtime_version=1.2.2 +klock_version=2.2.0 uuid_version=0.3.0 -ktor_version=1.6.0 +ktor_version=1.6.1 micro_utils_version=0.5.15 From 0bce5221018354aedde1b7fbeec58a3e3b1ab065 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 10 Jul 2021 00:03:20 +0600 Subject: [PATCH 47/57] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f531036ea8..a86e45866f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.incremental=true kotlin.incremental.js=true kotlin_version=1.5.20 -kotlin_coroutines_version=1.5.0 +kotlin_coroutines_version=1.5.1 kotlin_serialisation_runtime_version=1.2.2 klock_version=2.2.0 uuid_version=0.3.0 From 42bf896f7a76da9fd3758886a5bdefeaf53abd19 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 10 Jul 2021 00:42:04 +0600 Subject: [PATCH 48/57] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a86e45866f..fea8e082fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.2.0 uuid_version=0.3.0 ktor_version=1.6.1 -micro_utils_version=0.5.15 +micro_utils_version=0.5.16 javax_activation_version=1.1.1 From a303700b56d9fd8127ef465dbcbf302252bd06b3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 15 Jul 2021 23:00:08 +0600 Subject: [PATCH 49/57] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index fea8e082fc..4db1b4bebc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.js.generate.externals=true kotlin.incremental=true kotlin.incremental.js=true -kotlin_version=1.5.20 +kotlin_version=1.5.21 kotlin_coroutines_version=1.5.1 kotlin_serialisation_runtime_version=1.2.2 klock_version=2.2.0 From 0ad2d9afc40dc6aaa5a0d753e8c0b17a4180d537 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 17 Jul 2021 13:40:05 +0600 Subject: [PATCH 50/57] Fill changelog with versions updates --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60f307165f..f394ec363a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## 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`: From 399793243b1375b72cabf9fb3048564939e35653 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 Aug 2021 11:14:21 +0600 Subject: [PATCH 51/57] start 0.35.3 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f394ec363a..1e2d4c8c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.35.3 + ## 0.35.2 * `Common`: diff --git a/gradle.properties b/gradle.properties index 4db1b4bebc..1dc0a03442 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.5.16 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.35.2 +library_version=0.35.3 github_release_plugin_version=2.2.12 From e7a2dc51aaaf8530ba229b1e55acda8aeaa72bac Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 Aug 2021 11:18:30 +0600 Subject: [PATCH 52/57] update dependencies --- CHANGELOG.md | 6 ++++++ gradle.properties | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2d4c8c2f..8e0252ca34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 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.17` + ## 0.35.2 * `Common`: diff --git a/gradle.properties b/gradle.properties index 1dc0a03442..2059030165 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ kotlin.incremental.js=true kotlin_version=1.5.21 kotlin_coroutines_version=1.5.1 kotlin_serialisation_runtime_version=1.2.2 -klock_version=2.2.0 +klock_version=2.3.1 uuid_version=0.3.0 -ktor_version=1.6.1 +ktor_version=1.6.2 -micro_utils_version=0.5.16 +micro_utils_version=0.5.17 javax_activation_version=1.1.1 From adf5fd6288c8b5760b9c3f2ab704aa7dc0ad1483 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 Aug 2021 11:27:39 +0600 Subject: [PATCH 53/57] improvements in buildBehaviour --- CHANGELOG.md | 6 +++ .../behaviour_builder/BehaviourBuilders.kt | 40 ++++++++++++++++++- .../DefaultCoroutineScopeProvider.kt | 8 ++++ .../DefaultCoroutineScopeProvider.kt | 8 ++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/jsMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultCoroutineScopeProvider.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e0252ca34..6806ed75fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ * `Klock`: `2.2.0` -> `2.3.1` * `Ktor`: `1.6.1` -> `1.6.2` * `MicroUtils`: `0.5.16` -> `0.5.17` +* `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` ## 0.35.2 diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt index e4473c5431..6ec5c5a862 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt @@ -10,6 +10,42 @@ import dev.inmo.tgbotapi.utils.PreviewFeature import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.plus +/** + * This function is used in [buildBehaviour] extensions to provide default [CoroutineScope] and allow to avoid all + * unnecessary parameters except of block + */ +expect var defaultCoroutineScopeProvider: () -> CoroutineScope + +/** + * Use this method in case you wish to make some additional actions with [flowUpdatesFilter]. + * + * **WARNING** This method WILL NOT launch any listening of updates. Use something like + * [startGettingOfUpdatesByLongPolling] or tools for work with webhooks + * + * @see [BehaviourContext] + * @see startGettingOfUpdatesByLongPolling + */ +@PreviewFeature +@Deprecated("Parameters has been reordered. Replace scope and flowUpdatesFilter for correct order") +suspend fun TelegramBot.buildBehaviour( + scope: CoroutineScope, + flowUpdatesFilter: FlowsUpdatesFilter, + defaultExceptionsHandler: ExceptionHandler? = null, + block: BehaviourContextReceiver +) { + BehaviourContext( + this, + scope.let { + if (defaultExceptionsHandler == null) { + it + } else { + it + ContextSafelyExceptionHandler(defaultExceptionsHandler) + } + }, + flowUpdatesFilter + ).block() +} + /** * Use this method in case you wish to make some additional actions with [flowUpdatesFilter]. * @@ -21,8 +57,8 @@ import kotlinx.coroutines.plus */ @PreviewFeature suspend fun TelegramBot.buildBehaviour( - scope: CoroutineScope, flowUpdatesFilter: FlowsUpdatesFilter, + scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) { @@ -49,7 +85,7 @@ suspend fun TelegramBot.buildBehaviour( */ @PreviewFeature suspend fun TelegramBot.buildBehaviour( - scope: CoroutineScope, + scope: CoroutineScope = defaultCoroutineScopeProvider(), defaultExceptionsHandler: ExceptionHandler? = null, block: BehaviourContextReceiver ) = FlowsUpdatesFilter().let { diff --git a/tgbotapi.extensions.behaviour_builder/src/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) +} From 3e891d50fd8c3eabda876cb60daa038ae2f8133b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 Aug 2021 11:33:52 +0600 Subject: [PATCH 54/57] downloadFile for MediaContent --- CHANGELOG.md | 2 ++ .../dev/inmo/tgbotapi/extensions/api/DownloadFile.kt | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6806ed75fa..87391ebe07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Klock`: `2.2.0` -> `2.3.1` * `Ktor`: `1.6.1` -> `1.6.2` * `MicroUtils`: `0.5.16` -> `0.5.17` +* `API`: + * New extension `TelegramBot#downloadFile` for any `MediaContent` * `Behaviour Builder`: * New provider `defaultCoroutineScopeProvider` * Now it is not necessary to provide `CoroutineScope` to `TelegramBot#buildBehaviour` 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) +) From 530394fd158df582fd8b07060d308e15459f063e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 Aug 2021 11:46:23 +0600 Subject: [PATCH 55/57] SimpleFilter --- CHANGELOG.md | 1 + .../CallbackQueryTriggers.kt | 21 ++++----- .../ChatMemberUpdatedTriggers.kt | 9 ++-- .../triggers_handling/ContentTriggers.kt | 5 ++- .../triggers_handling/EventTriggers.kt | 43 ++++++++++--------- .../triggers_handling/InlineQueryTriggers.kt | 9 ++-- .../triggers_handling/MediaGroupTriggers.kt | 17 ++++---- .../triggers_handling/PassportTriggers.kt | 5 ++- .../behaviour_builder/utils/SimpleFilter.kt | 3 ++ 9 files changed, 62 insertions(+), 51 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 87391ebe07..19b5eb9128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ extension * New `TelegramBot#buildBehaviour` extension with `FlowUpdatesFilter` and `CoroutineScope` with default `CoroutineScope` + * New typealias `SimpleFilter` for unifying triggers filter signatures ## 0.35.2 diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index e6e4c3b565..51480d43d4 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate @@ -11,7 +12,7 @@ import dev.inmo.tgbotapi.types.CallbackQuery.* internal suspend inline fun BehaviourContext.onCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (T) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -41,56 +42,56 @@ internal suspend inline fun BehaviourContext.onCallb suspend fun BehaviourContext.onDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (DataCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (GameShortNameCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineMessageIdCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineMessageIdDataCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onInlineMessageIdGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineMessageIdGameShortNameCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (MessageCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageDataCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (MessageDataCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageGameShortNameCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (MessageGameShortNameCallbackQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onUnknownCallbackQueryType( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (UnknownCallbackQueryType) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onCallbackQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index eff524264b..6994853ec7 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatMemberUpdatedMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -13,7 +14,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -38,7 +39,7 @@ internal suspend inline fun BehaviourConte suspend fun BehaviourContext.onChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -50,7 +51,7 @@ suspend fun BehaviourContext.onChatMemberUpdated( suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -62,7 +63,7 @@ suspend fun BehaviourContext.onCommonChatMemberUpdated( suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index bbdd4d6b65..9c0d76855a 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.* @@ -17,7 +18,7 @@ import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.utils.PreviewFeature -typealias CommonMessageFilter = (suspend (CommonMessage) -> Boolean) +typealias CommonMessageFilter = SimpleFilter> @PreviewFeature internal suspend inline fun BehaviourContext.onContent( @@ -123,7 +124,7 @@ suspend fun BehaviourContext.onDocumentMediaGroupContent( suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = false, - additionalFilter: (suspend (CommonMessage>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 9e44c0d449..c72c39d18d 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -4,6 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate @@ -16,7 +17,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage internal suspend inline fun BehaviourContext.onEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ) = flowsUpdatesFilter.expectFlow(bot) { @@ -44,122 +45,122 @@ internal suspend inline fun BehaviourContext.onEvent( suspend fun BehaviourContext.onChannelEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatStartedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatEndedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVoiceChatParticipantsInvitedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onCommonEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onChannelChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDeleteChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onGroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onLeftChatMember( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatMembers( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onNewChatTitle( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPinnedMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onProximityAlertTriggered( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onSupergroupChatCreated( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (ChatEventMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter>? = null, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onEvent(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 79db28675a..381bff6932 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserInlineQueryMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate @@ -11,7 +12,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.* internal suspend inline fun BehaviourContext.onInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (T) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -41,7 +42,7 @@ internal suspend inline fun BehaviourContext.onInlineQ suspend fun BehaviourContext.onAnyInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (InlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) @@ -49,7 +50,7 @@ suspend fun BehaviourContext.onAnyInlineQuery( suspend fun BehaviourContext.onBaseInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (BaseInlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) @@ -57,7 +58,7 @@ suspend fun BehaviourContext.onBaseInlineQuery( suspend fun BehaviourContext.onLocationInlineQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (LocationInlineQuery) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onInlineQuery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index dfc1e53bac..305baaddd8 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate @@ -19,7 +20,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (List>) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = flowsUpdatesFilter.expectFlow(bot) { update -> @@ -47,43 +48,43 @@ internal suspend inline fun BehaviourContext.bui suspend fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVisualMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List>) -> Boolean)? = null, + additionalFilter: SimpleFilter>>? = null, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt index 30e35a4196..ed130e4f5d 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate @@ -13,7 +14,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportEle internal suspend inline fun BehaviourContext.onPassportMessageWith( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + noinline additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, noinline scenarioReceiver: BehaviourContextAndTypeReceiver ) = flowsUpdatesFilter.expectFlow(bot) { @@ -40,7 +41,7 @@ internal suspend inline fun BehaviourCont suspend fun BehaviourContext.onPassportMessage( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + additionalFilter: SimpleFilter? = null, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: BehaviourContextAndTypeReceiver ) = onPassportMessageWith( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt new file mode 100644 index 0000000000..b7b7ca17e1 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.utils + +typealias SimpleFilter = suspend (T) -> Boolean From e25ce57f6ae81d444c1839a8f826e0f7bb50b638 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Aug 2021 23:12:17 +0600 Subject: [PATCH 56/57] update microutils version --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19b5eb9128..f9f7484dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * `Version`: * `Klock`: `2.2.0` -> `2.3.1` * `Ktor`: `1.6.1` -> `1.6.2` - * `MicroUtils`: `0.5.16` -> `0.5.17` + * `MicroUtils`: `0.5.16` -> `0.5.18` * `API`: * New extension `TelegramBot#downloadFile` for any `MediaContent` * `Behaviour Builder`: diff --git a/gradle.properties b/gradle.properties index 2059030165..feeee555b0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.3.1 uuid_version=0.3.0 ktor_version=1.6.2 -micro_utils_version=0.5.17 +micro_utils_version=0.5.18 javax_activation_version=1.1.1 From 6b89c94ef11776d5f707a88f35ea06765385a15a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Aug 2021 23:36:01 +0600 Subject: [PATCH 57/57] include support of ietf language codes --- CHANGELOG.md | 2 ++ tgbotapi.core/build.gradle | 1 + .../CommonAbstracts/WithLanguageCode.kt | 17 +++++++++++++++++ .../inmo/tgbotapi/requests/bot/BotCommand.kt | 4 ++-- .../tgbotapi/requests/bot/DeleteMyCommands.kt | 16 +++++++++++++--- .../inmo/tgbotapi/requests/bot/GetMyCommands.kt | 13 ++++++++++++- .../inmo/tgbotapi/requests/bot/SetMyCommands.kt | 15 ++++++++++++++- .../kotlin/dev/inmo/tgbotapi/types/User.kt | 16 ++++++++++++++-- .../dev/inmo/tgbotapi/types/UserLocale.kt | 7 ++++--- .../extensions/api/bot/DeleteMyCommands.kt | 8 +++++++- .../extensions/api/bot/GetMyCommands.kt | 8 +++++++- .../extensions/api/bot/SetMyCommands.kt | 15 ++++++++++++++- 12 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/WithLanguageCode.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index f9f7484dda..b9f80096ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `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`: diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index 1948d03bc0..83582016f5 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -51,6 +51,7 @@ kotlin { api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version" api "dev.inmo:micro_utils.serialization.encapsulator:$micro_utils_version" api "dev.inmo:micro_utils.serialization.typed_serializer:$micro_utils_version" + api "dev.inmo:micro_utils.language_codes:$micro_utils_version" api "io.ktor:ktor-client-core:$ktor_version" } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/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/requests/bot/BotCommand.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt index bc6b7cac0b..e5fb89c6c3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/BotCommand.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.requests.bot +import dev.inmo.tgbotapi.CommonAbstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.commands.BotCommandScope -sealed interface MyCommandsRequest : SimpleRequest { +sealed interface MyCommandsRequest : SimpleRequest, WithOptionalLanguageCode { val scope: BotCommandScope - val languageCode: String? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt index 867b5fc978..61b01180cb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/DeleteMyCommands.kt @@ -1,8 +1,9 @@ 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 dev.inmo.tgbotapi.types.languageCodeField -import dev.inmo.tgbotapi.types.scopeField import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @@ -12,11 +13,20 @@ data class DeleteMyCommands( @Serializable(BotCommandScopeSerializer::class) override val scope: BotCommandScope = BotCommandScopeDefault, @SerialName(languageCodeField) - override val languageCode: String? = null + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null ) : MyCommandsRequest { override fun method(): String = "deleteMyCommands" override val requestSerializer: SerializationStrategy = serializer() override val resultDeserializer: DeserializationStrategy = Boolean.serializer() + constructor( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? + ) : this( + scope, + languageCode ?.let(::IetfLanguageCode) + ) + companion object : MyCommandsRequest by DeleteMyCommands() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt index 31b8fe194a..511fc9e33f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyCommands.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.requests.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.commands.* import kotlinx.serialization.* @@ -13,7 +15,8 @@ data class GetMyCommands( @Serializable(BotCommandScopeSerializer::class) override val scope: BotCommandScope = BotCommandScopeDefault, @SerialName(languageCodeField) - override val languageCode: String? = null + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null ) : MyCommandsRequest> { override fun method(): String = "getMyCommands" override val resultDeserializer: DeserializationStrategy> @@ -21,5 +24,13 @@ data class GetMyCommands( override val requestSerializer: SerializationStrategy<*> get() = serializer() + constructor( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? + ) : this( + scope, + languageCode ?.let(::IetfLanguageCode) + ) + companion object : MyCommandsRequest> by GetMyCommands() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt index 4f926840e2..6df10c13b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyCommands.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.requests.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.commands.* import kotlinx.serialization.* @@ -13,7 +15,8 @@ class SetMyCommands( @Serializable(BotCommandScopeSerializer::class) override val scope: BotCommandScope = BotCommandScopeDefault, @SerialName(languageCodeField) - override val languageCode: String? = null + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null ) : MyCommandsRequest { override fun method(): String = "setMyCommands" override val resultDeserializer: DeserializationStrategy @@ -21,6 +24,16 @@ class SetMyCommands( override val requestSerializer: SerializationStrategy<*> get() = serializer() + constructor( + commands: List, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? + ) : this( + commands, + scope, + languageCode ?.let(::IetfLanguageCode) + ) + init { if (commands.size !in botCommandsLimit) { error("Bot commands list size able to be in range $botCommandsLimit, but incoming size is ${commands.size}") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt index bcc2ea2875..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,5 +1,8 @@ package dev.inmo.tgbotapi.types +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer +import dev.inmo.tgbotapi.CommonAbstracts.WithOptionalLanguageCode import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat import dev.inmo.tgbotapi.types.chat.extended.ExtendedPrivateChatImpl import dev.inmo.tgbotapi.utils.* @@ -22,8 +25,17 @@ data class CommonUser( @SerialName(usernameField) override val username: Username? = null, @SerialName(languageCodeField) - val languageCode: String? = null -) : User() + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null +) : User(), WithOptionalLanguageCode { + constructor( + id: UserId, + firstName: String, + lastName: String = "", + username: Username? = null, + languageCode: String + ) : this(id, firstName, lastName, username, IetfLanguageCode(languageCode)) +} @PreviewFeature typealias ExtendedUser = ExtendedPrivateChatImpl diff --git a/tgbotapi.core/src/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/bot/DeleteMyCommands.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt index 31abad88f5..3995e5384a 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/DeleteMyCommands.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.bot.DeleteMyCommands import dev.inmo.tgbotapi.types.commands.BotCommandScope @@ -7,5 +8,10 @@ import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.deleteMyCommands( scope: BotCommandScope = BotCommandScopeDefault, - languageCode: String? = null + languageCode: IetfLanguageCode? ) = execute(DeleteMyCommands(scope, languageCode)) + +suspend fun TelegramBot.deleteMyCommands( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = deleteMyCommands(scope, languageCode ?.let(::IetfLanguageCode)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt index 07a0c6a3ac..59fb66828d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyCommands.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.bot.GetMyCommands import dev.inmo.tgbotapi.types.commands.BotCommandScope @@ -7,5 +8,10 @@ import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.getMyCommands( scope: BotCommandScope = BotCommandScopeDefault, - languageCode: String? = null + languageCode: IetfLanguageCode? = null ) = execute(GetMyCommands(scope, languageCode)) + +suspend fun TelegramBot.getMyCommands( + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = getMyCommands(scope, languageCode ?.let(::IetfLanguageCode)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt index d0d8b0a8cc..e7f5ef01bc 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyCommands.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.bot +import dev.inmo.micro_utils.language_codes.IetfLanguageCode import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.bot.SetMyCommands import dev.inmo.tgbotapi.types.BotCommand @@ -9,9 +10,21 @@ import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault suspend fun TelegramBot.setMyCommands( commands: List, scope: BotCommandScope = BotCommandScopeDefault, - languageCode: String? = null + languageCode: IetfLanguageCode? ) = execute(SetMyCommands(commands, scope, languageCode)) +suspend fun TelegramBot.setMyCommands( + vararg commands: BotCommand, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: IetfLanguageCode? +) = setMyCommands(commands.toList(), scope, languageCode) + +suspend fun TelegramBot.setMyCommands( + commands: List, + scope: BotCommandScope = BotCommandScopeDefault, + languageCode: String? = null +) = setMyCommands(commands, scope, languageCode ?.let(::IetfLanguageCode)) + suspend fun TelegramBot.setMyCommands( vararg commands: BotCommand, scope: BotCommandScope = BotCommandScopeDefault,