From 2a3ffd707ecf69f8763df1316891513663aa3d04 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 5 Feb 2023 23:41:02 +0600 Subject: [PATCH] improvements in KeyboardButtonRequestChat --- .../buttons/KeyboardButtonRequestChat.kt | 45 ++++++++++++++- .../reply/ReplyKeyboardButtonsShortcuts.kt | 55 +++++++++++++++++++ .../types/buttons/ReplyKeyboardBuilder.kt | 54 ++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestChat.kt index 487b9ad57f..fccb2c64ce 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestChat.kt @@ -13,6 +13,10 @@ import dev.inmo.tgbotapi.types.userAdministratorRightsField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +/** + * @see Channel + * @see Group + */ @Serializable data class KeyboardButtonRequestChat( @SerialName(requestIdField) @@ -31,5 +35,44 @@ data class KeyboardButtonRequestChat( val botRightsInChat: ChatAdministratorRights? = null, @SerialName(botIsMemberField) val botIsMember: Boolean? = null -) +) { + companion object { + fun Channel( + requestId: RequestId, + isPublic: Boolean? = null, + isOwnedBy: Boolean? = null, + userRightsInChat: ChatAdministratorRights? = null, + botRightsInChat: ChatAdministratorRights? = null, + botIsMember: Boolean? = null + ) = KeyboardButtonRequestChat( + requestId = requestId, + isChannel = true, + isForum = null, + isPublic = isPublic, + isOwnedBy = isOwnedBy, + userRightsInChat = userRightsInChat, + botRightsInChat = botRightsInChat, + botIsMember = botIsMember + ) + + fun Group( + requestId: RequestId, + isForum: Boolean? = null, + isPublic: Boolean? = null, + isOwnedBy: Boolean? = null, + userRightsInChat: ChatAdministratorRights? = null, + botRightsInChat: ChatAdministratorRights? = null, + botIsMember: Boolean? = null + ) = KeyboardButtonRequestChat( + requestId = requestId, + isChannel = false, + isForum = isForum, + isPublic = isPublic, + isOwnedBy = isOwnedBy, + userRightsInChat = userRightsInChat, + botRightsInChat = botRightsInChat, + botIsMember = botIsMember + ) + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt index e6c495d990..434faf7723 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt @@ -172,3 +172,58 @@ inline fun requestChatReplyButton( botIsMember = botIsMember ) ) + +/** + * Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Channel] + * + * @see replyKeyboard + * @see ReplyKeyboardBuilder.row + */ +inline fun requestChannelReplyButton( + text: String, + requestId: RequestId, + isPublic: Boolean? = null, + isOwnedBy: Boolean? = null, + userRightsInChat: ChatAdministratorRights? = null, + botRightsInChat: ChatAdministratorRights? = null, + botIsMember: Boolean = false +) = requestChatReplyButton( + text, + KeyboardButtonRequestChat.Channel( + requestId = requestId, + isPublic = isPublic, + isOwnedBy = isOwnedBy, + userRightsInChat = userRightsInChat, + botRightsInChat = botRightsInChat, + botIsMember = botIsMember + ) +) + + +/** + * Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group] + * + * @see replyKeyboard + * @see ReplyKeyboardBuilder.row + */ +inline fun requestChannelReplyButton( + text: String, + requestId: RequestId, + isForum: Boolean? = null, + isPublic: Boolean? = null, + isOwnedBy: Boolean? = null, + userRightsInChat: ChatAdministratorRights? = null, + botRightsInChat: ChatAdministratorRights? = null, + botIsMember: Boolean? = null +) = requestChatReplyButton( + text, + KeyboardButtonRequestChat.Group( + requestId = requestId, + isForum = isForum, + isPublic = isPublic, + isOwnedBy = isOwnedBy, + userRightsInChat = userRightsInChat, + botRightsInChat = botRightsInChat, + botIsMember = botIsMember + ) +) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt index 12a6216558..22acc0e117 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt @@ -249,3 +249,57 @@ inline fun ReplyKeyboardRowBuilder.requestChatButton( botIsMember = botIsMember ) ) + +/** + * Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Channel] + * + * @see replyKeyboard + * @see ReplyKeyboardBuilder.row + */ +inline fun ReplyKeyboardRowBuilder.requestChannelButton( + text: String, + requestId: RequestId, + isPublic: Boolean? = null, + isOwnedBy: Boolean? = null, + userRightsInChat: ChatAdministratorRights? = null, + botRightsInChat: ChatAdministratorRights? = null, + botIsMember: Boolean? = null +) = requestChatButton( + text, + KeyboardButtonRequestChat.Channel( + requestId = requestId, + isPublic = isPublic, + isOwnedBy = isOwnedBy, + userRightsInChat = userRightsInChat, + botRightsInChat = botRightsInChat, + botIsMember = botIsMember + ) +) + +/** + * Creates and put [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group] + * + * @see replyKeyboard + * @see ReplyKeyboardBuilder.row + */ +inline fun ReplyKeyboardRowBuilder.requestGroupButton( + text: String, + requestId: RequestId, + isForum: Boolean? = null, + isPublic: Boolean? = null, + isOwnedBy: Boolean? = null, + userRightsInChat: ChatAdministratorRights? = null, + botRightsInChat: ChatAdministratorRights? = null, + botIsMember: Boolean? = null +) = requestChatButton( + text, + KeyboardButtonRequestChat.Group( + requestId = requestId, + isForum = isForum, + isPublic = isPublic, + isOwnedBy = isOwnedBy, + userRightsInChat = userRightsInChat, + botRightsInChat = botRightsInChat, + botIsMember = botIsMember + ) +)