1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

fixes in SwitchInlineQueryChosenChat

This commit is contained in:
InsanusMokrassar 2023-04-21 23:53:53 +06:00
parent 33b6ff1c1e
commit 3d2df4e255
3 changed files with 42 additions and 14 deletions

View File

@ -1,19 +1,32 @@
package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@OptIn(ExperimentalSerializationApi::class)
@Serializable @Serializable
data class SwitchInlineQueryChosenChat( data class SwitchInlineQueryChosenChat (
@SerialName(queryField) @SerialName(queryField)
val query: String? = null, val query: String? = null,
@SerialName(allowUserChatsField) @SerialName(allowUserChatsField)
val allowUsers: Boolean? = null, @EncodeDefault
val allowUsers: Boolean = false,
@SerialName(allowBotChatsField) @SerialName(allowBotChatsField)
val allowBots: Boolean? = null, @EncodeDefault
val allowBots: Boolean = false,
@SerialName(allowGroupChatsField) @SerialName(allowGroupChatsField)
val allowGroups: Boolean? = null, @EncodeDefault
val allowGroups: Boolean = false,
@SerialName(allowChannelChatsField) @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"
}
}
}

View File

@ -77,10 +77,10 @@ inline fun inlineQueryInCurrentChatInlineButton(
inline fun inlineQueryInCurrentChatInlineButton( inline fun inlineQueryInCurrentChatInlineButton(
text: String, text: String,
query: String? = null, query: String? = null,
allowUsers: Boolean? = null, allowUsers: Boolean = false,
allowBots: Boolean? = null, allowBots: Boolean = false,
allowGroups: Boolean? = null, allowGroups: Boolean = false,
allowChannels: Boolean? = null, allowChannels: Boolean = false,
) = inlineQueryInCurrentChatInlineButton( ) = inlineQueryInCurrentChatInlineButton(
text, text,
SwitchInlineQueryChosenChat( 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] * Creates and put [SwitchInlineQueryInlineKeyboardButton]
* *

View File

@ -123,10 +123,10 @@ inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton( inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
text: String, text: String,
query: String? = null, query: String? = null,
allowUsers: Boolean? = null, allowUsers: Boolean = false,
allowBots: Boolean? = null, allowBots: Boolean = false,
allowGroups: Boolean? = null, allowGroups: Boolean = false,
allowChannels: Boolean? = null, allowChannels: Boolean = false,
) = inlineQueryInChosenChatButton( ) = inlineQueryInChosenChatButton(
text, text,
SwitchInlineQueryChosenChat( SwitchInlineQueryChosenChat(
@ -137,6 +137,10 @@ inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
allowChannels = allowChannels 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] * Creates and put [SwitchInlineQueryInlineKeyboardButton]