From 48db305541485e5fdc4148815aef852fff4334cf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 29 Jun 2023 12:18:44 +0600 Subject: [PATCH 01/16] start 8.1.1 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 645421bf7f..7f07b74d29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 8.1.1 + ## 8.1.0 **PARTIALLY BREAKING CHANGES: Exclude `.*Impl` classcasts from `ClassCastsNew`** diff --git a/gradle.properties b/gradle.properties index a8958ff8f7..54d3f0957d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=8.1.0 +library_version=8.1.1 From 13e4740d0a8ba911eab43628d492b40155297586 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 29 Jun 2023 13:45:08 +0600 Subject: [PATCH 02/16] improve Update.sourceChat --- CHANGELOG.md | 3 ++ .../utils/extensions/UpdateChatRetriever.kt | 51 +++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f07b74d29..e66c33cfcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 8.1.1 +* `Utils`: + * Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default + ## 8.1.0 **PARTIALLY BREAKING CHANGES: Exclude `.*Impl` classcasts from `ClassCastsNew`** diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt index 56ec9dc233..4c7911fe71 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt @@ -3,17 +3,60 @@ package dev.inmo.tgbotapi.extensions.utils.extensions import dev.inmo.tgbotapi.abstracts.FromUser import dev.inmo.tgbotapi.abstracts.WithUser import dev.inmo.tgbotapi.extensions.utils.asUser +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult +import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult +import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery +import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.User -import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate +import dev.inmo.tgbotapi.types.queries.callback.* +import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.utils.PreviewFeature +fun CallbackQuery.sourceChat() = when (this) { + is InlineMessageIdDataCallbackQuery -> null + is MessageDataCallbackQuery -> message.chat + is InlineMessageIdGameShortNameCallbackQuery -> null + is MessageGameShortNameCallbackQuery -> message.chat + is UnknownCallbackQueryType -> null +} + @PreviewFeature -fun Update.sourceChat(): Chat? = when (this) { - is BaseMessageUpdate -> data.chat - is ChatJoinRequestUpdate -> data.chat +fun Update.sourceChat( + baseMessageUpdateConverter: (BaseMessageUpdate) -> Chat? = { it.data.chat }, + chatJoinRequestUpdateConverter: (ChatJoinRequestUpdate) -> Chat? = { it.data.chat }, + shippingQueryUpdateConverter: (ShippingQueryUpdate) -> Chat? = { it.data.from }, + pollAnswerUpdateConverter: (PollAnswerUpdate) -> Chat? = { it.data.from }, + preCheckoutQueryUpdateConverter: (PreCheckoutQueryUpdate) -> Chat? = { it.data.from }, + callbackQueryUpdateConverter: (CallbackQueryUpdate) -> Chat? = { it.data.sourceChat() }, + chosenInlineResultUpdateConverter: (ChosenInlineResultUpdate) -> Chat? = { null }, + inlineQueryUpdateConverter: (InlineQueryUpdate) -> Chat? = { null }, + pollUpdateConverter: (PollUpdate) -> Chat? = { null }, + channelPostUpdateConverter: (ChannelPostUpdate) -> Chat? = { it.data.chat }, + messageUpdateConverter: (MessageUpdate) -> Chat? = { it.data.chat }, + editChannelPostUpdateConverter: (EditChannelPostUpdate) -> Chat? = { it.data.chat }, + editMessageUpdateConverter: (EditMessageUpdate) -> Chat? = { it.data.chat }, + myChatMemberUpdatedUpdateConverter: (MyChatMemberUpdatedUpdate) -> Chat? = { it.data.chat }, + commonChatMemberUpdatedUpdateConverter: (CommonChatMemberUpdatedUpdate) -> Chat? = { it.data.chat } +): Chat? = when (this) { + is BaseMessageUpdate -> baseMessageUpdateConverter(this) + is ChatJoinRequestUpdate -> chatJoinRequestUpdateConverter(this) + is ShippingQueryUpdate -> shippingQueryUpdateConverter(this) + is PollAnswerUpdate -> pollAnswerUpdateConverter(this) + is PreCheckoutQueryUpdate -> preCheckoutQueryUpdateConverter(this) + is CallbackQueryUpdate -> callbackQueryUpdateConverter(this) + is ChosenInlineResultUpdate -> chosenInlineResultUpdateConverter(this) + is InlineQueryUpdate -> inlineQueryUpdateConverter(this) + is PollUpdate -> pollUpdateConverter(this) + is ChannelPostUpdate -> channelPostUpdateConverter(this) + is MessageUpdate -> messageUpdateConverter(this) + is EditChannelPostUpdate -> editChannelPostUpdateConverter(this) + is EditMessageUpdate -> editMessageUpdateConverter(this) + is MyChatMemberUpdatedUpdate -> myChatMemberUpdatedUpdateConverter(this) + is CommonChatMemberUpdatedUpdate -> commonChatMemberUpdatedUpdateConverter(this) else -> { when (val data = data) { is FromUser -> data.from From 67b74728685dbdb98aac1394031b66df63cb2ebc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 30 Jun 2023 02:55:27 +0600 Subject: [PATCH 03/16] Update libs.versions.toml --- gradle/libs.versions.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0b02384517..0f84e044d0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,18 +2,18 @@ kotlin = "1.8.22" kotlin-serialization = "1.5.1" -kotlin-coroutines = "1.6.4" +kotlin-coroutines = "1.7.1" javax-activation = "1.1.1" korlibs = "4.0.3" uuid = "0.7.1" -ktor = "2.3.1" +ktor = "2.3.2" ksp = "1.8.22-1.0.11" kotlin-poet = "1.14.2" -microutils = "0.19.4" +microutils = "0.19.6" github-release-plugin = "2.4.1" dokka = "1.8.20" From 8247e7c69cf41a7dc7360125b802573ff45c467b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 29 Jun 2023 14:03:13 +0600 Subject: [PATCH 04/16] add backward compatibility change --- .../extensions/utils/extensions/UpdateChatRetriever.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt index 4c7911fe71..b3de4b565f 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt @@ -25,11 +25,11 @@ fun CallbackQuery.sourceChat() = when (this) { } @PreviewFeature -fun Update.sourceChat( +fun Update.sourceChatWithConverters( baseMessageUpdateConverter: (BaseMessageUpdate) -> Chat? = { it.data.chat }, chatJoinRequestUpdateConverter: (ChatJoinRequestUpdate) -> Chat? = { it.data.chat }, - shippingQueryUpdateConverter: (ShippingQueryUpdate) -> Chat? = { it.data.from }, - pollAnswerUpdateConverter: (PollAnswerUpdate) -> Chat? = { it.data.from }, + shippingQueryUpdateConverter: (ShippingQueryUpdate) -> Chat? = { null }, + pollAnswerUpdateConverter: (PollAnswerUpdate) -> Chat? = { null }, preCheckoutQueryUpdateConverter: (PreCheckoutQueryUpdate) -> Chat? = { it.data.from }, callbackQueryUpdateConverter: (CallbackQueryUpdate) -> Chat? = { it.data.sourceChat() }, chosenInlineResultUpdateConverter: (ChosenInlineResultUpdate) -> Chat? = { null }, @@ -66,6 +66,9 @@ fun Update.sourceChat( } } +@PreviewFeature +fun Update.sourceChat(): Chat? = sourceChatWithConverters() + @PreviewFeature fun Update.sourceUser(): User? = when (val data = data) { is FromUser -> data.from From b3a657b7d6618f878c6675688da5c80eb9a1887a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 30 Jun 2023 14:09:13 +0600 Subject: [PATCH 05/16] make bots username nullable --- .../kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt | 10 ++++------ .../kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index 5b9188e7de..5dbadf9633 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -170,12 +170,12 @@ data class ExtendedForumChatImpl( @Serializable data class ExtendedBot( override val id: UserId, - @SerialName(usernameField) - override val username: Username, @SerialName(firstNameField) override val firstName: String, @SerialName(lastNameField) override val lastName: String = "", + @SerialName(usernameField) + override val username: Username? = null, @SerialName(canJoinGroupsField) val canJoinGroups: Boolean = false, @SerialName(canReadAllGroupMessagesField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt index 0ccc48b172..660fe4c554 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt @@ -67,19 +67,17 @@ data class ChannelChatImpl( sealed class User : PrivateChat @Serializable(UserSerializer::class) -sealed class Bot : User() { - abstract override val username: Username -} +sealed class Bot : User() @Serializable data class CommonBot( override val id: UserId, - @SerialName(usernameField) - override val username: Username, @SerialName(firstNameField) override val firstName: String, @SerialName(lastNameField) - override val lastName: String = "" + override val lastName: String = "", + @SerialName(usernameField) + override val username: Username? = null, ) : Bot() { @SerialName(isBotField) private val isBot = true diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt index facd42061e..a89a98b93c 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt @@ -28,9 +28,9 @@ val WebAppUser.isPremium fun WebAppUser.asUser() = if (isBot == true) { CommonBot( UserId(id), - username ?.let(::Username) ?: error("Username is absent for bot, but must exists"), firstName, - lastName ?: "" + lastName ?: "", + username ?.let(::Username) ?: error("Username is absent for bot, but must exists") ) } else { CommonUser( From 81ed820602eece38ad4a23455c0fd8560fac0277 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 30 Jun 2023 15:13:36 +0600 Subject: [PATCH 06/16] Migrate onto 9.0.0 and update dependenices Update libs.versions.toml Update CHANGELOG.md Update gradle.properties Update CHANGELOG.md --- CHANGELOG.md | 4 +++- gradle.properties | 2 +- gradle/libs.versions.toml | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e66c33cfcf..9e0319ca71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # TelegramBotAPI changelog -## 8.1.1 +## 9.0.0 + +**THIS UPDATE CONTAINS BREAKING CHANGES: USERNAMES OF BOTS NOW BECAME NULLABLE** * `Utils`: * Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default diff --git a/gradle.properties b/gradle.properties index 54d3f0957d..923f424c4e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=8.1.1 +library_version=9.0.0 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0f84e044d0..7808783a44 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.8.22" kotlin-serialization = "1.5.1" -kotlin-coroutines = "1.7.1" +kotlin-coroutines = "1.7.2" javax-activation = "1.1.1" @@ -13,7 +13,7 @@ ktor = "2.3.2" ksp = "1.8.22-1.0.11" kotlin-poet = "1.14.2" -microutils = "0.19.6" +microutils = "0.19.7" github-release-plugin = "2.4.1" dokka = "1.8.20" From 2e815a4c3719749db35803f6463308baac2adf78 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 30 Jun 2023 16:35:14 +0600 Subject: [PATCH 07/16] #773 fix, improvements in updates handling --- CHANGELOG.md | 4 ++ .../tgbotapi/extensions/api/GetUpdatesRaw.kt | 27 ++++++++++++++ .../ktor/base/AbstractRequestCallFactory.kt | 4 +- .../dev/inmo/tgbotapi/requests/GetUpdates.kt | 12 +++--- .../inmo/tgbotapi/requests/GetUpdatesRaw.kt | 37 +++++++++++++++++++ .../tgbotapi/requests/GetUpdatesRequest.kt | 17 +++++++++ .../inmo/tgbotapi/types/update/RawUpdate.kt | 21 +++++------ .../tgbotapi/types/update/abstracts/Update.kt | 31 ++++++++++++---- .../extensions/utils/updates/UpdatesUtils.kt | 2 +- .../utils/updates/retrieving/LongPolling.kt | 5 ++- 10 files changed, 130 insertions(+), 30 deletions(-) create mode 100644 tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/GetUpdatesRaw.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRaw.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRequest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e0319ca71..b1b2da0212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ **THIS UPDATE CONTAINS BREAKING CHANGES: USERNAMES OF BOTS NOW BECAME NULLABLE** +* `Core`: + * All bots now have nullable usernames just like common users ([#772](https://github.com/InsanusMokrassar/ktgbotapi/issues/772)) + * Decrease possible errors in updates handling by additional handling of update deserialization wrapping ([#773](https://github.com/InsanusMokrassar/ktgbotapi/issues/773)) + * Now it is possible to get raw updates with `GetUpdatesRaw` request * `Utils`: * Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/GetUpdatesRaw.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/GetUpdatesRaw.kt new file mode 100644 index 0000000000..040ff36ac5 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/GetUpdatesRaw.kt @@ -0,0 +1,27 @@ +package dev.inmo.tgbotapi.extensions.api + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.GetUpdates +import dev.inmo.tgbotapi.requests.GetUpdatesRaw +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.update.abstracts.Update + +suspend fun TelegramBot.getRawUpdates( + offset: UpdateIdentifier? = null, + limit: Int = getUpdatesLimit.last, + timeout: Seconds? = null, + allowed_updates: List? = ALL_UPDATES_LIST +) = execute( + GetUpdatesRaw( + offset, limit, timeout, allowed_updates + ) +) + +suspend fun TelegramBot.getRawUpdates( + lastUpdate: Update, + limit: Int = getUpdatesLimit.last, + timeout: Seconds? = null, + allowed_updates: List? = ALL_UPDATES_LIST +) = getRawUpdates( + lastUpdate.updateId + 1, limit, timeout, allowed_updates +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt index 5d6346236e..7d1d957aaf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.bot.ktor.base import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory import dev.inmo.tgbotapi.bot.exceptions.newRequestException -import dev.inmo.tgbotapi.requests.GetUpdates +import dev.inmo.tgbotapi.requests.GetUpdatesRequest import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.Response import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper @@ -35,7 +35,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory { ) accept(ContentType.Application.Json) - if (request is GetUpdates) { + if (request is GetUpdatesRequest) { request.timeout?.times(1000L) ?.let { customTimeoutMillis -> if (customTimeoutMillis > 0) { timeout { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt index e603a53d1c..f75ba755c3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdates.kt @@ -22,13 +22,11 @@ private val updatesListSerializer = ListSerializer( */ @Serializable data class GetUpdates( - val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates - val limit: Int = getUpdatesLimit.last, - val timeout: Seconds? = null, - val allowed_updates: List? = ALL_UPDATES_LIST -): SimpleRequest> { - override fun method(): String = "getUpdates" - + override val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates + override val limit: Int = getUpdatesLimit.last, + override val timeout: Seconds? = null, + override val allowed_updates: List? = ALL_UPDATES_LIST +): GetUpdatesRequest> { override val resultDeserializer: DeserializationStrategy> get() = updatesListSerializer diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRaw.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRaw.kt new file mode 100644 index 0000000000..25789b30b5 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRaw.kt @@ -0,0 +1,37 @@ +package dev.inmo.tgbotapi.requests + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.ALL_UPDATES_LIST +import dev.inmo.tgbotapi.types.Seconds +import dev.inmo.tgbotapi.types.UpdateIdentifier +import dev.inmo.tgbotapi.types.getUpdatesLimit +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.json.JsonArray + +/** + * Raw variant of [GetUpdates]. This type will be useful in case you wish to get some updates and handle them by + * yourself or with [dev.inmo.tgbotapi.utils.convertWithMediaGroupUpdates] + */ +@Serializable +data class GetUpdatesRaw( + override val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates + override val limit: Int = getUpdatesLimit.last, + override val timeout: Seconds? = null, + override val allowed_updates: List? = ALL_UPDATES_LIST +): GetUpdatesRequest { + override fun method(): String = "getUpdates" + + override val resultDeserializer: DeserializationStrategy + get() = JsonArray.serializer() + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + init { + if (limit !in getUpdatesLimit) { + error("GetUpdates request can be called only with limit in range $getUpdatesLimit (actual value is $limit)") + } + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRequest.kt new file mode 100644 index 0000000000..4db8c1fafe --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/GetUpdatesRequest.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.requests + +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.ALL_UPDATES_LIST +import dev.inmo.tgbotapi.types.Seconds +import dev.inmo.tgbotapi.types.UpdateIdentifier +import dev.inmo.tgbotapi.types.getUpdatesLimit + +interface GetUpdatesRequest : SimpleRequest { + val offset: UpdateIdentifier? + val limit: Int + val timeout: Seconds? + val allowed_updates: List? + + override fun method(): String = "getUpdates" +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt index 5f07aed6d2..20f57940c0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/RawUpdate.kt @@ -67,20 +67,19 @@ internal data class RawUpdate constructor( chat_join_request != null -> ChatJoinRequestUpdate(updateId, chat_join_request) else -> UnknownUpdate( updateId, - raw.toString(), raw ) } - } catch (e: Error) { - when (e) { - is SerializationException, - is NotImplementedError -> UnknownUpdate( - updateId, - raw.toString(), - raw - ) - else -> throw e - } + } catch (e: NotImplementedError) { + UnknownUpdate( + updateId, + raw + ) + } catch (e: SerializationException) { + UnknownUpdate( + updateId, + raw + ) }.also { initedUpdate = it } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/Update.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/Update.kt index c1f44eeb77..168eb57ebd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/Update.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/Update.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.update.abstracts import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.update.RawUpdate +import dev.inmo.tgbotapi.types.updateIdField import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.* @@ -10,6 +11,9 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.longOrNull @ClassCastsIncluded interface Update { @@ -19,9 +23,12 @@ interface Update { data class UnknownUpdate( override val updateId: UpdateIdentifier, - override val data: String, + override val data: JsonElement, + val throwable: Throwable? = null +) : Update { val rawJson: JsonElement -) : Update + get() = data +} @RiskFeature object UpdateSerializerWithoutSerialization : KSerializer { @@ -44,11 +51,19 @@ object UpdateDeserializationStrategy : DeserializationStrategy { override fun deserialize(decoder: Decoder): Update { val asJson = JsonElement.serializer().deserialize(decoder) - return nonstrictJsonFormat.decodeFromJsonElement( - RawUpdate.serializer(), - asJson - ).asUpdate( - asJson - ) + return runCatching { + nonstrictJsonFormat.decodeFromJsonElement( + RawUpdate.serializer(), + asJson + ).asUpdate( + asJson + ) + }.getOrElse { + UnknownUpdate( + (asJson as? JsonObject) ?.get(updateIdField) ?.jsonPrimitive ?.longOrNull ?: -1L, + asJson, + it + ) + } } } diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt index add4bcbefe..c6d0e4b90c 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt @@ -15,7 +15,7 @@ import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage * @see [Update.lastUpdateIdentifier] */ fun List.lastUpdateIdentifier(): UpdateIdentifier? { - return maxByOrNull { it.updateId } ?.updateId + return maxByOrNull { it.updateId } ?.updateId ?.takeIf { it > -1 } } /** diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index a891eed163..8f83d31002 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.exceptions.* import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.requests.GetUpdates +import dev.inmo.tgbotapi.requests.GetUpdatesRaw import dev.inmo.tgbotapi.requests.webhook.DeleteWebhook import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage @@ -91,7 +92,9 @@ fun TelegramBot.longPollingFlow( for (update in updates) { send(update) - lastUpdateIdentifier = update.updateId + if (update.updateId > -1) { + lastUpdateIdentifier = update.updateId + } } }.onFailure { cancel(it as? CancellationException ?: return@onFailure) From 40a0d2c37dca5a3d2ad5cf7e0827a374501ce381 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 30 Jun 2023 22:42:48 +0600 Subject: [PATCH 08/16] fixes in default filters of updates --- .../behaviour_builder/filters/MessageFilterByChat.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt index 79f983b9f8..3bed7dcfda 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.filters import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat +import dev.inmo.tgbotapi.extensions.utils.extensions.sourceUser import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery import dev.inmo.tgbotapi.types.chat.ChatJoinRequest import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated @@ -41,13 +42,13 @@ val ShippingQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> - update.sourceChat() ?.id == query.user.id + update.sourceUser() ?.id == query.user.id } /** * Allow only updates from the same user as base [InlineQuery.from] */ val InlineQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> - update.sourceChat() ?.id == query.from.id + update.sourceUser() ?.id == query.from.id } /** * Allow only events from the same chat as base [ChatMemberUpdated] From 4853a5b3ade5d56c6bd9a9fbd1624d12083c0909 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 30 Jun 2023 22:46:58 +0600 Subject: [PATCH 09/16] improve docs of onInlineQuery --- .../triggers_handling/InlineQueryTriggers.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 52bc9e271a..8106a24084 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -20,7 +20,7 @@ internal suspend inline fun BC. /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -40,7 +40,7 @@ suspend fun BC.onAnyInlineQuery( /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -60,7 +60,7 @@ suspend fun BC.onBaseInlineQuery( /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] From 0441b53da22189de8bd1cbdbaf83869a8432c0c2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 03:46:29 +0600 Subject: [PATCH 10/16] all query triggers got null default subcontext filter --- CHANGELOG.md | 2 + .../CallbackQueryTriggers.kt | 35 ++++++------ .../CallbackQueryTriggersUnhandled.kt | 7 ++- .../ChatMemberUpdatedTriggers.kt | 9 ++-- .../triggers_handling/CommandHandling.kt | 26 ++++----- .../CommandHandlingUnhandled.kt | 8 +-- .../triggers_handling/ContentTriggers.kt | 54 +++++++++---------- .../triggers_handling/DeepLinkHandling.kt | 6 +-- .../EditedContentTriggers.kt | 42 +++++++-------- .../triggers_handling/InlineQueryTriggers.kt | 15 +++--- 10 files changed, 101 insertions(+), 103 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b2da0212..66700099ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * Now it is possible to get raw updates with `GetUpdatesRaw` request * `Utils`: * Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default +* `BehaviourBuilder`: + * All query triggers got null default subcontext filter ## 8.1.0 diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index c2ca912858..295ca7d02c 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -5,7 +5,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser 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 @@ -17,7 +16,7 @@ import kotlinx.coroutines.Job internal suspend inline fun BC.onCallbackQuery( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { @@ -38,7 +37,7 @@ internal suspend inline fun B */ internal suspend inline fun BC.onDataCallbackQueryCounted( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job { @@ -80,7 +79,7 @@ internal suspend inline fun BC.onDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQueryCounted( @@ -107,7 +106,7 @@ suspend fun BC.onDataCallbackQuery( suspend fun BC.onDataCallbackQuery( dataRegex: Regex, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQuery( @@ -135,7 +134,7 @@ suspend fun BC.onDataCallbackQuery( suspend fun BC.onDataCallbackQuery( data: String, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQuery( @@ -160,7 +159,7 @@ suspend fun BC.onDataCallbackQuery( */ suspend fun BC.onGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -184,7 +183,7 @@ suspend fun BC.onGameShortNameCallbackQuery( */ suspend fun BC.onInlineMessageIdCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -208,7 +207,7 @@ suspend fun BC.onInlineMessageIdCallbackQuery( */ suspend fun BC.onInlineMessageIdDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQueryCounted( @@ -235,7 +234,7 @@ suspend fun BC.onInlineMessageIdDataCallbackQuery( suspend fun BC.onInlineMessageIdDataCallbackQuery( dataRegex: Regex, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineMessageIdDataCallbackQuery( @@ -263,7 +262,7 @@ suspend fun BC.onInlineMessageIdDataCallbackQuery( suspend fun BC.onInlineMessageIdDataCallbackQuery( data: String, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineMessageIdDataCallbackQuery( @@ -288,7 +287,7 @@ suspend fun BC.onInlineMessageIdDataCallbackQuery( */ suspend fun BC.onInlineMessageIdGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -312,7 +311,7 @@ suspend fun BC.onInlineMessageIdGameShortNameCallbackQue */ suspend fun BC.onMessageCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -336,7 +335,7 @@ suspend fun BC.onMessageCallbackQuery( */ suspend fun BC.onMessageDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQueryCounted( @@ -363,7 +362,7 @@ suspend fun BC.onMessageDataCallbackQuery( suspend fun BC.onMessageDataCallbackQuery( dataRegex: Regex, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onMessageDataCallbackQuery( @@ -391,7 +390,7 @@ suspend fun BC.onMessageDataCallbackQuery( suspend fun BC.onMessageDataCallbackQuery( data: String, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onMessageDataCallbackQuery( @@ -416,7 +415,7 @@ suspend fun BC.onMessageDataCallbackQuery( */ suspend fun BC.onMessageGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -440,7 +439,7 @@ suspend fun BC.onMessageGameShortNameCallbackQuery( */ suspend fun BC.onUnknownCallbackQueryType( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt index ef0c85a334..95889f052c 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.* import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory @@ -26,7 +25,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature suspend fun BC.onUnhandledDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery ( @@ -51,7 +50,7 @@ suspend fun BC.onUnhandledDataCallbackQuery( @PreviewFeature suspend fun BC.onUnhandledInlineMessageIdDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery ( @@ -76,7 +75,7 @@ suspend fun BC.onUnhandledInlineMessageIdDataCallbackQue @PreviewFeature suspend fun BC.onUnhandledMessageDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index c6954be2d2..349f168a6c 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ChatMemberUpdatedFilterByChat 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 @@ -15,7 +14,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update internal suspend inline fun BC.onChatMemberUpdatedInternal( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { @@ -37,7 +36,7 @@ internal suspend inline fun BC.onChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -61,7 +60,7 @@ suspend fun BC.onChatMemberUpdated( */ suspend fun BC.onCommonChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -85,7 +84,7 @@ suspend fun BC.onCommonChatMemberUpdated( */ suspend fun BC.onMyChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index 3802ee5dc1..ebfa9d0cb3 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -22,7 +22,7 @@ internal suspend fun BC.commandUncounted( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = onText( @@ -49,7 +49,7 @@ suspend fun BC.command( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = runCatchingSafely { @@ -78,7 +78,7 @@ suspend fun BC.command( command: String, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = command(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -87,7 +87,7 @@ suspend fun BC.command( botCommand: BotCommand, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = command(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -96,7 +96,7 @@ suspend fun BC.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = command(commandRegex, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -105,7 +105,7 @@ suspend fun BC.onCommand( command: String, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -114,7 +114,7 @@ suspend fun BC.onCommand( botCommand: BotCommand, requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = onCommand(botCommand.command, requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -122,7 +122,7 @@ suspend fun BC.onCommand( suspend fun BC.commandWithArgs( commandRegex: Regex, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ) = command( @@ -142,7 +142,7 @@ suspend fun BC.commandWithArgs( suspend fun BC.commandWithArgs( command: String, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ) = commandWithArgs( @@ -156,7 +156,7 @@ suspend fun BC.commandWithArgs( suspend fun BC.commandWithArgs( botCommand: BotCommand, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ) = commandWithArgs( @@ -170,7 +170,7 @@ suspend fun BC.commandWithArgs( suspend fun BC.onCommandWithArgs( commandRegex: Regex, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ): Job = commandWithArgs(commandRegex, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -178,7 +178,7 @@ suspend fun BC.onCommandWithArgs( suspend fun BC.onCommandWithArgs( command: String, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ): Job = onCommandWithArgs(command.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -186,7 +186,7 @@ suspend fun BC.onCommandWithArgs( suspend fun BC.onCommandWithArgs( botCommand: BotCommand, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver> ): Job = onCommandWithArgs(botCommand.command, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandlingUnhandled.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandlingUnhandled.kt index 0219490400..4ec378cb27 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandlingUnhandled.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandlingUnhandled.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.Job suspend fun BC.unhandledCommand( requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = onText( @@ -48,7 +48,7 @@ suspend fun BC.unhandledCommand( suspend fun BC.onUnhandledCommand( requireOnlyCommandInMessage: Boolean = true, initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job = unhandledCommand(requireOnlyCommandInMessage, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -56,7 +56,7 @@ suspend fun BC.onUnhandledCommand( @PreviewFeature suspend fun BC.unhandledCommandWithArgs( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver>> ) = onUnhandledCommand( @@ -74,7 +74,7 @@ suspend fun BC.unhandledCommandWithArgs( @PreviewFeature suspend fun BC.onUnhandledCommandWithArgs( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver>> ): Job = unhandledCommandWithArgs(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index 2ff230af77..80901c26bf 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -46,7 +46,7 @@ internal suspend inline fun */ suspend fun BC.onContentMessage( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContentMessageWithType( @@ -70,7 +70,7 @@ suspend fun BC.onContentMessage( */ suspend fun BC.onContact( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -94,7 +94,7 @@ suspend fun BC.onContact( */ suspend fun BC.onDice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -118,7 +118,7 @@ suspend fun BC.onDice( */ suspend fun BC.onGame( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -142,7 +142,7 @@ suspend fun BC.onGame( */ suspend fun BC.onLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -166,7 +166,7 @@ suspend fun BC.onLocation( */ suspend fun BC.onLiveLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -190,7 +190,7 @@ suspend fun BC.onLiveLocation( */ suspend fun BC.onStaticLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -214,7 +214,7 @@ suspend fun BC.onStaticLocation( */ suspend fun BC.onPoll( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -238,7 +238,7 @@ suspend fun BC.onPoll( */ suspend fun BC.onText( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -262,7 +262,7 @@ suspend fun BC.onText( */ suspend fun BC.onTextedContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -286,7 +286,7 @@ suspend fun BC.onTextedContent( */ suspend fun BC.onVenue( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -310,7 +310,7 @@ suspend fun BC.onVenue( */ suspend fun BC.onAudioMediaGroup( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -334,7 +334,7 @@ suspend fun BC.onAudioMediaGroup( */ suspend fun BC.onDocumentMediaGroupContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -358,7 +358,7 @@ suspend fun BC.onDocumentMediaGroupContent( */ suspend fun BC.onTextedMediaContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -382,7 +382,7 @@ suspend fun BC.onTextedMediaContent( */ suspend fun BC.onMediaCollection( initialFilter: CommonMessageFilter>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onContentMessageWithType( @@ -406,7 +406,7 @@ suspend fun BC.onMediaCollection( */ suspend fun BC.onMedia( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -430,7 +430,7 @@ suspend fun BC.onMedia( */ suspend fun BC.onAnimation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -454,7 +454,7 @@ suspend fun BC.onAnimation( */ suspend fun BC.onAudio( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -478,7 +478,7 @@ suspend fun BC.onAudio( */ suspend fun BC.onDocument( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -502,7 +502,7 @@ suspend fun BC.onDocument( */ suspend fun BC.onPhoto( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -526,7 +526,7 @@ suspend fun BC.onPhoto( */ suspend fun BC.onSticker( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -550,7 +550,7 @@ suspend fun BC.onSticker( */ suspend fun BC.onVideo( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -574,7 +574,7 @@ suspend fun BC.onVideo( */ suspend fun BC.onVideoNote( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -598,7 +598,7 @@ suspend fun BC.onVideoNote( */ suspend fun BC.onVoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -622,7 +622,7 @@ suspend fun BC.onVoice( */ suspend fun BC.onInvoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -646,7 +646,7 @@ suspend fun BC.onInvoice( */ suspend fun BC.onVisualContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( @@ -670,7 +670,7 @@ suspend fun BC.onVisualContent( */ suspend fun BC.onMediaContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onContentMessageWithType( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/DeepLinkHandling.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/DeepLinkHandling.kt index 62e38cda02..9ca2030f10 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/DeepLinkHandling.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/DeepLinkHandling.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.filter private val startRegex = Regex("start") suspend fun BC.onDeepLink( initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = { (message, _), update -> MessageFilterByChat(this, message, update) }, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = { (message, _), update -> MessageFilterByChat(this, message, update) }, markerFactory: MarkerFactory, Any> = MarkerFactory { (message, _) -> ByChatMessageMarkerFactory(message) }, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ): Job = on( @@ -50,7 +50,7 @@ suspend fun BC.onDeepLink( suspend fun BC.onDeepLink( regex: Regex, initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = { (message, _), update -> MessageFilterByChat(this, message, update) }, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = { (message, _), update -> MessageFilterByChat(this, message, update) }, markerFactory: MarkerFactory, Any> = MarkerFactory { (message, _) -> ByChatMessageMarkerFactory(message) }, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ): Job { @@ -63,7 +63,7 @@ suspend fun BC.onDeepLink( suspend fun BC.onDeepLink( deepLink: String, initialFilter: SimpleFilter>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = { (message, _), update -> MessageFilterByChat(this, message, update) }, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = { (message, _), update -> MessageFilterByChat(this, message, update) }, markerFactory: MarkerFactory, Any> = MarkerFactory { (message, _) -> ByChatMessageMarkerFactory(message) }, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ): Job = onDeepLink(Regex("^$deepLink$"), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt index 3141a57439..57912762bd 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt @@ -40,7 +40,7 @@ internal suspend inline fun */ suspend fun BC.onEditedContentMessage( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( @@ -64,7 +64,7 @@ suspend fun BC.onEditedContentMessage( */ suspend fun BC.onEditedContact( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -88,7 +88,7 @@ suspend fun BC.onEditedContact( */ suspend fun BC.onEditedDice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -112,7 +112,7 @@ suspend fun BC.onEditedDice( */ suspend fun BC.onEditedGame( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -136,7 +136,7 @@ suspend fun BC.onEditedGame( */ suspend fun BC.onEditedLocation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -160,7 +160,7 @@ suspend fun BC.onEditedLocation( */ suspend fun BC.onEditedText( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -184,7 +184,7 @@ suspend fun BC.onEditedText( */ suspend fun BC.onEditedVenue( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -208,7 +208,7 @@ suspend fun BC.onEditedVenue( */ suspend fun BC.onEditedAudioMediaGroup( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -232,7 +232,7 @@ suspend fun BC.onEditedAudioMediaGroup( */ suspend fun BC.onEditedDocumentMediaGroupContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -256,7 +256,7 @@ suspend fun BC.onEditedDocumentMediaGroupContent( */ suspend fun BC.onEditedTextedMediaContent( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -280,7 +280,7 @@ suspend fun BC.onEditedTextedMediaContent( */ suspend fun BC.onEditedMediaCollection( initialFilter: CommonMessageFilter>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update> = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> )= onEditedContent( @@ -304,7 +304,7 @@ suspend fun BC.onEditedMediaCollection( */ suspend fun BC.onEditedMedia( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -328,7 +328,7 @@ suspend fun BC.onEditedMedia( */ suspend fun BC.onEditedAnimation( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -352,7 +352,7 @@ suspend fun BC.onEditedAnimation( */ suspend fun BC.onEditedAudio( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -376,7 +376,7 @@ suspend fun BC.onEditedAudio( */ suspend fun BC.onEditedDocument( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -400,7 +400,7 @@ suspend fun BC.onEditedDocument( */ suspend fun BC.onEditedPhoto( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -424,7 +424,7 @@ suspend fun BC.onEditedPhoto( */ suspend fun BC.onEditedSticker( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -448,7 +448,7 @@ suspend fun BC.onEditedSticker( */ suspend fun BC.onEditedVideo( initialFilter: CommonMessageFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -472,7 +472,7 @@ suspend fun BC.onEditedVideo( */ suspend fun BC.onEditedVideoNote( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -496,7 +496,7 @@ suspend fun BC.onEditedVideoNote( */ suspend fun BC.onEditedVoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( @@ -520,7 +520,7 @@ suspend fun BC.onEditedVoice( */ suspend fun BC.onEditedInvoice( initialFilter: CommonMessageFilter? = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver )= onEditedContent( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 8106a24084..432213f547 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.InlineQueryFilterByUser 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 @@ -11,7 +10,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update internal suspend inline fun BC.onInlineQuery( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { @@ -20,7 +19,7 @@ internal suspend inline fun BC. /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [null]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -32,7 +31,7 @@ internal suspend inline fun BC. */ suspend fun BC.onAnyInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -40,7 +39,7 @@ suspend fun BC.onAnyInlineQuery( /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [null]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -52,7 +51,7 @@ suspend fun BC.onAnyInlineQuery( */ suspend fun BC.onBaseInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -60,7 +59,7 @@ suspend fun BC.onBaseInlineQuery( /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [null]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -72,7 +71,7 @@ suspend fun BC.onBaseInlineQuery( */ suspend fun BC.onLocationInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) From b81308da8bc55cbd9f44e06b3dbff8bec6b8c20f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 13:53:26 +0600 Subject: [PATCH 11/16] get back default filters for the queries but fix them --- CHANGELOG.md | 2 -- .../filters/MessageFilterByChat.kt | 24 +++++++++---- .../CallbackQueryTriggers.kt | 35 ++++++++++--------- .../CallbackQueryTriggersUnhandled.kt | 7 ++-- .../triggers_handling/InlineQueryTriggers.kt | 15 ++++---- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66700099ec..b1b2da0212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,6 @@ * Now it is possible to get raw updates with `GetUpdatesRaw` request * `Utils`: * Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default -* `BehaviourBuilder`: - * All query triggers got null default subcontext filter ## 8.1.0 diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt index 3bed7dcfda..85bbad10ba 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChat.kt @@ -16,7 +16,9 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update * Allow only events from the same chat as base [Message] */ val MessageFilterByChat: BehaviourContextAndTwoTypesReceiver = { message, update -> - update.sourceChat() ?.id == message.chat.id + update.sourceChat() ?.let { + it.id == message.chat.id + } != false } /** * Allow only events from the same chat as base [List] of [Message] @@ -30,31 +32,41 @@ val MessagesFilterByChat: BehaviourContextAndTwoTypesReceiver = { query, update -> - update.sourceChat() ?.id == query.user.id + update.sourceUser() ?.let { + it.id == query.user.id + } != false } /** * Allow only updates from the same user as base [ShippingQuery.user] */ val ShippingQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> - update.sourceChat() ?.id == query.user.id + update.sourceUser() ?.let { + it.id == query.user.id + } != false } /** * Allow only updates from the same user as base [ShippingQuery.user] */ val PreCheckoutQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> - update.sourceUser() ?.id == query.user.id + update.sourceUser() ?.let { + it.id == query.user.id + } != false } /** * Allow only updates from the same user as base [InlineQuery.from] */ val InlineQueryFilterByUser: BehaviourContextAndTwoTypesReceiver = { query, update -> - update.sourceUser() ?.id == query.from.id + update.sourceUser() ?.let { + it.id == query.user.id + } != false } /** * Allow only events from the same chat as base [ChatMemberUpdated] */ val ChatMemberUpdatedFilterByChat: BehaviourContextAndTwoTypesReceiver = { updated, update -> - update.sourceChat() ?.id == updated.chat.id + update.sourceChat() ?.let { + it.id == updated.chat.id + } != false } /** * Allow only events from the same chat as base [ChatMemberUpdated] diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index 295ca7d02c..c2ca912858 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser 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 @@ -16,7 +17,7 @@ import kotlinx.coroutines.Job internal suspend inline fun BC.onCallbackQuery( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { @@ -37,7 +38,7 @@ internal suspend inline fun B */ internal suspend inline fun BC.onDataCallbackQueryCounted( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ): Job { @@ -79,7 +80,7 @@ internal suspend inline fun BC.onDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQueryCounted( @@ -106,7 +107,7 @@ suspend fun BC.onDataCallbackQuery( suspend fun BC.onDataCallbackQuery( dataRegex: Regex, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQuery( @@ -134,7 +135,7 @@ suspend fun BC.onDataCallbackQuery( suspend fun BC.onDataCallbackQuery( data: String, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQuery( @@ -159,7 +160,7 @@ suspend fun BC.onDataCallbackQuery( */ suspend fun BC.onGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -183,7 +184,7 @@ suspend fun BC.onGameShortNameCallbackQuery( */ suspend fun BC.onInlineMessageIdCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -207,7 +208,7 @@ suspend fun BC.onInlineMessageIdCallbackQuery( */ suspend fun BC.onInlineMessageIdDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQueryCounted( @@ -234,7 +235,7 @@ suspend fun BC.onInlineMessageIdDataCallbackQuery( suspend fun BC.onInlineMessageIdDataCallbackQuery( dataRegex: Regex, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineMessageIdDataCallbackQuery( @@ -262,7 +263,7 @@ suspend fun BC.onInlineMessageIdDataCallbackQuery( suspend fun BC.onInlineMessageIdDataCallbackQuery( data: String, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineMessageIdDataCallbackQuery( @@ -287,7 +288,7 @@ suspend fun BC.onInlineMessageIdDataCallbackQuery( */ suspend fun BC.onInlineMessageIdGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -311,7 +312,7 @@ suspend fun BC.onInlineMessageIdGameShortNameCallbackQue */ suspend fun BC.onMessageCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -335,7 +336,7 @@ suspend fun BC.onMessageCallbackQuery( */ suspend fun BC.onMessageDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onDataCallbackQueryCounted( @@ -362,7 +363,7 @@ suspend fun BC.onMessageDataCallbackQuery( suspend fun BC.onMessageDataCallbackQuery( dataRegex: Regex, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onMessageDataCallbackQuery( @@ -390,7 +391,7 @@ suspend fun BC.onMessageDataCallbackQuery( suspend fun BC.onMessageDataCallbackQuery( data: String, initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onMessageDataCallbackQuery( @@ -415,7 +416,7 @@ suspend fun BC.onMessageDataCallbackQuery( */ suspend fun BC.onMessageGameShortNameCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( @@ -439,7 +440,7 @@ suspend fun BC.onMessageGameShortNameCallbackQuery( */ suspend fun BC.onUnknownCallbackQueryType( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt index 95889f052c..ef0c85a334 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggersUnhandled.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.* import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory @@ -25,7 +26,7 @@ import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature suspend fun BC.onUnhandledDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery ( @@ -50,7 +51,7 @@ suspend fun BC.onUnhandledDataCallbackQuery( @PreviewFeature suspend fun BC.onUnhandledInlineMessageIdDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery ( @@ -75,7 +76,7 @@ suspend fun BC.onUnhandledInlineMessageIdDataCallbackQue @PreviewFeature suspend fun BC.onUnhandledMessageDataCallbackQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = CallbackQueryFilterByUser, markerFactory: MarkerFactory = ByUserCallbackQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onCallbackQuery( diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 432213f547..8106a24084 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.InlineQueryFilterByUser 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 @@ -10,7 +11,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update internal suspend inline fun BC.onInlineQuery( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { @@ -19,7 +20,7 @@ internal suspend inline fun BC. /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter **Default is [null]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -31,7 +32,7 @@ internal suspend inline fun BC. */ suspend fun BC.onAnyInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -39,7 +40,7 @@ suspend fun BC.onAnyInlineQuery( /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter **Default is [null]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -51,7 +52,7 @@ suspend fun BC.onAnyInlineQuery( */ suspend fun BC.onBaseInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) @@ -59,7 +60,7 @@ suspend fun BC.onBaseInlineQuery( /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call - * @param subcontextUpdatesFilter **Default is [null]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, + * @param subcontextUpdatesFilter **Default is [InlineQueryFilterByUser]]**. This filter will be applied to each update inside of [scenarioReceiver]. For example, * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] @@ -71,7 +72,7 @@ suspend fun BC.onBaseInlineQuery( */ suspend fun BC.onLocationInlineQuery( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = InlineQueryFilterByUser, markerFactory: MarkerFactory = ByUserInlineQueryMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onInlineQuery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) From 93e72230a1f14bd62cfe69456ba0f07a408b3c84 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 14:17:42 +0600 Subject: [PATCH 12/16] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b2da0212..6f35c4dc30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ **THIS UPDATE CONTAINS BREAKING CHANGES: USERNAMES OF BOTS NOW BECAME NULLABLE** +* `Version`: + * `Coroutines`: `1.6.4` -> `1.7.1` + * `Ktor`: `2.3.1` -> `2.3.2` + * `MicroUtils`: `0.19.4` -> `0.19.7` * `Core`: * All bots now have nullable usernames just like common users ([#772](https://github.com/InsanusMokrassar/ktgbotapi/issues/772)) * Decrease possible errors in updates handling by additional handling of update deserialization wrapping ([#773](https://github.com/InsanusMokrassar/ktgbotapi/issues/773)) From cf666aad112e66215ff6ba179a35b0d5a215dd1e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 14:24:35 +0600 Subject: [PATCH 13/16] update gradle wrapper --- 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 d2d5d93833..4a71a623f6 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-7.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip From bff2713bbde4f450cd5aa6a1db8307df7785137b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 14:26:46 +0600 Subject: [PATCH 14/16] one more fix of triggers --- .../triggers_handling/ChatJoinRequestTriggers.kt | 3 +-- .../triggers_handling/ChatMemberUpdatedTriggers.kt | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatJoinRequestTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatJoinRequestTriggers.kt index 71d244e100..21cbd37159 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatJoinRequestTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatJoinRequestTriggers.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.tgbotapi.extensions.behaviour_builder.* -import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ChatJoinRequestFilterByChat import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatJoinRequestMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory @@ -25,7 +24,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update */ suspend fun BC.onChatJoinRequest( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatJoinRequestFilterByChat, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, markerFactory: MarkerFactory = ByChatChatJoinRequestMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index 349f168a6c..c6954be2d2 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.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.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ChatMemberUpdatedFilterByChat 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 @@ -14,7 +15,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update internal suspend inline fun BC.onChatMemberUpdatedInternal( initialFilter: SimpleFilter? = null, - noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { @@ -36,7 +37,7 @@ internal suspend inline fun BC.onChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -60,7 +61,7 @@ suspend fun BC.onChatMemberUpdated( */ suspend fun BC.onCommonChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( @@ -84,7 +85,7 @@ suspend fun BC.onCommonChatMemberUpdated( */ suspend fun BC.onMyChatMemberUpdated( initialFilter: SimpleFilter? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver? = ChatMemberUpdatedFilterByChat, markerFactory: MarkerFactory = ByChatChatMemberUpdatedMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver ) = onChatMemberUpdatedInternal( From 77ea1f741eaec470b31e054de421c1cdffb1ad18 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 14:29:49 +0600 Subject: [PATCH 15/16] fill changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f35c4dc30..b42fcc03cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,11 @@ * `Ktor`: `2.3.1` -> `2.3.2` * `MicroUtils`: `0.19.4` -> `0.19.7` * `Core`: - * All bots now have nullable usernames just like common users ([#772](https://github.com/InsanusMokrassar/ktgbotapi/issues/772)) + * **All bots now have nullable usernames just like common users ([#772](https://github.com/InsanusMokrassar/ktgbotapi/issues/772))** * Decrease possible errors in updates handling by additional handling of update deserialization wrapping ([#773](https://github.com/InsanusMokrassar/ktgbotapi/issues/773)) - * Now it is possible to get raw updates with `GetUpdatesRaw` request + * New interface `GetUpdatesRequest`. You may implement it to show default telegram bot ktor executor that this + request is an updates request and should be handled in a different way + * Now it is possible to get raw updates with `GetUpdatesRaw` request * `Utils`: * Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default From 187f340e88a814298f9c8b580cc67d1956012d06 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 1 Jul 2023 14:32:58 +0600 Subject: [PATCH 16/16] fixes in webappuser --- .../dev/inmo/tgbotapi/webapps/WebAppUser.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt index a89a98b93c..9c8ac9431e 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt @@ -27,18 +27,18 @@ val WebAppUser.isPremium fun WebAppUser.asUser() = if (isBot == true) { CommonBot( - UserId(id), - firstName, - lastName ?: "", - username ?.let(::Username) ?: error("Username is absent for bot, but must exists") + id = UserId(id), + firstName = firstName, + lastName = lastName ?: "", + username = username ?.let(::Username) ) } else { CommonUser( - UserId(id), - firstName, - lastName ?: "", - username ?.let(::Username), - languageCode ?.let(::IetfLanguageCode), + id = UserId(id), + firstName = firstName, + lastName = lastName ?: "", + username = username ?.let(::Username), + ietfLanguageCode = languageCode ?.let(::IetfLanguageCode), isPremium = isPremium ) }