mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
improve users shared DSLs
This commit is contained in:
parent
86c86dfb8a
commit
89524290c5
@ -17,12 +17,15 @@ import kotlinx.serialization.encoding.Encoder
|
||||
sealed interface KeyboardButtonRequestUsers {
|
||||
val requestId: RequestId
|
||||
val isBot: Boolean?
|
||||
val isPremium: Boolean?
|
||||
val maxCount: Int
|
||||
|
||||
@Serializable
|
||||
data class Any(
|
||||
@SerialName(requestIdField)
|
||||
override val requestId: RequestId,
|
||||
@SerialName(userIsPremiumField)
|
||||
override val isPremium: Boolean? = null,
|
||||
@SerialName(maxQuantityField)
|
||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) : KeyboardButtonRequestUsers {
|
||||
@ -36,7 +39,7 @@ sealed interface KeyboardButtonRequestUsers {
|
||||
@SerialName(requestIdField)
|
||||
override val requestId: RequestId,
|
||||
@SerialName(userIsPremiumField)
|
||||
val isPremium: Boolean? = null,
|
||||
override val isPremium: Boolean? = null,
|
||||
@SerialName(maxQuantityField)
|
||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) : KeyboardButtonRequestUsers {
|
||||
@ -55,6 +58,8 @@ sealed interface KeyboardButtonRequestUsers {
|
||||
@SerialName(userIsBotField)
|
||||
@EncodeDefault
|
||||
override val isBot: Boolean = true
|
||||
override val isPremium: Boolean?
|
||||
get() = null
|
||||
}
|
||||
|
||||
@Serializer(KeyboardButtonRequestUsers::class)
|
||||
@ -80,7 +85,7 @@ sealed interface KeyboardButtonRequestUsers {
|
||||
return when (surrogate.userIsBot) {
|
||||
true -> Bot(surrogate.requestId, surrogate.maxCount)
|
||||
false -> Common(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
||||
null -> Any(surrogate.requestId, surrogate.maxCount)
|
||||
null -> Any(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,10 @@ package dev.inmo.tgbotapi.types.buttons.reply
|
||||
|
||||
import dev.inmo.tgbotapi.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||
import dev.inmo.tgbotapi.types.request.RequestId
|
||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||
import kotlin.math.max
|
||||
|
||||
|
||||
/**
|
||||
@ -55,7 +57,7 @@ inline fun webAppReplyButton(
|
||||
/**
|
||||
* Creates [RequestUserKeyboardButton]
|
||||
*/
|
||||
inline fun requestUserReplyButton(
|
||||
inline fun requestUsersReplyButton(
|
||||
text: String,
|
||||
requestUser: KeyboardButtonRequestUsers
|
||||
) = RequestUserKeyboardButton(
|
||||
@ -63,15 +65,51 @@ inline fun requestUserReplyButton(
|
||||
requestUser
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* Creates [RequestUserKeyboardButton]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("requestUsersReplyButton(text, requestUser)", "dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton"))
|
||||
inline fun requestUserReplyButton(
|
||||
text: String,
|
||||
requestUser: KeyboardButtonRequestUsers
|
||||
) = requestUsersReplyButton(text, requestUser)
|
||||
|
||||
/**
|
||||
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
||||
*/
|
||||
inline fun requestBotsReplyButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersReplyButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("requestBotsReplyButton(text, requestId)", "dev.inmo.tgbotapi.types.buttons.reply.requestBotsReplyButton"))
|
||||
inline fun requestBotReplyButton(
|
||||
text: String,
|
||||
requestId: RequestId
|
||||
) = requestUserReplyButton(
|
||||
requestId: RequestId,
|
||||
) = requestBotsReplyButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Bot(requestId)
|
||||
requestId,
|
||||
)
|
||||
|
||||
/**
|
||||
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Common]
|
||||
*/
|
||||
inline fun requestUsersReplyButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
premiumUser: Boolean? = null,
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersReplyButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
@ -80,10 +118,26 @@ inline fun requestBotReplyButton(
|
||||
inline fun requestUserReplyButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
premiumUser: Boolean? = null
|
||||
) = requestUserReplyButton(
|
||||
premiumUser: Boolean? = null,
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersReplyButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser)
|
||||
requestId,
|
||||
premiumUser,
|
||||
maxCount
|
||||
)
|
||||
|
||||
/**
|
||||
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Any]
|
||||
*/
|
||||
inline fun requestUsersOrBotsReplyButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
premiumUser: Boolean? = null,
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersReplyButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Any(requestId, premiumUser, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
|
||||
import dev.inmo.tgbotapi.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
||||
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
||||
import dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||
import dev.inmo.tgbotapi.types.request.RequestId
|
||||
@ -142,7 +143,7 @@ inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
||||
text: String,
|
||||
requestUser: KeyboardButtonRequestUsers
|
||||
) = add(
|
||||
requestUserReplyButton(
|
||||
requestUsersReplyButton(
|
||||
text,
|
||||
requestUser
|
||||
)
|
||||
@ -169,7 +170,7 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
inline fun ReplyKeyboardRowBuilder.requestBotsButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
maxCount: Int
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
||||
@ -200,7 +201,7 @@ inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
premiumUser: Boolean? = null,
|
||||
maxCount: Int
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
||||
@ -227,10 +228,11 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
||||
inline fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
|
||||
text: String,
|
||||
requestId: RequestId,
|
||||
maxCount: Int
|
||||
premiumUser: Boolean? = null,
|
||||
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||
) = requestUsersButton(
|
||||
text,
|
||||
KeyboardButtonRequestUsers.Any(requestId, maxCount)
|
||||
KeyboardButtonRequestUsers.Any(requestId, premiumUser, maxCount)
|
||||
)
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user