From 3d2df4e255c66d8d61304a79984e12c17ddcfcce Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 21 Apr 2023 23:53:53 +0600 Subject: [PATCH] fixes in SwitchInlineQueryChosenChat --- .../SwitchInlineQueryChosenChat.kt | 25 ++++++++++++++----- .../inline/InlineKeyboardButtonsShortcuts.kt | 19 +++++++++++--- .../types/buttons/InlineKeyboardBuilder.kt | 12 ++++++--- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt index d5eec4dfca..186a9fdb97 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt @@ -1,19 +1,32 @@ package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.EncodeDefault +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +@OptIn(ExperimentalSerializationApi::class) @Serializable -data class SwitchInlineQueryChosenChat( +data class SwitchInlineQueryChosenChat ( @SerialName(queryField) val query: String? = null, @SerialName(allowUserChatsField) - val allowUsers: Boolean? = null, + @EncodeDefault + val allowUsers: Boolean = false, @SerialName(allowBotChatsField) - val allowBots: Boolean? = null, + @EncodeDefault + val allowBots: Boolean = false, @SerialName(allowGroupChatsField) - val allowGroups: Boolean? = null, + @EncodeDefault + val allowGroups: Boolean = false, @SerialName(allowChannelChatsField) - val allowChannels: Boolean? = null, -) + @EncodeDefault + val allowChannels: Boolean = false, +) { + init { + require(allowUsers || allowBots || allowGroups || allowChannels) { + "Bot must allow to choose at least one of available variants in choosing of inline query recipient" + } + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt index 886dd9e650..da81c82547 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt @@ -77,10 +77,10 @@ inline fun inlineQueryInCurrentChatInlineButton( inline fun inlineQueryInCurrentChatInlineButton( text: String, query: String? = null, - allowUsers: Boolean? = null, - allowBots: Boolean? = null, - allowGroups: Boolean? = null, - allowChannels: Boolean? = null, + allowUsers: Boolean = false, + allowBots: Boolean = false, + allowGroups: Boolean = false, + allowChannels: Boolean = false, ) = inlineQueryInCurrentChatInlineButton( text, SwitchInlineQueryChosenChat( @@ -92,6 +92,17 @@ inline fun inlineQueryInCurrentChatInlineButton( ) ) +/** + * Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton] + * + * @see inlineKeyboard + * @see InlineKeyboardBuilder.row + */ +inline fun inlineQueryInAnyCurrentChatInlineButton( + text: String, + query: String? = null, +) = inlineQueryInCurrentChatInlineButton(text, query, allowUsers = true, allowBots = true, allowGroups = true, allowChannels = true) + /** * Creates and put [SwitchInlineQueryInlineKeyboardButton] * diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt index 57625f1d0f..796f06ce7c 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt @@ -123,10 +123,10 @@ inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton( inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton( text: String, query: String? = null, - allowUsers: Boolean? = null, - allowBots: Boolean? = null, - allowGroups: Boolean? = null, - allowChannels: Boolean? = null, + allowUsers: Boolean = false, + allowBots: Boolean = false, + allowGroups: Boolean = false, + allowChannels: Boolean = false, ) = inlineQueryInChosenChatButton( text, SwitchInlineQueryChosenChat( @@ -137,6 +137,10 @@ inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton( allowChannels = allowChannels ) ) +inline fun InlineKeyboardRowBuilder.inlineQueryInAnyChosenChatButton( + text: String, + query: String? = null, +) = inlineQueryInChosenChatButton(text, query, allowUsers = true, allowBots = true, allowGroups = true, allowChannels = true) /** * Creates and put [SwitchInlineQueryInlineKeyboardButton]